浏览代码

Show town-specific tower icon in battle queue, if such icon exists

Ivan Savenko 2 年之前
父节点
当前提交
178cd0226f

+ 1 - 1
client/battle/CBattleInterface.cpp

@@ -156,7 +156,6 @@ CBattleInterface::CBattleInterface(const CCreatureSet *army1, const CCreatureSet
 
 		queue->moveTo(Point(pos.x, pos.y - queue->pos.h));
 	}
-	queue->update();
 
 	//preparing siege info
 	const CGTownInstance *town = curInt->cb->battleGetDefendedTown();
@@ -423,6 +422,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet *army1, const CCreatureSet
 	currentAction = PossiblePlayerBattleAction::INVALID;
 	selectedAction = PossiblePlayerBattleAction::INVALID;
 	addUsedEvents(RCLICK | MOVE | KEYBOARD);
+	queue->update();
 	blockUI(true);
 }
 

+ 2 - 1
client/battle/CBattleInterface.h

@@ -59,6 +59,7 @@ struct ProjectileInfo;
 class CClickableHex;
 class CAnimation;
 class IImage;
+class CStackQueue;
 
 /// Small struct which contains information about the id of the attacked stack, the damage dealt,...
 struct StackAttackedInfo
@@ -396,7 +397,7 @@ public:
 	friend class CPlayerInterface;
 	friend class CButton;
 	friend class CInGameConsole;
-
+	friend class CStackQueue;
 	friend class CBattleResultWindow;
 	friend class CBattleHero;
 	friend class CEffectAnimation;

+ 17 - 2
client/battle/CBattleInterfaceClasses.cpp

@@ -763,7 +763,13 @@ void CStackQueue::update()
 		stackBoxes[boxIndex]->setUnit(nullptr);
 }
 
-CStackQueue::StackBox::StackBox(CStackQueue * owner)
+int32_t CStackQueue::getSiegeShooterIconID()
+{
+		return owner->siegeH->town->town->faction->index;
+}
+
+CStackQueue::StackBox::StackBox(CStackQueue * owner):
+	owner(owner)
 {
 	OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
 	background = std::make_shared<CPicture>(owner->embedded ? "StackQueueSmall" : "StackQueueLarge");
@@ -795,7 +801,16 @@ void CStackQueue::StackBox::setUnit(const battle::Unit * unit, size_t turn)
 	{
 		background->colorize(unit->unitOwner());
 		icon->visible = true;
-		icon->setFrame(unit->creatureIconIndex());
+
+		// temporary code for mod compatibility:
+		// first, set icon that should definitely exist (arrow tower icon in base vcmi mod)
+		// second, try to switch to icon that should be provided by mod
+		// if mod is not up to date and does have arrow tower icon yet - second setFrame call will fail and retain previously set image
+		// for 1.2 release & later next line should be moved into 'else' block
+		icon->setFrame(unit->creatureIconIndex(), 0);
+		if (unit->unitType()->idNumber == CreatureID::ARROW_TOWERS)
+			icon->setFrame(owner->getSiegeShooterIconID(), 1);
+
 		amount->setText(makeNumberShort(unit->getCount()));
 
 		if(stateIcon)

+ 2 - 0
client/battle/CBattleInterfaceClasses.h

@@ -157,6 +157,7 @@ class CStackQueue : public CIntObject
 {
 	class StackBox : public CIntObject
 	{
+		CStackQueue * owner;
 	public:
 		std::shared_ptr<CPicture> background;
 		std::shared_ptr<CAnimImage> icon;
@@ -175,6 +176,7 @@ class CStackQueue : public CIntObject
 	std::shared_ptr<CAnimation> icons;
 	std::shared_ptr<CAnimation> stateIcons;
 
+	int32_t getSiegeShooterIconID();
 public:
 	const bool embedded;