GUIClasses.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970
  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. enum EType
  462. {
  463. RESOURCE, PLAYER, ARTIFACT
  464. };
  465. class CTradeableItem : public CIntObject
  466. {
  467. public:
  468. int type; //0 - res, 1 - artif big, 2 - artif small, 3 - player flag
  469. int id;
  470. bool left;
  471. CFunctionList<void()> callback;
  472. void show(SDL_Surface * to);
  473. void clickLeft(tribool down, bool previousState);
  474. SDL_Surface *getSurface();
  475. CTradeableItem(int Type, int ID, bool Left);
  476. };
  477. CPicture *bg; //background
  478. std::vector<CTradeableItem*> left, right;
  479. std::vector<std::string> rSubs; //offer caption
  480. CTradeableItem *hLeft, *hRight; //highlighted items (NULL if no highlight)
  481. EType ltype, rtype;
  482. int mode,//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact
  483. r1, r2; //suggested amounts of traded resources
  484. AdventureMapButton *ok, *max, *deal;
  485. CSlider *slider; //for choosing amount to be exchanged
  486. void show(SDL_Surface * to);
  487. void setMax();
  488. void sliderMoved(int to);
  489. void makeDeal();
  490. void selectionChanged(bool side); //true == left
  491. CMarketplaceWindow(int Mode = RESOURCE_RESOURCE); //c-tor
  492. ~CMarketplaceWindow(); //d-tor
  493. void setMode(int Mode); //mode setter
  494. void getPositionsFor(std::vector<Rect> &poss, bool Right, EType type) const;
  495. };
  496. class CSystemOptionsWindow : public CIntObject
  497. {
  498. private:
  499. SDL_Surface * background; //background of window
  500. AdventureMapButton *load, *save, *restart, *mainMenu, *quitGame, *backToMap; //load and restart are not used yet
  501. CHighlightableButtonsGroup * heroMoveSpeed;
  502. CHighlightableButtonsGroup * mapScrollSpeed;
  503. CHighlightableButtonsGroup * musicVolume, * effectsVolume;
  504. public:
  505. CSystemOptionsWindow(const SDL_Rect & pos, CPlayerInterface * owner); //c-tor
  506. ~CSystemOptionsWindow(); //d-tor
  507. //functions bound to buttons
  508. void bsavef(); //save game
  509. void bquitf(); //quit game
  510. void breturnf(); //return to game
  511. void bmainmenuf(); //return to main menu
  512. void pushSDLEvent(int type, int usercode);
  513. void activate();
  514. void deactivate();
  515. void show(SDL_Surface * to);
  516. };
  517. class CTavernWindow : public CIntObject
  518. {
  519. public:
  520. class HeroPortrait : public CIntObject
  521. {
  522. public:
  523. std::string hoverName;
  524. vstd::assigner<int,int> as;
  525. const CGHeroInstance *h;
  526. void activate();
  527. void deactivate();
  528. void clickLeft(tribool down, bool previousState);
  529. void clickRight(tribool down, bool previousState);
  530. void hover (bool on);
  531. HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H);
  532. void show(SDL_Surface * to);
  533. char descr[100]; // "XXX is a level Y ZZZ with N artifacts"
  534. } h1, h2; //recruitable heroes
  535. SDL_Surface *bg; //background
  536. CStatusBar *bar; //tavern's internal status bar
  537. int selected;//0 (left) or 1 (right)
  538. int oldSelected;//0 (left) or 1 (right)
  539. AdventureMapButton *thiefGuild, *cancel, *recruit;
  540. CTavernWindow(const CGHeroInstance *H1, const CGHeroInstance *H2, const std::string &gossip); //c-tor
  541. ~CTavernWindow(); //d-tor
  542. void recruitb();
  543. void close();
  544. void thievesguildb();
  545. void activate();
  546. void deactivate();
  547. void show(SDL_Surface * to);
  548. };
  549. class CInGameConsole : public CIntObject
  550. {
  551. private:
  552. std::list< std::pair< std::string, int > > texts; //<text to show, time of add>
  553. boost::mutex texts_mx; // protects texts
  554. std::vector< std::string > previouslyEntered; //previously entered texts, for up/down arrows to work
  555. int prevEntDisp; //displayed entry from previouslyEntered - if none it's -1
  556. int defaultTimeout; //timeout for new texts (in ms)
  557. int maxDisplayedTexts; //hiw many texts can be displayed simultaneously
  558. public:
  559. std::string enteredText;
  560. void activate();
  561. void deactivate();
  562. void show(SDL_Surface * to);
  563. void print(const std::string &txt);
  564. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  565. void startEnteringText();
  566. void endEnteringText(bool printEnteredText);
  567. void refreshEnteredText();
  568. CInGameConsole(); //c-tor
  569. };
  570. class HoverableArea: public virtual CIntObject
  571. {
  572. public:
  573. std::string hoverText;
  574. virtual void hover (bool on);
  575. virtual void activate();
  576. virtual void deactivate();
  577. };
  578. class LClickableArea: public virtual CIntObject
  579. {
  580. public:
  581. virtual void clickLeft(tribool down, bool previousState);
  582. virtual void activate();
  583. virtual void deactivate();
  584. };
  585. class RClickableArea: public virtual CIntObject
  586. {
  587. public:
  588. virtual void clickRight(tribool down, bool previousState);
  589. virtual void activate();
  590. virtual void deactivate();
  591. };
  592. class LClickableAreaHero : public LClickableArea
  593. {
  594. public:
  595. int id;
  596. CHeroWindow * owner;
  597. virtual void clickLeft(tribool down, bool previousState);
  598. };
  599. class LRClickableAreaWText: public LClickableArea, public RClickableArea, public HoverableArea
  600. {
  601. public:
  602. std::string text;
  603. virtual void activate();
  604. virtual void deactivate();
  605. virtual void clickLeft(tribool down, bool previousState);
  606. virtual void clickRight(tribool down, bool previousState);
  607. };
  608. class LRClickableAreaWTextComp: public LClickableArea, public RClickableArea, public HoverableArea
  609. {
  610. public:
  611. std::string text;
  612. int baseType;
  613. int bonus, type;
  614. virtual void activate();
  615. virtual void deactivate();
  616. virtual void clickLeft(tribool down, bool previousState);
  617. virtual void clickRight(tribool down, bool previousState);
  618. };
  619. class MoraleLuckBox : public LRClickableAreaWTextComp
  620. {
  621. public:
  622. void set(bool morale, const CGHeroInstance *hero);
  623. };
  624. class LRClickableAreaOpenHero: public LRClickableAreaWTextComp
  625. {
  626. public:
  627. const CGHeroInstance * hero;
  628. void clickLeft(tribool down, bool previousState);
  629. void clickRight(tribool down, bool previousState);
  630. };
  631. class LRClickableAreaOpenTown: public LRClickableAreaWTextComp
  632. {
  633. public:
  634. const CGTownInstance * town;
  635. void clickLeft(tribool down, bool previousState);
  636. void clickRight(tribool down, bool previousState);
  637. };
  638. class CCreInfoWindow : public CIntObject
  639. {
  640. public:
  641. //bool active; //TODO: comment me
  642. int type;//0 - rclick popup; 1 - normal window
  643. CPicture *bitmap; //background
  644. char anf; //animation counter
  645. std::string count; //creature count in text format
  646. boost::function<void()> dsm; //dismiss button callback
  647. CCreaturePic *anim; //related creature's animation
  648. const CCreature *c; //related creature
  649. std::vector<SComponent*> upgResCost; //cost of upgrade (if not possible then empty)
  650. //MoraleLuckBox *luck, *morale;
  651. AdventureMapButton *dismiss, *upgrade, *ok;
  652. CCreInfoWindow(const CStackInstance &st, int Type = 0, boost::function<void()> Upg = 0, boost::function<void()> Dsm = 0, UpgradeInfo *ui = NULL); //c-tor
  653. CCreInfoWindow(int Cid, int Type, int creatureCount); //c-tor
  654. void init(const CCreature *cre, const CStackInstance *stack, int creatureCount);
  655. void printLine(int nr, const std::string &text, int baseVal, int val=-1, bool range=false);
  656. ~CCreInfoWindow(); //d-tor
  657. void activate();
  658. void close();
  659. void clickRight(tribool down, bool previousState); //call-in
  660. void dismissF();
  661. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  662. void deactivate();
  663. void show(SDL_Surface * to);
  664. };
  665. class CArtPlace: public LRClickableAreaWTextComp
  666. {
  667. private:
  668. bool active;
  669. public:
  670. //bool spellBook, warMachine1, warMachine2, warMachine3, warMachine4,
  671. // misc1, misc2, misc3, misc4, misc5, feet, lRing, rRing, torso,
  672. // lHand, rHand, neck, shoulders, head; //my types
  673. 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
  674. bool marked;
  675. bool selectedNo;
  676. CArtifactsOfHero * ourOwner;
  677. const CArtifact * ourArt;
  678. CArtPlace(const CArtifact * Art); //c-tor
  679. void clickLeft(tribool down, bool previousState);
  680. void clickRight(tribool down, bool previousState);
  681. void select ();
  682. void deselect ();
  683. void activate();
  684. void deactivate();
  685. void show(SDL_Surface * to);
  686. bool fitsHere (const CArtifact * art); //returns true if given artifact can be placed here
  687. bool locked () const;
  688. void userSelectedNo ();
  689. ~CArtPlace(); //d-tor
  690. };
  691. inline bool CArtPlace::locked () const
  692. {
  693. return ourArt && ourArt->id == 145;
  694. }
  695. class CArtifactsOfHero : public CIntObject
  696. {
  697. const CGHeroInstance * curHero;
  698. 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
  699. std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!)
  700. int backpackPos; //number of first art visible in backpack (in hero's vector)
  701. public:
  702. struct SCommonPart
  703. {
  704. std::set<CArtifactsOfHero *> participants; // Needed to mark slots.
  705. const CArtifact * srcArtifact; // Held artifact.
  706. const CArtifactsOfHero * srcAOH; // Following two needed to uniquely identify the source.
  707. int srcSlotID; //
  708. const CArtifactsOfHero * destAOH; // For swapping. (i.e. changing what is held)
  709. int destSlotID; // Needed to determine what kind of action was last taken in setHero
  710. const CArtifact * destArtifact; // For swapping.
  711. } * 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
  712. bool updateState; // Whether the commonInfo should be updated on setHero or not.
  713. AdventureMapButton * leftArtRoll, * rightArtRoll;
  714. void activate();
  715. void deactivate();
  716. void show(SDL_Surface * to);
  717. void setHero(const CGHeroInstance * hero);
  718. void dispose(); //free resources not needed after closing windows and reset state
  719. void rollback();
  720. void scrollBackpack(int dir); //dir==-1 => to left; dir==1 => to right
  721. void markPossibleSlots (const CArtifact* art);
  722. void unmarkSlots ();
  723. void setSlotData (CArtPlace* artPlace, int slotID);
  724. void eraseSlotData (CArtPlace* artPlace, int slotID);
  725. CArtifactsOfHero(const SDL_Rect & position); //c-tor
  726. ~CArtifactsOfHero(); //d-tor
  727. friend class CArtPlace;
  728. };
  729. class CGarrisonWindow : public CWindowWithGarrison
  730. {
  731. public:
  732. SDL_Surface *bg; //background surface
  733. AdventureMapButton *quit;
  734. void close();
  735. void activate();
  736. void deactivate();
  737. void show(SDL_Surface * to);
  738. void showAll(SDL_Surface * to){show(to);};
  739. CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits); //c-tor
  740. ~CGarrisonWindow(); //d-tor
  741. };
  742. class CExchangeWindow : public CWindowWithGarrison
  743. {
  744. CStatusBar * ourBar; //internal statusbar
  745. SDL_Surface *bg; //background
  746. AdventureMapButton * quit, * questlogButton[2];
  747. std::vector<LRClickableAreaWTextComp *> secSkillAreas[2], primSkillAreas;
  748. MoraleLuckBox *morale[2], *luck[2];
  749. LRClickableAreaWText *speciality[2];
  750. LRClickableAreaWText *experience[2];
  751. LRClickableAreaWText *spellPoints[2];
  752. LRClickableAreaOpenHero *portrait[2];
  753. public:
  754. const CGHeroInstance * heroInst[2];
  755. CArtifactsOfHero * artifs[2];
  756. void close();
  757. void activate();
  758. void deactivate();
  759. void show(SDL_Surface * to);
  760. void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right
  761. void prepareBackground(); //prepares or redraws bg
  762. CExchangeWindow(si32 hero1, si32 hero2); //c-tor
  763. ~CExchangeWindow(); //d-tor
  764. };
  765. class CShipyardWindow : public CIntObject
  766. {
  767. public:
  768. CStatusBar *bar;
  769. SDL_Surface *bg; //background
  770. AdventureMapButton *build, *quit;
  771. unsigned char frame; //frame of the boat animation
  772. int boat; //which boat graphic should be used
  773. void activate();
  774. void deactivate();
  775. void show(SDL_Surface * to);
  776. CShipyardWindow(const std::vector<si32> &cost, int state, int boatType, const boost::function<void()> &onBuy);
  777. ~CShipyardWindow();
  778. };
  779. class CPuzzleWindow : public CIntObject
  780. {
  781. private:
  782. SDL_Surface * background;
  783. AdventureMapButton * quitb;
  784. CResDataBar * resdatabar;
  785. std::vector<std::pair<SDL_Surface *, SPuzzleInfo *> > puzzlesToPullBack;
  786. ui8 animCount;
  787. public:
  788. void activate();
  789. void deactivate();
  790. void show(SDL_Surface * to);
  791. CPuzzleWindow(const int3 &grailPos, float discoveredRatio);
  792. ~CPuzzleWindow();
  793. };
  794. class CShopWindow : public CIntObject
  795. {
  796. public:
  797. std::map<ui16, Component> available, chosen, bought;
  798. bool swapItem (ui16 which, bool choose);
  799. virtual void Buy() {};
  800. };
  801. class CArtMerchantWindow : public CShopWindow
  802. {
  803. public:
  804. void activate();
  805. void deactivate();
  806. void show(SDL_Surface * to);
  807. void Buy();
  808. CArtMerchantWindow();
  809. ~CArtMerchantWindow();
  810. };
  811. class CUniversityWindow : public CShopWindow
  812. {};
  813. class CAltarWindow : public CShopWindow
  814. {};
  815. class CRefugeeCampWindow : public CShopWindow
  816. {};
  817. class CWarMachineWindow : public CShopWindow
  818. {};
  819. class CFreelancersWindow : public CShopWindow
  820. {};
  821. class CHillFortWindow : public CIntObject //garrison dialog? shop?
  822. {};
  823. class CThievesGuildWindow : public CIntObject
  824. {
  825. const CGObjectInstance * owner;
  826. CStatusBar * statusBar;
  827. AdventureMapButton * exitb;
  828. SDL_Surface * background;
  829. CMinorResDataBar * resdatabar;
  830. public:
  831. void activate();
  832. void show(SDL_Surface * to);
  833. void bexitf();
  834. CThievesGuildWindow(const CGObjectInstance * _owner);
  835. ~CThievesGuildWindow();
  836. };
  837. #endif //__GUICLASSES_H__