Skip to content

Commit

Permalink
Shorten hero name if name plus level is too long (#9485)
Browse files Browse the repository at this point in the history
  • Loading branch information
zenseii authored Jan 26, 2025
1 parent 7b48080 commit 7a2e795
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/fheroes2/dialog/dialog_quickinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,19 +718,20 @@ namespace

const bool isActiveHero = ( activeHero != nullptr );

std::string message;
// hero's name
const fheroes2::FontType smallWhite = fheroes2::FontType::smallWhite();
fheroes2::Text text( hero.GetName(), smallWhite );
// hero's level
if ( isFullInfo && isActiveHero ) {
message = _( "%{name} (Level %{level})" );
StringReplace( message, "%{name}", hero.GetName() );
StringReplace( message, "%{level}", activeHero->GetLevel() );
}
else {
message = hero.GetName();
std::string heroLevel = _( "heroQuickInfo|(Level %{level})" );
StringReplace( heroLevel, "%{level}", activeHero->GetLevel() );
heroLevel.insert( 0, " " );
// if Identify Hero has been cast then we want to know the hero's level rather than name.
const int32_t boxShadowAndBorder = 39;
text.fitToOneRow( box.width() - boxShadowAndBorder - fheroes2::Text{ heroLevel, smallWhite }.width() );
text.set( text.text() + heroLevel, smallWhite );
}

const fheroes2::FontType smallWhite = fheroes2::FontType::smallWhite();
fheroes2::Text text( message, smallWhite );
dst_pt.x = cur_rt.x + ( cur_rt.width - text.width() ) / 2;
dst_pt.y = cur_rt.y + 2;
text.draw( dst_pt.x, dst_pt.y, display );
Expand Down

0 comments on commit 7a2e795

Please sign in to comment.