From 05735a20e128179604721d944b0aedeb656e7322 Mon Sep 17 00:00:00 2001 From: Dydzio Date: Sat, 22 Jul 2023 15:32:00 +0200 Subject: [PATCH] Fix for hero info window mana points not getting spent on spellcast --- client/battle/BattleInterface.cpp | 8 ++++++++ client/battle/BattleInterfaceClasses.cpp | 14 ++++++++++++++ client/battle/BattleInterfaceClasses.h | 3 +++ client/battle/BattleWindow.cpp | 10 ++++++++-- client/battle/BattleWindow.h | 3 +++ 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/client/battle/BattleInterface.cpp b/client/battle/BattleInterface.cpp index 53fb5f3c7..c7e5cb07c 100644 --- a/client/battle/BattleInterface.cpp +++ b/client/battle/BattleInterface.cpp @@ -584,7 +584,15 @@ 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/BattleInterfaceClasses.cpp b/client/battle/BattleInterfaceClasses.cpp index 68dbd9a3a..a6289d07f 100644 --- a/client/battle/BattleInterfaceClasses.cpp +++ b/client/battle/BattleInterfaceClasses.cpp @@ -389,6 +389,12 @@ HeroInfoBasicPanel::HeroInfoBasicPanel(const InfoAboutHero & hero, Point * posit background->colorize(hero.owner); } + initializeData(hero); +} + +void HeroInfoBasicPanel::initializeData(const InfoAboutHero & hero) +{ + OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; auto attack = hero.details->primskills[0]; auto defense = hero.details->primskills[1]; auto power = hero.details->primskills[2]; @@ -423,6 +429,14 @@ HeroInfoBasicPanel::HeroInfoBasicPanel(const InfoAboutHero & hero, Point * posit labels.push_back(std::make_shared(39, 186, EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, std::to_string(currentSpellPoints) + "/" + std::to_string(maxSpellPoints))); } +void HeroInfoBasicPanel::update(const InfoAboutHero & updatedInfo) +{ + icons.clear(); + labels.clear(); + + initializeData(updatedInfo); +} + void HeroInfoBasicPanel::show(Canvas & to) { showAll(to); diff --git a/client/battle/BattleInterfaceClasses.h b/client/battle/BattleInterfaceClasses.h index 5f730d56e..aa5668bc5 100644 --- a/client/battle/BattleInterfaceClasses.h +++ b/client/battle/BattleInterfaceClasses.h @@ -137,6 +137,9 @@ public: HeroInfoBasicPanel(const InfoAboutHero & hero, Point * position, bool initializeBackground = true); void show(Canvas & to) override; + + void initializeData(const InfoAboutHero & hero); + void update(const InfoAboutHero & updatedInfo); }; class HeroInfoWindow : public CWindowObject diff --git a/client/battle/BattleWindow.cpp b/client/battle/BattleWindow.cpp index 4fe763e04..1d0e314d1 100644 --- a/client/battle/BattleWindow.cpp +++ b/client/battle/BattleWindow.cpp @@ -237,8 +237,8 @@ void BattleWindow::showStickyHeroWindows() if(settings["battle"]["stickyHeroInfoWindows"].Bool() == true) return; - Settings showStickyHeroInfoWIndows = settings.write["battle"]["stickyHeroInfoWindows"]; - showStickyHeroInfoWIndows->Bool() = true; + Settings showStickyHeroInfoWindows = settings.write["battle"]["stickyHeroInfoWindows"]; + showStickyHeroInfoWindows->Bool() = true; createStickyHeroInfoWindows(); @@ -250,6 +250,12 @@ void BattleWindow::updateQueue() queue->update(); } +void BattleWindow::updateHeroInfoWindow(uint8_t side, const InfoAboutHero & hero) +{ + std::shared_ptr panelToUpdate = side == 0 ? attackerHeroWindow : defenderHeroWindow; + panelToUpdate->update(hero); +} + void BattleWindow::activate() { GH.setStatusbar(console); diff --git a/client/battle/BattleWindow.h b/client/battle/BattleWindow.h index 0b37f1e1e..a16d913ca 100644 --- a/client/battle/BattleWindow.h +++ b/client/battle/BattleWindow.h @@ -88,6 +88,9 @@ public: /// Refresh queue after turn order changes void updateQueue(); + /// Refresh sticky variant of hero info window after spellcast, side same as in BattleSpellCast::side + void updateHeroInfoWindow(uint8_t side, const InfoAboutHero & hero); + /// Get mouse-hovered battle queue unit ID if any found std::optional getQueueHoveredUnitId();