Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make battle buttons translatable #7706

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion files/lang/nb.po
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 3.2.2\n"
"X-Generator: Poedit 3.4.1\n"

msgid ""
"BATTLE\n"
Expand Down Expand Up @@ -228,6 +228,9 @@ msgstr ""
"A\n"
"T"

msgid "SKIP"
msgstr "PASS"

msgid ""
"C\n"
"A\n"
Expand Down
6 changes: 6 additions & 0 deletions files/lang/ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ msgstr ""
"А\n"
"Я"

msgid "SKIP"
msgstr "ПРОП"

msgid "AUTO"
msgstr "АВТО"

msgid "Warrior"
msgstr "Воин"

Expand Down
183 changes: 169 additions & 14 deletions src/fheroes2/agg/agg_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ namespace
ICN::BUTTON_HSCORES_VERTICAL_EXIT,
ICN::BUTTON_HSCORES_VERTICAL_STANDARD,
ICN::DISMISS_HERO_DISABLED_BUTTON,
ICN::NEW_CAMPAIGN_DISABLED_BUTTON };
ICN::NEW_CAMPAIGN_DISABLED_BUTTON,
ICN::BUTTON_SKIP,
ICN::BUTTON_AUTO,
ICN::BUTTON_BATTLE_SETTINGS,
ICN::STATUSBAR_BATTLE };

#ifndef NDEBUG
bool isLanguageDependentIcnId( const int id )
Expand Down Expand Up @@ -1924,6 +1928,34 @@ namespace fheroes2

break;
}
case ICN::BUTTON_SKIP: {
_icnVsSprite[id].resize( 2 );
const int32_t originalId = ICN::TEXTBAR;

if ( useOriginalResources() ) {
_icnVsSprite[id][0] = GetICN( originalId, 0 );
_icnVsSprite[id][1] = GetICN( originalId, 1 );
break;
}

getTextAdaptedButton( _icnVsSprite[id][0], _icnVsSprite[id][1], gettext_noop( "SKIP" ), ICN::EMPTY_GOOD_SKIP_BUTTON, ICN::UNKNOWN );

break;
}
case ICN::BUTTON_AUTO: {
_icnVsSprite[id].resize( 2 );
const int32_t originalId = ICN::TEXTBAR;

if ( useOriginalResources() ) {
_icnVsSprite[id][0] = GetICN( originalId, 4 );
_icnVsSprite[id][1] = GetICN( originalId, 5 );
break;
}

getTextAdaptedButton( _icnVsSprite[id][0], _icnVsSprite[id][1], gettext_noop( "AUTO" ), ICN::EMPTY_GOOD_BATTLE_BUTTON, ICN::UNKNOWN );

break;
}
case ICN::BUTTON_HSCORES_VERTICAL_CAMPAIGN:
case ICN::BUTTON_HSCORES_VERTICAL_EXIT:
case ICN::BUTTON_HSCORES_VERTICAL_STANDARD: {
Expand Down Expand Up @@ -2513,19 +2545,6 @@ namespace fheroes2
}
}
return true;
case ICN::BATTLESKIP:
_icnVsSprite[id].resize( 2 );
for ( uint32_t i = 0; i < 2; ++i ) {
Sprite & out = _icnVsSprite[id][i];
out = GetICN( ICN::TEXTBAR, 4 + i );

// clean the button
Blit( GetICN( ICN::SYSTEM, 11 + i ), 3, 8, out, 3, 1, 43, 14 );

// add 'skip'
Blit( GetICN( ICN::TEXTBAR, i ), 3, 10, out, 3, 0, 43, 14 );
}
return true;
case ICN::BUYMAX:
case ICN::BUTTON_NEW_GAME_GOOD:
case ICN::BUTTON_NEW_GAME_EVIL:
Expand Down Expand Up @@ -2615,6 +2634,8 @@ namespace fheroes2
case ICN::BUTTON_VIEWWORLD_EXIT_EVIL:
case ICN::BUTTON_VERTICAL_DISMISS:
case ICN::BUTTON_VERTICAL_EXIT:
case ICN::BUTTON_SKIP:
case ICN::BUTTON_AUTO:
case ICN::BUTTON_HSCORES_VERTICAL_CAMPAIGN:
case ICN::BUTTON_HSCORES_VERTICAL_EXIT:
case ICN::BUTTON_HSCORES_VERTICAL_STANDARD:
Expand Down Expand Up @@ -4270,6 +4291,54 @@ namespace fheroes2

return true;
}
case ICN::EMPTY_GOOD_BATTLE_BUTTON: {
const int originalID = ICN::TEXTBAR;
loadICN( originalID );

if ( _icnVsSprite[originalID].size() < 3 ) {
return true;
}
_icnVsSprite[id].resize( 2 );

for ( int32_t i = 0; i < static_cast<int32_t>( _icnVsSprite[id].size() ); ++i ) {
const Sprite & original = GetICN( originalID, 4 + i );

Sprite & out = _icnVsSprite[id][i];
// the empty button needs to shortened by 1 px so that when it is divided by 3 in resizeButton() in ui_tools it will give an integer result
out.resize( original.width() - 1, original.height() );

Copy( original, 0, 0, out, 0, 0, original.width() - 5 - i, original.height() );
Copy( original, original.width() - 4 - i, 0, out, original.width() - 5 - i, 0, 4 + i, original.height() );

Fill( out, 4 - i, 2 + i, 40, 13, getButtonFillingColor( i == 0 ) );
}

return true;
}
case ICN::EMPTY_GOOD_SKIP_BUTTON: {
const int originalID = ICN::TEXTBAR;
loadICN( originalID );

if ( _icnVsSprite[originalID].size() < 3 ) {
return true;
}
_icnVsSprite[id].resize( 2 );

for ( int32_t i = 0; i < static_cast<int32_t>( _icnVsSprite[id].size() ); ++i ) {
const Sprite & original = GetICN( originalID, 0 + i );

Sprite & out = _icnVsSprite[id][i];
// the empty button needs to shortened by 1 px so that when it is divided by 3 in resizeButton() in ui_tools it will give an integer result
out.resize( original.width() - 1, original.height() );

Copy( original, 0, 0, out, 0, 0, original.width() - 5 - i, original.height() );
Copy( original, original.width() - 4 - i, 0, out, original.width() - 5 - i, 0, 4 + i, original.height() );

Fill( out, 4 - i, 3, 40, 30 + 2 * i, getButtonFillingColor( i == 0 ) );
}

return true;
}
case ICN::EMPTY_GOOD_MEDIUM_BUTTON:
case ICN::EMPTY_EVIL_MEDIUM_BUTTON: {
const bool isGoodInterface = ( id == ICN::EMPTY_GOOD_MEDIUM_BUTTON );
Expand Down Expand Up @@ -4361,6 +4430,92 @@ namespace fheroes2

return true;
}
case ICN::BUTTON_BATTLE_SETTINGS: {
const int32_t originalId = ICN::TEXTBAR;
loadICN( originalId );

if ( _icnVsSprite[originalId].size() < 15 ) {
return true;
}

_icnVsSprite[id].resize( 2 );

if ( useOriginalResources() ) {
_icnVsSprite[id][0] = GetICN( originalId, 6 );
_icnVsSprite[id][1] = GetICN( originalId, 7 );
return true;
}

const Sprite & autoButtonReleased = GetICN( ICN::BUTTON_AUTO, 0 );
const Sprite & autoButtonPressed = GetICN( ICN::BUTTON_AUTO, 1 );

Sprite & released = _icnVsSprite[id][0];
Sprite & pressed = _icnVsSprite[id][1];

const int32_t buttonWidth = autoButtonReleased.width();

released.resize( buttonWidth, autoButtonReleased.height() + 1 );
pressed.resize( buttonWidth, autoButtonPressed.height() + 1 );

// We need to add 1 pixel in height because the Settings button should be 1 pixel higher than the AUTO button.
Copy( autoButtonReleased, 0, 0, released, 0, 0, buttonWidth, 10 );
Copy( autoButtonReleased, 0, 9, released, 0, 10, buttonWidth, 9 );

Copy( autoButtonPressed, 0, 0, pressed, 0, 0, buttonWidth, 10 );
Copy( autoButtonPressed, 0, 9, pressed, 0, 10, buttonWidth, 9 );

Fill( released, 4, 2, buttonWidth - 8, 14, getButtonFillingColor( true ) );
Fill( pressed, 3, 3, buttonWidth - 8, 14, getButtonFillingColor( false ) );

Copy( GetICN( originalId, 6 ), 12, 2, released, buttonWidth / 2 - 27 / 2, 2, 27, 14 );
Copy( GetICN( originalId, 7 ), 11, 3, pressed, buttonWidth / 2 - 27 / 2 - 1, 3, 27, 14 );

return true;
}
case ICN::STATUSBAR_BATTLE: {
const int32_t originalId = ICN::TEXTBAR;
loadICN( originalId );

if ( _icnVsSprite[originalId].size() < 15 ) {
return true;
}

_icnVsSprite[id].resize( 2 );

if ( useOriginalResources() ) {
_icnVsSprite[id][0] = GetICN( originalId, 8 );
_icnVsSprite[id][1] = GetICN( originalId, 9 );
return true;
}

const Sprite & originalTopHalf = GetICN( originalId, 8 );
const Sprite & originalBottomHalf = GetICN( originalId, 9 );

Sprite & topHalf = _icnVsSprite[id][0];
Sprite & bottomHalf = _icnVsSprite[id][1];

const int32_t buttonAutoWidth = fheroes2::AGG::GetICN( ICN::BUTTON_AUTO, 0 ).width();
const int32_t buttonSkipWidth = fheroes2::AGG::GetICN( ICN::BUTTON_SKIP, 0 ).width();
const int32_t originalButtonAutoWidth = fheroes2::AGG::GetICN( originalId, 4 ).width();
const int32_t originalButtonSkipWidth = fheroes2::AGG::GetICN( originalId, 0 ).width();
const int32_t topBarHeight = originalTopHalf.height();
const int32_t bottomBarHeight = originalBottomHalf.height();

const int32_t excessWidth = ( ( buttonAutoWidth + buttonSkipWidth ) - ( originalButtonAutoWidth + originalButtonSkipWidth ) );

topHalf.resize( originalTopHalf.width() - excessWidth, topBarHeight );
bottomHalf.resize( originalBottomHalf.width() - excessWidth, bottomBarHeight );

fheroes2::Copy( originalTopHalf, 0, 0, topHalf, 0, 0, fheroes2::Display::DEFAULT_WIDTH / 2 - buttonAutoWidth, topBarHeight );
fheroes2::Copy( originalTopHalf, originalTopHalf.width() - fheroes2::Display::DEFAULT_WIDTH / 2 + buttonSkipWidth - 1, 0, topHalf,
fheroes2::Display::DEFAULT_WIDTH / 2 - buttonAutoWidth, 0, fheroes2::Display::DEFAULT_WIDTH / 2 - buttonSkipWidth + 1, topBarHeight );

fheroes2::Copy( originalBottomHalf, 0, 0, bottomHalf, 0, 0, fheroes2::Display::DEFAULT_WIDTH / 2 - buttonAutoWidth, bottomBarHeight );
fheroes2::Copy( originalBottomHalf, originalBottomHalf.width() - fheroes2::Display::DEFAULT_WIDTH / 2 + buttonSkipWidth - 1, 0, bottomHalf,
fheroes2::Display::DEFAULT_WIDTH / 2 - buttonAutoWidth, 0, fheroes2::Display::DEFAULT_WIDTH / 2 - buttonSkipWidth + 1, bottomBarHeight );

return true;
}
case ICN::BRCREST: {
LoadOriginalICN( id );
// First sprite in this ICN has incorrect transparent pixel at position 30x5.
Expand Down
9 changes: 8 additions & 1 deletion src/fheroes2/agg/icn.h
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,6 @@ namespace ICN
ROUTERED,
YELLOW_FONT,
YELLOW_SMALLFONT,
BATTLESKIP,
BUYMAX,
BTNBATTLEONLY,
BTNGIFT_GOOD,
Expand Down Expand Up @@ -997,6 +996,8 @@ namespace ICN
EMPTY_POL_BUTTON,
EMPTY_GUILDWELL_BUTTON,
EMPTY_VERTICAL_GOOD_BUTTON,
EMPTY_GOOD_BATTLE_BUTTON,
EMPTY_GOOD_SKIP_BUTTON,

BUTTON_STANDARD_GAME,
BUTTON_CAMPAIGN_GAME,
Expand Down Expand Up @@ -1082,8 +1083,14 @@ namespace ICN
BUTTON_HSCORES_VERTICAL_EXIT,
BUTTON_HSCORES_VERTICAL_STANDARD,

BUTTON_SKIP,
BUTTON_AUTO,
BUTTON_BATTLE_SETTINGS,

GAME_OPTION_ICON,

STATUSBAR_BATTLE,

// IMPORTANT! Put any new entry just above this one.
LASTICN
};
Expand Down
20 changes: 10 additions & 10 deletions src/fheroes2/battle/battle_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,8 +923,8 @@ bool Battle::OpponentSprite::updateAnimationState()
}

Battle::Status::Status()
: back1( fheroes2::AGG::GetICN( ICN::TEXTBAR, 8 ) )
, back2( fheroes2::AGG::GetICN( ICN::TEXTBAR, 9 ) )
: back1( fheroes2::AGG::GetICN( ICN::STATUSBAR_BATTLE, 0 ) )
, back2( fheroes2::AGG::GetICN( ICN::STATUSBAR_BATTLE, 1 ) )
, listlog( nullptr )
{
width = back1.width();
Expand Down Expand Up @@ -1246,8 +1246,8 @@ Battle::Interface::Interface( Arena & battleArena, const int32_t tileIndex )
// As '_mainSurface' is used to prepare battlefield screen to render on display it does not need to have a transform layer.
_mainSurface._disableTransformLayer();

btn_auto.setICNInfo( ICN::TEXTBAR, 4, 5 );
btn_settings.setICNInfo( ICN::TEXTBAR, 6, 7 );
btn_auto.setICNInfo( ICN::BUTTON_AUTO, 0, 1 );
btn_settings.setICNInfo( ICN::BUTTON_BATTLE_SETTINGS, 0, 1 );

// opponents
_opponent1 = arena.GetCommander1() ? std::make_unique<OpponentSprite>( _surfaceInnerArea, arena.GetCommander1(), false ) : nullptr;
Expand All @@ -1259,15 +1259,15 @@ Battle::Interface::Interface( Arena & battleArena, const int32_t tileIndex )

const fheroes2::Rect & area = border.GetArea();

const fheroes2::Rect settingsRect = btn_settings.area();
const int32_t satusOffsetY = area.y + area.height - settingsRect.height - btn_auto.area().height;
btn_auto.setPosition( area.x, satusOffsetY );
btn_settings.setPosition( area.x, area.y + area.height - settingsRect.height );
const fheroes2::Rect settingsButtonRect = btn_settings.area();
const int32_t statusOffsetY = area.y + area.height - settingsButtonRect.height - btn_auto.area().height;
btn_auto.setPosition( area.x, statusOffsetY );
btn_settings.setPosition( area.x, area.y + area.height - settingsButtonRect.height );

btn_skip.setICNInfo( ICN::TEXTBAR, 0, 1 );
btn_skip.setICNInfo( ICN::BUTTON_SKIP, 0, 1 );
btn_skip.setPosition( area.x + area.width - btn_skip.area().width, area.y + area.height - btn_skip.area().height );

status.SetPosition( area.x + settingsRect.width, satusOffsetY );
status.SetPosition( area.x + settingsButtonRect.width, statusOffsetY );

listlog = std::make_unique<StatusListBox>();

Expand Down
16 changes: 16 additions & 0 deletions src/fheroes2/gui/ui_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ namespace
releasedOffset = { 5, 52 };
pressedOffset = { 4, 53 };
break;
case ICN::EMPTY_GOOD_BATTLE_BUTTON:
font = fheroes2::FontColor::WHITE;
textMargin = 1 + 1;
minimumTextAreaWidth = 41;
backgroundBorders = 4 + 4;
releasedOffset = { 4, 1 };
pressedOffset = { 3, 2 };
break;
case ICN::EMPTY_GOOD_SKIP_BUTTON:
font = fheroes2::FontColor::WHITE;
textMargin = 1 + 1;
minimumTextAreaWidth = 40;
backgroundBorders = 4 + 4;
releasedOffset = { 4, 11 };
pressedOffset = { 3, 12 };
break;
default:
// Was a new empty button template added?
assert( 0 );
Expand Down