Răsfoiți Sursa

add battle animation

Laserlicht 4 luni în urmă
părinte
comite
d0d3b96fa9

+ 3 - 0
client/mapView/IMapRendererContext.h

@@ -56,6 +56,9 @@ public:
 	/// returns true if specified object is the currently active hero
 	virtual bool isActiveHero(const CGObjectInstance* obj) const = 0;
 
+	/// returns true if specified object is a monster and currently attacked
+	virtual bool isMonsterAttacked(const CGObjectInstance * obj) const = 0;
+
 	virtual size_t objectGroupIndex(ObjectInstanceID objectID) const = 0;
 	virtual Point objectImageOffset(ObjectInstanceID objectID, const int3 & coordinates) const = 0;
 

+ 6 - 0
client/mapView/MapRenderer.cpp

@@ -465,6 +465,12 @@ std::shared_ptr<IImage> MapRendererObjects::getImage(IMapRendererContext & conte
 
 	if(animation->size(groupIndex) == 0)
 		return nullptr;
+	
+	if(context.isMonsterAttacked(obj))
+	{
+		auto img = ENGINE->renderHandler().loadImage(ImagePath::builtin("AvWattak:0:0"), EImageBlitMode::SIMPLE);
+		return img;
+	}
 
 	size_t frameIndex = context.objectImageIndex(obj->id, animation->size(groupIndex));
 

+ 14 - 0
client/mapView/MapRendererContext.cpp

@@ -25,6 +25,8 @@
 #include "../../lib/spells/CSpellHandler.h"
 #include "../../lib/mapping/CMap.h"
 #include "../../lib/pathfinder/CGPathNode.h"
+#include "../../lib/battle/CPlayerBattleCallback.h"
+#include "../../lib/battle/IBattleState.h"
 
 MapRendererBaseContext::MapRendererBaseContext(const MapRendererContextState & viewState)
 	: viewState(viewState)
@@ -85,6 +87,18 @@ bool MapRendererBaseContext::isActiveHero(const CGObjectInstance * obj) const
 	return false;
 }
 
+bool MapRendererBaseContext::isMonsterAttacked(const CGObjectInstance * obj) const
+{
+	if(obj->ID != Obj::MONSTER)
+		return false;
+		
+	for(auto & battle : GAME->interface()->cb->getActiveBattles())
+		if(obj->pos == battle.second->getBattle()->getLocation())
+			return true;
+
+	return false;
+}
+
 bool MapRendererBaseContext::tileAnimated(const int3 & coordinates) const
 {
 	return false;

+ 1 - 0
client/mapView/MapRendererContext.h

@@ -36,6 +36,7 @@ public:
 	bool tileAnimated(const int3 & coordinates) const override;
 
 	bool isActiveHero(const CGObjectInstance* obj) const override;
+	bool isMonsterAttacked(const CGObjectInstance * obj) const override;
 
 	const TerrainTile & getMapTile(const int3 & coordinates) const override;
 	const MapObjectsList & getObjects(const int3 & coordinates) const override;

+ 10 - 0
client/renderSDL/RenderHandler.cpp

@@ -354,6 +354,16 @@ std::shared_ptr<IImage> RenderHandler::loadImage(const AnimationPath & path, int
 
 std::shared_ptr<IImage> RenderHandler::loadImage(const ImagePath & path, EImageBlitMode mode)
 {
+	auto name = path.getOriginalName();
+	
+	std::vector<std::string> splitted;
+    boost::split(splitted, name, boost::is_any_of(":"));
+	if(splitted.size() == 3)
+	{
+		ImageLocator locator = getLocatorForAnimationFrame(AnimationPath::builtin(splitted[0]), std::stoi(splitted[2]), std::stoi(splitted[1]), 1, mode);
+		return loadImage(locator);
+	}
+
 	ImageLocator locator(path, mode);
 	return loadImage(locator);
 }

+ 5 - 0
lib/callback/CBattleCallback.cpp

@@ -79,6 +79,11 @@ void CBattleCallback::onBattleEnded(const BattleID & battleID)
 	activeBattles.erase(battleID);
 }
 
+std::map<BattleID, std::shared_ptr<CPlayerBattleCallback>> CBattleCallback::getActiveBattles()
+{
+	return activeBattles;
+}
+
 void CBattleCallback::battleMakeSpellAction(const BattleID & battleID, const BattleAction & action)
 {
 	assert(action.actionType == EActionType::HERO_SPELL);

+ 1 - 0
lib/callback/CBattleCallback.h

@@ -39,6 +39,7 @@ public:
 
 	void onBattleStarted(const IBattleInfo * info);
 	void onBattleEnded(const BattleID & battleID);
+	std::map<BattleID, std::shared_ptr<CPlayerBattleCallback>> getActiveBattles();
 };
 
 VCMI_LIB_NAMESPACE_END