Animation.h 2.6 KB

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