GUIClasses.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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 IMarket;
  20. class CCreaturePic;
  21. class MoraleLuckBox;
  22. class CHeroArea;
  23. class CMinorResDataBar;
  24. class CSlider;
  25. class CComponentBox;
  26. class CTextInput;
  27. class CListBox;
  28. class CLabelGroup;
  29. class CToggleButton;
  30. class CToggleGroup;
  31. class CVolumeSlider;
  32. class CGStatusBar;
  33. /// Recruitment window where you can recruit creatures
  34. class CRecruitmentWindow : public CWindowObject
  35. {
  36. class CCreatureCard : public CIntObject
  37. {
  38. CRecruitmentWindow * parent;
  39. CCreaturePic * pic; //creature's animation
  40. bool selected;
  41. void clickLeft(tribool down, bool previousState) override;
  42. void clickRight(tribool down, bool previousState) override;
  43. void showAll(SDL_Surface * to) override;
  44. public:
  45. const CCreature * creature;
  46. si32 amount;
  47. void select(bool on);
  48. CCreatureCard(CRecruitmentWindow * window, const CCreature * crea, int totalAmount);
  49. };
  50. /// small class to display creature costs
  51. class CCostBox : public CIntObject
  52. {
  53. std::map<int, std::pair<CLabel *, CAnimImage *>> resources;
  54. public:
  55. //res - resources to show
  56. void set(TResources res);
  57. //res - visible resources
  58. CCostBox(Rect position, std::string title);
  59. void createItems(TResources res);
  60. };
  61. std::function<void(CreatureID, int)> onRecruit; //void (int ID, int amount) <-- call to recruit creatures
  62. int level;
  63. const CArmedInstance * dst;
  64. CCreatureCard * selected;
  65. std::vector<CCreatureCard *> cards;
  66. CSlider * slider; //for selecting amount
  67. CButton * maxButton, * buyButton, * cancelButton;
  68. //labels for visible values
  69. CLabel * title;
  70. CLabel * availableValue;
  71. CLabel * toRecruitValue;
  72. CCostBox * costPerTroopValue;
  73. CCostBox * totalCostValue;
  74. void select(CCreatureCard * card);
  75. void buy();
  76. void sliderMoved(int to);
  77. void showAll(SDL_Surface * to) override;
  78. public:
  79. const CGDwelling * const dwelling;
  80. CRecruitmentWindow(const CGDwelling * Dwelling, int Level, const CArmedInstance * Dst, const std::function<void(CreatureID, int)> & Recruit, int y_offset = 0); //creatures - pairs<creature_ID,amount> //c-tor
  81. void availableCreaturesChanged();
  82. };
  83. /// Split window where creatures can be split up into two single unit stacks
  84. class CSplitWindow : public CWindowObject
  85. {
  86. std::function<void(int, int)> callback;
  87. int leftAmount;
  88. int rightAmount;
  89. int leftMin;
  90. int rightMin;
  91. CSlider * slider;
  92. CCreaturePic * animLeft, * animRight; //creature's animation
  93. CButton * ok, * cancel;
  94. CTextInput * leftInput, * 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 windowe where you can select one out of two skills
  109. class CLevelWindow : public CWindowObject
  110. {
  111. CComponentBox * box; //skills to select
  112. std::function<void(ui32)> cb;
  113. void selectionChanged(unsigned to);
  114. public:
  115. CLevelWindow(const CGHeroInstance * hero, PrimarySkill::PrimarySkill pskill, std::vector<SecondarySkill> & skills, std::function<void(ui32)> callback);
  116. ~CLevelWindow();
  117. };
  118. /// Town portal, castle gate window
  119. class CObjectListWindow : public CWindowObject
  120. {
  121. class CItem : public CIntObject
  122. {
  123. CObjectListWindow * parent;
  124. CLabel * text;
  125. CPicture * border;
  126. public:
  127. const size_t index;
  128. CItem(CObjectListWindow * parent, size_t id, std::string text);
  129. void select(bool on);
  130. void clickLeft(tribool down, bool previousState) override;
  131. };
  132. std::function<void(int)> onSelect; //called when OK button is pressed, returns id of selected item.
  133. CLabel * title;
  134. CLabel * descr;
  135. CListBox * list;
  136. CButton * ok, * exit;
  137. std::vector<std::pair<int, std::string>> items; //all items present in list
  138. void init(CIntObject * titlePic, std::string _title, std::string _descr);
  139. void exitPressed();
  140. public:
  141. size_t selected; //index of currently selected item
  142. std::function<void()> onExit; //optional exit callback
  143. /// Callback will be called when OK button is pressed, returns id of selected item. initState = initially selected item
  144. /// Image can be nullptr
  145. ///item names will be taken from map objects
  146. CObjectListWindow(const std::vector<int> & _items, CIntObject * titlePic, std::string _title, std::string _descr, std::function<void(int)> Callback);
  147. CObjectListWindow(const std::vector<std::string> & _items, CIntObject * titlePic, std::string _title, std::string _descr, std::function<void(int)> Callback);
  148. CIntObject * genItem(size_t index);
  149. void elementSelected(); //call callback and close this window
  150. void changeSelection(size_t which);
  151. void keyPressed(const SDL_KeyboardEvent & key) override;
  152. };
  153. class CSystemOptionsWindow : public CWindowObject
  154. {
  155. private:
  156. CLabel * title;
  157. CLabelGroup * leftGroup;
  158. CLabelGroup * rightGroup;
  159. CButton * load, * save, * restart, * mainMenu, * quitGame, * backToMap; //load and restart are not used yet
  160. CToggleGroup * heroMoveSpeed;
  161. CToggleGroup * enemyMoveSpeed;
  162. CToggleGroup * mapScrollSpeed;
  163. CVolumeSlider * musicVolume, * effectsVolume;
  164. //CHighlightableButton * showPath;
  165. CToggleButton * showReminder;
  166. CToggleButton * quickCombat;
  167. CToggleButton * spellbookAnim;
  168. CToggleButton * fullscreen;
  169. CButton * gameResButton;
  170. CLabel * gameResLabel;
  171. SettingsListener onFullscreenChanged;
  172. //functions bound to buttons
  173. void bloadf(); //load game
  174. void bsavef(); //save game
  175. void bquitf(); //quit game
  176. void breturnf(); //return to game
  177. void brestartf(); //restart game
  178. void bmainmenuf(); //return to main menu
  179. void selectGameRes();
  180. void setGameRes(int index);
  181. void closeAndPushEvent(int eventType, int code = 0);
  182. public:
  183. CSystemOptionsWindow();
  184. };
  185. class CTavernWindow : public CWindowObject
  186. {
  187. public:
  188. class HeroPortrait : public CIntObject
  189. {
  190. public:
  191. std::string hoverName;
  192. std::string description; // "XXX is a level Y ZZZ with N artifacts"
  193. const CGHeroInstance * h;
  194. void clickLeft(tribool down, bool previousState) override;
  195. void clickRight(tribool down, bool previousState) override;
  196. void hover(bool on) override;
  197. HeroPortrait(int & sel, int id, int x, int y, const CGHeroInstance * H);
  198. private:
  199. int * _sel;
  200. const int _id;
  201. } *h1, *h2; //recruitable heroes
  202. int selected; //0 (left) or 1 (right)
  203. int oldSelected; //0 (left) or 1 (right)
  204. CButton * thiefGuild, * cancel, * recruit;
  205. const CGObjectInstance * tavernObj;
  206. CTavernWindow(const CGObjectInstance * TavernObj);
  207. ~CTavernWindow();
  208. void recruitb();
  209. void thievesguildb();
  210. void show(SDL_Surface * to) override;
  211. };
  212. class CExchangeWindow : public CWindowObject, public CWindowWithGarrison, public CWindowWithArtifacts
  213. {
  214. CGStatusBar * ourBar; //internal statusbar
  215. CButton * quit, * questlogButton[2];
  216. std::vector<LRClickableAreaWTextComp *> secSkillAreas[2], primSkillAreas;
  217. MoraleLuckBox * morale[2], * luck[2];
  218. LRClickableAreaWText * specialty[2];
  219. LRClickableAreaWText * experience[2];
  220. LRClickableAreaWText * spellPoints[2];
  221. CHeroArea * portrait[2];
  222. public:
  223. const CGHeroInstance * heroInst[2];
  224. CArtifactsOfHero * artifs[2];
  225. void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right
  226. void prepareBackground(); //prepares or redraws bg
  227. CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2, QueryID queryID);
  228. ~CExchangeWindow();
  229. };
  230. /// Here you can buy ships
  231. class CShipyardWindow : public CWindowObject
  232. {
  233. public:
  234. CGStatusBar * bar;
  235. CPicture * bgWater;
  236. CLabel * title;
  237. CLabel * costLabel;
  238. CAnimImage * woodPic, * goldPic;
  239. CLabel * woodCost, * goldCost;
  240. CAnimImage * bgShip;
  241. CButton * build, * quit;
  242. CGStatusBar * statusBar;
  243. CShipyardWindow(const std::vector<si32> & cost, int state, int boatType, const std::function<void()> & onBuy);
  244. };
  245. /// Puzzle screen which gets uncovered when you visit obilisks
  246. class CPuzzleWindow : public CWindowObject
  247. {
  248. private:
  249. int3 grailPos;
  250. CButton * quitb;
  251. std::vector<CPicture *> piecesToRemove;
  252. ui8 currentAlpha;
  253. public:
  254. void showAll(SDL_Surface * to) override;
  255. void show(SDL_Surface * to) override;
  256. CPuzzleWindow(const int3 & grailPos, double discoveredRatio);
  257. };
  258. /// Creature transformer window
  259. class CTransformerWindow : public CWindowObject, public CGarrisonHolder
  260. {
  261. public:
  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. CAnimImage * icon;
  270. void move();
  271. void clickLeft(tribool down, bool previousState) override;
  272. void update();
  273. CItem(CTransformerWindow * parent, int size, int id);
  274. };
  275. const CArmedInstance * army; //object with army for transforming (hero or town)
  276. const CGHeroInstance * hero; //only if we have hero in town
  277. const CGTownInstance * town; //market, town garrison is used if hero == nullptr
  278. std::vector<CItem *> items;
  279. CButton * all, * convert, * cancel;
  280. CGStatusBar * bar;
  281. void makeDeal();
  282. void addAll();
  283. void updateGarrisons() override;
  284. CTransformerWindow(const CGHeroInstance * _hero, const CGTownInstance * _town);
  285. };
  286. class CUniversityWindow : public CWindowObject
  287. {
  288. class CItem : public CAnimImage
  289. {
  290. public:
  291. int ID; //id of selected skill
  292. CUniversityWindow * parent;
  293. void showAll(SDL_Surface * to) override;
  294. void clickLeft(tribool down, bool previousState) override;
  295. void clickRight(tribool down, bool previousState) override;
  296. void hover(bool on) override;
  297. int state(); //0=can't learn, 1=learned, 2=can learn
  298. CItem(CUniversityWindow * _parent, int _ID, int X, int Y);
  299. };
  300. public:
  301. const CGHeroInstance * hero;
  302. const IMarket * market;
  303. CPicture * green, * yellow, * red; //colored bars near skills
  304. std::vector<CItem *> items;
  305. CButton * cancel;
  306. CGStatusBar * bar;
  307. CUniversityWindow(const CGHeroInstance * _hero, const IMarket * _market);
  308. };
  309. /// Confirmation window for University
  310. class CUnivConfirmWindow : public CWindowObject
  311. {
  312. public:
  313. CUniversityWindow * parent;
  314. CGStatusBar * bar;
  315. CButton * confirm, * cancel;
  316. CUnivConfirmWindow(CUniversityWindow * PARENT, int SKILL, bool available);
  317. void makeDeal(int skill);
  318. };
  319. /// Hill fort is the building where you can upgrade units
  320. class CHillFortWindow : public CWindowObject, public CWindowWithGarrison
  321. {
  322. private:
  323. static const int slotsCount = 7;
  324. //todo: mithril support
  325. static const int resCount = 7;
  326. const CGObjectInstance * fort;
  327. const CGHeroInstance * hero;
  328. CGStatusBar * bar;
  329. CHeroArea * heroPic; //clickable hero image
  330. CButton * quit; //closes window
  331. CButton * upgradeAll; //upgrade all creatures
  332. std::array<CButton *, slotsCount> upgrade; //upgrade single creature
  333. std::array<int, slotsCount + 1> currState; //current state of slot - to avoid calls to getState or updating buttons
  334. //there is a place for only 2 resources per slot
  335. std::array<std::array<CAnimImage *, 2>, slotsCount> slotIcons;
  336. std::array<std::array<CLabel *, 2>, slotsCount> slotLabels;
  337. std::array<CAnimImage *, resCount> totalIcons;
  338. std::array<CLabel *, resCount> totalLabels;
  339. std::string getDefForSlot(SlotID slot); //return def name for this slot
  340. std::string getTextForSlot(SlotID slot); //return hover text for this slot
  341. void makeDeal(SlotID slot); //-1 for upgrading all creatures
  342. int getState(SlotID slot); //-1 = no creature 0=can't upgrade, 1=upgraded, 2=can upgrade
  343. public:
  344. CHillFortWindow(const CGHeroInstance * visitor, const CGObjectInstance * object);
  345. void updateGarrisons() override; //update buttons after garrison changes
  346. };
  347. class CThievesGuildWindow : public CWindowObject
  348. {
  349. const CGObjectInstance * owner;
  350. CGStatusBar * statusBar;
  351. CButton * exitb;
  352. CMinorResDataBar * resdatabar;
  353. public:
  354. CThievesGuildWindow(const CGObjectInstance * _owner);
  355. };