CTradeWindow.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * CTradeWindow.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 "../widgets/CTradeBase.h"
  12. #include "../widgets/CWindowWithArtifacts.h"
  13. #include "CWindowObject.h"
  14. class CSlider;
  15. class CGStatusBar;
  16. class CTradeWindow : public CTradeBase, public CWindowObject, public CWindowWithArtifacts //base for markets and altar of sacrifice
  17. {
  18. public:
  19. EType itemsType[2];
  20. EMarketMode mode;
  21. std::shared_ptr<CButton> ok;
  22. std::shared_ptr<CButton> max;
  23. std::shared_ptr<CSlider> slider; //for choosing amount to be exchanged
  24. bool readyToTrade;
  25. CTradeWindow(const ImagePath & bgName, const IMarket * Market, const CGHeroInstance * Hero, const std::function<void()> & onWindowClosed, EMarketMode Mode); //c
  26. void showAll(Canvas & to) override;
  27. void close() override;
  28. void initSubs(bool Left);
  29. void initTypes();
  30. void initItems(bool Left);
  31. std::vector<int> *getItemsIds(bool Left); //nullptr if default
  32. void getPositionsFor(std::vector<Rect> &poss, bool Left, EType type) const;
  33. void setMode(EMarketMode Mode); //mode setter
  34. void artifactSelected(CArtPlace * slot); //used when selling artifacts -> called when user clicked on artifact slot
  35. virtual void selectionChanged(bool side) = 0; //true == left
  36. virtual Point selectionOffset(bool Left) const = 0;
  37. virtual std::string updateSlotSubtitle(bool Left) const = 0;
  38. virtual void updateGarrison() = 0;
  39. virtual void artifactsChanged(bool left) = 0;
  40. protected:
  41. std::function<void()> onWindowClosed;
  42. std::shared_ptr<CGStatusBar> statusBar;
  43. std::vector<std::shared_ptr<CPicture>> images;
  44. };
  45. class CMarketplaceWindow : public CTradeWindow
  46. {
  47. std::shared_ptr<CLabel> titleLabel;
  48. std::shared_ptr<CArtifactsOfHeroMarket> arts;
  49. bool printButtonFor(EMarketMode M) const;
  50. ImagePath getBackgroundForMode(EMarketMode mode);
  51. public:
  52. int r1, r2; //suggested amounts of traded resources
  53. bool madeTransaction; //if player made at least one transaction
  54. std::shared_ptr<CTextBox> traderText;
  55. void setMax();
  56. void sliderMoved(int to);
  57. void makeDeal() override;
  58. void selectionChanged(bool side) override; //true == left
  59. CMarketplaceWindow(const IMarket * Market, const CGHeroInstance * Hero, const std::function<void()> & onWindowClosed, EMarketMode Mode);
  60. ~CMarketplaceWindow();
  61. Point selectionOffset(bool Left) const override;
  62. std::string updateSlotSubtitle(bool Left) const override;
  63. void updateGarrison() override; //removes creatures with count 0 from the list (apparently whole stack has been sold)
  64. void artifactsChanged(bool left) override;
  65. void resourceChanged();
  66. void updateTraderText();
  67. };