Browse Source

Fix battle queue stack highlighting

Ivan Savenko 2 years ago
parent
commit
0be9aff99f
2 changed files with 18 additions and 16 deletions
  1. 13 12
      client/battle/BattleInterfaceClasses.cpp
  2. 5 4
      client/battle/BattleInterfaceClasses.h

+ 13 - 12
client/battle/BattleInterfaceClasses.cpp

@@ -652,14 +652,6 @@ StackQueue::StackQueue(bool Embedded, BattleInterface & owner)
 
 void StackQueue::show(Canvas & to)
 {
-	auto unitIdsToHighlight = owner.stacksController->getHoveredStacksUnitIds();
-
-	for(auto & stackBox : stackBoxes)
-	{
-		bool isBoundUnitCurrentlyHovered = vstd::contains(unitIdsToHighlight, stackBox->getBoundUnitID());
-		stackBox->toggleHighlight(isBoundUnitCurrentlyHovered);
-	}
-
 	if (embedded)
 		showAll(to);
 	CIntObject::show(to);
@@ -783,15 +775,24 @@ std::optional<uint32_t> StackQueue::StackBox::getBoundUnitID() const
 	return boundUnitID;
 }
 
-void StackQueue::StackBox::toggleHighlight(bool value)
+bool StackQueue::StackBox::isBoundUnitHighlighted() const
 {
-	highlighted = value;
+	auto unitIdsToHighlight = owner->owner.stacksController->getHoveredStacksUnitIds();
+	return vstd::contains(unitIdsToHighlight, getBoundUnitID());
 }
 
-void StackQueue::StackBox::show(Canvas & to)
+void StackQueue::StackBox::showAll(Canvas & to)
 {
-	if(highlighted)
+	CIntObject::showAll(to);
+
+	if(isBoundUnitHighlighted())
 		to.drawBorder(background->pos, Colors::CYAN, 2);
+}
 
+void StackQueue::StackBox::show(Canvas & to)
+{
 	CIntObject::show(to);
+
+	if(isBoundUnitHighlighted())
+		to.drawBorder(background->pos, Colors::CYAN, 2);
 }

+ 5 - 4
client/battle/BattleInterfaceClasses.h

@@ -167,20 +167,21 @@ class StackQueue : public CIntObject
 	{
 		StackQueue * owner;
 		std::optional<uint32_t> boundUnitID;
-		bool highlighted = false;
 
-	public:
 		std::shared_ptr<CPicture> background;
 		std::shared_ptr<CAnimImage> icon;
 		std::shared_ptr<CLabel> amount;
 		std::shared_ptr<CAnimImage> stateIcon;
 
+		void show(Canvas & to) override;
+		void showAll(Canvas & to) override;
+
+		bool isBoundUnitHighlighted() const;
+	public:
 		StackBox(StackQueue * owner);
 		void setUnit(const battle::Unit * unit, size_t turn = 0);
-		void toggleHighlight(bool value);
 		std::optional<uint32_t> getBoundUnitID() const;
 
-		void show(Canvas & to) override;
 	};
 
 	static const int QUEUE_SIZE = 10;