GUIClasses.h 12 KB

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