GUIClasses.h 29 KB

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