GUIClasses.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. /*
  2. * GUIClasses.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 "../lib/ResourceSet.h"
  12. #include "../widgets/CExchangeController.h"
  13. #include "../widgets/CWindowWithArtifacts.h"
  14. #include "../widgets/Images.h"
  15. VCMI_LIB_NAMESPACE_BEGIN
  16. class CGObjectInstance;
  17. class CGDwelling;
  18. class IMarket;
  19. VCMI_LIB_NAMESPACE_END
  20. class CreatureCostBox;
  21. class CCreaturePic;
  22. class MoraleLuckBox;
  23. class CHeroArea;
  24. class CSlider;
  25. class CComponentBox;
  26. class CTextInput;
  27. class CListBox;
  28. class CLabelGroup;
  29. class CGStatusBar;
  30. class CTextBox;
  31. class CGarrisonInt;
  32. class CGarrisonSlot;
  33. enum class EUserEvent;
  34. /// Recruitment window where you can recruit creatures
  35. class CRecruitmentWindow : public CStatusbarWindow
  36. {
  37. class CCreatureCard : public CIntObject, public std::enable_shared_from_this<CCreatureCard>
  38. {
  39. CRecruitmentWindow * parent;
  40. std::shared_ptr<CCreaturePic> animation;
  41. bool selected;
  42. public:
  43. const CCreature * creature;
  44. si32 amount;
  45. void select(bool on);
  46. CCreatureCard(CRecruitmentWindow * window, const CCreature * crea, int totalAmount);
  47. void clickPressed(const Point & cursorPosition) override;
  48. void showPopupWindow(const Point & cursorPosition) override;
  49. void showAll(Canvas & to) override;
  50. };
  51. std::function<void(CreatureID,int)> onRecruit; //void (int ID, int amount) <-- call to recruit creatures
  52. int level;
  53. const CArmedInstance * dst;
  54. std::shared_ptr<CCreatureCard> selected;
  55. std::vector<std::shared_ptr<CCreatureCard>> cards;
  56. std::shared_ptr<CSlider> slider;
  57. std::shared_ptr<CButton> maxButton;
  58. std::shared_ptr<CButton> buyButton;
  59. std::shared_ptr<CButton> cancelButton;
  60. std::shared_ptr<CLabel> title;
  61. std::shared_ptr<CLabel> availableValue;
  62. std::shared_ptr<CLabel> toRecruitValue;
  63. std::shared_ptr<CLabel> availableTitle;
  64. std::shared_ptr<CLabel> toRecruitTitle;
  65. std::shared_ptr<CreatureCostBox> costPerTroopValue;
  66. std::shared_ptr<CreatureCostBox> totalCostValue;
  67. void select(std::shared_ptr<CCreatureCard> card);
  68. void buy();
  69. void sliderMoved(int to);
  70. void showAll(Canvas & to) override;
  71. public:
  72. const CGDwelling * const dwelling;
  73. CRecruitmentWindow(const CGDwelling * Dwelling, int Level, const CArmedInstance * Dst, const std::function<void(CreatureID,int)> & Recruit, int y_offset = 0);
  74. void availableCreaturesChanged();
  75. };
  76. /// Split window where creatures can be split up into two single unit stacks
  77. class CSplitWindow : public CWindowObject
  78. {
  79. std::function<void(int, int)> callback;
  80. int leftAmount;
  81. int rightAmount;
  82. int leftMin;
  83. int rightMin;
  84. std::shared_ptr<CLabel> title;
  85. std::shared_ptr<CSlider> slider;
  86. std::shared_ptr<CCreaturePic> animLeft;
  87. std::shared_ptr<CCreaturePic> animRight;
  88. std::shared_ptr<CButton> ok;
  89. std::shared_ptr<CButton> cancel;
  90. std::shared_ptr<CTextInput> leftInput;
  91. std::shared_ptr<CTextInput> rightInput;
  92. void setAmountText(std::string text, bool left);
  93. void setAmount(int value, bool left);
  94. void sliderMoved(int value);
  95. void apply();
  96. public:
  97. /**
  98. * creature - displayed creature
  99. * callback(leftAmount, rightAmount) - function to call on close
  100. * leftMin, rightMin - minimal amount of creatures in each stack
  101. * leftAmount, rightAmount - amount of creatures in each stack
  102. */
  103. CSplitWindow(const CCreature * creature, std::function<void(int, int)> callback, int leftMin, int rightMin, int leftAmount, int rightAmount);
  104. };
  105. /// Raised up level window where you can select one out of two skills
  106. class CLevelWindow : public CWindowObject
  107. {
  108. std::shared_ptr<CAnimImage> portrait;
  109. std::shared_ptr<CButton> ok;
  110. std::shared_ptr<CLabel> mainTitle;
  111. std::shared_ptr<CLabel> levelTitle;
  112. std::shared_ptr<CAnimImage> skillIcon;
  113. std::shared_ptr<CLabel> skillValue;
  114. std::shared_ptr<CComponentBox> box; //skills to select
  115. std::function<void(ui32)> cb;
  116. void selectionChanged(unsigned to);
  117. public:
  118. CLevelWindow(const CGHeroInstance *hero, PrimarySkill pskill, std::vector<SecondarySkill> &skills, std::function<void(ui32)> callback);
  119. ~CLevelWindow();
  120. };
  121. /// Town portal, castle gate window
  122. class CObjectListWindow : public CWindowObject
  123. {
  124. class CItem : public CIntObject
  125. {
  126. CObjectListWindow * parent;
  127. std::shared_ptr<CLabel> text;
  128. std::shared_ptr<CPicture> border;
  129. public:
  130. const size_t index;
  131. CItem(CObjectListWindow * parent, size_t id, std::string text);
  132. void select(bool on);
  133. void clickPressed(const Point & cursorPosition) override;
  134. void clickDouble(const Point & cursorPosition) override;
  135. };
  136. std::function<void(int)> onSelect;//called when OK button is pressed, returns id of selected item.
  137. std::shared_ptr<CIntObject> titleWidget;
  138. std::shared_ptr<CLabel> title;
  139. std::shared_ptr<CLabel> descr;
  140. std::shared_ptr<CListBox> list;
  141. std::shared_ptr<CButton> ok;
  142. std::shared_ptr<CButton> exit;
  143. std::vector< std::pair<int, std::string> > items;//all items present in list
  144. void init(std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr);
  145. void exitPressed();
  146. public:
  147. size_t selected;//index of currently selected item
  148. std::function<void()> onExit;//optional exit callback
  149. /// Callback will be called when OK button is pressed, returns id of selected item. initState = initially selected item
  150. /// Image can be nullptr
  151. ///item names will be taken from map objects
  152. CObjectListWindow(const std::vector<int> &_items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback, size_t initialSelection = 0);
  153. CObjectListWindow(const std::vector<std::string> &_items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback, size_t initialSelection = 0);
  154. std::shared_ptr<CIntObject> genItem(size_t index);
  155. void elementSelected();//call callback and close this window
  156. void changeSelection(size_t which);
  157. void keyPressed(EShortcut key) override;
  158. };
  159. class CTavernWindow : public CStatusbarWindow
  160. {
  161. public:
  162. class HeroPortrait : public CIntObject
  163. {
  164. public:
  165. std::string hoverName;
  166. std::string description; // "XXX is a level Y ZZZ with N artifacts"
  167. const CGHeroInstance * h;
  168. void clickPressed(const Point & cursorPosition) override;
  169. void showPopupWindow(const Point & cursorPosition) override;
  170. void hover (bool on) override;
  171. HeroPortrait(int & sel, int id, int x, int y, const CGHeroInstance * H);
  172. private:
  173. int *_sel;
  174. const int _id;
  175. std::shared_ptr<CAnimImage> portrait;
  176. };
  177. //recruitable heroes
  178. std::shared_ptr<HeroPortrait> h1;
  179. std::shared_ptr<HeroPortrait> h2; //recruitable heroes
  180. int selected;//0 (left) or 1 (right)
  181. int oldSelected;//0 (left) or 1 (right)
  182. std::shared_ptr<CButton> thiefGuild;
  183. std::shared_ptr<CButton> cancel;
  184. std::shared_ptr<CButton> recruit;
  185. const CGObjectInstance * tavernObj;
  186. std::shared_ptr<CLabel> title;
  187. std::shared_ptr<CLabel> cost;
  188. std::shared_ptr<CLabel> heroesForHire;
  189. std::shared_ptr<CTextBox> heroDescription;
  190. std::shared_ptr<CTextBox> rumor;
  191. CTavernWindow(const CGObjectInstance * TavernObj);
  192. ~CTavernWindow();
  193. void recruitb();
  194. void thievesguildb();
  195. void show(Canvas & to) override;
  196. };
  197. class CExchangeWindow : public CStatusbarWindow, public IGarrisonHolder, public CWindowWithArtifacts
  198. {
  199. std::array<std::shared_ptr<CLabel>, 2> titles;
  200. std::vector<std::shared_ptr<CAnimImage>> primSkillImages;//shared for both heroes
  201. std::array<std::vector<std::shared_ptr<CLabel>>, 2> primSkillValues;
  202. std::array<std::vector<std::shared_ptr<CAnimImage>>, 2> secSkillIcons;
  203. std::array<std::shared_ptr<CAnimImage>, 2> specImages;
  204. std::array<std::shared_ptr<CAnimImage>, 2> expImages;
  205. std::array<std::shared_ptr<CLabel>, 2> expValues;
  206. std::array<std::shared_ptr<CAnimImage>, 2> manaImages;
  207. std::array<std::shared_ptr<CLabel>, 2> manaValues;
  208. std::vector<std::shared_ptr<LRClickableAreaWTextComp>> primSkillAreas;
  209. std::array<std::vector<std::shared_ptr<LRClickableAreaWTextComp>>, 2> secSkillAreas;
  210. std::array<std::shared_ptr<CHeroArea>, 2> heroAreas;
  211. std::array<std::shared_ptr<LRClickableAreaWText>, 2> specialtyAreas;
  212. std::array<std::shared_ptr<LRClickableAreaWText>, 2> experienceAreas;
  213. std::array<std::shared_ptr<LRClickableAreaWText>, 2> spellPointsAreas;
  214. std::array<std::shared_ptr<MoraleLuckBox>, 2> morale;
  215. std::array<std::shared_ptr<MoraleLuckBox>, 2> luck;
  216. std::shared_ptr<CButton> quit;
  217. std::array<std::shared_ptr<CButton>, 2> questlogButton;
  218. std::shared_ptr<CGarrisonInt> garr;
  219. std::shared_ptr<CButton> moveAllGarrButtonLeft;
  220. std::shared_ptr<CButton> exchangeGarrButton;
  221. std::shared_ptr<CButton> moveAllGarrButtonRight;
  222. std::shared_ptr<CButton> moveArtifactsButtonLeft;
  223. std::shared_ptr<CButton> exchangeArtifactsButton;
  224. std::shared_ptr<CButton> moveArtifactsButtonRight;
  225. std::vector<std::shared_ptr<CButton>> moveStackLeftButtons;
  226. std::vector<std::shared_ptr<CButton>> moveStackRightButtons;
  227. std::shared_ptr<CButton> backpackButtonLeft;
  228. std::shared_ptr<CButton> backpackButtonRight;
  229. CExchangeController controller;
  230. public:
  231. std::array<const CGHeroInstance *, 2> heroInst;
  232. std::array<std::shared_ptr<CArtifactsOfHeroMain>, 2> artifs;
  233. void updateGarrisons() override;
  234. void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right
  235. void updateWidgets();
  236. const CGarrisonSlot * getSelectedSlotID() const;
  237. CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2, QueryID queryID);
  238. };
  239. /// Here you can buy ships
  240. class CShipyardWindow : public CStatusbarWindow
  241. {
  242. std::shared_ptr<CPicture> bgWater;
  243. std::shared_ptr<CAnimImage> bgShip;
  244. std::shared_ptr<CLabel> title;
  245. std::shared_ptr<CLabel> costLabel;
  246. std::shared_ptr<CAnimImage> woodPic;
  247. std::shared_ptr<CAnimImage> goldPic;
  248. std::shared_ptr<CLabel> woodCost;
  249. std::shared_ptr<CLabel> goldCost;
  250. std::shared_ptr<CButton> build;
  251. std::shared_ptr<CButton> quit;
  252. public:
  253. CShipyardWindow(const TResources & cost, int state, BoatId boatType, const std::function<void()> & onBuy);
  254. };
  255. /// Creature transformer window
  256. class CTransformerWindow : public CStatusbarWindow, public IGarrisonHolder
  257. {
  258. class CItem : public CIntObject
  259. {
  260. public:
  261. int id;//position of creature in hero army
  262. bool left;//position of the item
  263. int size; //size of creature stack
  264. CTransformerWindow * parent;
  265. std::shared_ptr<CAnimImage> icon;
  266. std::shared_ptr<CLabel> count;
  267. void move();
  268. void clickPressed(const Point & cursorPosition) override;
  269. void update();
  270. CItem(CTransformerWindow * parent, int size, int id);
  271. };
  272. const CArmedInstance * army;//object with army for transforming (hero or town)
  273. const CGHeroInstance * hero;//only if we have hero in town
  274. const IMarket * market;//market, town garrison is used if hero == nullptr
  275. std::shared_ptr<CLabel> titleLeft;
  276. std::shared_ptr<CLabel> titleRight;
  277. std::shared_ptr<CTextBox> helpLeft;
  278. std::shared_ptr<CTextBox> helpRight;
  279. std::vector<std::shared_ptr<CItem>> items;
  280. std::shared_ptr<CButton> all;
  281. std::shared_ptr<CButton> convert;
  282. std::shared_ptr<CButton> cancel;
  283. public:
  284. void makeDeal();
  285. void addAll();
  286. void updateGarrisons() override;
  287. CTransformerWindow(const IMarket * _market, const CGHeroInstance * _hero);
  288. };
  289. class CUniversityWindow : public CStatusbarWindow
  290. {
  291. class CItem : public CIntObject
  292. {
  293. std::shared_ptr<CAnimImage> icon;
  294. std::shared_ptr<CAnimImage> topBar;
  295. std::shared_ptr<CAnimImage> bottomBar;
  296. std::shared_ptr<CLabel> name;
  297. std::shared_ptr<CLabel> level;
  298. public:
  299. int ID;//id of selected skill
  300. CUniversityWindow * parent;
  301. void showAll(Canvas & to) override;
  302. void clickPressed(const Point & cursorPosition) override;
  303. void showPopupWindow(const Point & cursorPosition) override;
  304. void hover(bool on) override;
  305. int state();//0=can't learn, 1=learned, 2=can learn
  306. CItem(CUniversityWindow * _parent, int _ID, int X, int Y);
  307. };
  308. const CGHeroInstance * hero;
  309. const IMarket * market;
  310. std::shared_ptr<CAnimation> bars;
  311. std::vector<std::shared_ptr<CItem>> items;
  312. std::shared_ptr<CButton> cancel;
  313. std::shared_ptr<CIntObject> titlePic;
  314. std::shared_ptr<CLabel> title;
  315. std::shared_ptr<CTextBox> clerkSpeech;
  316. public:
  317. CUniversityWindow(const CGHeroInstance * _hero, const IMarket * _market);
  318. void makeDeal(int skill);
  319. };
  320. /// Confirmation window for University
  321. class CUnivConfirmWindow : public CStatusbarWindow
  322. {
  323. std::shared_ptr<CTextBox> clerkSpeech;
  324. std::shared_ptr<CLabel> name;
  325. std::shared_ptr<CLabel> level;
  326. std::shared_ptr<CAnimImage> icon;
  327. CUniversityWindow * owner;
  328. std::shared_ptr<CButton> confirm;
  329. std::shared_ptr<CButton> cancel;
  330. std::shared_ptr<CAnimImage> costIcon;
  331. std::shared_ptr<CLabel> cost;
  332. void makeDeal(int skill);
  333. public:
  334. CUnivConfirmWindow(CUniversityWindow * PARENT, int SKILL, bool available);
  335. };
  336. /// Garrison window where you can take creatures out of the hero to place it on the garrison
  337. class CGarrisonWindow : public CWindowObject, public IGarrisonHolder
  338. {
  339. std::shared_ptr<CLabel> title;
  340. std::shared_ptr<CAnimImage> banner;
  341. std::shared_ptr<CAnimImage> portrait;
  342. std::shared_ptr<CGarrisonInt> garr;
  343. public:
  344. std::shared_ptr<CButton> quit;
  345. CGarrisonWindow(const CArmedInstance * up, const CGHeroInstance * down, bool removableUnits);
  346. void updateGarrisons() override;
  347. };
  348. /// Hill fort is the building where you can upgrade units
  349. class CHillFortWindow : public CStatusbarWindow, public IGarrisonHolder
  350. {
  351. private:
  352. static const int slotsCount = 7;
  353. //todo: mithril support
  354. static const int resCount = 7;
  355. const CGObjectInstance * fort;
  356. const CGHeroInstance * hero;
  357. std::shared_ptr<CLabel> title;
  358. std::shared_ptr<CHeroArea> heroPic;
  359. std::array<std::shared_ptr<CAnimImage>, resCount> totalIcons;
  360. std::array<std::shared_ptr<CLabel>, resCount> totalLabels;
  361. std::array<std::shared_ptr<CButton>, slotsCount> upgrade;//upgrade single creature
  362. std::array<int, slotsCount + 1> currState;//current state of slot - to avoid calls to getState or updating buttons
  363. //there is a place for only 2 resources per slot
  364. std::array< std::array<std::shared_ptr<CAnimImage>, 2>, slotsCount> slotIcons;
  365. std::array< std::array<std::shared_ptr<CLabel>, 2>, slotsCount> slotLabels;
  366. std::shared_ptr<CButton> upgradeAll;
  367. std::shared_ptr<CButton> quit;
  368. std::shared_ptr<CGarrisonInt> garr;
  369. std::string getDefForSlot(SlotID slot);
  370. std::string getTextForSlot(SlotID slot);
  371. void makeDeal(SlotID slot);//-1 for upgrading all creatures
  372. int getState(SlotID slot); //-1 = no creature 0=can't upgrade, 1=upgraded, 2=can upgrade
  373. public:
  374. CHillFortWindow(const CGHeroInstance * visitor, const CGObjectInstance * object);
  375. void updateGarrisons() override;//update buttons after garrison changes
  376. };
  377. class CThievesGuildWindow : public CStatusbarWindow
  378. {
  379. const CGObjectInstance * owner;
  380. std::shared_ptr<CButton> exitb;
  381. std::shared_ptr<CMinorResDataBar> resdatabar;
  382. std::vector<std::shared_ptr<CLabel>> rowHeaders;
  383. std::vector<std::shared_ptr<CAnimImage>> columnBackgrounds;
  384. std::vector<std::shared_ptr<CLabel>> columnHeaders;
  385. std::vector<std::shared_ptr<CAnimImage>> cells;
  386. std::vector<std::shared_ptr<CPicture>> banners;
  387. std::vector<std::shared_ptr<CAnimImage>> bestHeroes;
  388. std::vector<std::shared_ptr<CTextBox>> primSkillHeaders;
  389. std::vector<std::shared_ptr<CLabel>> primSkillValues;
  390. std::vector<std::shared_ptr<CAnimImage>> bestCreatures;
  391. std::vector<std::shared_ptr<CLabel>> personalities;
  392. public:
  393. CThievesGuildWindow(const CGObjectInstance * _owner);
  394. };