Skip to content

Commit

Permalink
Show ... in Load/Save File dialog for long names (#7624)
Browse files Browse the repository at this point in the history
  • Loading branch information
ihhub authored Aug 25, 2023
1 parent 4692ae4 commit 8e52bf2
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 82 deletions.
8 changes: 5 additions & 3 deletions src/fheroes2/army/army_ui_helper.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2021 - 2022 *
* Copyright (C) 2021 - 2023 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
Expand All @@ -18,14 +18,16 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/

#include "army_ui_helper.h"

#include <cassert>
#include <cstddef>
#include <string>
#include <utility>

#include "agg_image.h"
#include "army.h"
#include "army_troop.h"
#include "army_ui_helper.h"
#include "game.h"
#include "icn.h"
#include "image.h"
Expand Down Expand Up @@ -75,7 +77,7 @@ void fheroes2::drawMiniMonsters( const Troops & troops, int32_t cx, const int32_
}

const fheroes2::Sprite & monster = fheroes2::AGG::GetICN( ICN::MONS32, troop->GetSpriteIndex() );
fheroes2::Text text( monstersCountRepresentation, fheroes2::FontType::smallWhite() );
fheroes2::Text text( std::move( monstersCountRepresentation ), fheroes2::FontType::smallWhite() );

// This is the drawing of army troops in compact form in the small info window beneath resources
if ( isCompact ) {
Expand Down
3 changes: 2 additions & 1 deletion src/fheroes2/battle/battle_only.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <cstdint>
#include <string>
#include <utility>

#include "agg_image.h"
#include "army_bar.h"
Expand Down Expand Up @@ -573,7 +574,7 @@ void Battle::Only::RedrawBaseInfo( const fheroes2::Point & top ) const
StringReplace( message, _( "%{race2} %{name2}" ), _( "Monsters" ) );
}

fheroes2::Text text( message, fheroes2::FontType::normalWhite() );
fheroes2::Text text( std::move( message ), fheroes2::FontType::normalWhite() );
text.draw( top.x + 320 - text.width() / 2, top.y + 29, display );

// portrait
Expand Down
1 change: 1 addition & 0 deletions src/fheroes2/castle/castle_mageguild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <algorithm>
#include <cstdint>
#include <iterator>
#include <string>
#include <vector>

#include "agg_image.h"
Expand Down
3 changes: 2 additions & 1 deletion src/fheroes2/castle/castle_tavern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <cstdint>
#include <memory>
#include <string>
#include <utility>

#include "castle.h"
#include "dialog.h"
Expand All @@ -41,7 +42,7 @@ void Castle::OpenTavern() const
body += world.getCurrentRumor();

const fheroes2::AnimationDialogElement imageUI( ICN::TAVWIN, { 0, 1 }, 0, Game::getAnimationDelayValue( Game::CASTLE_TAVERN_DELAY ) );
const fheroes2::TextDialogElement textBodyUI( std::make_shared<fheroes2::Text>( body, fheroes2::FontType::normalWhite() ) );
const fheroes2::TextDialogElement textBodyUI( std::make_shared<fheroes2::Text>( std::move( body ), fheroes2::FontType::normalWhite() ) );

fheroes2::showMessage( fheroes2::Text( GetStringBuilding( BUILD_TAVERN ), fheroes2::FontType::normalYellow() ), fheroes2::Text( "", {} ), Dialog::OK,
{ &imageUI, &textBodyUI } );
Expand Down
5 changes: 3 additions & 2 deletions src/fheroes2/castle/castle_well.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <cstddef>
#include <cstdint>
#include <string>
#include <utility>
#include <vector>

#include "agg_image.h"
Expand Down Expand Up @@ -189,7 +190,7 @@ bool Castle::_recruitCastleMax( const Troops & currentCastleArmy )
}
}
else if ( fheroes2::showResourceMessage( fheroes2::Text( _( "Recruit Creatures" ), fheroes2::FontType::normalYellow() ),
fheroes2::Text( monstersRecruitedText, normalWhite ), Dialog::YES | Dialog::NO, totalMonstersCost )
fheroes2::Text( std::move( monstersRecruitedText ), normalWhite ), Dialog::YES | Dialog::NO, totalMonstersCost )
== Dialog::YES ) {
for ( const Troop & troop : totalRecruitmentResult ) {
RecruitMonster( troop, false );
Expand Down Expand Up @@ -359,7 +360,7 @@ void Castle::_wellRedrawAvailableMonsters( const uint32_t dwellingType, const bo
std::string textString = _( "Available" );
textString += ": ";

fheroes2::Text text( textString, fheroes2::FontType::smallWhite() );
fheroes2::Text text( std::move( textString ), fheroes2::FontType::smallWhite() );
text.draw( offset.x + 24, offset.y + 2, background );

text.set( std::to_string( population ), fheroes2::FontType::normalYellow() );
Expand Down
4 changes: 3 additions & 1 deletion src/fheroes2/dialog/dialog_language_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/

#include "dialog_language_selection.h"

#include <cassert>
#include <cstddef>
#include <cstdint>
#include <string>

#include "agg_image.h"
#include "cursor.h"
#include "dialog_language_selection.h"
#include "game_hotkeys.h"
#include "gamedefs.h"
#include "icn.h"
Expand Down
7 changes: 4 additions & 3 deletions src/fheroes2/dialog/dialog_recruit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <functional>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "agg_image.h"
Expand Down Expand Up @@ -106,10 +107,10 @@ void RedrawCurrentInfo( const fheroes2::Point & pos, const uint32_t result, cons

text.draw( pos.x + 151 - text.width() / 2, pos.y + 147, display );

const std::string sgold = std::to_string( paymentCosts.gold ) + " " + "(" + std::to_string( funds.gold - paymentCosts.gold ) + ")";
std::string sgold = std::to_string( paymentCosts.gold ) + " " + "(" + std::to_string( funds.gold - paymentCosts.gold ) + ")";
const int rsext = paymentMonster.GetValidItems() & ~Resource::GOLD;

text.set( sgold, fheroes2::FontType::smallWhite() );
text.set( std::move( sgold ), fheroes2::FontType::smallWhite() );

// Restore the background of the text before rendering it.
fheroes2::Copy( background, 0, 214, display, pos.x, pos.y + 214, background.width(), text.height() );
Expand Down Expand Up @@ -211,7 +212,7 @@ void RedrawMonsterInfo( const fheroes2::Rect & pos, const Monster & monster, con

str = _( "Available: %{count}" );
StringReplace( str, "%{count}", available );
text.set( str, fheroes2::FontType::smallWhite() );
text.set( std::move( str ), fheroes2::FontType::smallWhite() );
text.draw( pos.x + 64 - text.width() / 2, pos.y + 121, display );

if ( showTotalSum ) {
Expand Down
31 changes: 18 additions & 13 deletions src/fheroes2/dialog/dialog_selectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <memory>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#include "agg_image.h"
Expand Down Expand Up @@ -139,38 +140,42 @@ void FileInfoListBox::RedrawItem( const Maps::FileInfo & info, int32_t dstx, int
{
char shortDate[20];
char shortHours[20];
char shortTime[20];
char shortMinutes[20];

const tm tmi = System::GetTM( info.timestamp );

std::fill( shortDate, std::end( shortDate ), static_cast<char>( 0 ) );
std::fill( shortHours, std::end( shortHours ), static_cast<char>( 0 ) );
std::fill( shortTime, std::end( shortTime ), static_cast<char>( 0 ) );
std::fill( shortMinutes, std::end( shortMinutes ), static_cast<char>( 0 ) );
std::strftime( shortDate, ARRAY_COUNT( shortDate ) - 1, "%b %d,", &tmi );
std::strftime( shortHours, ARRAY_COUNT( shortHours ) - 1, "%H", &tmi );
std::strftime( shortTime, ARRAY_COUNT( shortTime ) - 1, ":%M", &tmi );
std::strftime( shortMinutes, ARRAY_COUNT( shortMinutes ) - 1, ":%M", &tmi );
std::string savname( System::GetBasename( info.file ) );

if ( !savname.empty() ) {
Text text;

const std::string saveExtension = Game::GetSaveFileExtension();
const size_t dotPos = savname.size() - saveExtension.size();

if ( StringLower( savname.substr( dotPos ) ) == saveExtension )
savname.erase( dotPos );

text.Set( savname, ( current ? Font::YELLOW_BIG : Font::BIG ) );
text.Blit( dstx + 5, dsty, 150 );
const fheroes2::FontType font = current ? fheroes2::FontType::normalYellow() : fheroes2::FontType::normalWhite();
fheroes2::Display & display = fheroes2::Display::instance();

dsty += 2;

fheroes2::Text text{ std::move( savname ), font };
text.fitToOneRow( 150 );
text.draw( dstx + 5, dsty, display );

text.Set( shortDate, ( current ? Font::YELLOW_BIG : Font::BIG ) );
text.Blit( dstx + 225 - text.w(), dsty );
text.set( shortDate, font );
text.draw( dstx + 225 - text.width(), dsty, display );

text.Set( shortHours, ( current ? Font::YELLOW_BIG : Font::BIG ) );
text.Blit( dstx + 245 - text.w(), dsty );
text.set( shortHours, font );
text.draw( dstx + 245 - text.width(), dsty, display );

text.Set( shortTime, ( current ? Font::YELLOW_BIG : Font::BIG ) );
text.Blit( dstx + 245, dsty );
text.set( shortMinutes, font );
text.draw( dstx + 245, dsty, display );
}
}

Expand Down
58 changes: 29 additions & 29 deletions src/fheroes2/game/game_credits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,39 +279,39 @@ namespace
title.draw( textInitialOffsetX - title.width() / 2, offsetY, output );
offsetY += title.height() + 5;

const std::string contributors( "LeHerosInconnu\n"
"undef21\n"
"shprotru\n"
"Arkadiy Illarionov\n"
"a1exsh\n"
"vincent-grosbois\n"
"eos428\n"
"felix642\n"
"Arthusppp\n"
"Vasilenko Alexey\n"
"Andrii Kurdiumov\n"
"dimag0g\n"
"tau3\n" );

fheroes2::Text name( contributors, fheroes2::FontType::normalWhite() );
std::string contributors( "LeHerosInconnu\n"
"undef21\n"
"shprotru\n"
"Arkadiy Illarionov\n"
"a1exsh\n"
"vincent-grosbois\n"
"eos428\n"
"felix642\n"
"Arthusppp\n"
"Vasilenko Alexey\n"
"Andrii Kurdiumov\n"
"dimag0g\n"
"tau3\n" );

fheroes2::Text name( std::move( contributors ), fheroes2::FontType::normalWhite() );
const int32_t constributorsHeight = name.height( textWidth );
const int32_t contributorCount = name.rows( textWidth );
name.draw( textOffsetX, offsetY, textWidth, output );

const std::string supporters( "Aimi Lindschouw\n"
"Aleksei Mazur\n"
"Andrew Szucs\n"
"Benjamin Hughes\n"
"Brandon Wright\n"
"Connor Townsend\n"
"Kiril Lipatov\n"
"Kresimir Condic\n"
"Kuza\n"
"Matt Taylor\n"
"slvclw\n"
"William Hoskinson\n" );

name.set( supporters, fheroes2::FontType::normalWhite() );
std::string supporters( "Aimi Lindschouw\n"
"Aleksei Mazur\n"
"Andrew Szucs\n"
"Benjamin Hughes\n"
"Brandon Wright\n"
"Connor Townsend\n"
"Kiril Lipatov\n"
"Kresimir Condic\n"
"Kuza\n"
"Matt Taylor\n"
"slvclw\n"
"William Hoskinson\n" );

name.set( std::move( supporters ), fheroes2::FontType::normalWhite() );
const int32_t supportersHeight = name.height( textWidth );
const int32_t supporterCount = name.rows( textWidth );
const int32_t countDifference = ( contributorCount - supporterCount );
Expand Down
26 changes: 3 additions & 23 deletions src/fheroes2/gui/ui_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,14 +490,7 @@ namespace fheroes2

TextBase::~TextBase() = default;

Text::Text( const std::string & text, const FontType fontType )
: _text( text )
, _fontType( fontType )
{
// Do nothing.
}

Text::Text( std::string && text, const FontType fontType )
Text::Text( std::string text, const FontType fontType )
: _text( std::move( text ) )
, _fontType( fontType )
{
Expand Down Expand Up @@ -632,13 +625,7 @@ namespace fheroes2
return _text.empty();
}

void Text::set( const std::string & text, const FontType fontType )
{
_text = text;
_fontType = fontType;
}

void Text::set( std::string && text, const FontType fontType )
void Text::set( std::string text, const FontType fontType )
{
_text = std::move( text );
_fontType = fontType;
Expand Down Expand Up @@ -680,14 +667,7 @@ namespace fheroes2

MultiFontText::~MultiFontText() = default;

void MultiFontText::add( const Text & text )
{
if ( !text._text.empty() ) {
_texts.emplace_back( text );
}
}

void MultiFontText::add( Text && text )
void MultiFontText::add( Text text )
{
if ( !text._text.empty() ) {
_texts.emplace_back( std::move( text ) );
Expand Down
9 changes: 3 additions & 6 deletions src/fheroes2/gui/ui_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ namespace fheroes2
friend class MultiFontText;

Text() = default;
Text( const std::string & text, const FontType fontType );
Text( std::string && text, const FontType fontType );
Text( std::string text, const FontType fontType );
Text( const Text & text ) = default;
Text( Text && text ) = default;
Text & operator=( const Text & text ) = default;
Expand All @@ -148,8 +147,7 @@ namespace fheroes2

bool empty() const override;

void set( const std::string & text, const FontType fontType );
void set( std::string && text, const FontType fontType );
void set( std::string text, const FontType fontType );

// This method modifies the underlying text and ends it with '...' if it is longer than the provided width.
void fitToOneRow( const int32_t maxWidth );
Expand All @@ -168,8 +166,7 @@ namespace fheroes2
MultiFontText() = default;
~MultiFontText() override;

void add( const Text & text );
void add( Text && text );
void add( Text text );

int32_t width() const override;
int32_t height() const override;
Expand Down

0 comments on commit 8e52bf2

Please sign in to comment.