浏览代码

Fix updating of heroes when moving to/from garrison

Ivan Savenko 2 年之前
父节点
当前提交
3836217da5
共有 2 个文件被更改,包括 6 次插入16 次删除
  1. 4 2
      client/CPlayerInterface.cpp
  2. 2 14
      client/adventureMap/CList.cpp

+ 4 - 2
client/CPlayerInterface.cpp

@@ -500,7 +500,7 @@ void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town)
 	if(town->garrisonHero) //wandering hero moved to the garrison
 	if(town->garrisonHero) //wandering hero moved to the garrison
 	{
 	{
 		// This method also gets called on hero recruitment -> garrisoned hero is already in garrison
 		// This method also gets called on hero recruitment -> garrisoned hero is already in garrison
-		if(town->garrisonHero->tempOwner == playerID && !vstd::contains(localState->getWanderingHeroes(), town->visitingHero))
+		if(town->garrisonHero->tempOwner == playerID && vstd::contains(localState->getWanderingHeroes(), town->garrisonHero))
 			localState->removeWanderingHero(town->garrisonHero);
 			localState->removeWanderingHero(town->garrisonHero);
 	}
 	}
 
 
@@ -520,7 +520,9 @@ void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town)
 		castleInt->garr->setArmy(town->visitingHero, 1);
 		castleInt->garr->setArmy(town->visitingHero, 1);
 		castleInt->garr->recreateSlots();
 		castleInt->garr->recreateSlots();
 		castleInt->heroes->update();
 		castleInt->heroes->update();
-		castleInt->redraw();
+
+		// Perform totalRedraw to update hero list on adventure map
+		GH.windows().totalRedraw();
 	}
 	}
 
 
 	for (auto ki : GH.windows().findWindows<CKingdomInterface>())
 	for (auto ki : GH.windows().findWindows<CKingdomInterface>())

+ 2 - 14
client/adventureMap/CList.cpp

@@ -287,14 +287,8 @@ void CHeroList::updateElement(const CGHeroInstance * hero)
 
 
 void CHeroList::updateWidget()
 void CHeroList::updateWidget()
 {
 {
-	for(auto & elem : listBox->getItems())
-	{
-		auto item = std::dynamic_pointer_cast<CHeroItem>(elem);
-		if (item)
-			item->update();
-	}
-
 	listBox->resize(LOCPLINT->localState->getWanderingHeroes().size());
 	listBox->resize(LOCPLINT->localState->getWanderingHeroes().size());
+	listBox->reset();
 	if (LOCPLINT->localState->getCurrentHero())
 	if (LOCPLINT->localState->getCurrentHero())
 		select(LOCPLINT->localState->getCurrentHero());
 		select(LOCPLINT->localState->getCurrentHero());
 
 
@@ -370,14 +364,8 @@ void CTownList::updateElement(const CGTownInstance * town)
 
 
 void CTownList::updateWidget()
 void CTownList::updateWidget()
 {
 {
-	for(auto & elem : listBox->getItems())
-	{
-		auto item = std::dynamic_pointer_cast<CTownItem>(elem);
-		if (item)
-			item->update();
-	}
-
 	listBox->resize(LOCPLINT->localState->getOwnedTowns().size());
 	listBox->resize(LOCPLINT->localState->getOwnedTowns().size());
+	listBox->reset();
 	if (LOCPLINT->localState->getCurrentTown())
 	if (LOCPLINT->localState->getCurrentTown())
 		select(LOCPLINT->localState->getCurrentTown());
 		select(LOCPLINT->localState->getCurrentTown());