GUIClasses.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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 CStatusbarWindow
  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<CCreatureCard> selected;
  58. std::vector<std::shared_ptr<CCreatureCard>> cards;
  59. std::shared_ptr<CSlider> slider;
  60. std::shared_ptr<CButton> maxButton;
  61. std::shared_ptr<CButton> buyButton;
  62. std::shared_ptr<CButton> cancelButton;
  63. std::shared_ptr<CLabel> title;
  64. std::shared_ptr<CLabel> availableValue;
  65. std::shared_ptr<CLabel> toRecruitValue;
  66. std::shared_ptr<CLabel> availableTitle;
  67. std::shared_ptr<CLabel> toRecruitTitle;
  68. std::shared_ptr<CreatureCostBox> costPerTroopValue;
  69. std::shared_ptr<CreatureCostBox> totalCostValue;
  70. void select(std::shared_ptr<CCreatureCard> card);
  71. void buy();
  72. void sliderMoved(int to);
  73. void showAll(SDL_Surface * to) override;
  74. public:
  75. const CGDwelling * const dwelling;
  76. CRecruitmentWindow(const CGDwelling * Dwelling, int Level, const CArmedInstance * Dst, const std::function<void(CreatureID,int)> & Recruit, int y_offset = 0);
  77. void availableCreaturesChanged();
  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<CAnimImage> 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::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 clickLeft(tribool down, bool previousState) 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);
  155. CObjectListWindow(const std::vector<std::string> &_items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback);
  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 (const SDL_KeyboardEvent & key) override;
  160. };
  161. class CSystemOptionsWindow : public CWindowObject
  162. {
  163. private:
  164. std::shared_ptr<CLabel> title;
  165. std::shared_ptr<CLabelGroup> leftGroup;
  166. std::shared_ptr<CLabelGroup> rightGroup;
  167. std::shared_ptr<CButton> load;
  168. std::shared_ptr<CButton> save;
  169. std::shared_ptr<CButton> restart;
  170. std::shared_ptr<CButton> mainMenu;
  171. std::shared_ptr<CButton> quitGame;
  172. std::shared_ptr<CButton> backToMap; //load and restart are not used yet
  173. std::shared_ptr<CToggleGroup> heroMoveSpeed;
  174. std::shared_ptr<CToggleGroup> enemyMoveSpeed;
  175. std::shared_ptr<CToggleGroup> mapScrollSpeed;
  176. std::shared_ptr<CVolumeSlider> musicVolume;
  177. std::shared_ptr<CVolumeSlider> effectsVolume;
  178. std::shared_ptr<CToggleButton> showReminder;
  179. std::shared_ptr<CToggleButton> quickCombat;
  180. std::shared_ptr<CToggleButton> spellbookAnim;
  181. std::shared_ptr<CToggleButton> fullscreen;
  182. std::shared_ptr<CButton> gameResButton;
  183. std::shared_ptr<CLabel> gameResLabel;
  184. SettingsListener onFullscreenChanged;
  185. //functions bound to buttons
  186. void bloadf(); //load game
  187. void bsavef(); //save game
  188. void bquitf(); //quit game
  189. void breturnf(); //return to game
  190. void brestartf(); //restart game
  191. void bmainmenuf(); //return to main menu
  192. void selectGameRes();
  193. void setGameRes(int index);
  194. void closeAndPushEvent(int eventType, int code = 0);
  195. public:
  196. CSystemOptionsWindow();
  197. };
  198. class CTavernWindow : public CStatusbarWindow
  199. {
  200. public:
  201. class HeroPortrait : public CIntObject
  202. {
  203. public:
  204. std::string hoverName;
  205. std::string description; // "XXX is a level Y ZZZ with N artifacts"
  206. const CGHeroInstance * h;
  207. void clickLeft(tribool down, bool previousState) override;
  208. void clickRight(tribool down, bool previousState) override;
  209. void hover (bool on) override;
  210. HeroPortrait(int & sel, int id, int x, int y, const CGHeroInstance * H);
  211. private:
  212. int *_sel;
  213. const int _id;
  214. std::shared_ptr<CAnimImage> portrait;
  215. };
  216. //recruitable heroes
  217. std::shared_ptr<HeroPortrait> h1;
  218. std::shared_ptr<HeroPortrait> h2; //recruitable heroes
  219. int selected;//0 (left) or 1 (right)
  220. int oldSelected;//0 (left) or 1 (right)
  221. std::shared_ptr<CButton> thiefGuild;
  222. std::shared_ptr<CButton> cancel;
  223. std::shared_ptr<CButton> recruit;
  224. const CGObjectInstance * tavernObj;
  225. std::shared_ptr<CLabel> title;
  226. std::shared_ptr<CLabel> cost;
  227. std::shared_ptr<CTextBox> rumor;
  228. CTavernWindow(const CGObjectInstance * TavernObj);
  229. ~CTavernWindow();
  230. void recruitb();
  231. void thievesguildb();
  232. void show(SDL_Surface * to) override;
  233. };
  234. class CExchangeWindow : public CStatusbarWindow, public CGarrisonHolder, public CWindowWithArtifacts
  235. {
  236. std::array<std::shared_ptr<CHeroWithMaybePickedArtifact>, 2> herosWArt;
  237. std::array<std::shared_ptr<CLabel>, 2> titles;
  238. std::vector<std::shared_ptr<CAnimImage>> primSkillImages;//shared for both heroes
  239. std::array<std::vector<std::shared_ptr<CLabel>>, 2> primSkillValues;
  240. std::array<std::vector<std::shared_ptr<CAnimImage>>, 2> secSkillIcons;
  241. std::array<std::shared_ptr<CAnimImage>, 2> specImages;
  242. std::array<std::shared_ptr<CAnimImage>, 2> expImages;
  243. std::array<std::shared_ptr<CLabel>, 2> expValues;
  244. std::array<std::shared_ptr<CAnimImage>, 2> manaImages;
  245. std::array<std::shared_ptr<CLabel>, 2> manaValues;
  246. std::array<std::shared_ptr<CAnimImage>, 2> portraits;
  247. std::vector<std::shared_ptr<LRClickableAreaWTextComp>> primSkillAreas;
  248. std::array<std::vector<std::shared_ptr<LRClickableAreaWTextComp>>, 2> secSkillAreas;
  249. std::array<std::shared_ptr<CHeroArea>, 2> heroAreas;
  250. std::array<std::shared_ptr<LRClickableAreaWText>, 2> specialtyAreas;
  251. std::array<std::shared_ptr<LRClickableAreaWText>, 2> experienceAreas;
  252. std::array<std::shared_ptr<LRClickableAreaWText>, 2> spellPointsAreas;
  253. std::array<std::shared_ptr<MoraleLuckBox>, 2> morale;
  254. std::array<std::shared_ptr<MoraleLuckBox>, 2> luck;
  255. std::shared_ptr<CButton> quit;
  256. std::array<std::shared_ptr<CButton>, 2> questlogButton;
  257. std::shared_ptr<CGarrisonInt> garr;
  258. public:
  259. std::array<const CGHeroInstance *, 2> heroInst;
  260. std::array<std::shared_ptr<CArtifactsOfHero>, 2> artifs;
  261. void updateGarrisons() override;
  262. void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right
  263. void updateWidgets();
  264. CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2, QueryID queryID);
  265. ~CExchangeWindow();
  266. };
  267. /// Here you can buy ships
  268. class CShipyardWindow : public CStatusbarWindow
  269. {
  270. std::shared_ptr<CPicture> bgWater;
  271. std::shared_ptr<CAnimImage> bgShip;
  272. std::shared_ptr<CLabel> title;
  273. std::shared_ptr<CLabel> costLabel;
  274. std::shared_ptr<CAnimImage> woodPic;
  275. std::shared_ptr<CAnimImage> goldPic;
  276. std::shared_ptr<CLabel> woodCost;
  277. std::shared_ptr<CLabel> goldCost;
  278. std::shared_ptr<CButton> build;
  279. std::shared_ptr<CButton> quit;
  280. public:
  281. CShipyardWindow(const std::vector<si32> & cost, int state, int boatType, const std::function<void()> & onBuy);
  282. };
  283. /// Puzzle screen which gets uncovered when you visit obilisks
  284. class CPuzzleWindow : public CWindowObject
  285. {
  286. private:
  287. int3 grailPos;
  288. std::shared_ptr<CPicture> logo;
  289. std::shared_ptr<CLabel> title;
  290. std::shared_ptr<CButton> quitb;
  291. std::shared_ptr<CResDataBar> resDataBar;
  292. std::vector<std::shared_ptr<CPicture>> piecesToRemove;
  293. std::vector<std::shared_ptr<CPicture>> visiblePieces;
  294. ui8 currentAlpha;
  295. public:
  296. void showAll(SDL_Surface * to) override;
  297. void show(SDL_Surface * to) override;
  298. CPuzzleWindow(const int3 & grailPos, double discoveredRatio);
  299. };
  300. /// Creature transformer window
  301. class CTransformerWindow : public CStatusbarWindow, public CGarrisonHolder
  302. {
  303. class CItem : public CIntObject
  304. {
  305. public:
  306. int id;//position of creature in hero army
  307. bool left;//position of the item
  308. int size; //size of creature stack
  309. CTransformerWindow * parent;
  310. std::shared_ptr<CAnimImage> icon;
  311. std::shared_ptr<CLabel> count;
  312. void move();
  313. void clickLeft(tribool down, bool previousState) override;
  314. void update();
  315. CItem(CTransformerWindow * parent, int size, int id);
  316. };
  317. const CArmedInstance * army;//object with army for transforming (hero or town)
  318. const CGHeroInstance * hero;//only if we have hero in town
  319. const CGTownInstance * town;//market, town garrison is used if hero == nullptr
  320. std::shared_ptr<CLabel> titleLeft;
  321. std::shared_ptr<CLabel> titleRight;
  322. std::shared_ptr<CTextBox> helpLeft;
  323. std::shared_ptr<CTextBox> helpRight;
  324. std::vector<std::shared_ptr<CItem>> items;
  325. std::shared_ptr<CButton> all;
  326. std::shared_ptr<CButton> convert;
  327. std::shared_ptr<CButton> cancel;
  328. public:
  329. void makeDeal();
  330. void addAll();
  331. void updateGarrisons() override;
  332. CTransformerWindow(const CGHeroInstance * _hero, const CGTownInstance * _town);
  333. };
  334. class CUniversityWindow : public CStatusbarWindow
  335. {
  336. class CItem : public CIntObject
  337. {
  338. std::shared_ptr<CAnimImage> icon;
  339. std::shared_ptr<CAnimImage> topBar;
  340. std::shared_ptr<CAnimImage> bottomBar;
  341. std::shared_ptr<CLabel> name;
  342. std::shared_ptr<CLabel> level;
  343. public:
  344. int ID;//id of selected skill
  345. CUniversityWindow * parent;
  346. void showAll(SDL_Surface * to) override;
  347. void clickLeft(tribool down, bool previousState) override;
  348. void clickRight(tribool down, bool previousState) override;
  349. void hover(bool on) override;
  350. int state();//0=can't learn, 1=learned, 2=can learn
  351. CItem(CUniversityWindow * _parent, int _ID, int X, int Y);
  352. };
  353. const CGHeroInstance * hero;
  354. const IMarket * market;
  355. std::shared_ptr<CAnimation> bars;
  356. std::vector<std::shared_ptr<CItem>> items;
  357. std::shared_ptr<CButton> cancel;
  358. std::shared_ptr<CIntObject> titlePic;
  359. std::shared_ptr<CLabel> title;
  360. std::shared_ptr<CTextBox> clerkSpeech;
  361. public:
  362. CUniversityWindow(const CGHeroInstance * _hero, const IMarket * _market);
  363. void makeDeal(int skill);
  364. };
  365. /// Confirmation window for University
  366. class CUnivConfirmWindow : public CStatusbarWindow
  367. {
  368. std::shared_ptr<CTextBox> clerkSpeech;
  369. std::shared_ptr<CLabel> name;
  370. std::shared_ptr<CLabel> level;
  371. std::shared_ptr<CAnimImage> icon;
  372. CUniversityWindow * owner;
  373. std::shared_ptr<CButton> confirm;
  374. std::shared_ptr<CButton> cancel;
  375. std::shared_ptr<CAnimImage> costIcon;
  376. std::shared_ptr<CLabel> cost;
  377. void makeDeal(int skill);
  378. public:
  379. CUnivConfirmWindow(CUniversityWindow * PARENT, int SKILL, bool available);
  380. };
  381. /// Garrison window where you can take creatures out of the hero to place it on the garrison
  382. class CGarrisonWindow : public CWindowObject, public CGarrisonHolder
  383. {
  384. std::shared_ptr<CLabel> title;
  385. std::shared_ptr<CAnimImage> banner;
  386. std::shared_ptr<CAnimImage> portrait;
  387. std::shared_ptr<CGarrisonInt> garr;
  388. public:
  389. std::shared_ptr<CButton> quit;
  390. CGarrisonWindow(const CArmedInstance * up, const CGHeroInstance * down, bool removableUnits);
  391. void updateGarrisons() override;
  392. };
  393. /// Hill fort is the building where you can upgrade units
  394. class CHillFortWindow : public CStatusbarWindow, public CGarrisonHolder
  395. {
  396. private:
  397. static const int slotsCount = 7;
  398. //todo: mithril support
  399. static const int resCount = 7;
  400. const CGObjectInstance * fort;
  401. const CGHeroInstance * hero;
  402. std::shared_ptr<CLabel> title;
  403. std::shared_ptr<CHeroArea> heroPic;
  404. std::array<std::shared_ptr<CAnimImage>, resCount> totalIcons;
  405. std::array<std::shared_ptr<CLabel>, resCount> totalLabels;
  406. std::array<std::shared_ptr<CButton>, slotsCount> upgrade;//upgrade single creature
  407. std::array<int, slotsCount + 1> currState;//current state of slot - to avoid calls to getState or updating buttons
  408. //there is a place for only 2 resources per slot
  409. std::array< std::array<std::shared_ptr<CAnimImage>, 2>, slotsCount> slotIcons;
  410. std::array< std::array<std::shared_ptr<CLabel>, 2>, slotsCount> slotLabels;
  411. std::shared_ptr<CButton> upgradeAll;
  412. std::shared_ptr<CButton> quit;
  413. std::shared_ptr<CGarrisonInt> garr;
  414. std::string getDefForSlot(SlotID slot);
  415. std::string getTextForSlot(SlotID slot);
  416. void makeDeal(SlotID slot);//-1 for upgrading all creatures
  417. int getState(SlotID slot); //-1 = no creature 0=can't upgrade, 1=upgraded, 2=can upgrade
  418. public:
  419. CHillFortWindow(const CGHeroInstance * visitor, const CGObjectInstance * object);
  420. void updateGarrisons() override;//update buttons after garrison changes
  421. };
  422. class CThievesGuildWindow : public CStatusbarWindow
  423. {
  424. const CGObjectInstance * owner;
  425. std::shared_ptr<CButton> exitb;
  426. std::shared_ptr<CMinorResDataBar> resdatabar;
  427. std::vector<std::shared_ptr<CLabel>> rowHeaders;
  428. std::vector<std::shared_ptr<CAnimImage>> columnBackgrounds;
  429. std::vector<std::shared_ptr<CLabel>> columnHeaders;
  430. std::vector<std::shared_ptr<CAnimImage>> cells;
  431. std::vector<std::shared_ptr<CPicture>> banners;
  432. std::vector<std::shared_ptr<CAnimImage>> bestHeroes;
  433. std::vector<std::shared_ptr<CTextBox>> primSkillHeaders;
  434. std::vector<std::shared_ptr<CLabel>> primSkillValues;
  435. std::vector<std::shared_ptr<CAnimImage>> bestCreatures;
  436. std::vector<std::shared_ptr<CLabel>> personalities;
  437. public:
  438. CThievesGuildWindow(const CGObjectInstance * _owner);
  439. };