GUIClasses.h 16 KB

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