Skip to content

Commit

Permalink
Make several buttons text adapted and fix okay button redraw (#8368)
Browse files Browse the repository at this point in the history
  • Loading branch information
zenseii authored Feb 8, 2024
1 parent d403b55 commit 5c6635c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 61 deletions.
68 changes: 18 additions & 50 deletions src/fheroes2/agg/agg_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,8 @@ namespace fheroes2
break;
}

const int32_t textWidth = 108;
createNormalButton( _icnVsSprite[id][0], _icnVsSprite[id][1], textWidth, gettext_noop( "ACCEPT" ), isEvilInterface );
getTextAdaptedButton( _icnVsSprite[id][0], _icnVsSprite[id][1], gettext_noop( "ACCEPT" ),
isEvilInterface ? ICN::EMPTY_EVIL_BUTTON : ICN::EMPTY_GOOD_BUTTON, isEvilInterface ? ICN::STONEBAK_EVIL : ICN::STONEBAK );

break;
}
Expand All @@ -894,8 +894,8 @@ namespace fheroes2
break;
}

const int32_t textWidth = 108;
createNormalButton( _icnVsSprite[id][0], _icnVsSprite[id][1], textWidth, gettext_noop( "DECLINE" ), isEvilInterface );
getTextAdaptedButton( _icnVsSprite[id][0], _icnVsSprite[id][1], gettext_noop( "DECLINE" ),
isEvilInterface ? ICN::EMPTY_EVIL_BUTTON : ICN::EMPTY_GOOD_BUTTON, isEvilInterface ? ICN::STONEBAK_EVIL : ICN::STONEBAK );

break;
}
Expand Down Expand Up @@ -934,35 +934,8 @@ namespace fheroes2
break;
}

const int baseIcnID = isEvilInterface ? ICN::SYSTEME : ICN::SYSTEM;

for ( int32_t i = 0; i < static_cast<int32_t>( _icnVsSprite[id].size() ); ++i ) {
Sprite & out = _icnVsSprite[id][i];
const Sprite & originalButton = GetICN( baseIcnID, 11 + i );
const int extendedAmount = 14;
out.resize( originalButton.width() + extendedAmount, originalButton.height() );
out.reset();

const int widthEndPart = 4 + 2 * i;
const int widthFirstPart = originalButton.width() - widthEndPart;
const int widthMiddlePart = extendedAmount + i;
const int offsetXEndPart = widthFirstPart + widthMiddlePart;
const int startOffsetXMiddlePart = 36;

// Copy left main body of button.
fheroes2::Copy( originalButton, 0, 0, out, 0, 0, widthFirstPart, originalButton.height() );

// Copy middle body of button.
fheroes2::Copy( originalButton, originalButton.width() - startOffsetXMiddlePart, 0, out, widthFirstPart, 0, widthMiddlePart,
originalButton.height() );

// Copy terminating right margin of the button.
fheroes2::Copy( originalButton, originalButton.width() - widthEndPart, 0, out, offsetXEndPart, 0, widthEndPart, originalButton.height() );
}

const fheroes2::FontColor buttonFontColor = isEvilInterface ? fheroes2::FontColor::GRAY : fheroes2::FontColor::WHITE;
renderTextOnButton( _icnVsSprite[id][0], _icnVsSprite[id][1], gettext_noop( "TRADE" ), { 6, 5 }, { 4, 6 }, { 100, 16 }, buttonFontColor );

getTextAdaptedButton( _icnVsSprite[id][0], _icnVsSprite[id][1], gettext_noop( "TRADE" ),
isEvilInterface ? ICN::EMPTY_EVIL_BUTTON : ICN::EMPTY_GOOD_BUTTON, isEvilInterface ? ICN::UNIFORMBAK_EVIL : ICN::UNIFORMBAK_GOOD );
break;
}
case ICN::BUTTON_SMALL_YES_GOOD:
Expand Down Expand Up @@ -1023,8 +996,8 @@ namespace fheroes2
break;
}

const int32_t textWidth = 85;
createNormalButton( _icnVsSprite[id][0], _icnVsSprite[id][1], textWidth, gettext_noop( "EXIT" ), isEvilInterface );
getTextAdaptedButton( _icnVsSprite[id][0], _icnVsSprite[id][1], gettext_noop( "EXIT" ), isEvilInterface ? ICN::EMPTY_EVIL_BUTTON : ICN::EMPTY_GOOD_BUTTON,
isEvilInterface ? ICN::STONEBAK_EVIL : ICN::STONEBAK );

break;
}
Expand Down Expand Up @@ -1115,8 +1088,8 @@ namespace fheroes2
break;
}

const int32_t textWidth = 110;
createNormalButton( _icnVsSprite[id][0], _icnVsSprite[id][1], textWidth, gettext_noop( "DISMISS" ), isEvilInterface );
getTextAdaptedButton( _icnVsSprite[id][0], _icnVsSprite[id][1], gettext_noop( "DISMISS" ),
isEvilInterface ? ICN::EMPTY_EVIL_BUTTON : ICN::EMPTY_GOOD_BUTTON, isEvilInterface ? ICN::STONEBAK_EVIL : ICN::STONEBAK );

break;
}
Expand All @@ -1132,8 +1105,8 @@ namespace fheroes2
break;
}

const int32_t textWidth = 110;
createNormalButton( _icnVsSprite[id][0], _icnVsSprite[id][1], textWidth, gettext_noop( "UPGRADE" ), isEvilInterface );
getTextAdaptedButton( _icnVsSprite[id][0], _icnVsSprite[id][1], gettext_noop( "UPGRADE" ),
isEvilInterface ? ICN::EMPTY_EVIL_BUTTON : ICN::EMPTY_GOOD_BUTTON, isEvilInterface ? ICN::STONEBAK_EVIL : ICN::STONEBAK );

break;
}
Expand All @@ -1149,8 +1122,8 @@ namespace fheroes2
break;
}

const int32_t textWidth = 102;
createNormalButton( _icnVsSprite[id][0], _icnVsSprite[id][1], textWidth, gettext_noop( "RESTART" ), isEvilInterface );
getTextAdaptedButton( _icnVsSprite[id][0], _icnVsSprite[id][1], gettext_noop( "RESTART" ),
isEvilInterface ? ICN::EMPTY_EVIL_BUTTON : ICN::EMPTY_GOOD_BUTTON, isEvilInterface ? ICN::STONEBAK_EVIL : ICN::STONEBAK );

break;
}
Expand Down Expand Up @@ -1799,14 +1772,14 @@ namespace fheroes2
case ICN::BUTTON_RESET_GOOD: {
_icnVsSprite[id].resize( 2 );

createNormalButton( _icnVsSprite[id][0], _icnVsSprite[id][1], 80, gettext_noop( "RESET" ), false );
getTextAdaptedButton( _icnVsSprite[id][0], _icnVsSprite[id][1], gettext_noop( "RESET" ), ICN::EMPTY_GOOD_BUTTON, ICN::STONEBAK );

break;
}
case ICN::BUTTON_START_GOOD: {
_icnVsSprite[id].resize( 2 );

createNormalButton( _icnVsSprite[id][0], _icnVsSprite[id][1], 80, gettext_noop( "START" ), false );
getTextAdaptedButton( _icnVsSprite[id][0], _icnVsSprite[id][1], gettext_noop( "START" ), ICN::EMPTY_GOOD_BUTTON, ICN::STONEBAK );

break;
}
Expand Down Expand Up @@ -1912,13 +1885,8 @@ namespace fheroes2
break;
}

for ( int32_t i = 0; i < static_cast<int32_t>( _icnVsSprite[id].size() ); ++i ) {
Sprite & out = _icnVsSprite[id][i];
out = GetICN( isEvilInterface ? ICN::SYSTEME : ICN::SYSTEM, 11 + i );
}

const fheroes2::FontColor buttonFontColor = isEvilInterface ? fheroes2::FontColor::GRAY : fheroes2::FontColor::WHITE;
renderTextOnButton( _icnVsSprite[id][0], _icnVsSprite[id][1], gettext_noop( "EXIT" ), { 7, 5 }, { 6, 6 }, { 86, 16 }, buttonFontColor );
getTextAdaptedButton( _icnVsSprite[id][0], _icnVsSprite[id][1], gettext_noop( "EXIT" ), isEvilInterface ? ICN::EMPTY_EVIL_BUTTON : ICN::EMPTY_GOOD_BUTTON,
isEvilInterface ? ICN::UNIFORMBAK_EVIL : ICN::UNIFORMBAK_GOOD );

break;
}
Expand Down
4 changes: 3 additions & 1 deletion src/fheroes2/dialog/dialog_armyinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,9 @@ int Dialog::ArmyInfo( const Troop & troop, int flags, bool isReflected, const in
fheroes2::Button buttonDismiss( dst_pt.x, dst_pt.y, dismissButtonIcnID, 0, 1 );

const int exitButtonIcnID = isEvilInterface ? ICN::BUTTON_SMALL_EXIT_EVIL : ICN::BUTTON_SMALL_EXIT_GOOD;
dst_pt.x = pos_rt.x + 415;
const int32_t exitWidth = fheroes2::AGG::GetICN( exitButtonIcnID, 0 ).width();
const int32_t interfaceAdjustment = isEvilInterface ? 0 : 18;
dst_pt.x = pos_rt.x + sprite_dialog.width() - 58 - exitWidth + interfaceAdjustment;
dst_pt.y = pos_rt.y + 221;
fheroes2::Button buttonExit( dst_pt.x, dst_pt.y, exitButtonIcnID, 0, 1 );

Expand Down
18 changes: 8 additions & 10 deletions src/fheroes2/dialog/dialog_system_options.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2021 - 2023 *
* Copyright (C) 2021 - 2024 *
* *
* 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 Down Expand Up @@ -241,16 +241,17 @@ namespace

drawOptions();

const auto refreshWindow = [&drawOptions, &emptyDialogRestorer, &display]() {
const fheroes2::Point buttonOffset( 112 + windowRoi.x, 362 + windowRoi.y );
fheroes2::Button okayButton( buttonOffset.x, buttonOffset.y, isEvilInterface ? ICN::BUTTON_SMALL_OKAY_EVIL : ICN::BUTTON_SMALL_OKAY_GOOD, 0, 1 );
okayButton.draw();

const auto refreshWindow = [&drawOptions, &emptyDialogRestorer, &okayButton, &display]() {
emptyDialogRestorer.restore();
drawOptions();
okayButton.draw();
display.render( emptyDialogRestorer.rect() );
};

const fheroes2::Point buttonOffset( 112 + windowRoi.x, 362 + windowRoi.y );
fheroes2::Button okayButton( buttonOffset.x, buttonOffset.y, isEvilInterface ? ICN::BUTTON_SMALL_OKAY_EVIL : ICN::BUTTON_SMALL_OKAY_GOOD, 0, 1 );
okayButton.draw();

display.render();

bool isTextSupportModeEnabled = conf.isTextSupportModeEnabled();
Expand Down Expand Up @@ -397,10 +398,7 @@ namespace
if ( isTextSupportModeEnabled != conf.isTextSupportModeEnabled() ) {
isTextSupportModeEnabled = conf.isTextSupportModeEnabled();

emptyDialogRestorer.restore();
drawOptions();

display.render( emptyDialogRestorer.rect() );
refreshWindow();
}
}

Expand Down

0 comments on commit 5c6635c

Please sign in to comment.