1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Merge pull request #2390 from dydzio0614/hero-window-mana-fix

Fix for hero info window mana points not getting spent on spellcast - option 1
This commit is contained in:
Ivan Savenko 2023-07-24 00:48:54 +03:00 committed by GitHub
commit 8dd1545e25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 2 deletions

View File

@ -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<BattleWindow>())
window->heroManaPointsChanged(hero);
}
void CPlayerInterface::heroMovePointsChanged(const CGHeroInstance * hero)
{

View File

@ -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<CLabel>(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);

View File

@ -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

View File

@ -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,27 @@ void BattleWindow::updateQueue()
queue->update();
}
void BattleWindow::updateHeroInfoWindow(uint8_t side, const InfoAboutHero & hero)
{
std::shared_ptr<HeroInfoBasicPanel> panelToUpdate = side == 0 ? attackerHeroWindow : defenderHeroWindow;
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);

View File

@ -79,15 +79,22 @@ 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);
/// 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<uint32_t> getQueueHoveredUnitId();