GUIClasses.h 13 KB

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