Răsfoiți Sursa

Improve feature by triggering hero window refresh in response to netpack

Dydzio 2 ani în urmă
părinte
comite
47b6358e6e

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

+ 0 - 8
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)

+ 15 - 0
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);

+ 4 - 0
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);