GUIClasses.h 13 KB

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