GUIClasses.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. #ifndef __GUICLASSES_H__
  2. #define __GUICLASSES_H__
  3. #include "../global.h"
  4. #include "SDL_framerate.h"
  5. #include "GUIBase.h"
  6. #include "FunctionList.h"
  7. #include <set>
  8. #include <list>
  9. #ifdef max
  10. #undef max
  11. #endif
  12. #ifdef min
  13. #undef min
  14. #endif
  15. /*
  16. * GUIClasses.h, part of VCMI engine
  17. *
  18. * Authors: listed in file AUTHORS in main folder
  19. *
  20. * License: GNU General Public License v2.0 or later
  21. * Full text of license available in license.txt file, in main folder
  22. *
  23. */
  24. class CDefEssential;
  25. class AdventureMapButton;
  26. class CHighlightableButtonsGroup;
  27. class CDefHandler;
  28. struct HeroMoveDetails;
  29. class CDefEssential;
  30. class CGHeroInstance;
  31. class CAdvMapInt;
  32. class CCastleInterface;
  33. class CBattleInterface;
  34. class CStack;
  35. class SComponent;
  36. class CCreature;
  37. struct SDL_Surface;
  38. struct CPath;
  39. class CCreatureAnimation;
  40. class CSelectableComponent;
  41. class CCreatureSet;
  42. class CGObjectInstance;
  43. class CSlider;
  44. struct UpgradeInfo;
  45. template <typename T> struct CondSh;
  46. class CInGameConsole;
  47. class CGarrisonInt;
  48. class CInGameConsole;
  49. class Component;
  50. class CArmedInstance;
  51. class CGTownInstance;
  52. class StackState;
  53. class CPlayerInterface;
  54. class CInfoWindow : public CSimpleWindow //text + comp. + ok button
  55. { //window able to delete its components when closed
  56. public:
  57. bool delComps; //whether comps will be deleted
  58. std::vector<AdventureMapButton *> buttons;
  59. std::vector<SComponent*> components;
  60. virtual void close();
  61. virtual void show(SDL_Surface * to);
  62. void activate();
  63. void deactivate();
  64. CInfoWindow(std::string text, int player, int charperline, const std::vector<SComponent*> &comps, std::vector<std::pair<std::string,CFunctionList<void()> > > &Buttons, bool delComps); //c-tor
  65. CInfoWindow(); //c-tor
  66. ~CInfoWindow(); //d-tor
  67. };
  68. class CSelWindow : public CInfoWindow //component selection window
  69. { //warning - this window deletes its components by closing!
  70. public:
  71. void selectionChange(unsigned to);
  72. void madeChoice(); //looks for selected component and calls callback
  73. CSelWindow(const std::string& text, int player, int charperline ,const std::vector<CSelectableComponent*> &comps, const std::vector<std::pair<std::string,CFunctionList<void()> > > &Buttons, int askID); //c-tor
  74. CSelWindow(){}; //c-tor
  75. //notification - this class inherits important destructor from CInfoWindow
  76. };
  77. class CRClickPopup : public IShowActivable, public ClickableR //popup displayed on R-click
  78. {
  79. public:
  80. virtual void activate();
  81. virtual void deactivate();
  82. virtual void close();
  83. void clickRight (boost::logic::tribool down);
  84. virtual ~CRClickPopup(){}; //d-tor
  85. };
  86. class CRClickPopupInt : public CRClickPopup //popup displayed on R-click
  87. {
  88. public:
  89. IShowActivable *inner;
  90. bool delInner;
  91. void show(SDL_Surface * to);
  92. CRClickPopupInt(IShowActivable *our, bool deleteInt); //c-tor
  93. virtual ~CRClickPopupInt(); //d-tor
  94. };
  95. class CInfoPopup : public CRClickPopup
  96. {
  97. public:
  98. bool free; //TODO: comment me
  99. SDL_Surface * bitmap; //popup background
  100. void close();
  101. void show(SDL_Surface * to);
  102. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false); //c-tor
  103. CInfoPopup(SDL_Surface *Bitmap = NULL, bool Free = false); //default c-tor
  104. ~CInfoPopup(){}; //d-tor
  105. };
  106. class SComponent : public ClickableR //common popup window component
  107. {
  108. public:
  109. enum Etype
  110. {
  111. primskill, secskill, resource, creature, artifact, experience, secskill44, spell, morale, luck
  112. } type; //component type
  113. int subtype; //TODO: comment me
  114. int val; //TODO: comment me
  115. std::string description; //r-click
  116. std::string subtitle; //TODO: comment me
  117. void init(Etype Type, int Subtype, int Val);
  118. SComponent(Etype Type, int Subtype, int Val); //c-tor
  119. SComponent(const Component &c); //c-tor
  120. SComponent(){}; //c-tor
  121. virtual ~SComponent(){}; //d-tor
  122. void clickRight (boost::logic::tribool down); //call-in
  123. virtual SDL_Surface * getImg();
  124. virtual void show(SDL_Surface * to);
  125. virtual void activate();
  126. virtual void deactivate();
  127. };
  128. class CCustomImgComponent : public SComponent
  129. {
  130. public:
  131. SDL_Surface *bmp; //our image
  132. bool free; //should surface be freed on delete
  133. SDL_Surface * getImg();
  134. CCustomImgComponent(Etype Type, int Subtype, int Val, SDL_Surface *sur, bool freeSur); //c-tor
  135. ~CCustomImgComponent(); //d-tor
  136. };
  137. class CSelectableComponent : public SComponent, public KeyShortcut
  138. {
  139. public:
  140. bool selected; //if true, this component is selected
  141. bool customB; //TODO: comment me
  142. SDL_Surface * border, *myBitmap;
  143. boost::function<void()> onSelect; //function called on selection change
  144. void clickLeft(boost::logic::tribool down); //call-in
  145. void init(SDL_Surface * Border);
  146. CSelectableComponent(Etype Type, int Sub, int Val, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
  147. CSelectableComponent(const Component &c, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
  148. ~CSelectableComponent(); //d-tor
  149. virtual void show(SDL_Surface * to);
  150. void activate();
  151. void deactivate();
  152. void select(bool on);
  153. SDL_Surface * getImg(); //returns myBitmap
  154. };
  155. class CGarrisonInt;
  156. class CGarrisonSlot : public ClickableL, public ClickableR, public Hoverable
  157. {
  158. public:
  159. CGarrisonInt *owner;
  160. const CCreature * creature; //creature in slot
  161. int count; //number of creatures
  162. int upg; //0 - up garrison, 1 - down garrison
  163. bool active; //TODO: comment me
  164. virtual void hover (bool on); //call-in
  165. const CArmedInstance * getObj();
  166. void clickRight (boost::logic::tribool down);
  167. void clickLeft(boost::logic::tribool down);
  168. void activate();
  169. void deactivate();
  170. void show(SDL_Surface * to);
  171. CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg=0, const CCreature * Creature=NULL, int Count=0);
  172. ~CGarrisonSlot(); //d-tor
  173. };
  174. class CGarrisonInt :public CIntObject
  175. {
  176. public:
  177. int interx, intery; //intervals between slots
  178. CGarrisonSlot *highlighted; //choosen slot
  179. SDL_Surface *&sur; //TODO: comment me
  180. int offx, offy, p2; //TODO: comment me
  181. bool ignoreEvent, update, active, splitting, pb;
  182. const CCreatureSet *set1; //top set of creatures
  183. const CCreatureSet *set2; //bottom set of creatures
  184. std::vector<CGarrisonSlot*> *sup, *sdown; //slots of upper and lower garrison
  185. const CArmedInstance *oup, *odown; //upper and lower garrisons (heroes or towns)
  186. void activate();
  187. void deactivate();
  188. void show(SDL_Surface * to);
  189. void activeteSlots();
  190. void deactiveteSlots();
  191. void deleteSlots();
  192. void createSlots();
  193. void recreateSlots();
  194. void splitClick(); //handles click on split button
  195. void splitStacks(int am2); //TODO: comment me
  196. CGarrisonInt(int x, int y, int inx, int iny, SDL_Surface *&pomsur, int OX, int OY, const CArmedInstance *s1, const CArmedInstance *s2=NULL); //c-tor
  197. ~CGarrisonInt(); //d-tor
  198. };
  199. class CStatusBar
  200. : public CIntObject, public IStatusBar
  201. {
  202. public:
  203. SDL_Surface * bg; //background
  204. int middlex, middley; //middle of statusbar
  205. std::string current; //text currently printed
  206. CStatusBar(int x, int y, std::string name="ADROLLVR.bmp", int maxw=-1); //c-tor
  207. ~CStatusBar(); //d-tor
  208. void print(const std::string & text); //prints text and refreshes statusbar
  209. void clear();//clears statusbar and refreshes
  210. void show(SDL_Surface * to); //shows statusbar (with current text)
  211. std::string getCurrent(); //getter for current
  212. };
  213. class CList
  214. : public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public virtual CIntObject, public MotionInterested
  215. {
  216. public:
  217. SDL_Surface * bg; //background bitmap
  218. CDefHandler *arrup, *arrdo; //button arrows for scrolling list
  219. SDL_Surface *empty, *selection;
  220. SDL_Rect arrupp, arrdop; //positions of arrows
  221. int posw, posh; //position width/height
  222. int selected, //id of selected position, <0 if none
  223. from;
  224. const int SIZE; //size of list
  225. boost::logic::tribool pressed; //true=up; false=down; indeterminate=none
  226. CList(int Size = 5); //c-tor
  227. void clickLeft(boost::logic::tribool down);
  228. void activate();
  229. void deactivate();
  230. virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; //call-in
  231. virtual void genList()=0;
  232. virtual void select(int which)=0;
  233. virtual void draw(SDL_Surface * to)=0;
  234. };
  235. class CHeroList
  236. : public CList
  237. {
  238. public:
  239. CDefHandler *mobile, *mana; //mana and movement indicators
  240. std::vector<std::pair<const CGHeroInstance*, CPath *> > items;
  241. int posmobx, posporx, posmanx, posmoby, pospory, posmany;
  242. CHeroList(int Size); //c-tor
  243. int getPosOfHero(const CArmedInstance* h); //hero's position on list
  244. void genList();
  245. void select(int which); //call-in
  246. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  247. void clickLeft(boost::logic::tribool down); //call-in
  248. void clickRight(boost::logic::tribool down); //call-in
  249. void hover (bool on); //call-in
  250. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  251. void updateHList(const CGHeroInstance *toRemove=NULL); //removes specific hero from the list or recreates it
  252. void updateMove(const CGHeroInstance* which); //draws move points bar
  253. void redrawAllOne(int which); //not imeplemented
  254. void draw(SDL_Surface * to);
  255. void init();
  256. };
  257. class CTownList
  258. : public CList
  259. {
  260. public:
  261. boost::function<void()> fun; //function called on selection change
  262. std::vector<const CGTownInstance*> items; //towns on list
  263. int posporx,pospory;
  264. CTownList(int Size, int x, int y, std::string arrupg, std::string arrdog); //c-tor
  265. ~CTownList(); //d-tor
  266. void genList();
  267. void select(int which); //call-in
  268. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  269. void clickLeft(boost::logic::tribool down); //call-in
  270. void clickRight(boost::logic::tribool down); //call-in
  271. void hover (bool on); //call-in
  272. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  273. void draw(SDL_Surface * to);
  274. };
  275. class CCreaturePic //draws picture with creature on background, use nextFrame=true to get animation
  276. {
  277. public:
  278. CCreature *c; //which creature's picture
  279. bool big; //big => 100x130; !big => 100x120
  280. CCreatureAnimation *anim; //displayed animation
  281. CCreaturePic(CCreature *cre, bool Big=true); //c-tor
  282. ~CCreaturePic(); //d-tor
  283. int blitPic(SDL_Surface *to, int x, int y, bool nextFrame); //prints creature on screen
  284. SDL_Surface * getPic(bool nextFrame); //returns frame of animation
  285. };
  286. class CRecruitmentWindow : public IShowActivable, public ClickableL, public ClickableR
  287. {
  288. public:
  289. struct creinfo
  290. {
  291. SDL_Rect pos;
  292. CCreaturePic *pic; //creature's animation
  293. int ID, amount; //creature ID and available amount
  294. std::vector<std::pair<int,int> > res; //res_id - cost_per_unit
  295. };
  296. std::vector<int> amounts; //how many creatures we can afford
  297. std::vector<creinfo> creatures; //recruitable creatures
  298. boost::function<void(int,int)> recruit; //void (int ID, int amount) <-- call to recruit creatures
  299. CSlider *slider; //for selecting amount
  300. AdventureMapButton *max, *buy, *cancel;
  301. SDL_Surface *bitmap; //background
  302. CStatusBar *bar;
  303. int which; //which creature is active
  304. void close();
  305. void Max();
  306. void Buy();
  307. void Cancel();
  308. void sliderMoved(int to);
  309. void clickLeft(boost::logic::tribool down);
  310. void clickRight(boost::logic::tribool down);
  311. void activate();
  312. void deactivate();
  313. void show(SDL_Surface * to);
  314. CRecruitmentWindow(const std::vector<std::pair<int,int> > & Creatures, const boost::function<void(int,int)> & Recruit); //creatures - pairs<creature_ID,amount> //c-tor
  315. ~CRecruitmentWindow(); //d-tor
  316. };
  317. class CSplitWindow : public IShowActivable, public KeyInterested, public ClickableL
  318. {
  319. public:
  320. CGarrisonInt *gar;
  321. CSlider *slider;
  322. CCreaturePic *anim; //creature's animation
  323. AdventureMapButton *ok, *cancel;
  324. SDL_Surface *bitmap; //background
  325. int a1, a2, c; //TODO: comment me
  326. bool which; //which creature is selected
  327. int last; //0/1/2 - at least one creature must be in the src/dst/both stacks; -1 - no restrictions
  328. CSplitWindow(int cid, int max, CGarrisonInt *Owner, int Last = -1, int val=0); //c-tor; val - initial amount of second stack
  329. ~CSplitWindow(); //d-tor
  330. void activate();
  331. void split();
  332. void close();
  333. void deactivate();
  334. void show(SDL_Surface * to);
  335. void clickLeft(boost::logic::tribool down); //call-in
  336. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  337. void sliderMoved(int to);
  338. };
  339. class CCreInfoWindow : public IShowActivable, public KeyInterested, public ClickableR
  340. {
  341. public:
  342. //bool active; //TODO: comment me
  343. int type;//0 - rclick popup; 1 - normal window
  344. SDL_Surface *bitmap; //background
  345. char anf; //animation counter
  346. std::string count; //creature count in text format
  347. boost::function<void()> dsm; //dismiss button callback
  348. CCreaturePic *anim; //related creature's animation
  349. CCreature *c; //related creature
  350. std::vector<SComponent*> upgResCost; //cost of upgrade (if not possible then empty)
  351. AdventureMapButton *dismiss, *upgrade, *ok;
  352. CCreInfoWindow(int Cid, int Type, int creatureCount, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm, UpgradeInfo *ui); //c-tor
  353. ~CCreInfoWindow(); //d-tor
  354. void activate();
  355. void close();
  356. void clickRight(boost::logic::tribool down); //call-in
  357. void dismissF();
  358. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  359. void deactivate();
  360. void show(SDL_Surface * to);
  361. };
  362. class CLevelWindow : public IShowActivable, public CIntObject
  363. {
  364. public:
  365. int heroType;
  366. SDL_Surface *bitmap; //background
  367. std::vector<CSelectableComponent *> comps; //skills to select
  368. AdventureMapButton *ok;
  369. boost::function<void(ui32)> cb;
  370. void close();
  371. CLevelWindow(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback); //c-tor
  372. ~CLevelWindow(); //d-tor
  373. void activate();
  374. void deactivate();
  375. void selectionChanged(unsigned to);
  376. void show(SDL_Surface * to);
  377. };
  378. class CMinorResDataBar : public IShowable, public CIntObject
  379. {
  380. public:
  381. SDL_Surface *bg; //background bitmap
  382. void show(SDL_Surface * to);
  383. CMinorResDataBar(); //c-tor
  384. ~CMinorResDataBar(); //d-tor
  385. };
  386. class CMarketplaceWindow : public IShowActivable, public CIntObject
  387. {
  388. public:
  389. class CTradeableItem : public ClickableL
  390. {
  391. public:
  392. int type; //0 - res, 1 - artif big, 2 - artif small, 3 - player flag
  393. int id;
  394. bool left;
  395. CFunctionList<void()> callback;
  396. void activate();
  397. void deactivate();
  398. void show(SDL_Surface * to);
  399. void clickLeft(boost::logic::tribool down);
  400. SDL_Surface *getSurface();
  401. CTradeableItem(int Type, int ID, bool Left);
  402. };
  403. SDL_Surface *bg; //background
  404. std::vector<CTradeableItem*> left, right;
  405. std::vector<std::string> rSubs; //offer caption
  406. CTradeableItem *hLeft, *hRight; //highlighted items (NULL if no highlight)
  407. int mode,//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact
  408. r1, r2; //suggested amounts of traded resources
  409. AdventureMapButton *ok, *max, *deal;
  410. CSlider *slider; //for choosing amount to be exchanged
  411. void activate();
  412. void deactivate();
  413. void show(SDL_Surface * to);
  414. void setMax();
  415. void sliderMoved(int to);
  416. void makeDeal();
  417. void selectionChanged(bool side); //true == left
  418. CMarketplaceWindow(int Mode=0); //c-tor
  419. ~CMarketplaceWindow(); //d-tor
  420. void setMode(int mode); //mode setter
  421. void clear();
  422. };
  423. class CSystemOptionsWindow : public IShowActivable, public CIntObject
  424. {
  425. private:
  426. SDL_Surface * background; //background of window
  427. AdventureMapButton *load, *save, *restart, *mainMenu, * quitGame, * backToMap; //load, restart and main menu are not used yet
  428. CHighlightableButtonsGroup * heroMoveSpeed;
  429. CHighlightableButtonsGroup * mapScrollSpeed;
  430. CHighlightableButtonsGroup * musicVolume, * effectsVolume;
  431. public:
  432. CSystemOptionsWindow(const SDL_Rect & pos, CPlayerInterface * owner); //c-tor
  433. ~CSystemOptionsWindow(); //d-tor
  434. //functions bound to buttons
  435. void bsavef(); //save game
  436. void bquitf(); //quit game
  437. void breturnf(); //return to game
  438. void activate();
  439. void deactivate();
  440. void show(SDL_Surface * to);
  441. };
  442. class CTavernWindow : public IShowActivable, public CIntObject
  443. {
  444. public:
  445. class HeroPortrait : public ClickableL, public ClickableR, public Hoverable
  446. {
  447. public:
  448. std::string hoverName;
  449. vstd::assigner<int,int> as;
  450. const CGHeroInstance *h;
  451. void activate();
  452. void deactivate();
  453. void clickLeft(boost::logic::tribool down);
  454. void clickRight(boost::logic::tribool down);
  455. void hover (bool on);
  456. HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H);
  457. void show(SDL_Surface * to);
  458. char descr[100]; // "XXX is a level Y ZZZ with N artifacts"
  459. } h1, h2; //recruitable heroes
  460. SDL_Surface *bg; //background
  461. CStatusBar *bar; //tavern's internal status bar
  462. int selected;//0 (left) or 1 (right)
  463. int oldSelected;//0 (left) or 1 (right)
  464. AdventureMapButton *thiefGuild, *cancel, *recruit;
  465. CTavernWindow(const CGHeroInstance *H1, const CGHeroInstance *H2, const std::string &gossip); //c-tor
  466. ~CTavernWindow(); //d-tor
  467. void recruitb();
  468. void close();
  469. void activate();
  470. void deactivate();
  471. void show(SDL_Surface * to);
  472. };
  473. class CInGameConsole : public IShowActivable, public KeyInterested
  474. {
  475. private:
  476. std::list< std::pair< std::string, int > > texts; //<text to show, time of add>
  477. std::vector< std::string > previouslyEntered; //previously entered texts, for up/down arrows to work
  478. int prevEntDisp; //displayed entry from previouslyEntered - if none it's -1
  479. int defaultTimeout; //timeout for new texts (in ms)
  480. int maxDisplayedTexts; //hiw many texts can be displayed simultaneously
  481. public:
  482. std::string enteredText;
  483. void activate();
  484. void deactivate();
  485. void show(SDL_Surface * to);
  486. void print(const std::string &txt);
  487. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  488. void startEnteringText();
  489. void endEnteringText(bool printEnteredText);
  490. void refreshEnteredText();
  491. CInGameConsole(); //c-tor
  492. };
  493. class CGarrisonWindow : public CWindowWithGarrison, public CIntObject
  494. {
  495. public:
  496. SDL_Surface *bg; //background surface
  497. AdventureMapButton *split, *quit;
  498. void close();
  499. void activate();
  500. void deactivate();
  501. void show(SDL_Surface * to);
  502. CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down); //c-tor
  503. ~CGarrisonWindow(); //d-tor
  504. };
  505. #endif //__GUICLASSES_H__