From 7543fdf787133dd9f9791038f5bab0312f9c5e54 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Sun, 26 Mar 2023 03:48:11 +0300 Subject: [PATCH] vcmi: add reverse effect animation type To be used later with obstacle removal --- client/battle/BattleAnimationClasses.cpp | 33 ++++++++++++++--------- client/battle/BattleAnimationClasses.h | 13 ++++----- client/battle/BattleEffectsController.cpp | 2 +- client/battle/BattleEffectsController.h | 7 +++++ 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/client/battle/BattleAnimationClasses.cpp b/client/battle/BattleAnimationClasses.cpp index 30f1eb2b7..a64e96ec2 100644 --- a/client/battle/BattleAnimationClasses.cpp +++ b/client/battle/BattleAnimationClasses.cpp @@ -871,42 +871,43 @@ uint32_t CastAnimation::getAttackClimaxFrame() const return maxFrames / 2; } -EffectAnimation::EffectAnimation(BattleInterface & owner, std::string animationName, int effects): +EffectAnimation::EffectAnimation(BattleInterface & owner, std::string animationName, int effects, bool reversed): BattleAnimation(owner), animation(std::make_shared(animationName)), effectFlags(effects), - effectFinished(false) + effectFinished(false), + reversed(reversed) { logAnim->debug("CPointEffectAnimation::init: effect %s", animationName); } -EffectAnimation::EffectAnimation(BattleInterface & owner, std::string animationName, std::vector hex, int effects): - EffectAnimation(owner, animationName, effects) +EffectAnimation::EffectAnimation(BattleInterface & owner, std::string animationName, std::vector hex, int effects, bool reversed): + EffectAnimation(owner, animationName, effects, reversed) { battlehexes = hex; } -EffectAnimation::EffectAnimation(BattleInterface & owner, std::string animationName, BattleHex hex, int effects): - EffectAnimation(owner, animationName, effects) +EffectAnimation::EffectAnimation(BattleInterface & owner, std::string animationName, BattleHex hex, int effects, bool reversed): + EffectAnimation(owner, animationName, effects, reversed) { assert(hex.isValid()); battlehexes.push_back(hex); } -EffectAnimation::EffectAnimation(BattleInterface & owner, std::string animationName, std::vector pos, int effects): - EffectAnimation(owner, animationName, effects) +EffectAnimation::EffectAnimation(BattleInterface & owner, std::string animationName, std::vector pos, int effects, bool reversed): + EffectAnimation(owner, animationName, effects, reversed) { positions = pos; } -EffectAnimation::EffectAnimation(BattleInterface & owner, std::string animationName, Point pos, int effects): - EffectAnimation(owner, animationName, effects) +EffectAnimation::EffectAnimation(BattleInterface & owner, std::string animationName, Point pos, int effects, bool reversed): + EffectAnimation(owner, animationName, effects, reversed) { positions.push_back(pos); } -EffectAnimation::EffectAnimation(BattleInterface & owner, std::string animationName, Point pos, BattleHex hex, int effects): - EffectAnimation(owner, animationName, effects) +EffectAnimation::EffectAnimation(BattleInterface & owner, std::string animationName, Point pos, BattleHex hex, int effects, bool reversed): + EffectAnimation(owner, animationName, effects, reversed) { assert(hex.isValid()); battlehexes.push_back(hex); @@ -924,6 +925,13 @@ bool EffectAnimation::init() return false; } + for (size_t i = 0; i < animation->size(size_t(BattleEffect::AnimType::DEFAULT)); ++i) + { + size_t current = animation->size(size_t(BattleEffect::AnimType::DEFAULT)) - 1 - i; + + animation->duplicateImage(size_t(BattleEffect::AnimType::DEFAULT), current, size_t(BattleEffect::AnimType::REVERSE)); + } + if (screenFill()) { for(int i=0; i * first->width() < owner.fieldController->pos.w ; ++i) @@ -935,6 +943,7 @@ bool EffectAnimation::init() be.effectID = ID; be.animation = animation; be.currentFrame = 0; + be.type = reversed ? BattleEffect::AnimType::REVERSE : BattleEffect::AnimType::DEFAULT; for (size_t i = 0; i < std::max(battlehexes.size(), positions.size()); ++i) { diff --git a/client/battle/BattleAnimationClasses.h b/client/battle/BattleAnimationClasses.h index 230f15709..82b9ae2ca 100644 --- a/client/battle/BattleAnimationClasses.h +++ b/client/battle/BattleAnimationClasses.h @@ -310,6 +310,7 @@ class EffectAnimation : public BattleAnimation { std::string soundName; bool effectFinished; + bool reversed; int effectFlags; std::shared_ptr animation; @@ -334,17 +335,17 @@ public: }; /// Create animation with screen-wide effect - EffectAnimation(BattleInterface & owner, std::string animationName, int effects = 0); + EffectAnimation(BattleInterface & owner, std::string animationName, int effects = 0, bool reversed = false); /// Create animation positioned at point(s). Note that positions must be are absolute, including battleint position offset - EffectAnimation(BattleInterface & owner, std::string animationName, Point pos , int effects = 0); - EffectAnimation(BattleInterface & owner, std::string animationName, std::vector pos , int effects = 0); + EffectAnimation(BattleInterface & owner, std::string animationName, Point pos , int effects = 0, bool reversed = false); + EffectAnimation(BattleInterface & owner, std::string animationName, std::vector pos , int effects = 0, bool reversed = false); /// Create animation positioned at certain hex(es) - EffectAnimation(BattleInterface & owner, std::string animationName, BattleHex hex , int effects = 0); - EffectAnimation(BattleInterface & owner, std::string animationName, std::vector hex, int effects = 0); + EffectAnimation(BattleInterface & owner, std::string animationName, BattleHex hex , int effects = 0, bool reversed = false); + EffectAnimation(BattleInterface & owner, std::string animationName, std::vector hex, int effects = 0, bool reversed = false); - EffectAnimation(BattleInterface & owner, std::string animationName, Point pos, BattleHex hex, int effects = 0); + EffectAnimation(BattleInterface & owner, std::string animationName, Point pos, BattleHex hex, int effects = 0, bool reversed = false); ~EffectAnimation(); bool init() override; diff --git a/client/battle/BattleEffectsController.cpp b/client/battle/BattleEffectsController.cpp index 28a83a72b..a995a13d8 100644 --- a/client/battle/BattleEffectsController.cpp +++ b/client/battle/BattleEffectsController.cpp @@ -122,7 +122,7 @@ void BattleEffectsController::collectRenderableObjects(BattleRenderer & renderer int currentFrame = static_cast(floor(elem.currentFrame)); currentFrame %= elem.animation->size(); - auto img = elem.animation->getImage(currentFrame); + auto img = elem.animation->getImage(currentFrame, static_cast(elem.type)); canvas.draw(img, elem.pos); }); diff --git a/client/battle/BattleEffectsController.h b/client/battle/BattleEffectsController.h index 49af24316..574b85212 100644 --- a/client/battle/BattleEffectsController.h +++ b/client/battle/BattleEffectsController.h @@ -30,6 +30,13 @@ class EffectAnimation; /// Struct for battle effect animation e.g. morale, prayer, armageddon, bless,... struct BattleEffect { + enum class AnimType : ui8 + { + DEFAULT = 0, //If we have such animation + REVERSE = 1 //Reverse DEFAULT will be used + }; + + AnimType type; Point pos; //position on the screen float currentFrame; std::shared_ptr animation;