Skip to content

Commit

Permalink
Fix the issue with the status of the pressed buttons on the battle sc…
Browse files Browse the repository at this point in the history
…reen
  • Loading branch information
oleg-derevenetz committed Jan 10, 2025
1 parent 92395ac commit 49fbf21
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 45 deletions.
65 changes: 23 additions & 42 deletions src/fheroes2/battle/battle_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2787,6 +2787,10 @@ void Battle::Interface::HumanBattleTurn( const Unit & unit, Actions & actions, s

BoardActionIntentUpdater boardActionIntentUpdater( _boardActionIntent, le.isMouseEventFromTouchpad() );

_buttonAuto.drawOnState( le.isMouseLeftButtonPressedInArea( _buttonAuto.area() ) );
_buttonSettings.drawOnState( le.isMouseLeftButtonPressedInArea( _buttonSettings.area() ) );
_buttonSkip.drawOnState( le.isMouseLeftButtonPressedInArea( _buttonSkip.area() ) );

if ( le.isAnyKeyPressed() ) {
// Skip the turn
if ( Game::HotKeyPressEvent( Game::HotKeyEvent::BATTLE_SKIP ) ) {
Expand Down Expand Up @@ -2867,28 +2871,41 @@ void Battle::Interface::HumanBattleTurn( const Unit & unit, Actions & actions, s
}
else if ( le.isMouseCursorPosInArea( _buttonAuto.area() ) ) {
cursor.SetThemes( Cursor::WAR_POINTER );

msg = _( "Enable auto combat" );
ButtonAutoAction( unit, actions );

if ( le.isMouseRightButtonPressed() ) {
if ( le.MouseClickLeft( _buttonAuto.area() ) ) {
EventStartAutoBattle( unit, actions );
}
else if ( le.isMouseRightButtonPressed() ) {
fheroes2::showStandardTextMessage( _( "Auto Combat" ), _( "Allows the computer to fight out the battle for you." ), Dialog::ZERO );
}
}
else if ( le.isMouseCursorPosInArea( _buttonSettings.area() ) ) {
cursor.SetThemes( Cursor::WAR_POINTER );

msg = _( "Customize system options" );
ButtonSettingsAction();

if ( le.isMouseRightButtonPressed() ) {
if ( le.MouseClickLeft( _buttonSettings.area() ) ) {
_openBattleSettingsDialog();

humanturn_redraw = true;
}
else if ( le.isMouseRightButtonPressed() ) {
fheroes2::showStandardTextMessage( _( "System Options" ), _( "Allows you to customize the combat screen." ), Dialog::ZERO );
}
}
else if ( le.isMouseCursorPosInArea( _buttonSkip.area() ) ) {
cursor.SetThemes( Cursor::WAR_POINTER );

msg = _( "Skip this unit" );
ButtonSkipAction( actions );

if ( le.isMouseRightButtonPressed() ) {
if ( le.MouseClickLeft( _buttonSkip.area() ) && _currentUnit ) {
actions.emplace_back( Command::SKIP, _currentUnit->GetUID() );

humanturn_exit = true;
}
else if ( le.isMouseRightButtonPressed() ) {
fheroes2::showStandardTextMessage( _( "Skip" ),
_( "Skips the current creature. The current creature ends its turn and does not get to go again until the next round." ),
Dialog::ZERO );
Expand Down Expand Up @@ -3205,42 +3222,6 @@ void Battle::Interface::EventAutoFinish( Actions & actions )
humanturn_exit = true;
}

void Battle::Interface::ButtonAutoAction( const Unit & unit, Actions & actions )
{
LocalEvent & le = LocalEvent::Get();

_buttonAuto.drawOnState( le.isMouseLeftButtonPressedInArea( _buttonAuto.area() ) );

if ( le.MouseClickLeft( _buttonAuto.area() ) ) {
EventStartAutoBattle( unit, actions );
}
}

void Battle::Interface::ButtonSettingsAction()
{
LocalEvent & le = LocalEvent::Get();

_buttonSettings.drawOnState( le.isMouseLeftButtonPressedInArea( _buttonSettings.area() ) );

if ( le.MouseClickLeft( _buttonSettings.area() ) ) {
_openBattleSettingsDialog();

humanturn_redraw = true;
}
}

void Battle::Interface::ButtonSkipAction( Actions & actions )
{
LocalEvent & le = LocalEvent::Get();

_buttonSkip.drawOnState( le.isMouseLeftButtonPressedInArea( _buttonSkip.area() ) );

if ( le.MouseClickLeft( _buttonSkip.area() ) && _currentUnit ) {
actions.emplace_back( Command::SKIP, _currentUnit->GetUID() );
humanturn_exit = true;
}
}

void Battle::Interface::MousePressRightBoardAction( const Cell & cell ) const
{
const auto getUnit = [this, &cell]() -> const Unit * {
Expand Down
3 changes: 0 additions & 3 deletions src/fheroes2/battle/battle_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,6 @@ namespace Battle
void EventStartAutoBattle( const Unit & unit, Actions & actions );
void EventAutoFinish( Actions & actions );
void EventShowOptions();
void ButtonAutoAction( const Unit & unit, Actions & actions );
void ButtonSettingsAction();
void ButtonSkipAction( Actions & actions );
void MouseLeftClickBoardAction( const int themes, const Cell & cell, const bool isConfirmed, Actions & actions );
void MousePressRightBoardAction( const Cell & cell ) const;

Expand Down

0 comments on commit 49fbf21

Please sign in to comment.