GUIClasses.h 30 KB

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