From 3e8debc243baffcc6d8ffe47b0090e3ef5de1286 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sat, 15 Jul 2023 15:47:24 +0300 Subject: [PATCH] Allow dismissing heroes from kingdom overview window --- client/CPlayerInterface.cpp | 3 +++ client/windows/CHeroWindow.cpp | 8 ++++---- client/windows/CKingdomInterface.cpp | 20 ++++++++++++++------ client/windows/CKingdomInterface.h | 1 + 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 777dae781..81c5158a4 100644 --- a/client/CPlayerInterface.cpp +++ b/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()) + ki->heroRemoved(); } void CPlayerInterface::heroVisit(const CGHeroInstance * visitor, const CGObjectInstance * visitedObj, bool start) diff --git a/client/windows/CHeroWindow.cpp b/client/windows/CHeroWindow.cpp index cefd5c059..ab1083441 100644 --- a/client/windows/CHeroWindow.cpp +++ b/client/windows/CHeroWindow.cpp @@ -319,9 +319,6 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded) noDismiss = true; } - for(auto ki : GH.windows().findWindows()) - 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) { diff --git a/client/windows/CKingdomInterface.cpp b/client/windows/CKingdomInterface.cpp index f0dbb73f6..1369ad42c 100644 --- a/client/windows/CKingdomInterface.cpp +++ b/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(tabArea->getItem())) @@ -694,11 +700,12 @@ void CKingdHeroList::updateGarrisons() std::shared_ptr 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(LOCPLINT->cb->getHeroBySerial((int)index, false)); + auto hero = std::make_shared(heroesList[index]); addSet(hero->heroArts); return hero; } @@ -745,10 +752,11 @@ void CKingdTownList::updateGarrisons() std::shared_ptr 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(LOCPLINT->cb->getTownBySerial((int)index)); + auto townsList = LOCPLINT->localState->getOwnedTowns(); + + if(index < townsList.size()) + return std::make_shared(townsList[index]); else return std::make_shared("OVSLOT", (index-2) % picCount ); } diff --git a/client/windows/CKingdomInterface.h b/client/windows/CKingdomInterface.h index df47ee33e..e305f2e16 100644 --- a/client/windows/CKingdomInterface.h +++ b/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;