Browse Source

Show spell cursor when casting spell in touch input mode

Ivan Savenko 2 years ago
parent
commit
346eead8e0

+ 18 - 3
client/battle/BattleFieldController.cpp

@@ -128,6 +128,9 @@ BattleFieldController::BattleFieldController(BattleInterface & owner):
 	attackCursors = std::make_shared<CAnimation>("CRCOMBAT");
 	attackCursors->preload();
 
+	spellCursors = std::make_shared<CAnimation>("CRSPELL");
+	spellCursors->preload();
+
 	initializeHexEdgeMaskToFrameIndex();
 
 	rangedFullDamageLimitImages = std::make_shared<CAnimation>("battle/rangeHighlights/rangeHighlightsGreen.json");
@@ -888,10 +891,22 @@ void BattleFieldController::show(Canvas & to)
 
 	if (isActive() && isGesturing() && getHoveredHex() != BattleHex::INVALID)
 	{
-		auto cursorIndex = CCS->curh->get<Cursor::Combat>();
-		auto imageIndex = static_cast<size_t>(cursorIndex);
+		auto combatCursorIndex = CCS->curh->get<Cursor::Combat>();
+		if (combatCursorIndex)
+		{
+			auto combatImageIndex = static_cast<size_t>(*combatCursorIndex);
+			to.draw(attackCursors->getImage(combatImageIndex), hexPositionAbsolute(getHoveredHex()).center() - CCS->curh->getPivotOffsetCombat(combatImageIndex));
+			return;
+		}
+
+		auto spellCursorIndex = CCS->curh->get<Cursor::Spellcast>();
+		if (spellCursorIndex)
+		{
+			auto spellImageIndex = static_cast<size_t>(*spellCursorIndex);
+			to.draw(spellCursors->getImage(spellImageIndex), hexPositionAbsolute(getHoveredHex()).center() - CCS->curh->getPivotOffsetSpellcast());
+			return;
+		}
 
-		to.draw(attackCursors->getImage(imageIndex), hexPositionAbsolute(getHoveredHex()).center() - CCS->curh->getPivotOffsetCombat(imageIndex));
 	}
 }
 

+ 1 - 0
client/battle/BattleFieldController.h

@@ -37,6 +37,7 @@ class BattleFieldController : public CIntObject
 	std::shared_ptr<CAnimation> shootingRangeLimitImages;
 
 	std::shared_ptr<CAnimation> attackCursors;
+	std::shared_ptr<CAnimation> spellCursors;
 
 	/// Canvas that contains background, hex grid (if enabled), absolute obstacles and movement range of active stack
 	std::unique_ptr<Canvas> backgroundWithHexes;

+ 3 - 3
client/gui/CursorHandler.h

@@ -125,7 +125,6 @@ class CursorHandler final
 
 	void changeGraphic(Cursor::Type type, size_t index);
 
-	Point getPivotOffsetSpellcast();
 	Point getPivotOffset();
 
 	void updateSpellcastCursor();
@@ -153,7 +152,7 @@ public:
 
 	/// Returns current index of cursor
 	template<typename Index>
-	Index get()
+	std::optional<Index> get()
 	{
 		bool typeValid = true;
 
@@ -164,9 +163,10 @@ public:
 
 		if (typeValid)
 			return static_cast<Index>(frame);
-		return Index::POINTER;
+		return std::nullopt;
 	}
 
+	Point getPivotOffsetSpellcast();
 	Point getPivotOffsetDefault(size_t index);
 	Point getPivotOffsetMap(size_t index);
 	Point getPivotOffsetCombat(size_t index);