TradePanels.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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, ARTIFACT
  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. EType type;
  26. int32_t id;
  27. const int32_t serial;
  28. std::shared_ptr<CLabel> subtitle;
  29. ClickPressedFunctor clickPressedCallback;
  30. void setType(EType newType);
  31. void setID(int32_t newID);
  32. void clear();
  33. void showPopupWindow(const Point & cursorPosition) override;
  34. void hover(bool on) override;
  35. void clickPressed(const Point & cursorPosition) override;
  36. CTradeableItem(const Rect & area, EType Type, int32_t ID, int32_t serial);
  37. };
  38. class TradePanelBase : public CIntObject
  39. {
  40. public:
  41. using UpdateSlotsFunctor = std::function<void()>;
  42. using DeleteSlotsCheck = std::function<bool(const std::shared_ptr<CTradeableItem>&)>;
  43. std::vector<std::shared_ptr<CTradeableItem>> slots;
  44. UpdateSlotsFunctor updateSlotsCallback;
  45. DeleteSlotsCheck deleteSlotsCheck;
  46. const int selectionWidth = 2;
  47. std::shared_ptr<CTradeableItem> showcaseSlot; // Separate slot that displays the contents for trading
  48. std::shared_ptr<CTradeableItem> highlightedSlot; // One of the slots highlighted by a frame
  49. virtual void update();
  50. virtual void deselect();
  51. virtual void clearSubtitles();
  52. void updateOffer(CTradeableItem & slot, int, int);
  53. void setShowcaseSubtitle(const std::string & text);
  54. int32_t getHighlightedItemId() const;
  55. void onSlotClickPressed(const std::shared_ptr<CTradeableItem> & newSlot);
  56. bool isHighlighted() const;
  57. };
  58. class ResourcesPanel : public TradePanelBase
  59. {
  60. const std::vector<GameResID> resourcesForTrade =
  61. {
  62. GameResID::WOOD, GameResID::MERCURY, GameResID::ORE,
  63. GameResID::SULFUR, GameResID::CRYSTAL, GameResID::GEMS,
  64. GameResID::GOLD
  65. };
  66. const std::vector<Point> slotsPos =
  67. {
  68. Point(0, 0), Point(83, 0), Point(166, 0),
  69. Point(0, 79), Point(83, 79), Point(166, 79),
  70. Point(83, 158)
  71. };
  72. const Point slotDimension = Point(69, 66);
  73. const Point selectedPos = Point(83, 267);
  74. public:
  75. ResourcesPanel(const CTradeableItem::ClickPressedFunctor & clickPressedCallback, const UpdateSlotsFunctor & updateSubtitles);
  76. };
  77. class ArtifactsPanel : public TradePanelBase
  78. {
  79. const std::vector<Point> slotsPos =
  80. {
  81. Point(0, 0), Point(83, 0), Point(165, 0),
  82. Point(0, 79), Point(83, 79), Point(165, 79),
  83. Point(83, 158)
  84. };
  85. const size_t slotsForTrade = 7;
  86. const Point slotDimension = Point(69, 68);
  87. const Point selectedPos = Point(83, 266);
  88. public:
  89. ArtifactsPanel(const CTradeableItem::ClickPressedFunctor & clickPressedCallback,
  90. const UpdateSlotsFunctor & updateSubtitles, const std::vector<TradeItemBuy> & arts);
  91. };
  92. class PlayersPanel : public TradePanelBase
  93. {
  94. const std::vector<Point> slotsPos =
  95. {
  96. Point(0, 0), Point(83, 0), Point(166, 0),
  97. Point(0, 118), Point(83, 118), Point(166, 118),
  98. Point(83, 236)
  99. };
  100. const Point slotDimension = Point(58, 64);
  101. const Point selectedPos = Point(83, 367);
  102. public:
  103. explicit PlayersPanel(const CTradeableItem::ClickPressedFunctor & clickPressedCallback);
  104. };
  105. class CreaturesPanel : public TradePanelBase
  106. {
  107. const std::vector<Point> slotsPos =
  108. {
  109. Point(0, 0), Point(83, 0), Point(166, 0),
  110. Point(0, 98), Point(83, 98), Point(166, 98),
  111. Point(83, 196)
  112. };
  113. const Point slotDimension = Point(59, 64);
  114. const Point selectedPos = Point(83, 327);
  115. public:
  116. using slotsData = std::vector<std::tuple<CreatureID, SlotID, int>>;
  117. CreaturesPanel(const CTradeableItem::ClickPressedFunctor & clickPressedCallback, const slotsData & initialSlots);
  118. CreaturesPanel(const CTradeableItem::ClickPressedFunctor & clickPressedCallback,
  119. const std::vector<std::shared_ptr<CTradeableItem>> & srcSlots, bool emptySlots = true);
  120. };
  121. class ArtifactsAltarPanel : public TradePanelBase
  122. {
  123. const std::vector<Point> slotsPos =
  124. {
  125. Point(0, 0), Point(54, 0), Point(108, 0),
  126. Point(162, 0), Point(216, 0), Point(0, 70),
  127. Point(54, 70), Point(108, 70), Point(162, 70),
  128. Point(216, 70), Point(0, 140), Point(54, 140),
  129. Point(108, 140), Point(162, 140), Point(216, 140),
  130. Point(0, 210), Point(54, 210), Point(108, 210),
  131. Point(162, 210), Point(216, 210), Point(81, 280),
  132. Point(135, 280)
  133. };
  134. const Point slotDimension = Point(69, 66);
  135. const Point selectedPos = Point(-48, 389);
  136. public:
  137. explicit ArtifactsAltarPanel(const CTradeableItem::ClickPressedFunctor & clickPressedCallback);
  138. };