Animation.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Animation.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. //code is copied from vcmiclient/CAnimation.h with minimal changes
  12. #include "../lib/JsonNode.h"
  13. #include "../lib/GameConstants.h"
  14. #include <QRgb>
  15. #include <QImage>
  16. /*
  17. * Base class for images, can be used for non-animation pictures as well
  18. */
  19. class DefFile;
  20. /// Class for handling animation
  21. class Animation
  22. {
  23. private:
  24. //source[group][position] - file with this frame, if string is empty - image located in def file
  25. std::map<size_t, std::vector<JsonNode>> source;
  26. //bitmap[group][position], store objects with loaded bitmaps
  27. std::map<size_t, std::map<size_t, std::shared_ptr<QImage> > > images;
  28. //animation file name
  29. std::string name;
  30. bool preloaded;
  31. std::shared_ptr<DefFile> defFile;
  32. //loader, will be called by load(), require opened def file for loading from it. Returns true if image is loaded
  33. bool loadFrame(size_t frame, size_t group);
  34. //unloadFrame, returns true if image has been unloaded ( either deleted or decreased refCount)
  35. bool unloadFrame(size_t frame, size_t group);
  36. //initialize animation from file
  37. //void initFromJson(const JsonNode & input);
  38. void init();
  39. //to get rid of copy-pasting error message :]
  40. void printError(size_t frame, size_t group, std::string type) const;
  41. //not a very nice method to get image from another def file
  42. //TODO: remove after implementing resource manager
  43. std::shared_ptr<QImage> getFromExtraDef(std::string filename);
  44. public:
  45. Animation(std::string Name);
  46. Animation();
  47. ~Animation();
  48. //duplicates frame at [sourceGroup, sourceFrame] as last frame in targetGroup
  49. //and loads it if animation is preloaded
  50. void duplicateImage(size_t sourceGroup, size_t sourceFrame, size_t targetGroup);
  51. // adjust the color of the animation, used in battle spell effects, e.g. Cloned objects
  52. //add custom surface to the selected position.
  53. void setCustom(std::string filename, size_t frame, size_t group = 0);
  54. std::shared_ptr<QImage> getImage(size_t frame, size_t group = 0, bool verbose = true) const;
  55. //all available frames
  56. void load();
  57. void unload();
  58. void preload();
  59. //all frames from group
  60. void loadGroup (size_t group);
  61. void unloadGroup(size_t group);
  62. //single image
  63. void load (size_t frame, size_t group = 0);
  64. void unload(size_t frame, size_t group = 0);
  65. //total count of frames in group (including not loaded)
  66. size_t size(size_t group = 0) const;
  67. void horizontalFlip();
  68. void verticalFlip();
  69. void playerColored(PlayerColor player);
  70. void createFlippedGroup(const size_t sourceGroup, const size_t targetGroup);
  71. };