GUIClasses.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  1. #ifndef __GUICLASSES_H__
  2. #define __GUICLASSES_H__
  3. #include "../global.h"
  4. #include "../hch/CArtHandler.h"
  5. #include "SDL_framerate.h"
  6. #include "GUIBase.h"
  7. #include "FunctionList.h"
  8. #include <set>
  9. #include <list>
  10. #include <boost/thread/mutex.hpp>
  11. #ifdef max
  12. #undef max
  13. #endif
  14. #ifdef min
  15. #undef min
  16. #endif
  17. /*
  18. * GUIClasses.h, part of VCMI engine
  19. *
  20. * Authors: listed in file AUTHORS in main folder
  21. *
  22. * License: GNU General Public License v2.0 or later
  23. * Full text of license available in license.txt file, in main folder
  24. *
  25. */
  26. class CDefEssential;
  27. class AdventureMapButton;
  28. class CHighlightableButtonsGroup;
  29. class CDefHandler;
  30. struct HeroMoveDetails;
  31. class CDefEssential;
  32. class CGHeroInstance;
  33. class CAdvMapInt;
  34. class CCastleInterface;
  35. class CBattleInterface;
  36. class CStack;
  37. class SComponent;
  38. class CCreature;
  39. struct SDL_Surface;
  40. struct CPath;
  41. class CCreatureAnimation;
  42. class CSelectableComponent;
  43. class CCreatureSet;
  44. class CGObjectInstance;
  45. class CGDwelling;
  46. class CSlider;
  47. struct UpgradeInfo;
  48. template <typename T> struct CondSh;
  49. class CInGameConsole;
  50. class CGarrisonInt;
  51. class CInGameConsole;
  52. class Component;
  53. class CArmedInstance;
  54. class CGTownInstance;
  55. class StackState;
  56. class CPlayerInterface;
  57. class CHeroWindow;
  58. class CArtifact;
  59. class CArtifactsOfHero;
  60. class CResDataBar;
  61. struct SPuzzleInfo;
  62. class CGGarrison;
  63. class CStackInstance;
  64. extern SDL_Color tytulowy, tlo, zwykly ;
  65. class CInfoWindow : public CSimpleWindow //text + comp. + ok button
  66. { //window able to delete its components when closed
  67. public:
  68. bool delComps; //whether comps will be deleted
  69. std::vector<AdventureMapButton *> buttons;
  70. std::vector<SComponent*> components;
  71. CSlider *slider;
  72. virtual void close();
  73. void show(SDL_Surface * to);
  74. void showAll(SDL_Surface * to);
  75. void activate();
  76. void sliderMoved(int to);
  77. void deactivate();
  78. 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
  79. CInfoWindow(); //c-tor
  80. ~CInfoWindow(); //d-tor
  81. static void showYesNoDialog( const std::string & text, const std::vector<SComponent*> *components, const CFunctionList<void( ) > &onYes, const CFunctionList<void()> &onNo, bool DelComps = true, int player = 1); //use only before the game starts! (showYesNoDialog in LOCPLINT must be used then)
  82. static CInfoWindow *create(const std::string &text, int playerID = 1, const std::vector<SComponent*> *components = NULL);
  83. };
  84. class CSelWindow : public CInfoWindow //component selection window
  85. { //warning - this window deletes its components by closing!
  86. public:
  87. void selectionChange(unsigned to);
  88. void madeChoice(); //looks for selected component and calls callback
  89. 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
  90. CSelWindow(){}; //c-tor
  91. //notification - this class inherits important destructor from CInfoWindow
  92. };
  93. class CRClickPopup : public CIntObject //popup displayed on R-click
  94. {
  95. public:
  96. virtual void activate();
  97. virtual void deactivate();
  98. virtual void close();
  99. void clickRight(tribool down, bool previousState);
  100. CRClickPopup();
  101. virtual ~CRClickPopup(); //d-tor
  102. static void createAndPush(const std::string &txt);
  103. static void createAndPush(const CGObjectInstance *obj, const Point &p, EAlignment alignment = BOTTOMRIGHT);
  104. };
  105. class CRClickPopupInt : public CRClickPopup //popup displayed on R-click
  106. {
  107. public:
  108. IShowActivable *inner;
  109. bool delInner;
  110. void show(SDL_Surface * to);
  111. CRClickPopupInt(IShowActivable *our, bool deleteInt); //c-tor
  112. virtual ~CRClickPopupInt(); //d-tor
  113. };
  114. class CInfoPopup : public CRClickPopup
  115. {
  116. public:
  117. bool free; //TODO: comment me
  118. SDL_Surface * bitmap; //popup background
  119. void close();
  120. void show(SDL_Surface * to);
  121. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false); //c-tor
  122. CInfoPopup(SDL_Surface * Bitmap, const Point &p, EAlignment alignment, bool Free=false); //c-tor
  123. CInfoPopup(SDL_Surface *Bitmap = NULL, bool Free = false); //default c-tor
  124. void init(int x, int y);
  125. ~CInfoPopup(); //d-tor
  126. };
  127. class SComponent : public virtual CIntObject //common popup window component
  128. {
  129. public:
  130. enum Etype
  131. {
  132. primskill, secskill, resource, creature, artifact, experience, secskill44, spell, morale, luck, building, hero, flag
  133. } type; //component type
  134. int subtype; //TODO: comment me
  135. int val; //TODO: comment me
  136. std::string description; //r-click
  137. std::string subtitle; //TODO: comment me
  138. void init(Etype Type, int Subtype, int Val);
  139. SComponent(Etype Type, int Subtype, int Val); //c-tor
  140. SComponent(const Component &c); //c-tor
  141. SComponent(){}; //c-tor
  142. virtual ~SComponent(){}; //d-tor
  143. void clickRight(tribool down, bool previousState); //call-in
  144. virtual SDL_Surface * getImg();
  145. virtual void show(SDL_Surface * to);
  146. virtual void activate();
  147. virtual void deactivate();
  148. };
  149. class CCustomImgComponent : public SComponent
  150. {
  151. public:
  152. SDL_Surface *bmp; //our image
  153. bool free; //should surface be freed on delete
  154. SDL_Surface * getImg();
  155. CCustomImgComponent(Etype Type, int Subtype, int Val, SDL_Surface *sur, bool freeSur); //c-tor
  156. ~CCustomImgComponent(); //d-tor
  157. };
  158. class CSelectableComponent : public SComponent, public KeyShortcut
  159. {
  160. public:
  161. bool selected; //if true, this component is selected
  162. bool customB; //TODO: comment me
  163. SDL_Surface * border, *myBitmap;
  164. boost::function<void()> onSelect; //function called on selection change
  165. void clickLeft(tribool down, bool previousState); //call-in
  166. void init(SDL_Surface * Border);
  167. CSelectableComponent(Etype Type, int Sub, int Val, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
  168. CSelectableComponent(const Component &c, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
  169. ~CSelectableComponent(); //d-tor
  170. virtual void show(SDL_Surface * to);
  171. void activate();
  172. void deactivate();
  173. void select(bool on);
  174. SDL_Surface * getImg(); //returns myBitmap
  175. };
  176. class CGarrisonInt;
  177. class CGarrisonSlot : public CIntObject
  178. {
  179. public:
  180. CGarrisonInt *owner;
  181. const CStackInstance *myStack; //NULL if slot is empty
  182. const CCreature *creature;
  183. int count; //number of creatures
  184. int upg; //0 - up garrison, 1 - down garrison
  185. bool active; //TODO: comment me
  186. virtual void hover (bool on); //call-in
  187. const CArmedInstance * getObj();
  188. void clickRight(tribool down, bool previousState);
  189. void clickLeft(tribool down, bool previousState);
  190. void activate();
  191. void deactivate();
  192. void show(SDL_Surface * to);
  193. CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg=0, const CStackInstance * Creature=NULL);
  194. ~CGarrisonSlot(); //d-tor
  195. };
  196. class CGarrisonInt :public CIntObject
  197. {
  198. public:
  199. int interx; //space between slots
  200. Point garOffset, //offset between garrisons (not used if only one hero)
  201. surOffset, //offset between garrison position on the bg surface and position on the screen
  202. shiftPoint;//how last slots will be shifted (for second row, set shiftPoint for effect)
  203. CGarrisonSlot *highlighted; //chosen slot
  204. std::vector<AdventureMapButton *> splitButtons; //may be empty if no buttons
  205. SDL_Surface *&sur; //bg surface
  206. int p2, //TODO: comment me
  207. shiftPos;//1st slot of the second row, set shiftPoint for effect
  208. bool ignoreEvent, update, active, splitting, pb,
  209. smallIcons; //true - 32x32 imgs, false - 58x64
  210. bool removableUnits;
  211. const CCreatureSet *set1; //top set of creatures
  212. const CCreatureSet *set2; //bottom set of creatures
  213. std::vector<CGarrisonSlot*> *sup, *sdown; //slots of upper and lower garrison
  214. const CArmedInstance *oup, *odown; //upper and lower garrisons (heroes or towns)
  215. void activate();
  216. void deactivate();
  217. void show(SDL_Surface * to);
  218. void activeteSlots();
  219. void deactiveteSlots();
  220. void deleteSlots();
  221. void createSlots();
  222. void recreateSlots();
  223. void splitClick(); //handles click on split button
  224. void splitStacks(int am2); //TODO: comment me
  225. CGarrisonInt(int x, int y, int inx, const Point &garsOffset, SDL_Surface *&pomsur, const Point &SurOffset, const CArmedInstance *s1, const CArmedInstance *s2=NULL, bool _removableUnits = true, bool smallImgs = false, int _shiftPos = 0, const Point &_shiftPoint =Point()); //c-tor
  226. ~CGarrisonInt(); //d-tor
  227. };
  228. class CStatusBar
  229. : public CIntObject, public IStatusBar
  230. {
  231. public:
  232. SDL_Surface * bg; //background
  233. int middlex, middley; //middle of statusbar
  234. std::string current; //text currently printed
  235. CStatusBar(int x, int y, std::string name="ADROLLVR.bmp", int maxw=-1); //c-tor
  236. ~CStatusBar(); //d-tor
  237. void print(const std::string & text); //prints text and refreshes statusbar
  238. void clear();//clears statusbar and refreshes
  239. void show(SDL_Surface * to); //shows statusbar (with current text)
  240. std::string getCurrent(); //getter for current
  241. };
  242. class CLabel
  243. : public virtual CIntObject
  244. {
  245. public:
  246. EAlignment alignment;
  247. EFonts font;
  248. SDL_Color color;
  249. std::string text;
  250. CPicture *bg;
  251. bool autoRedraw;
  252. Point textOffset; //text will be blitted at pos + textOffset with appropriate alignment
  253. void setTxt(const std::string &Txt);
  254. void showAll(SDL_Surface * to); //shows statusbar (with current text)
  255. CLabel(int x=0, int y=0, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly, const std::string &Text = "");
  256. };
  257. class CGStatusBar
  258. : public CLabel, public IStatusBar
  259. {
  260. void init();
  261. public:
  262. IStatusBar *oldStatusBar;
  263. //statusbar interface overloads
  264. void print(const std::string & Text); //prints text and refreshes statusbar
  265. void clear();//clears statusbar and refreshes
  266. std::string getCurrent(); //returns currently displayed text
  267. void show(SDL_Surface * to); //shows statusbar (with current text)
  268. CGStatusBar(int x, int y, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = zwykly, const std::string &Text = "");
  269. CGStatusBar(CPicture *BG, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = zwykly); //given CPicture will be captured by created sbar and it's pos will be used as pos for sbar
  270. ~CGStatusBar();
  271. };
  272. class CFocusable
  273. : public virtual CIntObject
  274. {
  275. public:
  276. bool focus; //only one focusable control can have focus at one moment
  277. void giveFocus(); //captures focus
  278. void moveFocus(); //moves focus to next active control (may be used for tab switching)
  279. static std::list<CFocusable*> focusables; //all existing objs
  280. static CFocusable *inputWithFocus; //who has focus now
  281. CFocusable();
  282. ~CFocusable();
  283. };
  284. class CTextInput
  285. : public CLabel, public CFocusable
  286. {
  287. public:
  288. CFunctionList<void(const std::string &)> cb;
  289. void setText(const std::string &nText, bool callCb = false);
  290. CTextInput(const Rect &Pos, const Point &bgOffset, const std::string &bgName, const CFunctionList<void(const std::string &)> &CB);
  291. CTextInput(const Rect &Pos, SDL_Surface *srf);
  292. ~CTextInput();
  293. void showAll(SDL_Surface * to);
  294. void clickLeft(tribool down, bool previousState);
  295. void keyPressed(const SDL_KeyboardEvent & key);
  296. };
  297. class CList : public CIntObject
  298. {
  299. public:
  300. SDL_Surface * bg; //background bitmap
  301. CDefHandler *arrup, *arrdo; //button arrows for scrolling list
  302. SDL_Surface *empty, *selection;
  303. SDL_Rect arrupp, arrdop; //positions of arrows
  304. int posw, posh; //position width/height
  305. int selected, //id of selected position, <0 if none
  306. from;
  307. const int SIZE; //size of list
  308. tribool pressed; //true=up; false=down; indeterminate=none
  309. CList(int Size = 5); //c-tor
  310. void clickLeft(tribool down, bool previousState);
  311. void activate();
  312. void deactivate();
  313. virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; //call-in
  314. virtual void genList()=0;
  315. virtual void select(int which)=0;
  316. virtual void draw(SDL_Surface * to)=0;
  317. virtual int size() = 0; //how many elements do we have
  318. void fixPos(); //scrolls list, so the selection will be visible
  319. };
  320. class CHeroList
  321. : public CList
  322. {
  323. public:
  324. CDefHandler *mobile, *mana; //mana and movement indicators
  325. int posmobx, posporx, posmanx, posmoby, pospory, posmany;
  326. CHeroList(int Size); //c-tor
  327. int getPosOfHero(const CGHeroInstance* h); //hero's position on list
  328. void genList();
  329. void select(int which); //call-in
  330. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  331. void clickLeft(tribool down, bool previousState); //call-in
  332. void clickRight(tribool down, bool previousState); //call-in
  333. void hover (bool on); //call-in
  334. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  335. void updateHList(const CGHeroInstance *toRemove=NULL); //removes specific hero from the list or recreates it
  336. void updateMove(const CGHeroInstance* which); //draws move points bar
  337. void draw(SDL_Surface * to);
  338. void show(SDL_Surface * to);
  339. void init();
  340. int size(); //how many elements do we have
  341. };
  342. class CTownList
  343. : public CList
  344. {
  345. public:
  346. boost::function<void()> fun; //function called on selection change
  347. int posporx,pospory;
  348. CTownList(int Size, int x, int y, std::string arrupg, std::string arrdog); //c-tor
  349. ~CTownList(); //d-tor
  350. void genList();
  351. void select(int which); //call-in
  352. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  353. void clickLeft(tribool down, bool previousState); //call-in
  354. void clickRight(tribool down, bool previousState); //call-in
  355. void hover (bool on); //call-in
  356. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  357. void draw(SDL_Surface * to);
  358. void show(SDL_Surface * to);
  359. int size(); //how many elements do we have
  360. };
  361. class CCreaturePic //draws picture with creature on background, use nextFrame=true to get animation
  362. {
  363. public:
  364. const CCreature *c; //which creature's picture
  365. bool big; //big => 100x130; !big => 100x120
  366. CCreatureAnimation *anim; //displayed animation
  367. CCreaturePic(const CCreature *cre, bool Big=true); //c-tor
  368. ~CCreaturePic(); //d-tor
  369. int blitPic(SDL_Surface *to, int x, int y, bool nextFrame); //prints creature on screen
  370. SDL_Surface * getPic(bool nextFrame); //returns frame of animation
  371. };
  372. class CRecruitmentWindow : public CIntObject
  373. {
  374. public:
  375. static const int SPACE_BETWEEN = 8;
  376. static const int CREATURE_WIDTH = 102;
  377. static const int TOTAL_CREATURE_WIDTH = SPACE_BETWEEN + CREATURE_WIDTH;
  378. struct creinfo
  379. {
  380. SDL_Rect pos;
  381. CCreaturePic *pic; //creature's animation
  382. int ID, amount; //creature ID and available amount
  383. std::vector<std::pair<int,int> > res; //res_id - cost_per_unit
  384. };
  385. std::vector<int> amounts; //how many creatures we can afford
  386. std::vector<creinfo> creatures; //recruitable creatures
  387. boost::function<void(int,int)> recruit; //void (int ID, int amount) <-- call to recruit creatures
  388. CSlider *slider; //for selecting amount
  389. AdventureMapButton *max, *buy, *cancel;
  390. SDL_Surface *bitmap; //background
  391. CStatusBar *bar;
  392. int which; //which creature is active
  393. const CGDwelling *dwelling;
  394. int level;
  395. const CArmedInstance *dst;
  396. void close();
  397. void Max();
  398. void Buy();
  399. void Cancel();
  400. void sliderMoved(int to);
  401. void clickLeft(tribool down, bool previousState);
  402. void clickRight(tribool down, bool previousState);
  403. void activate();
  404. void deactivate();
  405. void show(SDL_Surface * to);
  406. void showAll(SDL_Surface * to){show(to);};
  407. void cleanCres();
  408. void initCres();
  409. CRecruitmentWindow(const CGDwelling *Dwelling, int Level, const CArmedInstance *Dst, const boost::function<void(int,int)> & Recruit); //creatures - pairs<creature_ID,amount> //c-tor
  410. ~CRecruitmentWindow(); //d-tor
  411. };
  412. class CSplitWindow : public CIntObject
  413. {
  414. public:
  415. CGarrisonInt *gar;
  416. CSlider *slider;
  417. CCreaturePic *anim; //creature's animation
  418. AdventureMapButton *ok, *cancel;
  419. SDL_Surface *bitmap; //background
  420. int a1, a2, c; //TODO: comment me
  421. bool which; //which creature is selected
  422. int last; //0/1/2 - at least one creature must be in the src/dst/both stacks; -1 - no restrictions
  423. CSplitWindow(int cid, int max, CGarrisonInt *Owner, int Last = -1, int val=0); //c-tor; val - initial amount of second stack
  424. ~CSplitWindow(); //d-tor
  425. void activate();
  426. void split();
  427. void close();
  428. void deactivate();
  429. void show(SDL_Surface * to);
  430. void clickLeft(tribool down, bool previousState); //call-in
  431. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  432. void sliderMoved(int to);
  433. };
  434. class CLevelWindow : public CIntObject
  435. {
  436. public:
  437. int heroPortrait;
  438. SDL_Surface *bitmap; //background
  439. std::vector<CSelectableComponent *> comps; //skills to select
  440. AdventureMapButton *ok;
  441. boost::function<void(ui32)> cb;
  442. void close();
  443. CLevelWindow(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback); //c-tor
  444. ~CLevelWindow(); //d-tor
  445. void activate();
  446. void deactivate();
  447. void selectionChanged(unsigned to);
  448. void show(SDL_Surface * to);
  449. };
  450. class CMinorResDataBar : public CIntObject
  451. {
  452. public:
  453. SDL_Surface *bg; //background bitmap
  454. void show(SDL_Surface * to);
  455. CMinorResDataBar(); //c-tor
  456. ~CMinorResDataBar(); //d-tor
  457. };
  458. class CMarketplaceWindow : public CIntObject
  459. {
  460. public:
  461. class CTradeableItem : public CIntObject
  462. {
  463. public:
  464. int type; //0 - res, 1 - artif big, 2 - artif small, 3 - player flag
  465. int id;
  466. bool left;
  467. CFunctionList<void()> callback;
  468. void activate();
  469. void deactivate();
  470. void show(SDL_Surface * to);
  471. void clickLeft(tribool down, bool previousState);
  472. SDL_Surface *getSurface();
  473. CTradeableItem(int Type, int ID, bool Left);
  474. };
  475. SDL_Surface *bg; //background
  476. std::vector<CTradeableItem*> left, right;
  477. std::vector<std::string> rSubs; //offer caption
  478. CTradeableItem *hLeft, *hRight; //highlighted items (NULL if no highlight)
  479. int mode,//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact
  480. r1, r2; //suggested amounts of traded resources
  481. AdventureMapButton *ok, *max, *deal;
  482. CSlider *slider; //for choosing amount to be exchanged
  483. void activate();
  484. void deactivate();
  485. void show(SDL_Surface * to);
  486. void setMax();
  487. void sliderMoved(int to);
  488. void makeDeal();
  489. void selectionChanged(bool side); //true == left
  490. CMarketplaceWindow(int Mode=0); //c-tor
  491. ~CMarketplaceWindow(); //d-tor
  492. void setMode(int mode); //mode setter
  493. void clear();
  494. };
  495. class CSystemOptionsWindow : public CIntObject
  496. {
  497. private:
  498. SDL_Surface * background; //background of window
  499. AdventureMapButton *load, *save, *restart, *mainMenu, *quitGame, *backToMap; //load and restart are not used yet
  500. CHighlightableButtonsGroup * heroMoveSpeed;
  501. CHighlightableButtonsGroup * mapScrollSpeed;
  502. CHighlightableButtonsGroup * musicVolume, * effectsVolume;
  503. public:
  504. CSystemOptionsWindow(const SDL_Rect & pos, CPlayerInterface * owner); //c-tor
  505. ~CSystemOptionsWindow(); //d-tor
  506. //functions bound to buttons
  507. void bsavef(); //save game
  508. void bquitf(); //quit game
  509. void breturnf(); //return to game
  510. void bmainmenuf(); //return to main menu
  511. void pushSDLEvent(int type, int usercode);
  512. void activate();
  513. void deactivate();
  514. void show(SDL_Surface * to);
  515. };
  516. class CTavernWindow : public CIntObject
  517. {
  518. public:
  519. class HeroPortrait : public CIntObject
  520. {
  521. public:
  522. std::string hoverName;
  523. vstd::assigner<int,int> as;
  524. const CGHeroInstance *h;
  525. void activate();
  526. void deactivate();
  527. void clickLeft(tribool down, bool previousState);
  528. void clickRight(tribool down, bool previousState);
  529. void hover (bool on);
  530. HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H);
  531. void show(SDL_Surface * to);
  532. char descr[100]; // "XXX is a level Y ZZZ with N artifacts"
  533. } h1, h2; //recruitable heroes
  534. SDL_Surface *bg; //background
  535. CStatusBar *bar; //tavern's internal status bar
  536. int selected;//0 (left) or 1 (right)
  537. int oldSelected;//0 (left) or 1 (right)
  538. AdventureMapButton *thiefGuild, *cancel, *recruit;
  539. CTavernWindow(const CGHeroInstance *H1, const CGHeroInstance *H2, const std::string &gossip); //c-tor
  540. ~CTavernWindow(); //d-tor
  541. void recruitb();
  542. void close();
  543. void thievesguildb();
  544. void activate();
  545. void deactivate();
  546. void show(SDL_Surface * to);
  547. };
  548. class CInGameConsole : public CIntObject
  549. {
  550. private:
  551. std::list< std::pair< std::string, int > > texts; //<text to show, time of add>
  552. boost::mutex texts_mx; // protects texts
  553. std::vector< std::string > previouslyEntered; //previously entered texts, for up/down arrows to work
  554. int prevEntDisp; //displayed entry from previouslyEntered - if none it's -1
  555. int defaultTimeout; //timeout for new texts (in ms)
  556. int maxDisplayedTexts; //hiw many texts can be displayed simultaneously
  557. public:
  558. std::string enteredText;
  559. void activate();
  560. void deactivate();
  561. void show(SDL_Surface * to);
  562. void print(const std::string &txt);
  563. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  564. void startEnteringText();
  565. void endEnteringText(bool printEnteredText);
  566. void refreshEnteredText();
  567. CInGameConsole(); //c-tor
  568. };
  569. class HoverableArea: public virtual CIntObject
  570. {
  571. public:
  572. std::string hoverText;
  573. virtual void hover (bool on);
  574. virtual void activate();
  575. virtual void deactivate();
  576. };
  577. class LClickableArea: public virtual CIntObject
  578. {
  579. public:
  580. virtual void clickLeft(tribool down, bool previousState);
  581. virtual void activate();
  582. virtual void deactivate();
  583. };
  584. class RClickableArea: public virtual CIntObject
  585. {
  586. public:
  587. virtual void clickRight(tribool down, bool previousState);
  588. virtual void activate();
  589. virtual void deactivate();
  590. };
  591. class LClickableAreaHero : public LClickableArea
  592. {
  593. public:
  594. int id;
  595. CHeroWindow * owner;
  596. virtual void clickLeft(tribool down, bool previousState);
  597. };
  598. class LRClickableAreaWText: public LClickableArea, public RClickableArea, public HoverableArea
  599. {
  600. public:
  601. std::string text;
  602. virtual void activate();
  603. virtual void deactivate();
  604. virtual void clickLeft(tribool down, bool previousState);
  605. virtual void clickRight(tribool down, bool previousState);
  606. };
  607. class LRClickableAreaWTextComp: public LClickableArea, public RClickableArea, public HoverableArea
  608. {
  609. public:
  610. std::string text;
  611. int baseType;
  612. int bonus, type;
  613. virtual void activate();
  614. virtual void deactivate();
  615. virtual void clickLeft(tribool down, bool previousState);
  616. virtual void clickRight(tribool down, bool previousState);
  617. };
  618. class MoraleLuckBox : public LRClickableAreaWTextComp
  619. {
  620. public:
  621. void set(bool morale, const CGHeroInstance *hero);
  622. };
  623. class LRClickableAreaOpenHero: public LRClickableAreaWTextComp
  624. {
  625. public:
  626. const CGHeroInstance * hero;
  627. void clickLeft(tribool down, bool previousState);
  628. void clickRight(tribool down, bool previousState);
  629. };
  630. class LRClickableAreaOpenTown: public LRClickableAreaWTextComp
  631. {
  632. public:
  633. const CGTownInstance * town;
  634. void clickLeft(tribool down, bool previousState);
  635. void clickRight(tribool down, bool previousState);
  636. };
  637. class CCreInfoWindow : public CIntObject
  638. {
  639. public:
  640. //bool active; //TODO: comment me
  641. int type;//0 - rclick popup; 1 - normal window
  642. CPicture *bitmap; //background
  643. char anf; //animation counter
  644. std::string count; //creature count in text format
  645. boost::function<void()> dsm; //dismiss button callback
  646. CCreaturePic *anim; //related creature's animation
  647. const CCreature *c; //related creature
  648. std::vector<SComponent*> upgResCost; //cost of upgrade (if not possible then empty)
  649. //MoraleLuckBox *luck, *morale;
  650. AdventureMapButton *dismiss, *upgrade, *ok;
  651. CCreInfoWindow(const CStackInstance &st, int Type = 0, boost::function<void()> Upg = 0, boost::function<void()> Dsm = 0, UpgradeInfo *ui = NULL); //c-tor
  652. CCreInfoWindow(int Cid, int Type, int creatureCount); //c-tor
  653. void init(const CCreature *cre, const CStackInstance *stack, int creatureCount);
  654. void printLine(int nr, const std::string &text, int baseVal, int val=-1, bool range=false);
  655. ~CCreInfoWindow(); //d-tor
  656. void activate();
  657. void close();
  658. void clickRight(tribool down, bool previousState); //call-in
  659. void dismissF();
  660. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  661. void deactivate();
  662. void show(SDL_Surface * to);
  663. };
  664. class CArtPlace: public LRClickableAreaWTextComp
  665. {
  666. private:
  667. bool active;
  668. public:
  669. //bool spellBook, warMachine1, warMachine2, warMachine3, warMachine4,
  670. // misc1, misc2, misc3, misc4, misc5, feet, lRing, rRing, torso,
  671. // lHand, rHand, neck, shoulders, head; //my types
  672. ui16 slotID; //0 head 1 shoulders 2 neck 3 right hand 4 left hand 5 torso 6 right ring 7 left ring 8 feet 9 misc. slot 1 10 misc. slot 2 11 misc. slot 3 12 misc. slot 4 13 ballista (war machine 1) 14 ammo cart (war machine 2) 15 first aid tent (war machine 3) 16 catapult 17 spell book 18 misc. slot 5 19+ backpack slots
  673. bool marked;
  674. bool selectedNo;
  675. CArtifactsOfHero * ourOwner;
  676. const CArtifact * ourArt;
  677. CArtPlace(const CArtifact * Art); //c-tor
  678. void clickLeft(tribool down, bool previousState);
  679. void clickRight(tribool down, bool previousState);
  680. void select ();
  681. void deselect ();
  682. void activate();
  683. void deactivate();
  684. void show(SDL_Surface * to);
  685. bool fitsHere (const CArtifact * art); //returns true if given artifact can be placed here
  686. bool locked () const;
  687. void userSelectedNo ();
  688. ~CArtPlace(); //d-tor
  689. };
  690. inline bool CArtPlace::locked () const
  691. {
  692. return ourArt && ourArt->id == 145;
  693. }
  694. class CArtifactsOfHero : public CIntObject
  695. {
  696. CGHeroInstance * curHero;
  697. std::vector<CArtPlace *> artWorn; // 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
  698. std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!)
  699. int backpackPos; //number of first art visible in backpack (in hero's vector)
  700. public:
  701. struct SCommonPart
  702. {
  703. std::set<CArtifactsOfHero *> participants; // Needed to mark slots.
  704. const CArtifact * srcArtifact; // Held artifact.
  705. const CArtifactsOfHero * srcAOH; // Following two needed to uniquely identify the source.
  706. int srcSlotID; //
  707. const CArtifactsOfHero * destAOH; // For swapping. (i.e. changing what is held)
  708. int destSlotID; // Needed to determine what kind of action was last taken in setHero
  709. const CArtifact * destArtifact; // For swapping.
  710. } * commonInfo; //when we have more than one CArtifactsOfHero in one window with exchange possibility, we use this (eg. in exchange window); to be provided externally
  711. bool updateState; // Whether the commonInfo should be updated on setHero or not.
  712. AdventureMapButton * leftArtRoll, * rightArtRoll;
  713. void activate();
  714. void deactivate();
  715. void show(SDL_Surface * to);
  716. void setHero(const CGHeroInstance * hero);
  717. void dispose(); //free resources not needed after closing windows and reset state
  718. void rollback();
  719. void scrollBackpack(int dir); //dir==-1 => to left; dir==1 => to right
  720. void markPossibleSlots (const CArtifact* art);
  721. void unmarkSlots ();
  722. void setSlotData (CArtPlace* artPlace, int slotID);
  723. void eraseSlotData (CArtPlace* artPlace, int slotID);
  724. CArtifactsOfHero(const SDL_Rect & position); //c-tor
  725. ~CArtifactsOfHero(); //d-tor
  726. friend class CArtPlace;
  727. };
  728. class CGarrisonWindow : public CWindowWithGarrison
  729. {
  730. public:
  731. SDL_Surface *bg; //background surface
  732. AdventureMapButton *quit;
  733. void close();
  734. void activate();
  735. void deactivate();
  736. void show(SDL_Surface * to);
  737. void showAll(SDL_Surface * to){show(to);};
  738. CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits); //c-tor
  739. ~CGarrisonWindow(); //d-tor
  740. };
  741. class CExchangeWindow : public CWindowWithGarrison
  742. {
  743. CStatusBar * ourBar; //internal statusbar
  744. SDL_Surface *bg; //background
  745. AdventureMapButton * quit, * questlogButton[2];
  746. std::vector<LRClickableAreaWTextComp *> secSkillAreas[2], primSkillAreas;
  747. MoraleLuckBox *morale[2], *luck[2];
  748. LRClickableAreaWText *speciality[2];
  749. LRClickableAreaWText *experience[2];
  750. LRClickableAreaWText *spellPoints[2];
  751. LRClickableAreaOpenHero *portrait[2];
  752. public:
  753. const CGHeroInstance * heroInst[2];
  754. CArtifactsOfHero * artifs[2];
  755. void close();
  756. void activate();
  757. void deactivate();
  758. void show(SDL_Surface * to);
  759. void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right
  760. void prepareBackground(); //prepares or redraws bg
  761. CExchangeWindow(si32 hero1, si32 hero2); //c-tor
  762. ~CExchangeWindow(); //d-tor
  763. };
  764. class CShipyardWindow : public CIntObject
  765. {
  766. public:
  767. CStatusBar *bar;
  768. SDL_Surface *bg; //background
  769. AdventureMapButton *build, *quit;
  770. unsigned char frame; //frame of the boat animation
  771. int boat; //which boat graphic should be used
  772. void activate();
  773. void deactivate();
  774. void show(SDL_Surface * to);
  775. CShipyardWindow(const std::vector<si32> &cost, int state, int boatType, const boost::function<void()> &onBuy);
  776. ~CShipyardWindow();
  777. };
  778. class CPuzzleWindow : public CIntObject
  779. {
  780. private:
  781. SDL_Surface * background;
  782. AdventureMapButton * quitb;
  783. CResDataBar * resdatabar;
  784. std::vector<std::pair<SDL_Surface *, SPuzzleInfo *> > puzzlesToPullBack;
  785. ui8 animCount;
  786. public:
  787. void activate();
  788. void deactivate();
  789. void show(SDL_Surface * to);
  790. CPuzzleWindow(const int3 &grailPos, float discoveredRatio);
  791. ~CPuzzleWindow();
  792. };
  793. class CShopWindow : public CIntObject
  794. {
  795. public:
  796. std::map<ui16, Component> available, chosen, bought;
  797. bool swapItem (ui16 which, bool choose);
  798. virtual void Buy() {};
  799. };
  800. class CArtMerchantWindow : public CShopWindow
  801. {
  802. public:
  803. void activate();
  804. void deactivate();
  805. void show(SDL_Surface * to);
  806. void Buy();
  807. CArtMerchantWindow();
  808. ~CArtMerchantWindow();
  809. };
  810. class CUniversityWindow : public CShopWindow
  811. {};
  812. class CAltarWindow : public CShopWindow
  813. {};
  814. class CRefugeeCampWindow : public CShopWindow
  815. {};
  816. class CWarMachineWindow : public CShopWindow
  817. {};
  818. class CFreelancersWindow : public CShopWindow
  819. {};
  820. class CHillFortWindow : public CIntObject //garrison dialog? shop?
  821. {};
  822. class CThievesGuildWindow : public CIntObject
  823. {
  824. const CGObjectInstance * owner;
  825. CStatusBar * statusBar;
  826. AdventureMapButton * exitb;
  827. SDL_Surface * background;
  828. CMinorResDataBar * resdatabar;
  829. public:
  830. void activate();
  831. void show(SDL_Surface * to);
  832. void bexitf();
  833. CThievesGuildWindow(const CGObjectInstance * _owner);
  834. ~CThievesGuildWindow();
  835. };
  836. #endif //__GUICLASSES_H__