GUIClasses.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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. #include <boost/thread/mutex.hpp>
  10. #ifdef max
  11. #undef max
  12. #endif
  13. #ifdef min
  14. #undef min
  15. #endif
  16. /*
  17. * GUIClasses.h, part of VCMI engine
  18. *
  19. * Authors: listed in file AUTHORS in main folder
  20. *
  21. * License: GNU General Public License v2.0 or later
  22. * Full text of license available in license.txt file, in main folder
  23. *
  24. */
  25. class CDefEssential;
  26. class AdventureMapButton;
  27. class CHighlightableButtonsGroup;
  28. class CDefHandler;
  29. struct HeroMoveDetails;
  30. class CDefEssential;
  31. class CGHeroInstance;
  32. class CAdvMapInt;
  33. class CCastleInterface;
  34. class CBattleInterface;
  35. class CStack;
  36. class SComponent;
  37. class CCreature;
  38. struct SDL_Surface;
  39. struct CPath;
  40. class CCreatureAnimation;
  41. class CSelectableComponent;
  42. class CCreatureSet;
  43. class CGObjectInstance;
  44. class CSlider;
  45. struct UpgradeInfo;
  46. template <typename T> struct CondSh;
  47. class CInGameConsole;
  48. class CGarrisonInt;
  49. class CInGameConsole;
  50. class Component;
  51. class CArmedInstance;
  52. class CGTownInstance;
  53. class StackState;
  54. class CPlayerInterface;
  55. class CInfoWindow : public CSimpleWindow //text + comp. + ok button
  56. { //window able to delete its components when closed
  57. public:
  58. bool delComps; //whether comps will be deleted
  59. std::vector<AdventureMapButton *> buttons;
  60. std::vector<SComponent*> components;
  61. virtual void close();
  62. virtual void show(SDL_Surface * to);
  63. void activate();
  64. void deactivate();
  65. 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
  66. CInfoWindow(); //c-tor
  67. ~CInfoWindow(); //d-tor
  68. };
  69. class CSelWindow : public CInfoWindow //component selection window
  70. { //warning - this window deletes its components by closing!
  71. public:
  72. void selectionChange(unsigned to);
  73. void madeChoice(); //looks for selected component and calls callback
  74. 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
  75. CSelWindow(){}; //c-tor
  76. //notification - this class inherits important destructor from CInfoWindow
  77. };
  78. class CRClickPopup : public IShowActivable, public ClickableR //popup displayed on R-click
  79. {
  80. public:
  81. virtual void activate();
  82. virtual void deactivate();
  83. virtual void close();
  84. void clickRight (boost::logic::tribool down);
  85. virtual ~CRClickPopup(){}; //d-tor
  86. };
  87. class CRClickPopupInt : public CRClickPopup //popup displayed on R-click
  88. {
  89. public:
  90. IShowActivable *inner;
  91. bool delInner;
  92. void show(SDL_Surface * to);
  93. CRClickPopupInt(IShowActivable *our, bool deleteInt); //c-tor
  94. virtual ~CRClickPopupInt(); //d-tor
  95. };
  96. class CInfoPopup : public CRClickPopup
  97. {
  98. public:
  99. bool free; //TODO: comment me
  100. SDL_Surface * bitmap; //popup background
  101. void close();
  102. void show(SDL_Surface * to);
  103. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false); //c-tor
  104. CInfoPopup(SDL_Surface *Bitmap = NULL, bool Free = false); //default c-tor
  105. ~CInfoPopup(){}; //d-tor
  106. };
  107. class SComponent : public ClickableR //common popup window component
  108. {
  109. public:
  110. enum Etype
  111. {
  112. primskill, secskill, resource, creature, artifact, experience, secskill44, spell, morale, luck
  113. } type; //component type
  114. int subtype; //TODO: comment me
  115. int val; //TODO: comment me
  116. std::string description; //r-click
  117. std::string subtitle; //TODO: comment me
  118. void init(Etype Type, int Subtype, int Val);
  119. SComponent(Etype Type, int Subtype, int Val); //c-tor
  120. SComponent(const Component &c); //c-tor
  121. SComponent(){}; //c-tor
  122. virtual ~SComponent(){}; //d-tor
  123. void clickRight (boost::logic::tribool down); //call-in
  124. virtual SDL_Surface * getImg();
  125. virtual void show(SDL_Surface * to);
  126. virtual void activate();
  127. virtual void deactivate();
  128. };
  129. class CCustomImgComponent : public SComponent
  130. {
  131. public:
  132. SDL_Surface *bmp; //our image
  133. bool free; //should surface be freed on delete
  134. SDL_Surface * getImg();
  135. CCustomImgComponent(Etype Type, int Subtype, int Val, SDL_Surface *sur, bool freeSur); //c-tor
  136. ~CCustomImgComponent(); //d-tor
  137. };
  138. class CSelectableComponent : public SComponent, public KeyShortcut
  139. {
  140. public:
  141. bool selected; //if true, this component is selected
  142. bool customB; //TODO: comment me
  143. SDL_Surface * border, *myBitmap;
  144. boost::function<void()> onSelect; //function called on selection change
  145. void clickLeft(boost::logic::tribool down); //call-in
  146. void init(SDL_Surface * Border);
  147. CSelectableComponent(Etype Type, int Sub, int Val, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
  148. CSelectableComponent(const Component &c, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
  149. ~CSelectableComponent(); //d-tor
  150. virtual void show(SDL_Surface * to);
  151. void activate();
  152. void deactivate();
  153. void select(bool on);
  154. SDL_Surface * getImg(); //returns myBitmap
  155. };
  156. class CGarrisonInt;
  157. class CGarrisonSlot : public ClickableL, public ClickableR, public Hoverable
  158. {
  159. public:
  160. CGarrisonInt *owner;
  161. const CCreature * creature; //creature in slot
  162. int count; //number of creatures
  163. int upg; //0 - up garrison, 1 - down garrison
  164. bool active; //TODO: comment me
  165. virtual void hover (bool on); //call-in
  166. const CArmedInstance * getObj();
  167. void clickRight (boost::logic::tribool down);
  168. void clickLeft(boost::logic::tribool down);
  169. void activate();
  170. void deactivate();
  171. void show(SDL_Surface * to);
  172. CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg=0, const CCreature * Creature=NULL, int Count=0);
  173. ~CGarrisonSlot(); //d-tor
  174. };
  175. class CGarrisonInt :public CIntObject
  176. {
  177. public:
  178. int interx, intery; //intervals between slots
  179. CGarrisonSlot *highlighted; //choosen slot
  180. SDL_Surface *&sur; //TODO: comment me
  181. int offx, offy, p2; //TODO: comment me
  182. bool ignoreEvent, update, active, splitting, pb;
  183. const CCreatureSet *set1; //top set of creatures
  184. const CCreatureSet *set2; //bottom set of creatures
  185. std::vector<CGarrisonSlot*> *sup, *sdown; //slots of upper and lower garrison
  186. const CArmedInstance *oup, *odown; //upper and lower garrisons (heroes or towns)
  187. void activate();
  188. void deactivate();
  189. void show(SDL_Surface * to);
  190. void activeteSlots();
  191. void deactiveteSlots();
  192. void deleteSlots();
  193. void createSlots();
  194. void recreateSlots();
  195. void splitClick(); //handles click on split button
  196. void splitStacks(int am2); //TODO: comment me
  197. 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
  198. ~CGarrisonInt(); //d-tor
  199. };
  200. class CStatusBar
  201. : public CIntObject, public IStatusBar
  202. {
  203. public:
  204. SDL_Surface * bg; //background
  205. int middlex, middley; //middle of statusbar
  206. std::string current; //text currently printed
  207. CStatusBar(int x, int y, std::string name="ADROLLVR.bmp", int maxw=-1); //c-tor
  208. ~CStatusBar(); //d-tor
  209. void print(const std::string & text); //prints text and refreshes statusbar
  210. void clear();//clears statusbar and refreshes
  211. void show(SDL_Surface * to); //shows statusbar (with current text)
  212. std::string getCurrent(); //getter for current
  213. };
  214. class CList
  215. : public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public virtual CIntObject, public MotionInterested
  216. {
  217. public:
  218. SDL_Surface * bg; //background bitmap
  219. CDefHandler *arrup, *arrdo; //button arrows for scrolling list
  220. SDL_Surface *empty, *selection;
  221. SDL_Rect arrupp, arrdop; //positions of arrows
  222. int posw, posh; //position width/height
  223. int selected, //id of selected position, <0 if none
  224. from;
  225. const int SIZE; //size of list
  226. boost::logic::tribool pressed; //true=up; false=down; indeterminate=none
  227. CList(int Size = 5); //c-tor
  228. void clickLeft(boost::logic::tribool down);
  229. void activate();
  230. void deactivate();
  231. virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; //call-in
  232. virtual void genList()=0;
  233. virtual void select(int which)=0;
  234. virtual void draw(SDL_Surface * to)=0;
  235. };
  236. class CHeroList
  237. : public CList
  238. {
  239. public:
  240. CDefHandler *mobile, *mana; //mana and movement indicators
  241. int posmobx, posporx, posmanx, posmoby, pospory, posmany;
  242. std::vector<const CGHeroInstance *> &heroes; //points to LOCPLINT->wandering heroes
  243. CHeroList(int Size); //c-tor
  244. int getPosOfHero(const CGHeroInstance* h); //hero's position on list
  245. void genList();
  246. void select(int which); //call-in
  247. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  248. void clickLeft(boost::logic::tribool down); //call-in
  249. void clickRight(boost::logic::tribool down); //call-in
  250. void hover (bool on); //call-in
  251. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  252. void updateHList(const CGHeroInstance *toRemove=NULL); //removes specific hero from the list or recreates it
  253. void updateMove(const CGHeroInstance* which); //draws move points bar
  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. boost::mutex texts_mx; // protects texts
  478. std::vector< std::string > previouslyEntered; //previously entered texts, for up/down arrows to work
  479. int prevEntDisp; //displayed entry from previouslyEntered - if none it's -1
  480. int defaultTimeout; //timeout for new texts (in ms)
  481. int maxDisplayedTexts; //hiw many texts can be displayed simultaneously
  482. public:
  483. std::string enteredText;
  484. void activate();
  485. void deactivate();
  486. void show(SDL_Surface * to);
  487. void print(const std::string &txt);
  488. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  489. void startEnteringText();
  490. void endEnteringText(bool printEnteredText);
  491. void refreshEnteredText();
  492. CInGameConsole(); //c-tor
  493. };
  494. class CGarrisonWindow : public CWindowWithGarrison, public CIntObject
  495. {
  496. public:
  497. SDL_Surface *bg; //background surface
  498. AdventureMapButton *split, *quit;
  499. void close();
  500. void activate();
  501. void deactivate();
  502. void show(SDL_Surface * to);
  503. CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down); //c-tor
  504. ~CGarrisonWindow(); //d-tor
  505. };
  506. #endif //__GUICLASSES_H__