CTradeWindow.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/markets/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. void setMode(EMarketMode Mode); //mode setter
  32. void artifactSelected(CArtPlace * slot); //used when selling artifacts -> called when user clicked on artifact slot
  33. virtual void selectionChanged(bool side) = 0; //true == left
  34. virtual Point selectionOffset(bool Left) const = 0;
  35. virtual std::string updateSlotSubtitle(bool Left) const = 0;
  36. virtual void updateGarrison() = 0;
  37. virtual void artifactsChanged(bool left) = 0;
  38. protected:
  39. std::function<void()> onWindowClosed;
  40. std::shared_ptr<CGStatusBar> statusBar;
  41. std::vector<std::shared_ptr<CPicture>> images;
  42. };
  43. class CMarketplaceWindow : public CTradeWindow
  44. {
  45. std::shared_ptr<CLabel> titleLabel;
  46. std::shared_ptr<CArtifactsOfHeroMarket> arts;
  47. bool printButtonFor(EMarketMode M) const;
  48. ImagePath getBackgroundForMode(EMarketMode mode);
  49. public:
  50. int r1, r2; //suggested amounts of traded resources
  51. bool madeTransaction; //if player made at least one transaction
  52. std::shared_ptr<CTextBox> traderText;
  53. void setMax();
  54. void sliderMoved(int to);
  55. void makeDeal() override;
  56. void selectionChanged(bool side) override; //true == left
  57. CMarketplaceWindow(const IMarket * Market, const CGHeroInstance * Hero, const std::function<void()> & onWindowClosed, EMarketMode Mode);
  58. ~CMarketplaceWindow();
  59. Point selectionOffset(bool Left) const override;
  60. std::string updateSlotSubtitle(bool Left) const override;
  61. void updateGarrison() override; //removes creatures with count 0 from the list (apparently whole stack has been sold)
  62. void artifactsChanged(bool left) override;
  63. void resourceChanged();
  64. void updateTraderText();
  65. };