CCreatureAnimation.h 3.1 KB

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