CTradeBase.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 "Images.h"
  12. #include "../../lib/FunctionList.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class IMarket;
  15. class CGHeroInstance;
  16. VCMI_LIB_NAMESPACE_END
  17. class CButton;
  18. class CTextBox;
  19. class CTradeBase
  20. {
  21. public:
  22. enum EType
  23. {
  24. RESOURCE, PLAYER, ARTIFACT_TYPE, CREATURE, CREATURE_PLACEHOLDER, ARTIFACT_PLACEHOLDER, ARTIFACT_INSTANCE
  25. };
  26. class CTradeableItem : public CIntObject, public std::enable_shared_from_this<CTradeableItem>
  27. {
  28. std::shared_ptr<CAnimImage> image;
  29. AnimationPath getFilename();
  30. int getIndex();
  31. public:
  32. const CArtifactInstance * hlp; //holds ptr to artifact instance id type artifact
  33. EType type;
  34. int id;
  35. const int serial;
  36. const bool left;
  37. std::string subtitle; //empty if default
  38. std::function<void(std::shared_ptr<CTradeableItem> altarSlot)> clickPressedCallback;
  39. void setType(EType newType);
  40. void setID(int newID);
  41. const CArtifactInstance* getArtInstance() const;
  42. void setArtInstance(const CArtifactInstance * art);
  43. CFunctionList<void()> callback;
  44. bool downSelection;
  45. void showAllAt(const Point & dstPos, const std::string & customSub, Canvas & to);
  46. void showPopupWindow(const Point & cursorPosition) override;
  47. void hover(bool on) override;
  48. void showAll(Canvas & to) override;
  49. void clickPressed(const Point & cursorPosition) override;
  50. std::string getName(int number = -1) const;
  51. CTradeableItem(Point pos, EType Type, int ID, bool Left, int Serial);
  52. };
  53. const IMarket * market;
  54. const CGHeroInstance * hero;
  55. //all indexes: 1 = left, 0 = right
  56. std::array<std::vector<std::shared_ptr<CTradeableItem>>, 2> items;
  57. //highlighted items (nullptr if no highlight)
  58. std::shared_ptr<CTradeableItem> hLeft;
  59. std::shared_ptr<CTradeableItem> hRight;
  60. std::shared_ptr<CButton> deal;
  61. CTradeBase(const IMarket * market, const CGHeroInstance * hero);
  62. void removeItems(const std::set<std::shared_ptr<CTradeableItem>> & toRemove);
  63. void removeItem(std::shared_ptr<CTradeableItem> item);
  64. void getEmptySlots(std::set<std::shared_ptr<CTradeableItem>> & toRemove);
  65. virtual void makeDeal() = 0;
  66. protected:
  67. std::vector<std::shared_ptr<CLabel>> labels;
  68. std::vector<std::shared_ptr<CButton>> buttons;
  69. std::vector<std::shared_ptr<CTextBox>> texts;
  70. };