From 47b6358e6e463e31a2ddd8da6db10392729fd01b Mon Sep 17 00:00:00 2001 From: Dydzio Date: Sat, 22 Jul 2023 21:51:14 +0200 Subject: [PATCH] Improve feature by triggering hero window refresh in response to netpack --- client/CPlayerInterface.cpp | 3 +++ client/battle/BattleInterface.cpp | 8 -------- client/battle/BattleWindow.cpp | 15 +++++++++++++++ client/battle/BattleWindow.h | 4 ++++ 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 445359148..3b70f4833 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -476,6 +476,9 @@ void CPlayerInterface::heroManaPointsChanged(const CGHeroInstance * hero) adventureInt->onHeroChanged(hero); if (makingTurn && hero->tempOwner == playerID) adventureInt->onHeroChanged(hero); + + for (auto window : GH.windows().findWindows()) + window->heroManaPointsChanged(hero); } void CPlayerInterface::heroMovePointsChanged(const CGHeroInstance * hero) { diff --git a/client/battle/BattleInterface.cpp b/client/battle/BattleInterface.cpp index c7e5cb07c..53fb5f3c7 100644 --- a/client/battle/BattleInterface.cpp +++ b/client/battle/BattleInterface.cpp @@ -584,15 +584,7 @@ void BattleInterface::endAction(const BattleAction* action) //we have activated next stack after sending request that has been just realized -> blockmap due to movement has changed if(action->actionType == EActionType::HERO_SPELL) - { fieldController->redrawBackgroundWithHexes(); - - //update casting hero info window - auto hero = action->side == 0 ? attackingHero : defendingHero; - InfoAboutHero heroInfo = InfoAboutHero(); - heroInfo.initFromHero(hero->instance(), InfoAboutHero::INBATTLE); - windowObject->updateHeroInfoWindow(action->side, heroInfo); - } } void BattleInterface::appendBattleLog(const std::string & newEntry) diff --git a/client/battle/BattleWindow.cpp b/client/battle/BattleWindow.cpp index 1d0e314d1..240106a31 100644 --- a/client/battle/BattleWindow.cpp +++ b/client/battle/BattleWindow.cpp @@ -256,6 +256,21 @@ void BattleWindow::updateHeroInfoWindow(uint8_t side, const InfoAboutHero & hero panelToUpdate->update(hero); } +void BattleWindow::heroManaPointsChanged(const CGHeroInstance * hero) +{ + if(hero == owner.attackingHeroInstance || hero == owner.defendingHeroInstance) + { + InfoAboutHero heroInfo = InfoAboutHero(); + heroInfo.initFromHero(hero, InfoAboutHero::INBATTLE); + + updateHeroInfoWindow(hero == owner.attackingHeroInstance ? 0 : 1, heroInfo); + } + else + { + logGlobal->error("BattleWindow::heroManaPointsChanged: 'Mana points changed' called for hero not belonging to current battle window"); + } +} + void BattleWindow::activate() { GH.setStatusbar(console); diff --git a/client/battle/BattleWindow.h b/client/battle/BattleWindow.h index a16d913ca..6241e3f57 100644 --- a/client/battle/BattleWindow.h +++ b/client/battle/BattleWindow.h @@ -79,9 +79,13 @@ public: void hideQueue(); void showQueue(); + /// Toggle permanent hero info windows visibility (HD mod feature) void hideStickyHeroWindows(); void showStickyHeroWindows(); + /// Event handler for netpack changing hero mana points + void heroManaPointsChanged(const CGHeroInstance * hero); + /// block all UI elements when player is not allowed to act, e.g. during enemy turn void blockUI(bool on);