Jelajahi Sumber

Army window

Laserlicht 1 tahun lalu
induk
melakukan
72911ec9a3

+ 37 - 0
client/battle/BattleInterfaceClasses.cpp

@@ -446,6 +446,43 @@ void HeroInfoBasicPanel::show(Canvas & to)
 	CIntObject::show(to);
 }
 
+
+ArmyInfoBasicPanel::ArmyInfoBasicPanel(const InfoAboutArmy & army, Point * position, bool initializeBackground)
+	: CIntObject(0)
+{
+	OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
+	if (position != nullptr)
+		moveTo(*position);
+
+	if(initializeBackground)
+	{
+		background = std::make_shared<CPicture>(ImagePath::builtin("CHRPOP"));
+		background->getSurface()->setBlitMode(EImageBlitMode::OPAQUE);
+		background->colorize(army.owner);
+	}
+
+	initializeData(army);
+}
+
+void ArmyInfoBasicPanel::initializeData(const InfoAboutArmy & army)
+{
+	OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
+}
+
+void ArmyInfoBasicPanel::update(const InfoAboutArmy & updatedInfo)
+{
+	icons.clear();
+	labels.clear();
+
+	initializeData(updatedInfo);
+}
+
+void ArmyInfoBasicPanel::show(Canvas & to)
+{
+	showAll(to);
+	CIntObject::show(to);
+}
+
 HeroInfoWindow::HeroInfoWindow(const InfoAboutHero & hero, Point * position)
 	: CWindowObject(RCLICK_POPUP | SHADOW_DISABLED, ImagePath::builtin("CHRPOP"))
 {

+ 16 - 0
client/battle/BattleInterfaceClasses.h

@@ -20,6 +20,7 @@ VCMI_LIB_NAMESPACE_BEGIN
 class CGHeroInstance;
 struct BattleResult;
 struct InfoAboutHero;
+struct InfoAboutArmy;
 class CStack;
 
 namespace battle
@@ -144,6 +145,21 @@ public:
 	void update(const InfoAboutHero & updatedInfo);
 };
 
+class ArmyInfoBasicPanel : public CIntObject
+{
+private:
+	std::shared_ptr<CPicture> background;
+	std::vector<std::shared_ptr<CLabel>> labels;
+	std::vector<std::shared_ptr<CAnimImage>> icons;
+public:
+	ArmyInfoBasicPanel(const InfoAboutArmy & army, Point * position, bool initializeBackground = true);
+
+	void show(Canvas & to) override;
+
+	void initializeData(const InfoAboutArmy & army);
+	void update(const InfoAboutArmy & updatedInfo);
+};
+
 class HeroInfoWindow : public CWindowObject
 {
 private:

+ 38 - 1
client/battle/BattleWindow.cpp

@@ -154,6 +154,41 @@ void BattleWindow::createStickyHeroInfoWindows()
 	}
 }
 
+void BattleWindow::createStickyArmyInfoWindows(std::optional<uint32_t> unitId)
+{
+	OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
+
+	if(owner.defendingHeroInstance)
+	{
+		InfoAboutHero info;
+		info.initFromHero(owner.defendingHeroInstance, InfoAboutHero::EInfoLevel::INBATTLE);
+		Point position = (GH.screenDimensions().x >= 1000)
+				? Point(pos.x + pos.w + 15, pos.y + 250)
+				: Point(pos.x + pos.w -79, pos.y + 135);
+		defenderArmyWindow = std::make_shared<ArmyInfoBasicPanel>(info, &position);
+	}
+	if(owner.attackingHeroInstance)
+	{
+		InfoAboutHero info;
+		info.initFromHero(owner.attackingHeroInstance, InfoAboutHero::EInfoLevel::INBATTLE);
+		Point position = (GH.screenDimensions().x >= 1000)
+				? Point(pos.x - 93, pos.y + 250)
+				: Point(pos.x + 1, pos.y + 135);
+		attackerArmyWindow = std::make_shared<ArmyInfoBasicPanel>(info, &position);
+	}
+
+	bool showInfoWindows = settings["battle"]["stickyHeroInfoWindows"].Bool();
+
+	if(!showInfoWindows)
+	{
+		if(attackerArmyWindow)
+			attackerArmyWindow->disable();
+
+		if(defenderArmyWindow)
+			defenderArmyWindow->disable();
+	}
+}
+
 BattleWindow::~BattleWindow()
 {
 	CPlayerInterface::battleInt = nullptr;
@@ -671,7 +706,9 @@ void BattleWindow::blockUI(bool on)
 
 std::optional<uint32_t> BattleWindow::getQueueHoveredUnitId()
 {
-	return queue->getHoveredUnitIdIfAny();
+	std::optional<uint32_t> unitId = queue->getHoveredUnitIdIfAny();
+	createStickyArmyInfoWindows(unitId);
+	return unitId;
 }
 
 void BattleWindow::showAll(Canvas & to)

+ 4 - 0
client/battle/BattleWindow.h

@@ -25,6 +25,7 @@ class BattleConsole;
 class BattleRenderer;
 class StackQueue;
 class HeroInfoBasicPanel;
+class ArmyInfoBasicPanel;
 
 /// GUI object that handles functionality of panel at the bottom of combat screen
 class BattleWindow : public InterfaceObjectConfigurable
@@ -35,6 +36,8 @@ class BattleWindow : public InterfaceObjectConfigurable
 	std::shared_ptr<BattleConsole> console;
 	std::shared_ptr<HeroInfoBasicPanel> attackerHeroWindow;
 	std::shared_ptr<HeroInfoBasicPanel> defenderHeroWindow;
+	std::shared_ptr<ArmyInfoBasicPanel> attackerArmyWindow;
+	std::shared_ptr<ArmyInfoBasicPanel> defenderArmyWindow;
 
 	/// button press handling functions
 	void bOptionsf();
@@ -65,6 +68,7 @@ class BattleWindow : public InterfaceObjectConfigurable
 
 	void toggleStickyHeroWindowsVisibility();
 	void createStickyHeroInfoWindows();
+	void createStickyArmyInfoWindows(std::optional<uint32_t> unitId);
 
 	std::shared_ptr<BattleConsole> buildBattleConsole(const JsonNode &) const;