GUIClasses.h 27 KB

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