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

Allow dismissing heroes from kingdom overview window

This commit is contained in:
Ivan Savenko 2023-07-15 15:47:24 +03:00
parent 8ed5f412e2
commit 3e8debc243
4 changed files with 22 additions and 10 deletions

View File

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

View File

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

View File

@ -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 );
}

View File

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