TradePanels.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. const bool left;
  30. std::string subtitle;
  31. ClickPressedFunctor clickPressedCallback;
  32. void setType(EType newType);
  33. void setID(int newID);
  34. const CArtifactInstance * getArtInstance() const;
  35. void setArtInstance(const CArtifactInstance * art);
  36. bool downSelection;
  37. void showAllAt(const Point & dstPos, const std::string & customSub, Canvas & to);
  38. void showPopupWindow(const Point & cursorPosition) override;
  39. void hover(bool on) override;
  40. void showAll(Canvas & to) override;
  41. void clickPressed(const Point & cursorPosition) override;
  42. std::string getName(int number = -1) const;
  43. CTradeableItem(const Rect & area, EType Type, int ID, bool Left, int Serial);
  44. };
  45. class TradePanelBase : public CIntObject
  46. {
  47. public:
  48. using UpdateSlotsFunctor = std::function<void()>;
  49. using DeleteSlotsCheck = std::function<bool(const std::shared_ptr<CTradeableItem>&)>;
  50. std::vector<std::shared_ptr<CTradeableItem>> slots;
  51. UpdateSlotsFunctor updateSlotsCallback;
  52. DeleteSlotsCheck deleteSlotsCheck;
  53. std::shared_ptr<CTradeableItem> selected;
  54. const int selectionWidth = 2;
  55. std::shared_ptr<CAnimImage> selectedImage;
  56. std::shared_ptr<CLabel> selectedSubtitle;
  57. virtual void updateSlots();
  58. virtual void deselect();
  59. virtual void clearSubtitles();
  60. void updateOffer(CTradeableItem & slot, int, int);
  61. void deleteSlots();
  62. void setSelectedFrameIndex(std::optional<size_t> index);
  63. };
  64. class ResourcesPanel : public TradePanelBase
  65. {
  66. const std::vector<GameResID> resourcesForTrade =
  67. {
  68. GameResID::WOOD, GameResID::MERCURY, GameResID::ORE,
  69. GameResID::SULFUR, GameResID::CRYSTAL, GameResID::GEMS,
  70. GameResID::GOLD
  71. };
  72. const std::vector<Point> slotsPos =
  73. {
  74. Point(0, 0), Point(83, 0), Point(166, 0),
  75. Point(0, 79), Point(83, 79), Point(166, 79),
  76. Point(83, 158)
  77. };
  78. const Point slotDimension = Point(69, 66);
  79. const Point selectedImagePos = Point(102, 276);
  80. const Point selectedSubtitlePos = Point(118, 324);
  81. public:
  82. ResourcesPanel(CTradeableItem::ClickPressedFunctor clickPressedCallback, UpdateSlotsFunctor updateSubtitles);
  83. };
  84. class ArtifactsPanel : public TradePanelBase
  85. {
  86. const std::vector<Point> slotsPos =
  87. {
  88. Point(0, 0), Point(83, 0), Point(166, 0),
  89. Point(0, 79), Point(83, 79), Point(166, 79),
  90. Point(83, 158)
  91. };
  92. const size_t slotsForTrade = 7;
  93. const Point slotDimension = Point(69, 66);
  94. public:
  95. ArtifactsPanel(CTradeableItem::ClickPressedFunctor clickPressedCallback, UpdateSlotsFunctor updateSubtitles,
  96. const std::vector<TradeItemBuy> & arts);
  97. };
  98. class PlayersPanel : public TradePanelBase
  99. {
  100. const std::vector<Point> slotsPos =
  101. {
  102. Point(0, 0), Point(83, 0), Point(166, 0),
  103. Point(0, 118), Point(83, 118), Point(166, 118),
  104. Point(83, 236)
  105. };
  106. const Point slotDimension = Point(58, 64);
  107. public:
  108. explicit PlayersPanel(CTradeableItem::ClickPressedFunctor clickPressedCallback);
  109. };
  110. class CreaturesPanel : public TradePanelBase
  111. {
  112. const std::vector<Point> slotsPos =
  113. {
  114. Point(0, 0), Point(83, 0), Point(166, 0),
  115. Point(0, 98), Point(83, 98), Point(166, 98),
  116. Point(83, 196)
  117. };
  118. const Point slotDimension = Point(58, 64);
  119. const Point selectedImagePos = Point(83, 327);
  120. const Point selectedSubtitlePos = Point(113, 403);
  121. public:
  122. using slotsData = std::vector<std::tuple<CreatureID, SlotID, int>>;
  123. CreaturesPanel(CTradeableItem::ClickPressedFunctor clickPressedCallback, const slotsData & initialSlots);
  124. CreaturesPanel(CTradeableItem::ClickPressedFunctor clickPressedCallback,
  125. const std::vector<std::shared_ptr<CTradeableItem>> & srcSlots, bool emptySlots = true);
  126. };