GUIClasses.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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 * enemyMoveSpeed;
  163. CToggleGroup * mapScrollSpeed;
  164. CToggleGroup * 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);
  196. void clickRight(tribool down, bool previousState);
  197. void hover (bool on);
  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. CGStatusBar *bar; //tavern's internal status bar
  204. int selected;//0 (left) or 1 (right)
  205. int oldSelected;//0 (left) or 1 (right)
  206. CButton *thiefGuild, *cancel, *recruit;
  207. const CGObjectInstance *tavernObj;
  208. CTavernWindow(const CGObjectInstance *TavernObj); //c-tor
  209. ~CTavernWindow(); //d-tor
  210. void recruitb();
  211. void thievesguildb();
  212. void show(SDL_Surface * to);
  213. };
  214. class CExchangeWindow : public CWindowObject, public CWindowWithGarrison, public CWindowWithArtifacts
  215. {
  216. CGStatusBar * ourBar; //internal statusbar
  217. CButton * quit, * questlogButton[2];
  218. std::vector<LRClickableAreaWTextComp *> secSkillAreas[2], primSkillAreas;
  219. MoraleLuckBox *morale[2], *luck[2];
  220. LRClickableAreaWText *specialty[2];
  221. LRClickableAreaWText *experience[2];
  222. LRClickableAreaWText *spellPoints[2];
  223. CHeroArea *portrait[2];
  224. public:
  225. const CGHeroInstance* heroInst[2];
  226. CArtifactsOfHero * artifs[2];
  227. void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right
  228. void prepareBackground(); //prepares or redraws bg
  229. CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2, QueryID queryID); //c-tor
  230. ~CExchangeWindow(); //d-tor
  231. };
  232. /// Here you can buy ships
  233. class CShipyardWindow : public CWindowObject
  234. {
  235. public:
  236. CGStatusBar *bar;
  237. CPicture *bgWater;
  238. CLabel *title;
  239. CLabel *costLabel;
  240. CAnimImage *woodPic, *goldPic;
  241. CLabel *woodCost, *goldCost;
  242. CAnimImage *bgShip;
  243. CButton *build, *quit;
  244. CGStatusBar * statusBar;
  245. CShipyardWindow(const std::vector<si32> &cost, int state, int boatType, const std::function<void()> &onBuy);
  246. };
  247. /// Puzzle screen which gets uncovered when you visit obilisks
  248. class CPuzzleWindow : public CWindowObject
  249. {
  250. private:
  251. int3 grailPos;
  252. CButton * quitb;
  253. std::vector<CPicture * > piecesToRemove;
  254. ui8 currentAlpha;
  255. public:
  256. void showAll(SDL_Surface * to);
  257. void show(SDL_Surface * to);
  258. CPuzzleWindow(const int3 &grailPos, double discoveredRatio);
  259. };
  260. /// Creature transformer window
  261. class CTransformerWindow : public CWindowObject, public CGarrisonHolder
  262. {
  263. public:
  264. class CItem : public CIntObject
  265. {
  266. public:
  267. int id;//position of creature in hero army
  268. bool left;//position of the item
  269. int size; //size of creature stack
  270. CTransformerWindow * parent;
  271. CAnimImage *icon;
  272. void move();
  273. void clickLeft(tribool down, bool previousState);
  274. void update();
  275. CItem(CTransformerWindow * parent, int size, int id);
  276. };
  277. const CArmedInstance *army;//object with army for transforming (hero or town)
  278. const CGHeroInstance *hero;//only if we have hero in town
  279. const CGTownInstance *town;//market, town garrison is used if hero == nullptr
  280. std::vector<CItem*> items;
  281. CButton *all, *convert, *cancel;
  282. CGStatusBar *bar;
  283. void makeDeal();
  284. void addAll();
  285. void updateGarrisons();
  286. CTransformerWindow(const CGHeroInstance * _hero, const CGTownInstance * _town); //c-tor
  287. };
  288. class CUniversityWindow : public CWindowObject
  289. {
  290. class CItem : public CAnimImage
  291. {
  292. public:
  293. int ID;//id of selected skill
  294. CUniversityWindow * parent;
  295. void showAll(SDL_Surface * to);
  296. void clickLeft(tribool down, bool previousState);
  297. void clickRight(tribool down, bool previousState);
  298. void hover(bool on);
  299. int state();//0=can't learn, 1=learned, 2=can learn
  300. CItem(CUniversityWindow * _parent, int _ID, int X, int Y);
  301. };
  302. public:
  303. const CGHeroInstance *hero;
  304. const IMarket * market;
  305. CPicture * green, * yellow, * red;//colored bars near skills
  306. std::vector<CItem*> items;
  307. CButton *cancel;
  308. CGStatusBar *bar;
  309. CUniversityWindow(const CGHeroInstance * _hero, const IMarket * _market); //c-tor
  310. };
  311. /// Confirmation window for University
  312. class CUnivConfirmWindow : public CWindowObject
  313. {
  314. public:
  315. CUniversityWindow * parent;
  316. CGStatusBar *bar;
  317. CButton *confirm, *cancel;
  318. CUnivConfirmWindow(CUniversityWindow * PARENT, int SKILL, bool available); //c-tor
  319. void makeDeal(int skill);
  320. };
  321. /// Hill fort is the building where you can upgrade units
  322. class CHillFortWindow : public CWindowObject, public CWindowWithGarrison
  323. {
  324. public:
  325. int slotsCount;//=7;
  326. CGStatusBar * bar;
  327. CDefEssential *resources;
  328. CHeroArea *heroPic;//clickable hero image
  329. CButton *quit,//closes window
  330. *upgradeAll,//upgrade all creatures
  331. *upgrade[7];//upgrade single creature
  332. const CGObjectInstance * fort;
  333. const CGHeroInstance * hero;
  334. std::vector<int> currState;//current state of slot - to avoid calls to getState or updating buttons
  335. std::vector<TResources> costs;// costs [slot ID] [resource ID] = resource count for upgrade
  336. TResources totalSumm; // totalSum[resource ID] = value
  337. CHillFortWindow(const CGHeroInstance *visitor, const CGObjectInstance *object); //c-tor
  338. void showAll (SDL_Surface *to);
  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. void updateGarrisons();//update buttons after garrison changes
  344. };
  345. class CThievesGuildWindow : public CWindowObject
  346. {
  347. const CGObjectInstance * owner;
  348. CGStatusBar * statusBar;
  349. CButton * exitb;
  350. CMinorResDataBar * resdatabar;
  351. public:
  352. CThievesGuildWindow(const CGObjectInstance * _owner);
  353. };