BattleHero.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * BattleHero.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "BattleConstants.h"
  12. #include "../gui/CIntObject.h"
  13. #include "../../lib/FunctionList.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class CGHeroInstance;
  16. VCMI_LIB_NAMESPACE_END
  17. class CAnimation;
  18. class BattleInterface;
  19. class BattleRenderer;
  20. /// Hero battle animation
  21. class BattleHero : public CIntObject
  22. {
  23. bool defender;
  24. CFunctionList<void()> phaseFinishedCallback;
  25. std::shared_ptr<CAnimation> animation;
  26. std::shared_ptr<CAnimation> flagAnimation;
  27. const CGHeroInstance * hero; //this animation's hero instance
  28. const BattleInterface & owner; //battle interface to which this animation is assigned
  29. EHeroAnimType phase; //stage of animation
  30. EHeroAnimType nextPhase; //stage of animation to be set after current phase is fully displayed
  31. float currentSpeed;
  32. float currentFrame; //frame of animation
  33. float flagCurrentFrame;
  34. void switchToNextPhase();
  35. void render(Canvas & canvas); //prints next frame of animation to to
  36. public:
  37. const CGHeroInstance * instance();
  38. void setPhase(EHeroAnimType newPhase); //sets phase of hero animation
  39. void collectRenderableObjects(BattleRenderer & renderer);
  40. void tick(uint32_t msPassed) override;
  41. float getFrame() const;
  42. void onPhaseFinished(const std::function<void()> &);
  43. void pause();
  44. void play();
  45. void heroLeftClicked();
  46. void heroRightClicked();
  47. BattleHero(const BattleInterface & owner, const CGHeroInstance * hero, bool defender);
  48. };