CTradeBase.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * CTradeBase.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 "TradePanels.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class IMarket;
  14. class CGHeroInstance;
  15. VCMI_LIB_NAMESPACE_END
  16. class CButton;
  17. class CSlider;
  18. class CTradeBase
  19. {
  20. public:
  21. const IMarket * market;
  22. const CGHeroInstance * hero;
  23. //all indexes: 1 = left, 0 = right
  24. std::array<std::vector<std::shared_ptr<CTradeableItem>>, 2> items;
  25. std::shared_ptr<TradePanelBase> leftTradePanel;
  26. std::shared_ptr<TradePanelBase> rightTradePanel;
  27. //highlighted items (nullptr if no highlight)
  28. std::shared_ptr<CTradeableItem> hLeft;
  29. std::shared_ptr<CTradeableItem> hRight;
  30. std::shared_ptr<CLabel> lSubtitle;
  31. std::shared_ptr<CLabel> rSubtitle;
  32. std::shared_ptr<CButton> deal;
  33. std::shared_ptr<CSlider> offerSlider;
  34. std::vector<std::shared_ptr<CLabel>> labels;
  35. std::vector<std::shared_ptr<CButton>> buttons;
  36. std::vector<std::shared_ptr<CTextBox>> texts;
  37. CTradeBase(const IMarket * market, const CGHeroInstance * hero);
  38. void removeItems(const std::set<std::shared_ptr<CTradeableItem>> & toRemove);
  39. void removeItem(std::shared_ptr<CTradeableItem> item);
  40. void getEmptySlots(std::set<std::shared_ptr<CTradeableItem>> & toRemove);
  41. virtual void makeDeal() = 0;
  42. virtual void deselect();
  43. virtual void onSlotClickPressed(const std::shared_ptr<CTradeableItem> & newSlot, std::shared_ptr<CTradeableItem> & hCurSlot);
  44. virtual void updateSlots() {}; // TODO make pure virtual
  45. };
  46. // Market subclasses
  47. class CExperienceAltar : virtual public CTradeBase, virtual public CIntObject
  48. {
  49. public:
  50. std::shared_ptr<CLabel> expToLevel;
  51. std::shared_ptr<CLabel> expForHero;
  52. std::shared_ptr<CButton> sacrificeAllButton;
  53. const Point dealButtonPos = Point(269, 520);
  54. CExperienceAltar();
  55. virtual void sacrificeAll() = 0;
  56. virtual TExpType calcExpAltarForHero() = 0;
  57. };
  58. class CCreaturesSelling : virtual public CTradeBase, virtual public CIntObject
  59. {
  60. public:
  61. CCreaturesSelling();
  62. bool slotDeletingCheck(const std::shared_ptr<CTradeableItem> & slot);
  63. void updateSubtitle();
  64. void updateSlots() override;
  65. };
  66. class CResourcesMarket : virtual public CTradeBase, virtual public CIntObject
  67. {
  68. public:
  69. CResourcesMarket(EMarketMode marketMode);
  70. private:
  71. void updateSubtitles(EMarketMode marketMode);
  72. };