GUIClasses.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  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 virtual 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 = CENTER, const SDL_Color &Color = zwykly, const std::string &Text = "");
  260. 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
  261. ~CGStatusBar();
  262. };
  263. class CFocusable
  264. : public virtual CIntObject
  265. {
  266. public:
  267. bool focus; //only one focusable control can have focus at one moment
  268. void giveFocus(); //captures focus
  269. void moveFocus(); //moves focus to next active control (may be used for tab switching)
  270. static std::list<CFocusable*> focusables; //all existing objs
  271. static CFocusable *inputWithFocus; //who has focus now
  272. CFocusable();
  273. ~CFocusable();
  274. };
  275. class CTextInput
  276. : public CLabel, public CFocusable
  277. {
  278. public:
  279. CFunctionList<void(const std::string &)> cb;
  280. void setText(const std::string &nText, bool callCb = false);
  281. CTextInput(const Rect &Pos, const Point &bgOffset, const std::string &bgName, const CFunctionList<void(const std::string &)> &CB);
  282. CTextInput(const Rect &Pos, SDL_Surface *srf);
  283. ~CTextInput();
  284. void showAll(SDL_Surface * to);
  285. void clickLeft(tribool down, bool previousState);
  286. void keyPressed(const SDL_KeyboardEvent & key);
  287. };
  288. class CList : public CIntObject
  289. {
  290. public:
  291. SDL_Surface * bg; //background bitmap
  292. CDefHandler *arrup, *arrdo; //button arrows for scrolling list
  293. SDL_Surface *empty, *selection;
  294. SDL_Rect arrupp, arrdop; //positions of arrows
  295. int posw, posh; //position width/height
  296. int selected, //id of selected position, <0 if none
  297. from;
  298. const int SIZE; //size of list
  299. tribool pressed; //true=up; false=down; indeterminate=none
  300. CList(int Size = 5); //c-tor
  301. void clickLeft(tribool down, bool previousState);
  302. void activate();
  303. void deactivate();
  304. virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; //call-in
  305. virtual void genList()=0;
  306. virtual void select(int which)=0;
  307. virtual void draw(SDL_Surface * to)=0;
  308. virtual int size() = 0; //how many elements do we have
  309. void fixPos(); //scrolls list, so the selection will be visible
  310. };
  311. class CHeroList
  312. : public CList
  313. {
  314. public:
  315. CDefHandler *mobile, *mana; //mana and movement indicators
  316. int posmobx, posporx, posmanx, posmoby, pospory, posmany;
  317. CHeroList(int Size); //c-tor
  318. int getPosOfHero(const CGHeroInstance* h); //hero's position on list
  319. void genList();
  320. void select(int which); //call-in
  321. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  322. void clickLeft(tribool down, bool previousState); //call-in
  323. void clickRight(tribool down, bool previousState); //call-in
  324. void hover (bool on); //call-in
  325. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  326. void updateHList(const CGHeroInstance *toRemove=NULL); //removes specific hero from the list or recreates it
  327. void updateMove(const CGHeroInstance* which); //draws move points bar
  328. void draw(SDL_Surface * to);
  329. void show(SDL_Surface * to);
  330. void init();
  331. int size(); //how many elements do we have
  332. };
  333. class CTownList
  334. : public CList
  335. {
  336. public:
  337. boost::function<void()> fun; //function called on selection change
  338. int posporx,pospory;
  339. CTownList(int Size, int x, int y, std::string arrupg, std::string arrdog); //c-tor
  340. ~CTownList(); //d-tor
  341. void genList();
  342. void select(int which); //call-in
  343. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  344. void clickLeft(tribool down, bool previousState); //call-in
  345. void clickRight(tribool down, bool previousState); //call-in
  346. void hover (bool on); //call-in
  347. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  348. void draw(SDL_Surface * to);
  349. void show(SDL_Surface * to);
  350. int size(); //how many elements do we have
  351. };
  352. class CCreaturePic //draws picture with creature on background, use nextFrame=true to get animation
  353. {
  354. public:
  355. const CCreature *c; //which creature's picture
  356. bool big; //big => 100x130; !big => 100x120
  357. CCreatureAnimation *anim; //displayed animation
  358. CCreaturePic(const CCreature *cre, bool Big=true); //c-tor
  359. ~CCreaturePic(); //d-tor
  360. int blitPic(SDL_Surface *to, int x, int y, bool nextFrame); //prints creature on screen
  361. SDL_Surface * getPic(bool nextFrame); //returns frame of animation
  362. };
  363. class CRecruitmentWindow : public CIntObject
  364. {
  365. public:
  366. static const int SPACE_BETWEEN = 8;
  367. static const int CREATURE_WIDTH = 102;
  368. static const int TOTAL_CREATURE_WIDTH = SPACE_BETWEEN + CREATURE_WIDTH;
  369. struct creinfo
  370. {
  371. SDL_Rect pos;
  372. CCreaturePic *pic; //creature's animation
  373. int ID, amount; //creature ID and available amount
  374. std::vector<std::pair<int,int> > res; //res_id - cost_per_unit
  375. };
  376. std::vector<int> amounts; //how many creatures we can afford
  377. std::vector<creinfo> creatures; //recruitable creatures
  378. boost::function<void(int,int)> recruit; //void (int ID, int amount) <-- call to recruit creatures
  379. CSlider *slider; //for selecting amount
  380. AdventureMapButton *max, *buy, *cancel;
  381. SDL_Surface *bitmap; //background
  382. CStatusBar *bar;
  383. int which; //which creature is active
  384. const CGDwelling *dwelling;
  385. int level;
  386. const CArmedInstance *dst;
  387. void close();
  388. void Max();
  389. void Buy();
  390. void Cancel();
  391. void sliderMoved(int to);
  392. void clickLeft(tribool down, bool previousState);
  393. void clickRight(tribool down, bool previousState);
  394. void activate();
  395. void deactivate();
  396. void show(SDL_Surface * to);
  397. void showAll(SDL_Surface * to){show(to);};
  398. void cleanCres();
  399. void initCres();
  400. CRecruitmentWindow(const CGDwelling *Dwelling, int Level, const CArmedInstance *Dst, const boost::function<void(int,int)> & Recruit); //creatures - pairs<creature_ID,amount> //c-tor
  401. ~CRecruitmentWindow(); //d-tor
  402. };
  403. class CSplitWindow : public CIntObject
  404. {
  405. public:
  406. CGarrisonInt *gar;
  407. CSlider *slider;
  408. CCreaturePic *anim; //creature's animation
  409. AdventureMapButton *ok, *cancel;
  410. SDL_Surface *bitmap; //background
  411. int a1, a2, c; //TODO: comment me
  412. bool which; //which creature is selected
  413. int last; //0/1/2 - at least one creature must be in the src/dst/both stacks; -1 - no restrictions
  414. CSplitWindow(int cid, int max, CGarrisonInt *Owner, int Last = -1, int val=0); //c-tor; val - initial amount of second stack
  415. ~CSplitWindow(); //d-tor
  416. void activate();
  417. void split();
  418. void close();
  419. void deactivate();
  420. void show(SDL_Surface * to);
  421. void clickLeft(tribool down, bool previousState); //call-in
  422. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  423. void sliderMoved(int to);
  424. };
  425. class CLevelWindow : public CIntObject
  426. {
  427. public:
  428. int heroPortrait;
  429. SDL_Surface *bitmap; //background
  430. std::vector<CSelectableComponent *> comps; //skills to select
  431. AdventureMapButton *ok;
  432. boost::function<void(ui32)> cb;
  433. void close();
  434. CLevelWindow(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback); //c-tor
  435. ~CLevelWindow(); //d-tor
  436. void activate();
  437. void deactivate();
  438. void selectionChanged(unsigned to);
  439. void show(SDL_Surface * to);
  440. };
  441. class CMinorResDataBar : public CIntObject
  442. {
  443. public:
  444. SDL_Surface *bg; //background bitmap
  445. void show(SDL_Surface * to);
  446. CMinorResDataBar(); //c-tor
  447. ~CMinorResDataBar(); //d-tor
  448. };
  449. class CMarketplaceWindow : public CIntObject
  450. {
  451. public:
  452. class CTradeableItem : public CIntObject
  453. {
  454. public:
  455. int type; //0 - res, 1 - artif big, 2 - artif small, 3 - player flag
  456. int id;
  457. bool left;
  458. CFunctionList<void()> callback;
  459. void activate();
  460. void deactivate();
  461. void show(SDL_Surface * to);
  462. void clickLeft(tribool down, bool previousState);
  463. SDL_Surface *getSurface();
  464. CTradeableItem(int Type, int ID, bool Left);
  465. };
  466. SDL_Surface *bg; //background
  467. std::vector<CTradeableItem*> left, right;
  468. std::vector<std::string> rSubs; //offer caption
  469. CTradeableItem *hLeft, *hRight; //highlighted items (NULL if no highlight)
  470. int mode,//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact
  471. r1, r2; //suggested amounts of traded resources
  472. AdventureMapButton *ok, *max, *deal;
  473. CSlider *slider; //for choosing amount to be exchanged
  474. void activate();
  475. void deactivate();
  476. void show(SDL_Surface * to);
  477. void setMax();
  478. void sliderMoved(int to);
  479. void makeDeal();
  480. void selectionChanged(bool side); //true == left
  481. CMarketplaceWindow(int Mode=0); //c-tor
  482. ~CMarketplaceWindow(); //d-tor
  483. void setMode(int mode); //mode setter
  484. void clear();
  485. };
  486. class CSystemOptionsWindow : public CIntObject
  487. {
  488. private:
  489. SDL_Surface * background; //background of window
  490. AdventureMapButton *load, *save, *restart, *mainMenu, *quitGame, *backToMap; //load and restart are not used yet
  491. CHighlightableButtonsGroup * heroMoveSpeed;
  492. CHighlightableButtonsGroup * mapScrollSpeed;
  493. CHighlightableButtonsGroup * musicVolume, * effectsVolume;
  494. public:
  495. CSystemOptionsWindow(const SDL_Rect & pos, CPlayerInterface * owner); //c-tor
  496. ~CSystemOptionsWindow(); //d-tor
  497. //functions bound to buttons
  498. void bsavef(); //save game
  499. void bquitf(); //quit game
  500. void breturnf(); //return to game
  501. void bmainmenuf(); //return to main menu
  502. void pushSDLEvent(int type, int usercode);
  503. void activate();
  504. void deactivate();
  505. void show(SDL_Surface * to);
  506. };
  507. class CTavernWindow : public CIntObject
  508. {
  509. public:
  510. class HeroPortrait : public CIntObject
  511. {
  512. public:
  513. std::string hoverName;
  514. vstd::assigner<int,int> as;
  515. const CGHeroInstance *h;
  516. void activate();
  517. void deactivate();
  518. void clickLeft(tribool down, bool previousState);
  519. void clickRight(tribool down, bool previousState);
  520. void hover (bool on);
  521. HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H);
  522. void show(SDL_Surface * to);
  523. char descr[100]; // "XXX is a level Y ZZZ with N artifacts"
  524. } h1, h2; //recruitable heroes
  525. SDL_Surface *bg; //background
  526. CStatusBar *bar; //tavern's internal status bar
  527. int selected;//0 (left) or 1 (right)
  528. int oldSelected;//0 (left) or 1 (right)
  529. AdventureMapButton *thiefGuild, *cancel, *recruit;
  530. CTavernWindow(const CGHeroInstance *H1, const CGHeroInstance *H2, const std::string &gossip); //c-tor
  531. ~CTavernWindow(); //d-tor
  532. void recruitb();
  533. void close();
  534. void thievesguildb();
  535. void activate();
  536. void deactivate();
  537. void show(SDL_Surface * to);
  538. };
  539. class CInGameConsole : public CIntObject
  540. {
  541. private:
  542. std::list< std::pair< std::string, int > > texts; //<text to show, time of add>
  543. boost::mutex texts_mx; // protects texts
  544. std::vector< std::string > previouslyEntered; //previously entered texts, for up/down arrows to work
  545. int prevEntDisp; //displayed entry from previouslyEntered - if none it's -1
  546. int defaultTimeout; //timeout for new texts (in ms)
  547. int maxDisplayedTexts; //hiw many texts can be displayed simultaneously
  548. public:
  549. std::string enteredText;
  550. void activate();
  551. void deactivate();
  552. void show(SDL_Surface * to);
  553. void print(const std::string &txt);
  554. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  555. void startEnteringText();
  556. void endEnteringText(bool printEnteredText);
  557. void refreshEnteredText();
  558. CInGameConsole(); //c-tor
  559. };
  560. class HoverableArea: public virtual CIntObject
  561. {
  562. public:
  563. std::string hoverText;
  564. virtual void hover (bool on);
  565. virtual void activate();
  566. virtual void deactivate();
  567. };
  568. class LClickableArea: public virtual CIntObject
  569. {
  570. public:
  571. virtual void clickLeft(tribool down, bool previousState);
  572. virtual void activate();
  573. virtual void deactivate();
  574. };
  575. class RClickableArea: public virtual CIntObject
  576. {
  577. public:
  578. virtual void clickRight(tribool down, bool previousState);
  579. virtual void activate();
  580. virtual void deactivate();
  581. };
  582. class LClickableAreaHero : public LClickableArea
  583. {
  584. public:
  585. int id;
  586. CHeroWindow * owner;
  587. virtual void clickLeft(tribool down, bool previousState);
  588. };
  589. class LRClickableAreaWText: public LClickableArea, public RClickableArea, public HoverableArea
  590. {
  591. public:
  592. std::string text;
  593. virtual void activate();
  594. virtual void deactivate();
  595. virtual void clickLeft(tribool down, bool previousState);
  596. virtual void clickRight(tribool down, bool previousState);
  597. };
  598. class LRClickableAreaWTextComp: public LClickableArea, public RClickableArea, public HoverableArea
  599. {
  600. public:
  601. std::string text;
  602. int baseType;
  603. int bonus, type;
  604. virtual void activate();
  605. virtual void deactivate();
  606. virtual void clickLeft(tribool down, bool previousState);
  607. virtual void clickRight(tribool down, bool previousState);
  608. };
  609. class MoraleLuckBox : public LRClickableAreaWTextComp
  610. {
  611. public:
  612. void set(bool morale, const CGHeroInstance *hero, int slot = -1); //slot -1 means only hero modifiers
  613. };
  614. class LRClickableAreaOpenHero: public LRClickableAreaWTextComp
  615. {
  616. public:
  617. const CGHeroInstance * hero;
  618. void clickLeft(tribool down, bool previousState);
  619. void clickRight(tribool down, bool previousState);
  620. };
  621. class LRClickableAreaOpenTown: public LRClickableAreaWTextComp
  622. {
  623. public:
  624. const CGTownInstance * town;
  625. void clickLeft(tribool down, bool previousState);
  626. void clickRight(tribool down, bool previousState);
  627. };
  628. class CCreInfoWindow : public CIntObject
  629. {
  630. public:
  631. //bool active; //TODO: comment me
  632. int type;//0 - rclick popup; 1 - normal window
  633. SDL_Surface *bitmap; //background
  634. char anf; //animation counter
  635. std::string count; //creature count in text format
  636. boost::function<void()> dsm; //dismiss button callback
  637. CCreaturePic *anim; //related creature's animation
  638. CCreature *c; //related creature
  639. std::vector<SComponent*> upgResCost; //cost of upgrade (if not possible then empty)
  640. //MoraleLuckBox *luck, *morale;
  641. AdventureMapButton *dismiss, *upgrade, *ok;
  642. CCreInfoWindow(int Cid, int Type, int creatureCount, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm, UpgradeInfo *ui); //c-tor
  643. ~CCreInfoWindow(); //d-tor
  644. void activate();
  645. void close();
  646. void clickRight(tribool down, bool previousState); //call-in
  647. void dismissF();
  648. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  649. void deactivate();
  650. void show(SDL_Surface * to);
  651. };
  652. class CArtPlace: public LRClickableAreaWTextComp
  653. {
  654. private:
  655. bool active;
  656. public:
  657. //bool spellBook, warMachine1, warMachine2, warMachine3, warMachine4,
  658. // misc1, misc2, misc3, misc4, misc5, feet, lRing, rRing, torso,
  659. // lHand, rHand, neck, shoulders, head; //my types
  660. 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
  661. bool marked;
  662. CArtifactsOfHero * ourOwner;
  663. const CArtifact * ourArt;
  664. CArtPlace(const CArtifact * Art); //c-tor
  665. void clickLeft(tribool down, bool previousState);
  666. void clickRight(tribool down, bool previousState);
  667. void select ();
  668. void deselect ();
  669. void activate();
  670. void deactivate();
  671. void show(SDL_Surface * to);
  672. bool fitsHere (const CArtifact * art); //returns true if given artifact can be placed here
  673. bool locked () const;
  674. ~CArtPlace(); //d-tor
  675. };
  676. inline bool CArtPlace::locked () const
  677. {
  678. return ourArt && ourArt->id == 145;
  679. }
  680. class CArtifactsOfHero : public CIntObject
  681. {
  682. const CGHeroInstance * curHero;
  683. 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
  684. std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!)
  685. int backpackPos; //number of first art visible in backpack (in hero's vector)
  686. public:
  687. struct SCommonPart
  688. {
  689. std::set<CArtifactsOfHero *> participants; // Needed to mark slots.
  690. const CArtifact * srcArtifact; // Held artifact.
  691. const CArtifactsOfHero * srcAOH; // Following two needed to uniquely identify the source.
  692. int srcSlotID; //
  693. const CArtifactsOfHero * destAOH; // For swapping. (i.e. changing what is held)
  694. int destSlotID; // Needed to determine what kind of action was last taken in setHero
  695. const CArtifact * destArtifact; // For swapping.
  696. } * 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
  697. bool updateState; // Whether the commonInfo should be updated on setHero or not.
  698. AdventureMapButton * leftArtRoll, * rightArtRoll;
  699. void activate();
  700. void deactivate();
  701. void show(SDL_Surface * to);
  702. void setHero(const CGHeroInstance * hero);
  703. void dispose(); //free resources not needed after closing windows and reset state
  704. void rollback();
  705. void scrollBackpack(int dir); //dir==-1 => to left; dir==1 => to right
  706. void markPossibleSlots (const CArtifact* art);
  707. void unmarkSlots ();
  708. void setSlotData (CArtPlace* artPlace, int slotID);
  709. void eraseSlotData (CArtPlace* artPlace, int slotID);
  710. CArtifactsOfHero(const SDL_Rect & position); //c-tor
  711. ~CArtifactsOfHero(); //d-tor
  712. friend class CArtPlace;
  713. };
  714. class CGarrisonWindow : public CWindowWithGarrison
  715. {
  716. public:
  717. SDL_Surface *bg; //background surface
  718. AdventureMapButton *quit;
  719. void close();
  720. void activate();
  721. void deactivate();
  722. void show(SDL_Surface * to);
  723. void showAll(SDL_Surface * to){show(to);};
  724. CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits); //c-tor
  725. ~CGarrisonWindow(); //d-tor
  726. };
  727. class CExchangeWindow : public CWindowWithGarrison
  728. {
  729. CStatusBar * ourBar; //internal statusbar
  730. SDL_Surface *bg; //background
  731. AdventureMapButton * quit, * questlogButton[2];
  732. std::vector<LRClickableAreaWTextComp *> secSkillAreas[2], primSkillAreas;
  733. LRClickableAreaWTextComp *morale[2], *luck[2];
  734. LRClickableAreaWText *speciality[2];
  735. LRClickableAreaWText *experience[2];
  736. LRClickableAreaWText *spellPoints[2];
  737. LRClickableAreaOpenHero *portrait[2];
  738. public:
  739. const CGHeroInstance * heroInst[2];
  740. CArtifactsOfHero * artifs[2];
  741. void close();
  742. void activate();
  743. void deactivate();
  744. void show(SDL_Surface * to);
  745. void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right
  746. void prepareBackground(); //prepares or redraws bg
  747. CExchangeWindow(si32 hero1, si32 hero2); //c-tor
  748. ~CExchangeWindow(); //d-tor
  749. };
  750. class CShipyardWindow : public CIntObject
  751. {
  752. public:
  753. CStatusBar *bar;
  754. SDL_Surface *bg; //background
  755. AdventureMapButton *build, *quit;
  756. unsigned char frame; //frame of the boat animation
  757. int boat; //which boat graphic should be used
  758. void activate();
  759. void deactivate();
  760. void show(SDL_Surface * to);
  761. CShipyardWindow(const std::vector<si32> &cost, int state, int boatType, const boost::function<void()> &onBuy);
  762. ~CShipyardWindow();
  763. };
  764. class CPuzzleWindow : public CIntObject
  765. {
  766. private:
  767. SDL_Surface * background;
  768. AdventureMapButton * quitb;
  769. CResDataBar * resdatabar;
  770. std::vector<std::pair<SDL_Surface *, SPuzzleInfo *> > puzzlesToPullBack;
  771. ui8 animCount;
  772. public:
  773. void activate();
  774. void deactivate();
  775. void show(SDL_Surface * to);
  776. CPuzzleWindow(const int3 &grailPos, float discoveredRatio);
  777. ~CPuzzleWindow();
  778. };
  779. class CShopWindow : public CIntObject
  780. {
  781. public:
  782. std::map<ui16, Component> available, chosen, bought;
  783. bool swapItem (ui16 which, bool choose);
  784. virtual void Buy() {};
  785. };
  786. class CArtMerchantWindow : public CShopWindow
  787. {
  788. public:
  789. void activate();
  790. void deactivate();
  791. void show(SDL_Surface * to);
  792. void Buy();
  793. CArtMerchantWindow();
  794. ~CArtMerchantWindow();
  795. };
  796. class CUniversityWindow : public CShopWindow
  797. {};
  798. class CAltarWindow : public CShopWindow
  799. {};
  800. class CRefugeeCampWindow : public CShopWindow
  801. {};
  802. class CWarMachineWindow : public CShopWindow
  803. {};
  804. class CFreelancersWindow : public CShopWindow
  805. {};
  806. class CHillFortWindow : public CIntObject //garrison dialog? shop?
  807. {};
  808. class CThievesGuildWindow : public CIntObject
  809. {
  810. const CGObjectInstance * owner;
  811. CStatusBar * statusBar;
  812. AdventureMapButton * exitb;
  813. SDL_Surface * background;
  814. CMinorResDataBar * resdatabar;
  815. public:
  816. void activate();
  817. void show(SDL_Surface * to);
  818. void bexitf();
  819. CThievesGuildWindow(const CGObjectInstance * _owner);
  820. ~CThievesGuildWindow();
  821. };
  822. #endif //__GUICLASSES_H__