From 2fb2a79ca4966679daad162288d77cececed774b Mon Sep 17 00:00:00 2001 From: Konstantin Date: Mon, 6 Mar 2023 14:10:33 +0300 Subject: [PATCH] vcmi: fix components other than resources in infobar Do not redraw infobar when components shows and we request to show current adventure hero. Player already knows which hero he used to pick up components. --- client/CPlayerInterface.cpp | 25 ++++++++++++++++++++----- client/adventureMap/CInfoBar.cpp | 5 +++++ client/adventureMap/CInfoBar.h | 3 +++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index d5f60108b..bea2cee3d 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -1773,6 +1773,16 @@ void CPlayerInterface::tryDiggging(const CGHeroInstance * h) void CPlayerInterface::updateInfo(const CGObjectInstance * specific) { + bool isHero = dynamic_cast(specific) != nullptr; + bool changedHero = dynamic_cast(specific) != adventureInt->curHero(); + bool isTown = dynamic_cast(specific) != nullptr; + + bool update = (isHero && changedHero) || (isTown); + // If infobar is showing components and we request an update to hero + // do not force infobar tick here, it will prevents us to show components just picked up + if(adventureInt->infoBar->showingComponents() && !update) + return; + adventureInt->infoBar->showSelection(); } @@ -1883,14 +1893,16 @@ void CPlayerInterface::askToAssembleArtifact(const ArtifactLocation &al) void CPlayerInterface::artifactPut(const ArtifactLocation &al) { EVENT_HANDLER_CALLED_BY_CLIENT; - adventureInt->infoBar->showSelection(); + auto hero = boost::apply_visitor(HeroObjectRetriever(), al.artHolder); + updateInfo(hero); askToAssembleArtifact(al); } void CPlayerInterface::artifactRemoved(const ArtifactLocation &al) { EVENT_HANDLER_CALLED_BY_CLIENT; - adventureInt->infoBar->showSelection(); + auto hero = boost::apply_visitor(HeroObjectRetriever(), al.artHolder); + updateInfo(hero); for(auto isa : GH.listInt) { auto artWin = dynamic_cast(isa.get()); @@ -1904,7 +1916,8 @@ void CPlayerInterface::artifactRemoved(const ArtifactLocation &al) void CPlayerInterface::artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst) { EVENT_HANDLER_CALLED_BY_CLIENT; - adventureInt->infoBar->showSelection(); + auto hero = boost::apply_visitor(HeroObjectRetriever(), dst.artHolder); + updateInfo(hero); bool redraw = true; // If a bulk transfer has arrived, then redrawing only the last art movement. @@ -1932,7 +1945,8 @@ void CPlayerInterface::bulkArtMovementStart(size_t numOfArts) void CPlayerInterface::artifactAssembled(const ArtifactLocation &al) { EVENT_HANDLER_CALLED_BY_CLIENT; - adventureInt->infoBar->showSelection(); + auto hero = boost::apply_visitor(HeroObjectRetriever(), al.artHolder); + updateInfo(hero); for(auto isa : GH.listInt) { auto artWin = dynamic_cast(isa.get()); @@ -1944,7 +1958,8 @@ void CPlayerInterface::artifactAssembled(const ArtifactLocation &al) void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al) { EVENT_HANDLER_CALLED_BY_CLIENT; - adventureInt->infoBar->showSelection(); + auto hero = boost::apply_visitor(HeroObjectRetriever(), al.artHolder); + updateInfo(hero); for(auto isa : GH.listInt) { auto artWin = dynamic_cast(isa.get()); diff --git a/client/adventureMap/CInfoBar.cpp b/client/adventureMap/CInfoBar.cpp index bf948e78e..722f700a5 100644 --- a/client/adventureMap/CInfoBar.cpp +++ b/client/adventureMap/CInfoBar.cpp @@ -275,6 +275,11 @@ void CInfoBar::showComponent(const Component & comp, std::string message) redraw(); } +bool CInfoBar::showingComponents() +{ + return state == COMPONENT; +} + void CInfoBar::startEnemyTurn(PlayerColor color) { OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE); diff --git a/client/adventureMap/CInfoBar.h b/client/adventureMap/CInfoBar.h index 0c6106011..5b5809954 100644 --- a/client/adventureMap/CInfoBar.h +++ b/client/adventureMap/CInfoBar.h @@ -142,5 +142,8 @@ public: /// for 3 seconds shows amount of town halls and players status void showGameStatus(); + + /// check if infobar is showed something about pickups + bool showingComponents(); };