2
0

CArtifactHolder.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 SelectableSlot
  26. {
  27. public:
  28. using ClickFunctor = std::function<void(CArtPlace&, const Point&)>;
  29. ArtifactPosition slot;
  30. CArtPlace(Point position, const CArtifactInstance * art = nullptr);
  31. const CArtifactInstance * getArt();
  32. void lockSlot(bool on);
  33. bool isLocked() const;
  34. void setArtifact(const CArtifactInstance * art);
  35. void setClickPressedCallback(ClickFunctor callback);
  36. void setShowPopupCallback(ClickFunctor callback);
  37. void setGestureCallback(ClickFunctor callback);
  38. void clickPressed(const Point & cursorPosition) override;
  39. void showPopupWindow(const Point & cursorPosition) override;
  40. void gesture(bool on, const Point & initialPosition, const Point & finalPosition) override;
  41. protected:
  42. std::shared_ptr<CAnimImage> image;
  43. const CArtifactInstance * ourArt;
  44. int imageIndex;
  45. bool locked;
  46. ClickFunctor clickPressedCallback;
  47. ClickFunctor showPopupCallback;
  48. ClickFunctor gestureCallback;
  49. void setInternals(const CArtifactInstance * artInst);
  50. };
  51. class CCommanderArtPlace : public CArtPlace
  52. {
  53. protected:
  54. const CGHeroInstance * commanderOwner;
  55. ArtifactPosition commanderSlotID;
  56. void returnArtToHeroCallback();
  57. public:
  58. CCommanderArtPlace(Point position, const CGHeroInstance * commanderOwner, ArtifactPosition artSlot, const CArtifactInstance * art = nullptr);
  59. void clickPressed(const Point & cursorPosition) override;
  60. void showPopupWindow(const Point & cursorPosition) override;
  61. };
  62. class CHeroArtPlace: public CArtPlace
  63. {
  64. public:
  65. CHeroArtPlace(Point position, const CArtifactInstance * art = nullptr);
  66. void addCombinedArtInfo(std::map<const CArtifact*, int> & arts);
  67. };
  68. namespace ArtifactUtilsClient
  69. {
  70. bool askToAssemble(const CGHeroInstance * hero, const ArtifactPosition & slot);
  71. bool askToDisassemble(const CGHeroInstance * hero, const ArtifactPosition & slot);
  72. }