GUIClasses.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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 CGStatusBar;
  32. /// Recruitment window where you can recruit creatures
  33. class CRecruitmentWindow : public CWindowObject
  34. {
  35. class CCreatureCard : public CIntObject
  36. {
  37. CRecruitmentWindow * parent;
  38. CCreaturePic *pic; //creature's animation
  39. bool selected;
  40. void clickLeft(tribool down, bool previousState);
  41. void clickRight(tribool down, bool previousState);
  42. void showAll(SDL_Surface *to);
  43. public:
  44. const CCreature * creature;
  45. si32 amount;
  46. void select(bool on);
  47. CCreatureCard(CRecruitmentWindow * window, const CCreature *crea, int totalAmount);
  48. };
  49. /// small class to display creature costs
  50. class CCostBox : public CIntObject
  51. {
  52. std::map<int, std::pair<CLabel *, CAnimImage * > > resources;
  53. public:
  54. //res - resources to show
  55. void set(TResources res);
  56. //res - visible resources
  57. CCostBox(Rect position, std::string title);
  58. void createItems(TResources res);
  59. };
  60. std::function<void(CreatureID,int)> onRecruit; //void (int ID, int amount) <-- call to recruit creatures
  61. int level;
  62. const CArmedInstance *dst;
  63. CCreatureCard * selected;
  64. std::vector<CCreatureCard *> cards;
  65. CSlider *slider; //for selecting amount
  66. CButton *maxButton, *buyButton, *cancelButton;
  67. //labels for visible values
  68. CLabel * title;
  69. CLabel * availableValue;
  70. CLabel * toRecruitValue;
  71. CCostBox * costPerTroopValue;
  72. CCostBox * totalCostValue;
  73. void select(CCreatureCard * card);
  74. void buy();
  75. void sliderMoved(int to);
  76. void showAll(SDL_Surface *to);
  77. public:
  78. const CGDwelling * const dwelling;
  79. 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
  80. void availableCreaturesChanged();
  81. };
  82. /// Split window where creatures can be split up into two single unit stacks
  83. class CSplitWindow : public CWindowObject
  84. {
  85. std::function<void(int, int)> callback;
  86. int leftAmount;
  87. int rightAmount;
  88. int leftMin;
  89. int rightMin;
  90. CSlider *slider;
  91. CCreaturePic *animLeft, *animRight; //creature's animation
  92. CButton *ok, *cancel;
  93. CTextInput *leftInput, *rightInput;
  94. void setAmountText(std::string text, bool left);
  95. void setAmount(int value, bool left);
  96. void sliderMoved(int value);
  97. void apply();
  98. public:
  99. /**
  100. * creature - displayed creature
  101. * callback(leftAmount, rightAmount) - function to call on close
  102. * leftMin, rightMin - minimal amount of creatures in each stack
  103. * leftAmount, rightAmount - amount of creatures in each stack
  104. */
  105. CSplitWindow(const CCreature * creature, std::function<void(int, int)> callback,
  106. 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); //c-tor
  116. ~CLevelWindow(); //d-tor
  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);
  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. CIntObject * titleImage;//title image (castle gate\town portal picture)
  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);
  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 * mapScrollSpeed;
  163. CToggleGroup * musicVolume, * effectsVolume;
  164. //CHighlightableButton * showPath;
  165. CToggleButton * showReminder;
  166. CToggleButton * quickCombat;
  167. CToggleButton * spellbookAnim;
  168. CToggleButton * newCreatureWin;
  169. CToggleButton * fullscreen;
  170. CButton *gameResButton;
  171. CLabel *gameResLabel;
  172. SettingsListener onFullscreenChanged;
  173. void setMusicVolume( int newVolume );
  174. void setSoundVolume( int newVolume );
  175. void setHeroMoveSpeed( int newSpeed );
  176. void setMapScrollingSpeed( int newSpeed );
  177. //functions bound to buttons
  178. void bloadf(); //load game
  179. void bsavef(); //save game
  180. void bquitf(); //quit game
  181. void breturnf(); //return to game
  182. void brestartf(); //restart game
  183. void bmainmenuf(); //return to main menu
  184. //functions for checkboxes
  185. void toggleReminder(bool on);
  186. void toggleQuickCombat(bool on);
  187. void toggleSpellbookAnim(bool on);
  188. void toggleCreatureWin(bool on);
  189. void toggleFullscreen(bool on);
  190. void selectGameRes();
  191. void setGameRes(int index);
  192. void closeAndPushEvent(int eventType, int code = 0);
  193. public:
  194. CSystemOptionsWindow(); //c-tor
  195. };
  196. class CTavernWindow : public CWindowObject
  197. {
  198. public:
  199. class HeroPortrait : public CIntObject
  200. {
  201. public:
  202. std::string hoverName;
  203. std::string description; // "XXX is a level Y ZZZ with N artifacts"
  204. const CGHeroInstance *h;
  205. void clickLeft(tribool down, bool previousState);
  206. void clickRight(tribool down, bool previousState);
  207. void hover (bool on);
  208. HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H);
  209. private:
  210. int *_sel;
  211. const int _id;
  212. } *h1, *h2; //recruitable heroes
  213. CGStatusBar *bar; //tavern's internal status bar
  214. int selected;//0 (left) or 1 (right)
  215. int oldSelected;//0 (left) or 1 (right)
  216. CButton *thiefGuild, *cancel, *recruit;
  217. const CGObjectInstance *tavernObj;
  218. CTavernWindow(const CGObjectInstance *TavernObj); //c-tor
  219. ~CTavernWindow(); //d-tor
  220. void recruitb();
  221. void thievesguildb();
  222. void show(SDL_Surface * to);
  223. };
  224. class CExchangeWindow : public CWindowObject, public CWindowWithGarrison, public CWindowWithArtifacts
  225. {
  226. CGStatusBar * ourBar; //internal statusbar
  227. CButton * quit, * questlogButton[2];
  228. std::vector<LRClickableAreaWTextComp *> secSkillAreas[2], primSkillAreas;
  229. MoraleLuckBox *morale[2], *luck[2];
  230. LRClickableAreaWText *specialty[2];
  231. LRClickableAreaWText *experience[2];
  232. LRClickableAreaWText *spellPoints[2];
  233. CHeroArea *portrait[2];
  234. public:
  235. const CGHeroInstance* heroInst[2];
  236. CArtifactsOfHero * artifs[2];
  237. void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right
  238. void prepareBackground(); //prepares or redraws bg
  239. CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2, QueryID queryID); //c-tor
  240. ~CExchangeWindow(); //d-tor
  241. };
  242. /// Here you can buy ships
  243. class CShipyardWindow : public CWindowObject
  244. {
  245. public:
  246. CGStatusBar *bar;
  247. CPicture *bgWater;
  248. CLabel *title;
  249. CLabel *costLabel;
  250. CAnimImage *woodPic, *goldPic;
  251. CLabel *woodCost, *goldCost;
  252. CAnimImage *bgShip;
  253. CButton *build, *quit;
  254. CGStatusBar * statusBar;
  255. CShipyardWindow(const std::vector<si32> &cost, int state, int boatType, const std::function<void()> &onBuy);
  256. };
  257. /// Puzzle screen which gets uncovered when you visit obilisks
  258. class CPuzzleWindow : public CWindowObject
  259. {
  260. private:
  261. int3 grailPos;
  262. CButton * quitb;
  263. std::vector<CPicture * > piecesToRemove;
  264. ui8 currentAlpha;
  265. public:
  266. void showAll(SDL_Surface * to);
  267. void show(SDL_Surface * to);
  268. CPuzzleWindow(const int3 &grailPos, double discoveredRatio);
  269. };
  270. /// Creature transformer window
  271. class CTransformerWindow : public CWindowObject, public CGarrisonHolder
  272. {
  273. public:
  274. class CItem : public CIntObject
  275. {
  276. public:
  277. int id;//position of creature in hero army
  278. bool left;//position of the item
  279. int size; //size of creature stack
  280. CTransformerWindow * parent;
  281. CAnimImage *icon;
  282. void move();
  283. void clickLeft(tribool down, bool previousState);
  284. void update();
  285. CItem(CTransformerWindow * parent, int size, int id);
  286. };
  287. const CArmedInstance *army;//object with army for transforming (hero or town)
  288. const CGHeroInstance *hero;//only if we have hero in town
  289. const CGTownInstance *town;//market, town garrison is used if hero == nullptr
  290. std::vector<CItem*> items;
  291. CButton *all, *convert, *cancel;
  292. CGStatusBar *bar;
  293. void makeDeal();
  294. void addAll();
  295. void updateGarrisons();
  296. CTransformerWindow(const CGHeroInstance * _hero, const CGTownInstance * _town); //c-tor
  297. };
  298. class CUniversityWindow : public CWindowObject
  299. {
  300. class CItem : public CAnimImage
  301. {
  302. public:
  303. int ID;//id of selected skill
  304. CUniversityWindow * parent;
  305. void showAll(SDL_Surface * to);
  306. void clickLeft(tribool down, bool previousState);
  307. void clickRight(tribool down, bool previousState);
  308. void hover(bool on);
  309. int state();//0=can't learn, 1=learned, 2=can learn
  310. CItem(CUniversityWindow * _parent, int _ID, int X, int Y);
  311. };
  312. public:
  313. const CGHeroInstance *hero;
  314. const IMarket * market;
  315. CPicture * green, * yellow, * red;//colored bars near skills
  316. std::vector<CItem*> items;
  317. CButton *cancel;
  318. CGStatusBar *bar;
  319. CUniversityWindow(const CGHeroInstance * _hero, const IMarket * _market); //c-tor
  320. };
  321. /// Confirmation window for University
  322. class CUnivConfirmWindow : public CWindowObject
  323. {
  324. public:
  325. CUniversityWindow * parent;
  326. CGStatusBar *bar;
  327. CButton *confirm, *cancel;
  328. CUnivConfirmWindow(CUniversityWindow * PARENT, int SKILL, bool available); //c-tor
  329. void makeDeal(int skill);
  330. };
  331. /// Hill fort is the building where you can upgrade units
  332. class CHillFortWindow : public CWindowObject, public CWindowWithGarrison
  333. {
  334. public:
  335. int slotsCount;//=7;
  336. CGStatusBar * bar;
  337. CDefEssential *resources;
  338. CHeroArea *heroPic;//clickable hero image
  339. CButton *quit,//closes window
  340. *upgradeAll,//upgrade all creatures
  341. *upgrade[7];//upgrade single creature
  342. const CGObjectInstance * fort;
  343. const CGHeroInstance * hero;
  344. std::vector<int> currState;//current state of slot - to avoid calls to getState or updating buttons
  345. std::vector<TResources> costs;// costs [slot ID] [resource ID] = resource count for upgrade
  346. TResources totalSumm; // totalSum[resource ID] = value
  347. CHillFortWindow(const CGHeroInstance *visitor, const CGObjectInstance *object); //c-tor
  348. void showAll (SDL_Surface *to);
  349. std::string getDefForSlot(SlotID slot);//return def name for this slot
  350. std::string getTextForSlot(SlotID slot);//return hover text for this slot
  351. void makeDeal(SlotID slot);//-1 for upgrading all creatures
  352. int getState(SlotID slot); //-1 = no creature 0=can't upgrade, 1=upgraded, 2=can upgrade
  353. void updateGarrisons();//update buttons after garrison changes
  354. };
  355. class CThievesGuildWindow : public CWindowObject
  356. {
  357. const CGObjectInstance * owner;
  358. CGStatusBar * statusBar;
  359. CButton * exitb;
  360. CMinorResDataBar * resdatabar;
  361. public:
  362. CThievesGuildWindow(const CGObjectInstance * _owner);
  363. };