Browse Source

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.
Konstantin 2 years ago
parent
commit
2fb2a79ca4
3 changed files with 28 additions and 5 deletions
  1. 20 5
      client/CPlayerInterface.cpp
  2. 5 0
      client/adventureMap/CInfoBar.cpp
  3. 3 0
      client/adventureMap/CInfoBar.h

+ 20 - 5
client/CPlayerInterface.cpp

@@ -1773,6 +1773,16 @@ void CPlayerInterface::tryDiggging(const CGHeroInstance * h)
 
 void CPlayerInterface::updateInfo(const CGObjectInstance * specific)
 {
+	bool isHero = dynamic_cast<const CGHeroInstance *>(specific) != nullptr;
+	bool changedHero = dynamic_cast<const CGHeroInstance *>(specific) != adventureInt->curHero();
+	bool isTown = dynamic_cast<const CGTownInstance *>(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<CArtifactHolder*>(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<CArtifactHolder*>(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<CArtifactHolder*>(isa.get());

+ 5 - 0
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);

+ 3 - 0
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();
 };