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

Fix updating of hero & town lists on adventure map

This commit is contained in:
Ivan Savenko 2023-07-13 14:35:24 +03:00
parent 65d3b96ed0
commit 3e1125570d
4 changed files with 40 additions and 20 deletions

View File

@ -587,9 +587,11 @@ void CPlayerInterface::garrisonsChanged(std::vector<const CGObjectInstance *> ob
void CPlayerInterface::buildChanged(const CGTownInstance *town, BuildingID buildingID, int what) //what: 1 - built, 2 - demolished
{
EVENT_HANDLER_CALLED_BY_CLIENT;
adventureInt->onTownChanged(town);
if (castleInt)
{
castleInt->townlist->update(town);
castleInt->townlist->updateElement(town);
if (castleInt->town == town)
{
@ -604,8 +606,10 @@ void CPlayerInterface::buildChanged(const CGTownInstance *town, BuildingID build
break;
}
}
// Perform totalRedraw in order to force redraw of updated town list icon from adventure map
GH.windows().totalRedraw();
}
adventureInt->onTownChanged(town);
}
void CPlayerInterface::battleStartBefore(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2)

View File

@ -92,7 +92,7 @@ void AdventureMapInterface::onHeroMovementStarted(const CGHeroInstance * hero)
void AdventureMapInterface::onHeroChanged(const CGHeroInstance *h)
{
widget->getHeroList()->update(h);
widget->getHeroList()->updateElement(h);
if (h && h == LOCPLINT->localState->getCurrentHero() && !widget->getInfoBar()->showingComponents())
widget->getInfoBar()->showSelection();
@ -102,7 +102,7 @@ void AdventureMapInterface::onHeroChanged(const CGHeroInstance *h)
void AdventureMapInterface::onTownChanged(const CGTownInstance * town)
{
widget->getTownList()->update(town);
widget->getTownList()->updateElement(town);
if (town && town == LOCPLINT->localState->getCurrentTown() && !widget->getInfoBar()->showingComponents())
widget->getInfoBar()->showSelection();
@ -365,8 +365,8 @@ void AdventureMapInterface::onPlayerTurnStarted(PlayerColor playerID)
widget->getInfoBar()->showSelection();
}
widget->getHeroList()->update();
widget->getTownList()->update();
widget->getHeroList()->updateWidget();
widget->getTownList()->updateWidget();
const CGHeroInstance * heroToSelect = nullptr;

View File

@ -280,19 +280,19 @@ void CHeroList::select(const CGHeroInstance * hero)
selectIndex(vstd::find_pos(LOCPLINT->localState->getWanderingHeroes(), hero));
}
void CHeroList::update(const CGHeroInstance * hero)
void CHeroList::updateElement(const CGHeroInstance * hero)
{
updateWidget();
}
void CHeroList::updateWidget()
{
//this hero is already present, update its status
for(auto & elem : listBox->getItems())
{
auto item = std::dynamic_pointer_cast<CHeroItem>(elem);
if(item && item->hero == hero && vstd::contains(LOCPLINT->localState->getWanderingHeroes(), hero))
{
if (item)
item->update();
return;
}
}
//simplest solution for now: reset list and restore selection
listBox->resize(LOCPLINT->localState->getWanderingHeroes().size());
if (LOCPLINT->localState->getCurrentHero())
@ -363,9 +363,19 @@ void CTownList::select(const CGTownInstance * town)
selectIndex(vstd::find_pos(LOCPLINT->localState->getOwnedTowns(), town));
}
void CTownList::update(const CGTownInstance *)
void CTownList::updateElement(const CGTownInstance * town)
{
//simplest solution for now: reset list and restore selection
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());
if (LOCPLINT->localState->getCurrentTown())
@ -373,4 +383,3 @@ void CTownList::update(const CGTownInstance *)
CList::update();
}

View File

@ -77,6 +77,9 @@ protected:
virtual std::shared_ptr<CIntObject> createItem(size_t index) = 0;
/// should be called when list is invalidated
void update();
public:
/// functions that will be called when selection changes
CFunctionList<void()> onSelect;
@ -87,8 +90,6 @@ public:
void setScrollUpButton(std::shared_ptr<CButton> button);
void setScrollDownButton(std::shared_ptr<CButton> button);
/// should be called when list is invalidated
void update();
/// set of methods to switch selection
void selectIndex(int which);
@ -137,7 +138,10 @@ public:
void select(const CGHeroInstance * hero = nullptr);
/// Update hero. Will add or remove it from the list if needed
void update(const CGHeroInstance * hero = nullptr);
void updateElement(const CGHeroInstance * hero);
/// Update all heroes
void updateWidget();
};
/// List of towns which is shown at the right of the adventure map screen or in the town screen
@ -167,6 +171,9 @@ public:
void select(const CGTownInstance * town = nullptr);
/// Update town. Will add or remove it from the list if needed
void update(const CGTownInstance * town = nullptr);
void updateElement(const CGTownInstance * town);
/// Update all towns
void updateWidget();
};