CArtifactHolder.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #pragma once
  2. //#include "CComponent.h"
  3. #include "MiscWidgets.h"
  4. /*
  5. * CArtifactHolder.h, part of VCMI engine
  6. *
  7. * Authors: listed in file AUTHORS in main folder
  8. *
  9. * License: GNU General Public License v2.0 or later
  10. * Full text of license available in license.txt file, in main folder
  11. *
  12. */
  13. class CArtifactsOfHero;
  14. class CAnimImage;
  15. class CButton;
  16. struct ArtifactLocation;
  17. class CArtifactHolder
  18. {
  19. public:
  20. CArtifactHolder();
  21. virtual void artifactRemoved(const ArtifactLocation &artLoc)=0;
  22. virtual void artifactMoved(const ArtifactLocation &artLoc, const ArtifactLocation &destLoc)=0;
  23. virtual void artifactDisassembled(const ArtifactLocation &artLoc)=0;
  24. virtual void artifactAssembled(const ArtifactLocation &artLoc)=0;
  25. };
  26. class CWindowWithArtifacts : public CArtifactHolder
  27. {
  28. public:
  29. std::vector<CArtifactsOfHero *> artSets;
  30. void artifactRemoved(const ArtifactLocation &artLoc);
  31. void artifactMoved(const ArtifactLocation &artLoc, const ArtifactLocation &destLoc);
  32. void artifactDisassembled(const ArtifactLocation &artLoc);
  33. void artifactAssembled(const ArtifactLocation &artLoc);
  34. };
  35. /// Artifacts can be placed there. Gets shown at the hero window
  36. class CArtPlace: public LRClickableAreaWTextComp
  37. {
  38. CAnimImage *image;
  39. CAnimImage *selection;
  40. void createImage();
  41. public:
  42. // consider these members as const - change them only with appropriate methods e.g. lockSlot()
  43. bool locked;
  44. bool picked;
  45. bool marked;
  46. ArtifactPosition slotID; //Arts::EPOS enum + backpack starting from Arts::BACKPACK_START
  47. void lockSlot(bool on);
  48. void pickSlot(bool on);
  49. void selectSlot(bool on);
  50. CArtifactsOfHero * ourOwner;
  51. const CArtifactInstance * ourArt; // should be changed only with setArtifact()
  52. CArtPlace(Point position, const CArtifactInstance * Art = nullptr); //c-tor
  53. void clickLeft(tribool down, bool previousState);
  54. void clickRight(tribool down, bool previousState);
  55. void select ();
  56. void deselect ();
  57. void showAll(SDL_Surface * to);
  58. bool fitsHere (const CArtifactInstance * art) const; //returns true if given artifact can be placed here
  59. void setMeAsDest(bool backpackAsVoid = true);
  60. void setArtifact(const CArtifactInstance *art);
  61. };
  62. /// Contains artifacts of hero. Distincts which artifacts are worn or backpacked
  63. class CArtifactsOfHero : public CIntObject
  64. {
  65. const CGHeroInstance * curHero;
  66. std::map<ArtifactPosition, CArtPlace *> artWorn;
  67. std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!)
  68. int backpackPos; //number of first art visible in backpack (in hero's vector)
  69. public:
  70. struct SCommonPart
  71. {
  72. struct Artpos
  73. {
  74. ArtifactPosition slotID;
  75. const CArtifactsOfHero *AOH;
  76. const CArtifactInstance *art;
  77. Artpos();
  78. void clear();
  79. void setTo(const CArtPlace *place, bool dontTakeBackpack);
  80. bool valid();
  81. bool operator==(const ArtifactLocation &al) const;
  82. } src, dst;
  83. std::set<CArtifactsOfHero *> participants; // Needed to mark slots.
  84. void reset();
  85. } * commonInfo; //when we have more than one CArtifactsOfHero in one window with exchange possibility, we use this (eg. in exchange window); to be provided externally
  86. bool updateState; // Whether the commonInfo should be updated on setHero or not.
  87. CButton * leftArtRoll, * rightArtRoll;
  88. bool allowedAssembling;
  89. std::multiset<const CArtifactInstance*> artifactsOnAltar; //artifacts id that are technically present in backpack but in GUI are moved to the altar - they'll be omitted in backpack slots
  90. std::function<void(CArtPlace*)> highlightModeCallback; //if set, clicking on art place doesn't pick artifact but highlights the slot and calls this function
  91. void realizeCurrentTransaction(); //calls callback with parameters stored in commonInfo
  92. void artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst);
  93. void artifactRemoved(const ArtifactLocation &al);
  94. void artifactAssembled(const ArtifactLocation &al);
  95. void artifactDisassembled(const ArtifactLocation &al);
  96. CArtPlace *getArtPlace(int slot);//may return null
  97. void setHero(const CGHeroInstance * hero);
  98. const CGHeroInstance *getHero() const;
  99. void dispose(); //free resources not needed after closing windows and reset state
  100. void scrollBackpack(int dir); //dir==-1 => to left; dir==1 => to right
  101. void safeRedraw();
  102. void markPossibleSlots(const CArtifactInstance* art);
  103. void unmarkSlots(bool withRedraw = true); //unmarks slots in all visible AOHs
  104. void unmarkLocalSlots(bool withRedraw = true); //unmarks slots in that particular AOH
  105. void setSlotData (CArtPlace* artPlace, ArtifactPosition slotID);
  106. void updateWornSlots (bool redrawParent = true);
  107. void updateSlot(ArtifactPosition i);
  108. void eraseSlotData (CArtPlace* artPlace, ArtifactPosition slotID);
  109. CArtifactsOfHero(const Point& position, bool createCommonPart = false);
  110. //Alternative constructor, used if custom artifacts positioning required (Kingdom interface)
  111. CArtifactsOfHero(std::map<ArtifactPosition, CArtPlace *> ArtWorn, std::vector<CArtPlace *> Backpack,
  112. CButton *leftScroll, CButton *rightScroll, bool createCommonPart = false);
  113. ~CArtifactsOfHero(); //d-tor
  114. void updateParentWindow();
  115. friend class CArtPlace;
  116. };