mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-06 09:09:40 +02:00
add battle animation
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user