GUIClasses.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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/GameConstants.h"
  12. #include "../lib/ResourceSet.h"
  13. #include "../lib/CConfigHandler.h"
  14. #include "../widgets/CArtifactHolder.h"
  15. #include "../widgets/CGarrisonInt.h"
  16. #include "../widgets/Images.h"
  17. #include "../windows/CWindowObject.h"
  18. class CGDwelling;
  19. class CreatureCostBox;
  20. class IMarket;
  21. class CCreaturePic;
  22. class MoraleLuckBox;
  23. class CHeroArea;
  24. class CMinorResDataBar;
  25. class CSlider;
  26. class CComponentBox;
  27. class CTextInput;
  28. class CListBox;
  29. class CLabelGroup;
  30. class CToggleButton;
  31. class CToggleGroup;
  32. class CVolumeSlider;
  33. class CGStatusBar;
  34. class CTextBox;
  35. class CResDataBar;
  36. class CHeroWithMaybePickedArtifact;
  37. /// Recruitment window where you can recruit creatures
  38. class CRecruitmentWindow : public CWindowObject
  39. {
  40. class CCreatureCard : public CIntObject, public std::enable_shared_from_this<CCreatureCard>
  41. {
  42. CRecruitmentWindow * parent;
  43. std::shared_ptr<CCreaturePic> animation;
  44. bool selected;
  45. public:
  46. const CCreature * creature;
  47. si32 amount;
  48. void select(bool on);
  49. CCreatureCard(CRecruitmentWindow * window, const CCreature * crea, int totalAmount);
  50. void clickLeft(tribool down, bool previousState) override;
  51. void clickRight(tribool down, bool previousState) override;
  52. void showAll(SDL_Surface * to) override;
  53. };
  54. std::function<void(CreatureID,int)> onRecruit; //void (int ID, int amount) <-- call to recruit creatures
  55. int level;
  56. const CArmedInstance * dst;
  57. std::shared_ptr<CGStatusBar> statusBar;
  58. std::shared_ptr<CCreatureCard> selected;
  59. std::vector<std::shared_ptr<CCreatureCard>> cards;
  60. std::shared_ptr<CSlider> slider;
  61. std::shared_ptr<CButton> maxButton;
  62. std::shared_ptr<CButton> buyButton;
  63. std::shared_ptr<CButton> cancelButton;
  64. std::shared_ptr<CLabel> title;
  65. std::shared_ptr<CLabel> availableValue;
  66. std::shared_ptr<CLabel> toRecruitValue;
  67. std::shared_ptr<CLabel> availableTitle;
  68. std::shared_ptr<CLabel> toRecruitTitle;
  69. std::shared_ptr<CreatureCostBox> costPerTroopValue;
  70. std::shared_ptr<CreatureCostBox> totalCostValue;
  71. void select(std::shared_ptr<CCreatureCard> card);
  72. void buy();
  73. void sliderMoved(int to);
  74. void showAll(SDL_Surface * to) override;
  75. public:
  76. const CGDwelling * const dwelling;
  77. CRecruitmentWindow(const CGDwelling * Dwelling, int Level, const CArmedInstance * Dst, const std::function<void(CreatureID,int)> & Recruit, int y_offset = 0);
  78. void availableCreaturesChanged();
  79. };
  80. /// Split window where creatures can be split up into two single unit stacks
  81. class CSplitWindow : public CWindowObject
  82. {
  83. std::function<void(int, int)> callback;
  84. int leftAmount;
  85. int rightAmount;
  86. int leftMin;
  87. int rightMin;
  88. std::shared_ptr<CLabel> title;
  89. std::shared_ptr<CSlider> slider;
  90. std::shared_ptr<CCreaturePic> animLeft;
  91. std::shared_ptr<CCreaturePic> animRight;
  92. std::shared_ptr<CButton> ok;
  93. std::shared_ptr<CButton> cancel;
  94. std::shared_ptr<CTextInput> leftInput;
  95. std::shared_ptr<CTextInput> rightInput;
  96. void setAmountText(std::string text, bool left);
  97. void setAmount(int value, bool left);
  98. void sliderMoved(int value);
  99. void apply();
  100. public:
  101. /**
  102. * creature - displayed creature
  103. * callback(leftAmount, rightAmount) - function to call on close
  104. * leftMin, rightMin - minimal amount of creatures in each stack
  105. * leftAmount, rightAmount - amount of creatures in each stack
  106. */
  107. CSplitWindow(const CCreature * creature, std::function<void(int, int)> callback, int leftMin, int rightMin, int leftAmount, int rightAmount);
  108. };
  109. /// Raised up level window where you can select one out of two skills
  110. class CLevelWindow : public CWindowObject
  111. {
  112. std::shared_ptr<CAnimImage> portrait;
  113. std::shared_ptr<CButton> ok;
  114. std::shared_ptr<CLabel> mainTitle;
  115. std::shared_ptr<CLabel> levelTitle;
  116. std::shared_ptr<CAnimImage> skillIcon;
  117. std::shared_ptr<CLabel> skillValue;
  118. std::shared_ptr<CComponentBox> box; //skills to select
  119. std::function<void(ui32)> cb;
  120. void selectionChanged(unsigned to);
  121. public:
  122. CLevelWindow(const CGHeroInstance *hero, PrimarySkill::PrimarySkill pskill, std::vector<SecondarySkill> &skills, std::function<void(ui32)> callback);
  123. ~CLevelWindow();
  124. };
  125. /// Town portal, castle gate window
  126. class CObjectListWindow : public CWindowObject
  127. {
  128. class CItem : public CIntObject
  129. {
  130. CObjectListWindow * parent;
  131. std::shared_ptr<CLabel> text;
  132. std::shared_ptr<CPicture> border;
  133. public:
  134. const size_t index;
  135. CItem(CObjectListWindow * parent, size_t id, std::string text);
  136. void select(bool on);
  137. void clickLeft(tribool down, bool previousState) 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);
  156. CObjectListWindow(const std::vector<std::string> &_items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback);
  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 (const SDL_KeyboardEvent & key) override;
  161. };
  162. class CSystemOptionsWindow : public CWindowObject
  163. {
  164. private:
  165. std::shared_ptr<CLabel> title;
  166. std::shared_ptr<CLabelGroup> leftGroup;
  167. std::shared_ptr<CLabelGroup> rightGroup;
  168. std::shared_ptr<CButton> load;
  169. std::shared_ptr<CButton> save;
  170. std::shared_ptr<CButton> restart;
  171. std::shared_ptr<CButton> mainMenu;
  172. std::shared_ptr<CButton> quitGame;
  173. std::shared_ptr<CButton> backToMap; //load and restart are not used yet
  174. std::shared_ptr<CToggleGroup> heroMoveSpeed;
  175. std::shared_ptr<CToggleGroup> enemyMoveSpeed;
  176. std::shared_ptr<CToggleGroup> mapScrollSpeed;
  177. std::shared_ptr<CVolumeSlider> musicVolume;
  178. std::shared_ptr<CVolumeSlider> effectsVolume;
  179. std::shared_ptr<CToggleButton> showReminder;
  180. std::shared_ptr<CToggleButton> quickCombat;
  181. std::shared_ptr<CToggleButton> spellbookAnim;
  182. std::shared_ptr<CToggleButton> fullscreen;
  183. std::shared_ptr<CButton> gameResButton;
  184. std::shared_ptr<CLabel> gameResLabel;
  185. SettingsListener onFullscreenChanged;
  186. //functions bound to buttons
  187. void bloadf(); //load game
  188. void bsavef(); //save game
  189. void bquitf(); //quit game
  190. void breturnf(); //return to game
  191. void brestartf(); //restart game
  192. void bmainmenuf(); //return to main menu
  193. void selectGameRes();
  194. void setGameRes(int index);
  195. void closeAndPushEvent(int eventType, int code = 0);
  196. public:
  197. CSystemOptionsWindow();
  198. };
  199. class CTavernWindow : public CWindowObject
  200. {
  201. public:
  202. class HeroPortrait : public CIntObject
  203. {
  204. public:
  205. std::string hoverName;
  206. std::string description; // "XXX is a level Y ZZZ with N artifacts"
  207. const CGHeroInstance * h;
  208. void clickLeft(tribool down, bool previousState) override;
  209. void clickRight(tribool down, bool previousState) override;
  210. void hover (bool on) override;
  211. HeroPortrait(int & sel, int id, int x, int y, const CGHeroInstance * H);
  212. private:
  213. int *_sel;
  214. const int _id;
  215. std::shared_ptr<CAnimImage> portrait;
  216. };
  217. //recruitable heroes
  218. std::shared_ptr<HeroPortrait> h1;
  219. std::shared_ptr<HeroPortrait> h2; //recruitable heroes
  220. int selected;//0 (left) or 1 (right)
  221. int oldSelected;//0 (left) or 1 (right)
  222. std::shared_ptr<CButton> thiefGuild;
  223. std::shared_ptr<CButton> cancel;
  224. std::shared_ptr<CButton> recruit;
  225. const CGObjectInstance * tavernObj;
  226. std::shared_ptr<CLabel> title;
  227. std::shared_ptr<CLabel> cost;
  228. std::shared_ptr<CTextBox> rumor;
  229. std::shared_ptr<CGStatusBar> statusBar;
  230. CTavernWindow(const CGObjectInstance * TavernObj);
  231. ~CTavernWindow();
  232. void recruitb();
  233. void thievesguildb();
  234. void show(SDL_Surface * to) override;
  235. };
  236. class CExchangeWindow : public CWindowObject, public CGarrisonHolder, public CWindowWithArtifacts
  237. {
  238. std::array<std::shared_ptr<CHeroWithMaybePickedArtifact>, 2> herosWArt;
  239. std::array<std::shared_ptr<CLabel>, 2> titles;
  240. std::vector<std::shared_ptr<CAnimImage>> primSkillImages;//shared for both heroes
  241. std::array<std::vector<std::shared_ptr<CLabel>>, 2> primSkillValues;
  242. std::array<std::vector<std::shared_ptr<CAnimImage>>, 2> secSkillIcons;
  243. std::array<std::shared_ptr<CAnimImage>, 2> specImages;
  244. std::array<std::shared_ptr<CAnimImage>, 2> expImages;
  245. std::array<std::shared_ptr<CLabel>, 2> expValues;
  246. std::array<std::shared_ptr<CAnimImage>, 2> manaImages;
  247. std::array<std::shared_ptr<CLabel>, 2> manaValues;
  248. std::array<std::shared_ptr<CAnimImage>, 2> portraits;
  249. std::vector<std::shared_ptr<LRClickableAreaWTextComp>> primSkillAreas;
  250. std::array<std::vector<std::shared_ptr<LRClickableAreaWTextComp>>, 2> secSkillAreas;
  251. std::array<std::shared_ptr<CHeroArea>, 2> heroAreas;
  252. std::array<std::shared_ptr<LRClickableAreaWText>, 2> specialtyAreas;
  253. std::array<std::shared_ptr<LRClickableAreaWText>, 2> experienceAreas;
  254. std::array<std::shared_ptr<LRClickableAreaWText>, 2> spellPointsAreas;
  255. std::array<std::shared_ptr<MoraleLuckBox>, 2> morale;
  256. std::array<std::shared_ptr<MoraleLuckBox>, 2> luck;
  257. std::shared_ptr<CButton> quit;
  258. std::array<std::shared_ptr<CButton>, 2> questlogButton;
  259. std::shared_ptr<CGStatusBar> statusBar;
  260. std::shared_ptr<CGarrisonInt> garr;
  261. public:
  262. std::array<const CGHeroInstance *, 2> heroInst;
  263. std::array<std::shared_ptr<CArtifactsOfHero>, 2> artifs;
  264. void updateGarrisons() override;
  265. void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right
  266. void updateWidgets();
  267. CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2, QueryID queryID);
  268. ~CExchangeWindow();
  269. };
  270. /// Here you can buy ships
  271. class CShipyardWindow : public CWindowObject
  272. {
  273. std::shared_ptr<CPicture> bgWater;
  274. std::shared_ptr<CAnimImage> bgShip;
  275. std::shared_ptr<CLabel> title;
  276. std::shared_ptr<CLabel> costLabel;
  277. std::shared_ptr<CAnimImage> woodPic;
  278. std::shared_ptr<CAnimImage> goldPic;
  279. std::shared_ptr<CLabel> woodCost;
  280. std::shared_ptr<CLabel> goldCost;
  281. std::shared_ptr<CButton> build;
  282. std::shared_ptr<CButton> quit;
  283. std::shared_ptr<CGStatusBar> statusBar;
  284. public:
  285. CShipyardWindow(const std::vector<si32> & cost, int state, int boatType, const std::function<void()> & onBuy);
  286. };
  287. /// Puzzle screen which gets uncovered when you visit obilisks
  288. class CPuzzleWindow : public CWindowObject
  289. {
  290. private:
  291. int3 grailPos;
  292. std::shared_ptr<CPicture> logo;
  293. std::shared_ptr<CLabel> title;
  294. std::shared_ptr<CButton> quitb;
  295. std::shared_ptr<CResDataBar> resDataBar;
  296. std::vector<std::shared_ptr<CPicture>> piecesToRemove;
  297. std::vector<std::shared_ptr<CPicture>> visiblePieces;
  298. ui8 currentAlpha;
  299. public:
  300. void showAll(SDL_Surface * to) override;
  301. void show(SDL_Surface * to) override;
  302. CPuzzleWindow(const int3 & grailPos, double discoveredRatio);
  303. };
  304. /// Creature transformer window
  305. class CTransformerWindow : public CWindowObject, public CGarrisonHolder
  306. {
  307. class CItem : public CIntObject
  308. {
  309. public:
  310. int id;//position of creature in hero army
  311. bool left;//position of the item
  312. int size; //size of creature stack
  313. CTransformerWindow * parent;
  314. std::shared_ptr<CAnimImage> icon;
  315. std::shared_ptr<CLabel> count;
  316. void move();
  317. void clickLeft(tribool down, bool previousState) override;
  318. void update();
  319. CItem(CTransformerWindow * parent, int size, int id);
  320. };
  321. const CArmedInstance * army;//object with army for transforming (hero or town)
  322. const CGHeroInstance * hero;//only if we have hero in town
  323. const CGTownInstance * town;//market, town garrison is used if hero == nullptr
  324. std::shared_ptr<CLabel> titleLeft;
  325. std::shared_ptr<CLabel> titleRight;
  326. std::shared_ptr<CTextBox> helpLeft;
  327. std::shared_ptr<CTextBox> helpRight;
  328. std::vector<std::shared_ptr<CItem>> items;
  329. std::shared_ptr<CButton> all;
  330. std::shared_ptr<CButton> convert;
  331. std::shared_ptr<CButton> cancel;
  332. std::shared_ptr<CGStatusBar> statusBar;
  333. public:
  334. void makeDeal();
  335. void addAll();
  336. void updateGarrisons() override;
  337. CTransformerWindow(const CGHeroInstance * _hero, const CGTownInstance * _town);
  338. };
  339. class CUniversityWindow : public CWindowObject
  340. {
  341. class CItem : public CIntObject
  342. {
  343. std::shared_ptr<CAnimImage> icon;
  344. std::shared_ptr<CAnimImage> topBar;
  345. std::shared_ptr<CAnimImage> bottomBar;
  346. std::shared_ptr<CLabel> name;
  347. std::shared_ptr<CLabel> level;
  348. public:
  349. int ID;//id of selected skill
  350. CUniversityWindow * parent;
  351. void showAll(SDL_Surface * to) override;
  352. void clickLeft(tribool down, bool previousState) override;
  353. void clickRight(tribool down, bool previousState) override;
  354. void hover(bool on) override;
  355. int state();//0=can't learn, 1=learned, 2=can learn
  356. CItem(CUniversityWindow * _parent, int _ID, int X, int Y);
  357. };
  358. const CGHeroInstance * hero;
  359. const IMarket * market;
  360. std::shared_ptr<CAnimation> bars;
  361. std::vector<std::shared_ptr<CItem>> items;
  362. std::shared_ptr<CButton> cancel;
  363. std::shared_ptr<CGStatusBar> statusBar;
  364. std::shared_ptr<CIntObject> titlePic;
  365. std::shared_ptr<CLabel> title;
  366. std::shared_ptr<CTextBox> clerkSpeech;
  367. public:
  368. CUniversityWindow(const CGHeroInstance * _hero, const IMarket * _market);
  369. void makeDeal(int skill);
  370. };
  371. /// Confirmation window for University
  372. class CUnivConfirmWindow : public CWindowObject
  373. {
  374. std::shared_ptr<CTextBox> clerkSpeech;
  375. std::shared_ptr<CLabel> name;
  376. std::shared_ptr<CLabel> level;
  377. std::shared_ptr<CAnimImage> icon;
  378. CUniversityWindow * owner;
  379. std::shared_ptr<CGStatusBar> statusBar;
  380. std::shared_ptr<CButton> confirm;
  381. std::shared_ptr<CButton> cancel;
  382. std::shared_ptr<CAnimImage> costIcon;
  383. std::shared_ptr<CLabel> cost;
  384. void makeDeal(int skill);
  385. public:
  386. CUnivConfirmWindow(CUniversityWindow * PARENT, int SKILL, bool available);
  387. };
  388. /// Garrison window where you can take creatures out of the hero to place it on the garrison
  389. class CGarrisonWindow : public CWindowObject, public CGarrisonHolder
  390. {
  391. std::shared_ptr<CLabel> title;
  392. std::shared_ptr<CAnimImage> banner;
  393. std::shared_ptr<CAnimImage> portrait;
  394. std::shared_ptr<CGarrisonInt> garr;
  395. public:
  396. std::shared_ptr<CButton> quit;
  397. CGarrisonWindow(const CArmedInstance * up, const CGHeroInstance * down, bool removableUnits);
  398. void updateGarrisons() override;
  399. };
  400. /// Hill fort is the building where you can upgrade units
  401. class CHillFortWindow : public CWindowObject, public CGarrisonHolder
  402. {
  403. private:
  404. static const int slotsCount = 7;
  405. //todo: mithril support
  406. static const int resCount = 7;
  407. const CGObjectInstance * fort;
  408. const CGHeroInstance * hero;
  409. std::shared_ptr<CLabel> title;
  410. std::shared_ptr<CHeroArea> heroPic;
  411. std::array<std::shared_ptr<CAnimImage>, resCount> totalIcons;
  412. std::array<std::shared_ptr<CLabel>, resCount> totalLabels;
  413. std::array<std::shared_ptr<CButton>, slotsCount> upgrade;//upgrade single creature
  414. std::array<int, slotsCount + 1> currState;//current state of slot - to avoid calls to getState or updating buttons
  415. //there is a place for only 2 resources per slot
  416. std::array< std::array<std::shared_ptr<CAnimImage>, 2>, slotsCount> slotIcons;
  417. std::array< std::array<std::shared_ptr<CLabel>, 2>, slotsCount> slotLabels;
  418. std::shared_ptr<CButton> upgradeAll;
  419. std::shared_ptr<CButton> quit;
  420. std::shared_ptr<CGarrisonInt> garr;
  421. std::shared_ptr<CGStatusBar> statusBar;
  422. std::string getDefForSlot(SlotID slot);
  423. std::string getTextForSlot(SlotID slot);
  424. void makeDeal(SlotID slot);//-1 for upgrading all creatures
  425. int getState(SlotID slot); //-1 = no creature 0=can't upgrade, 1=upgraded, 2=can upgrade
  426. public:
  427. CHillFortWindow(const CGHeroInstance * visitor, const CGObjectInstance * object);
  428. void updateGarrisons() override;//update buttons after garrison changes
  429. };
  430. class CThievesGuildWindow : public CWindowObject
  431. {
  432. const CGObjectInstance * owner;
  433. std::shared_ptr<CGStatusBar> statusBar;
  434. std::shared_ptr<CButton> exitb;
  435. std::shared_ptr<CMinorResDataBar> resdatabar;
  436. std::vector<std::shared_ptr<CLabel>> rowHeaders;
  437. std::vector<std::shared_ptr<CAnimImage>> columnBackgrounds;
  438. std::vector<std::shared_ptr<CLabel>> columnHeaders;
  439. std::vector<std::shared_ptr<CAnimImage>> cells;
  440. std::vector<std::shared_ptr<CPicture>> banners;
  441. std::vector<std::shared_ptr<CAnimImage>> bestHeroes;
  442. std::vector<std::shared_ptr<CTextBox>> primSkillHeaders;
  443. std::vector<std::shared_ptr<CLabel>> primSkillValues;
  444. std::vector<std::shared_ptr<CAnimImage>> bestCreatures;
  445. std::vector<std::shared_ptr<CLabel>> personalities;
  446. public:
  447. CThievesGuildWindow(const CGObjectInstance * _owner);
  448. };