Bläddra i källkod

Allow dismissing heroes from kingdom overview window

Ivan Savenko 2 år sedan
förälder
incheckning
3e8debc243

+ 3 - 0
client/CPlayerInterface.cpp

@@ -401,6 +401,9 @@ void CPlayerInterface::heroKilled(const CGHeroInstance* hero)
 	localState->removeWanderingHero(hero);
 	adventureInt->onHeroChanged(hero);
 	localState->erasePath(hero);
+
+	for (auto ki : GH.windows().findWindows<CKingdomInterface>())
+		ki->heroRemoved();
 }
 
 void CPlayerInterface::heroVisit(const CGHeroInstance * visitor, const CGObjectInstance * visitedObj, bool start)

+ 4 - 4
client/windows/CHeroWindow.cpp

@@ -319,9 +319,6 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded)
 				noDismiss = true;
 	}
 
-	for(auto ki : GH.windows().findWindows<CKingdomInterface>())
-		noDismiss = true;
-
 	//if player only have one hero and no towns
 	if(!LOCPLINT->cb->howManyTowns() && LOCPLINT->cb->howManyHeroes() == 1)
 		noDismiss = true;
@@ -329,7 +326,10 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded)
 	if(curHero->isMissionCritical())
 		noDismiss = true;
 
-	dismissButton->block(!!curHero->visitedTown || noDismiss);
+	if (curHero->visitedTown)
+		noDismiss = true;
+
+	dismissButton->block(noDismiss);
 
 	if(curHero->valOfBonuses(Selector::type()(BonusType::BEFORE_BATTLE_REPOSITION)) == 0)
 	{

+ 14 - 6
client/windows/CKingdomInterface.cpp

@@ -15,6 +15,7 @@
 
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
+#include "../PlayerLocalState.h"
 #include "../adventureMap/CResDataBar.h"
 #include "../gui/CGuiHandler.h"
 #include "../gui/Shortcut.h"
@@ -638,6 +639,11 @@ void CKingdomInterface::townChanged(const CGTownInstance *town)
 		townList->townChanged(town);
 }
 
+void CKingdomInterface::heroRemoved()
+{
+	tabArea->reset();
+}
+
 void CKingdomInterface::updateGarrisons()
 {
 	if(auto garrison = std::dynamic_pointer_cast<CGarrisonHolder>(tabArea->getItem()))
@@ -694,11 +700,12 @@ void CKingdHeroList::updateGarrisons()
 std::shared_ptr<CIntObject> CKingdHeroList::createHeroItem(size_t index)
 {
 	ui32 picCount = 4; // OVSLOT contains 4 images
-	size_t heroesCount = LOCPLINT->cb->howManyHeroes(false);
 
-	if(index < heroesCount)
+	auto heroesList = LOCPLINT->localState->getWanderingHeroes();
+
+	if(index < heroesList.size())
 	{
-		auto hero = std::make_shared<CHeroItem>(LOCPLINT->cb->getHeroBySerial((int)index, false));
+		auto hero = std::make_shared<CHeroItem>(heroesList[index]);
 		addSet(hero->heroArts);
 		return hero;
 	}
@@ -745,10 +752,11 @@ void CKingdTownList::updateGarrisons()
 std::shared_ptr<CIntObject> CKingdTownList::createTownItem(size_t index)
 {
 	ui32 picCount = 4; // OVSLOT contains 4 images
-	size_t townsCount = LOCPLINT->cb->howManyTowns();
 
-	if(index < townsCount)
-		return std::make_shared<CTownItem>(LOCPLINT->cb->getTownBySerial((int)index));
+	auto townsList = LOCPLINT->localState->getOwnedTowns();
+
+	if(index < townsList.size())
+		return std::make_shared<CTownItem>(townsList[index]);
 	else
 		return std::make_shared<CAnimImage>("OVSLOT", (index-2) % picCount );
 }

+ 1 - 0
client/windows/CKingdomInterface.h

@@ -246,6 +246,7 @@ public:
 	CKingdomInterface();
 
 	void townChanged(const CGTownInstance *town);
+	void heroRemoved();
 	void updateGarrisons() override;
 	void artifactRemoved(const ArtifactLocation &artLoc) override;
 	void artifactMoved(const ArtifactLocation &artLoc, const ArtifactLocation &destLoc, bool withRedraw) override;