TradePanels.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * TradePanels.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. #include "../Images.h"
  13. #include "../../../lib/networkPacks/TradeItem.h"
  14. enum class EType
  15. {
  16. RESOURCE, PLAYER, ARTIFACT_TYPE, CREATURE, CREATURE_PLACEHOLDER, ARTIFACT_PLACEHOLDER, ARTIFACT_INSTANCE
  17. };
  18. class CTradeableItem : public SelectableSlot, public std::enable_shared_from_this<CTradeableItem>
  19. {
  20. public:
  21. std::shared_ptr<CAnimImage> image;
  22. AnimationPath getFilename();
  23. int getIndex();
  24. using ClickPressedFunctor = std::function<void(const std::shared_ptr<CTradeableItem>&)>;
  25. const CArtifactInstance * artInstance; //holds ptr to artifact instance id type artifact
  26. EType type;
  27. int id;
  28. const int serial;
  29. std::shared_ptr<CLabel> subtitle;
  30. ClickPressedFunctor clickPressedCallback;
  31. void setType(EType newType);
  32. void setID(int newID);
  33. const CArtifactInstance * getArtInstance() const;
  34. void setArtInstance(const CArtifactInstance * art);
  35. void showPopupWindow(const Point & cursorPosition) override;
  36. void hover(bool on) override;
  37. void clickPressed(const Point & cursorPosition) override;
  38. CTradeableItem(const Rect & area, EType Type, int ID, int Serial);
  39. };
  40. class TradePanelBase : public CIntObject
  41. {
  42. public:
  43. using UpdateSlotsFunctor = std::function<void()>;
  44. using DeleteSlotsCheck = std::function<bool(const std::shared_ptr<CTradeableItem>&)>;
  45. std::vector<std::shared_ptr<CTradeableItem>> slots;
  46. UpdateSlotsFunctor updateSlotsCallback;
  47. DeleteSlotsCheck deleteSlotsCheck;
  48. std::shared_ptr<CTradeableItem> selected;
  49. const int selectionWidth = 2;
  50. std::shared_ptr<CTradeableItem> selectedSlot;
  51. virtual void updateSlots();
  52. virtual void deselect();
  53. virtual void clearSubtitles();
  54. void updateOffer(CTradeableItem & slot, int, int);
  55. void setSelectedFrameIndex(const std::optional<size_t> & index);
  56. void setSelectedSubtitleText(const std::string & text);
  57. void clearSelectedSubtitleText();
  58. };
  59. class ResourcesPanel : public TradePanelBase
  60. {
  61. const std::vector<GameResID> resourcesForTrade =
  62. {
  63. GameResID::WOOD, GameResID::MERCURY, GameResID::ORE,
  64. GameResID::SULFUR, GameResID::CRYSTAL, GameResID::GEMS,
  65. GameResID::GOLD
  66. };
  67. const std::vector<Point> slotsPos =
  68. {
  69. Point(0, 0), Point(83, 0), Point(166, 0),
  70. Point(0, 79), Point(83, 79), Point(166, 79),
  71. Point(83, 158)
  72. };
  73. const Point slotDimension = Point(69, 66);
  74. const Point selectedPos = Point(83, 267);
  75. public:
  76. ResourcesPanel(const CTradeableItem::ClickPressedFunctor & clickPressedCallback, const UpdateSlotsFunctor & updateSubtitles);
  77. };
  78. class ArtifactsPanel : public TradePanelBase
  79. {
  80. const std::vector<Point> slotsPos =
  81. {
  82. Point(0, 0), Point(83, 0), Point(165, 0),
  83. Point(0, 79), Point(83, 79), Point(165, 79),
  84. Point(83, 158)
  85. };
  86. const size_t slotsForTrade = 7;
  87. const Point slotDimension = Point(69, 66);
  88. const Point selectedPos = Point(83, 266);
  89. public:
  90. ArtifactsPanel(const CTradeableItem::ClickPressedFunctor & clickPressedCallback,
  91. const UpdateSlotsFunctor & updateSubtitles, const std::vector<TradeItemBuy> & arts);
  92. };
  93. class PlayersPanel : public TradePanelBase
  94. {
  95. const std::vector<Point> slotsPos =
  96. {
  97. Point(0, 0), Point(83, 0), Point(166, 0),
  98. Point(0, 118), Point(83, 118), Point(166, 118),
  99. Point(83, 236)
  100. };
  101. const Point slotDimension = Point(58, 64);
  102. const Point selectedPos = Point(83, 367);
  103. public:
  104. explicit PlayersPanel(const CTradeableItem::ClickPressedFunctor & clickPressedCallback);
  105. };
  106. class CreaturesPanel : public TradePanelBase
  107. {
  108. const std::vector<Point> slotsPos =
  109. {
  110. Point(0, 0), Point(83, 0), Point(166, 0),
  111. Point(0, 98), Point(83, 98), Point(166, 98),
  112. Point(83, 196)
  113. };
  114. const Point slotDimension = Point(59, 64);
  115. const Point selectedPos = Point(83, 327);
  116. public:
  117. using slotsData = std::vector<std::tuple<CreatureID, SlotID, int>>;
  118. CreaturesPanel(const CTradeableItem::ClickPressedFunctor & clickPressedCallback, const slotsData & initialSlots);
  119. CreaturesPanel(const CTradeableItem::ClickPressedFunctor & clickPressedCallback,
  120. const std::vector<std::shared_ptr<CTradeableItem>> & srcSlots, bool emptySlots = true);
  121. };