CCreatureAnimation.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #pragma once
  2. #include "../CDefHandler.h"
  3. #include "../../client/CBitmapHandler.h"
  4. #include "../CAnimation.h"
  5. /*
  6. * CCreatureAnimation.h, part of VCMI engine
  7. *
  8. * Authors: listed in file AUTHORS in main folder
  9. *
  10. * License: GNU General Public License v2.0 or later
  11. * Full text of license available in license.txt file, in main folder
  12. *
  13. */
  14. struct SDL_Color;
  15. class CIntObject;
  16. /// Class which manages animations of creatures/units inside battles
  17. class CCreatureAnimation : public CIntObject
  18. {
  19. private:
  20. int totalEntries, DEFType, totalBlocks;
  21. struct SEntry
  22. {
  23. int offset;
  24. int group;
  25. } ;
  26. std::vector<SEntry> SEntries ;
  27. std::string defName, curDir;
  28. template<int bpp>
  29. void putPixel(
  30. SDL_Surface * dest,
  31. const int & ftcpX,
  32. const int & ftcpY,
  33. const SDL_Color & color,
  34. const ui8 & palc,
  35. const bool & yellowBorder,
  36. const bool & blueBorder,
  37. const ui8 & animCount
  38. ) const;
  39. ////////////
  40. ui8 * FDef; //animation raw data
  41. int curFrame, internalFrame; //number of currently displayed frame
  42. ui32 frames; //number of frames
  43. CCreatureAnim::EAnimType type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1])
  44. template<int bpp>
  45. int nextFrameT(SDL_Surface * dest, int x, int y, bool attacker, ui8 animCount, bool incrementFrame = true, bool yellowBorder = false, bool blueBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next
  46. int nextFrameMiddle(SDL_Surface * dest, int x, int y, bool attacker, ui8 animCount, bool IncrementFrame = true, bool yellowBorder = false, bool blueBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next
  47. std::map<int, std::vector<int> > frameGroups; //groups of frames; [groupID] -> vector of frame IDs in group
  48. bool once;
  49. public:
  50. int fullWidth, fullHeight; //read-only, please!
  51. CCreatureAnimation(std::string name); //c-tor
  52. ~CCreatureAnimation(); //d-tor
  53. void setType(CCreatureAnim::EAnimType type); //sets type of animation and cleares framecount
  54. CCreatureAnim::EAnimType getType() const; //returns type of animation
  55. int nextFrame(SDL_Surface * dest, int x, int y, bool attacker, ui8 animCount, bool incrementFrame = true, bool yellowBorder = false, bool blueBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next
  56. void incrementFrame();
  57. int getFrame() const; // Gets the current frame ID relative to DEF file.
  58. int getAnimationFrame() const; // Gets the current frame ID relative to frame group.
  59. bool onFirstFrameInGroup();
  60. bool onLastFrameInGroup();
  61. void playOnce(CCreatureAnim::EAnimType type); //plays once given stage of animation, then resets to 2
  62. int framesInGroup(CCreatureAnim::EAnimType group) const; //retirns number of fromes in given group
  63. };