CCreatureAnimation.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 BMPPalette;
  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. int length;
  22. BMPPalette palette[256];
  23. struct SEntry
  24. {
  25. int offset;
  26. int group;
  27. } ;
  28. std::vector<SEntry> SEntries ;
  29. std::string defName, curDir;
  30. template<int bpp>
  31. void putPixel(
  32. SDL_Surface * dest,
  33. const int & ftcpX,
  34. const int & ftcpY,
  35. const BMPPalette & color,
  36. const ui8 & palc,
  37. const bool & yellowBorder,
  38. const bool & blueBorder,
  39. const ui8 & animCount
  40. ) const;
  41. ////////////
  42. ui8 * FDef; //animation raw data
  43. int curFrame, internalFrame; //number of currently displayed frame
  44. ui32 frames; //number of frames
  45. CCreatureAnim::EAnimType type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1])
  46. template<int bpp>
  47. 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
  48. 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
  49. std::map<int, std::vector<int> > frameGroups; //groups of frames; [groupID] -> vector of frame IDs in group
  50. bool once;
  51. public:
  52. int fullWidth, fullHeight; //read-only, please!
  53. CCreatureAnimation(std::string name); //c-tor
  54. ~CCreatureAnimation(); //d-tor
  55. void setType(CCreatureAnim::EAnimType type); //sets type of animation and cleares framecount
  56. CCreatureAnim::EAnimType getType() const; //returns type of animation
  57. 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
  58. void incrementFrame();
  59. int getFrame() const; // Gets the current frame ID relative to DEF file.
  60. int getAnimationFrame() const; // Gets the current frame ID relative to frame group.
  61. bool onFirstFrameInGroup();
  62. bool onLastFrameInGroup();
  63. void playOnce(CCreatureAnim::EAnimType type); //plays once given stage of animation, then resets to 2
  64. int framesInGroup(CCreatureAnim::EAnimType group) const; //retirns number of fromes in given group
  65. };