CTradeWindow.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #pragma once
  2. #include "CIntObjectClasses.h"
  3. #include "CArtifactHolder.h"
  4. /*
  5. * CTradeWindow.h, part of VCMI engine
  6. *
  7. * Authors: listed in file AUTHORS in main folder
  8. *
  9. * License: GNU General Public License v2.0 or later
  10. * Full text of license available in license.txt file, in main folder
  11. *
  12. */
  13. class IMarket;
  14. class CTradeWindow : public CWindowObject, public CWindowWithArtifacts //base for markets and altar of sacrifice
  15. {
  16. public:
  17. enum EType
  18. {
  19. RESOURCE, PLAYER, ARTIFACT_TYPE, CREATURE, CREATURE_PLACEHOLDER, ARTIFACT_PLACEHOLDER, ARTIFACT_INSTANCE
  20. };
  21. class CTradeableItem : public CIntObject
  22. {
  23. CAnimImage * image;
  24. std::string getFilename();
  25. int getIndex();
  26. public:
  27. const CArtifactInstance *hlp; //holds ptr to artifact instance id type artifact
  28. EType type;
  29. int id;
  30. const int serial;
  31. const bool left;
  32. std::string subtitle; //empty if default
  33. void setType(EType newType);
  34. void setID(int newID);
  35. const CArtifactInstance *getArtInstance() const;
  36. void setArtInstance(const CArtifactInstance *art);
  37. CFunctionList<void()> callback;
  38. bool downSelection;
  39. void showAllAt(const Point &dstPos, const std::string &customSub, SDL_Surface * to);
  40. void clickRight(tribool down, bool previousState);
  41. void hover (bool on);
  42. void showAll(SDL_Surface * to);
  43. void clickLeft(tribool down, bool previousState);
  44. std::string getName(int number = -1) const;
  45. CTradeableItem(Point pos, EType Type, int ID, bool Left, int Serial);
  46. };
  47. const IMarket *market;
  48. const CGHeroInstance *hero;
  49. CArtifactsOfHero *arts;
  50. //all indexes: 1 = left, 0 = right
  51. std::vector<CTradeableItem*> items[2];
  52. CTradeableItem *hLeft, *hRight; //highlighted items (nullptr if no highlight)
  53. EType itemsType[2];
  54. EMarketMode::EMarketMode mode;//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact
  55. CAdventureMapButton *ok, *max, *deal;
  56. CSlider *slider; //for choosing amount to be exchanged
  57. bool readyToTrade;
  58. CTradeWindow(std::string bgName, const IMarket *Market, const CGHeroInstance *Hero, EMarketMode::EMarketMode Mode); //c
  59. void showAll(SDL_Surface * to);
  60. void initSubs(bool Left);
  61. void initTypes();
  62. void initItems(bool Left);
  63. std::vector<int> *getItemsIds(bool Left); //nullptr if default
  64. void getPositionsFor(std::vector<Rect> &poss, bool Left, EType type) const;
  65. void removeItems(const std::set<CTradeableItem *> &toRemove);
  66. void removeItem(CTradeableItem * t);
  67. void getEmptySlots(std::set<CTradeableItem *> &toRemove);
  68. void setMode(EMarketMode::EMarketMode Mode); //mode setter
  69. void artifactSelected(CArtPlace *slot); //used when selling artifacts -> called when user clicked on artifact slot
  70. virtual void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const = 0;
  71. virtual void selectionChanged(bool side) = 0; //true == left
  72. virtual Point selectionOffset(bool Left) const = 0;
  73. virtual std::string selectionSubtitle(bool Left) const = 0;
  74. virtual void garrisonChanged() = 0;
  75. virtual void artifactsChanged(bool left) = 0;
  76. };
  77. class CMarketplaceWindow : public CTradeWindow
  78. {
  79. bool printButtonFor(EMarketMode::EMarketMode M) const;
  80. std::string getBackgroundForMode(EMarketMode::EMarketMode mode);
  81. public:
  82. int r1, r2; //suggested amounts of traded resources
  83. bool madeTransaction; //if player made at least one transaction
  84. CTextBox *traderText;
  85. void setMax();
  86. void sliderMoved(int to);
  87. void makeDeal();
  88. void selectionChanged(bool side); //true == left
  89. CMarketplaceWindow(const IMarket *Market, const CGHeroInstance *Hero = nullptr, EMarketMode::EMarketMode Mode = EMarketMode::RESOURCE_RESOURCE); //c-tor
  90. ~CMarketplaceWindow(); //d-tor
  91. Point selectionOffset(bool Left) const;
  92. std::string selectionSubtitle(bool Left) const;
  93. void garrisonChanged(); //removes creatures with count 0 from the list (apparently whole stack has been sold)
  94. void artifactsChanged(bool left);
  95. void resourceChanged(int type, int val);
  96. void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const;
  97. void updateTraderText();
  98. };
  99. class CAltarWindow : public CTradeWindow
  100. {
  101. CAnimImage * artIcon;
  102. public:
  103. CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode::EMarketMode Mode); //c-tor
  104. void getExpValues();
  105. ~CAltarWindow(); //d-tor
  106. std::vector<int> sacrificedUnits, //[slot_nr] -> how many creatures from that slot will be sacrificed
  107. expPerUnit;
  108. CAdventureMapButton *sacrificeAll, *sacrificeBackpack;
  109. CLabel *expToLevel, *expOnAltar;
  110. void selectionChanged(bool side); //true == left
  111. void SacrificeAll();
  112. void SacrificeBackpack();
  113. void putOnAltar(int backpackIndex);
  114. bool putOnAltar(CTradeableItem* altarSlot, const CArtifactInstance *art);
  115. void makeDeal();
  116. void showAll(SDL_Surface * to);
  117. void blockTrade();
  118. void sliderMoved(int to);
  119. void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const;
  120. void mimicCres();
  121. Point selectionOffset(bool Left) const;
  122. std::string selectionSubtitle(bool Left) const;
  123. void garrisonChanged();
  124. void artifactsChanged(bool left);
  125. void calcTotalExp();
  126. void setExpToLevel();
  127. void updateRight(CTradeableItem *toUpdate);
  128. void artifactPicked();
  129. int firstFreeSlot();
  130. void moveFromSlotToAltar(ArtifactPosition slotID, CTradeableItem* altarSlot, const CArtifactInstance *art);
  131. };