CArtifactHolder.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * CArtifactHolder.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 "MiscWidgets.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. struct ArtifactLocation;
  14. class CArtifactSet;
  15. VCMI_LIB_NAMESPACE_END
  16. class CAnimImage;
  17. class CArtifactHolder
  18. {
  19. public:
  20. virtual void artifactRemoved(const ArtifactLocation & artLoc)=0;
  21. virtual void artifactMoved(const ArtifactLocation & artLoc, const ArtifactLocation & destLoc, bool withRedraw)=0;
  22. virtual void artifactDisassembled(const ArtifactLocation & artLoc)=0;
  23. virtual void artifactAssembled(const ArtifactLocation & artLoc)=0;
  24. };
  25. class CArtPlace : public LRClickableAreaWTextComp
  26. {
  27. public:
  28. CArtPlace(Point position, const CArtifactInstance * art = nullptr);
  29. const CArtifactInstance* getArt();
  30. void lockSlot(bool on);
  31. bool isLocked() const;
  32. void selectSlot(bool on);
  33. bool isSelected() const;
  34. void showAll(Canvas & to) override;
  35. void setArtifact(const CArtifactInstance * art);
  36. protected:
  37. std::shared_ptr<CAnimImage> image;
  38. const CArtifactInstance * ourArt;
  39. int imageIndex;
  40. std::shared_ptr<CAnimImage> selection;
  41. bool locked;
  42. void setInternals(const CArtifactInstance * artInst);
  43. };
  44. class CCommanderArtPlace : public CArtPlace
  45. {
  46. protected:
  47. const CGHeroInstance * commanderOwner;
  48. ArtifactPosition commanderSlotID;
  49. void returnArtToHeroCallback();
  50. public:
  51. CCommanderArtPlace(Point position, const CGHeroInstance * commanderOwner, ArtifactPosition artSlot, const CArtifactInstance * art = nullptr);
  52. void clickPressed(const Point & cursorPosition) override;
  53. void showPopupWindow(const Point & cursorPosition) override;
  54. };
  55. class CHeroArtPlace: public CArtPlace
  56. {
  57. public:
  58. using ClickFunctor = std::function<void(CHeroArtPlace&)>;
  59. ArtifactPosition slot;
  60. ClickFunctor leftClickCallback;
  61. ClickFunctor showPopupCallback;
  62. CHeroArtPlace(Point position, const CArtifactInstance * art = nullptr);
  63. void clickPressed(const Point & cursorPosition) override;
  64. void showPopupWindow(const Point & cursorPosition) override;
  65. void addCombinedArtInfo(std::map<const CArtifact*, int> & arts);
  66. };
  67. namespace ArtifactUtilsClient
  68. {
  69. bool askToAssemble(const CGHeroInstance * hero, const ArtifactPosition & slot);
  70. bool askToDisassemble(const CGHeroInstance * hero, const ArtifactPosition & slot);
  71. }