GUIClasses.h 16 KB

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