GUIClasses.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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 CInfoWindow : public CSimpleWindow //text + comp. + ok button
  60. { //window able to delete its components when closed
  61. public:
  62. bool delComps; //whether comps will be deleted
  63. std::vector<AdventureMapButton *> buttons;
  64. std::vector<SComponent*> components;
  65. virtual void close();
  66. void show(SDL_Surface * to);
  67. void showAll(SDL_Surface * to);
  68. void activate();
  69. void deactivate();
  70. 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
  71. CInfoWindow(); //c-tor
  72. ~CInfoWindow(); //d-tor
  73. };
  74. class CSelWindow : public CInfoWindow //component selection window
  75. { //warning - this window deletes its components by closing!
  76. public:
  77. void selectionChange(unsigned to);
  78. void madeChoice(); //looks for selected component and calls callback
  79. 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
  80. CSelWindow(){}; //c-tor
  81. //notification - this class inherits important destructor from CInfoWindow
  82. };
  83. class CRClickPopup : public CIntObject //popup displayed on R-click
  84. {
  85. public:
  86. virtual void activate();
  87. virtual void deactivate();
  88. virtual void close();
  89. void clickRight(tribool down, bool previousState);
  90. virtual ~CRClickPopup(){}; //d-tor
  91. };
  92. class CRClickPopupInt : public CRClickPopup //popup displayed on R-click
  93. {
  94. public:
  95. IShowActivable *inner;
  96. bool delInner;
  97. void show(SDL_Surface * to);
  98. CRClickPopupInt(IShowActivable *our, bool deleteInt); //c-tor
  99. virtual ~CRClickPopupInt(); //d-tor
  100. };
  101. class CInfoPopup : public CRClickPopup
  102. {
  103. public:
  104. bool free; //TODO: comment me
  105. SDL_Surface * bitmap; //popup background
  106. void close();
  107. void show(SDL_Surface * to);
  108. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false); //c-tor
  109. CInfoPopup(SDL_Surface *Bitmap = NULL, bool Free = false); //default c-tor
  110. ~CInfoPopup(){}; //d-tor
  111. };
  112. class SComponent : public virtual CIntObject //common popup window component
  113. {
  114. public:
  115. enum Etype
  116. {
  117. primskill, secskill, resource, creature, artifact, experience, secskill44, spell, morale, luck
  118. } type; //component type
  119. int subtype; //TODO: comment me
  120. int val; //TODO: comment me
  121. std::string description; //r-click
  122. std::string subtitle; //TODO: comment me
  123. void init(Etype Type, int Subtype, int Val);
  124. SComponent(Etype Type, int Subtype, int Val); //c-tor
  125. SComponent(const Component &c); //c-tor
  126. SComponent(){}; //c-tor
  127. virtual ~SComponent(){}; //d-tor
  128. void clickRight(tribool down, bool previousState); //call-in
  129. virtual SDL_Surface * getImg();
  130. virtual void show(SDL_Surface * to);
  131. virtual void activate();
  132. virtual void deactivate();
  133. };
  134. class CCustomImgComponent : public SComponent
  135. {
  136. public:
  137. SDL_Surface *bmp; //our image
  138. bool free; //should surface be freed on delete
  139. SDL_Surface * getImg();
  140. CCustomImgComponent(Etype Type, int Subtype, int Val, SDL_Surface *sur, bool freeSur); //c-tor
  141. ~CCustomImgComponent(); //d-tor
  142. };
  143. class CSelectableComponent : public SComponent, public KeyShortcut
  144. {
  145. public:
  146. bool selected; //if true, this component is selected
  147. bool customB; //TODO: comment me
  148. SDL_Surface * border, *myBitmap;
  149. boost::function<void()> onSelect; //function called on selection change
  150. void clickLeft(tribool down, bool previousState); //call-in
  151. void init(SDL_Surface * Border);
  152. CSelectableComponent(Etype Type, int Sub, int Val, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
  153. CSelectableComponent(const Component &c, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
  154. ~CSelectableComponent(); //d-tor
  155. virtual void show(SDL_Surface * to);
  156. void activate();
  157. void deactivate();
  158. void select(bool on);
  159. SDL_Surface * getImg(); //returns myBitmap
  160. };
  161. class CGarrisonInt;
  162. class CGarrisonSlot : public CIntObject
  163. {
  164. public:
  165. CGarrisonInt *owner;
  166. const CCreature * creature; //creature in slot
  167. int count; //number of creatures
  168. int upg; //0 - up garrison, 1 - down garrison
  169. bool active; //TODO: comment me
  170. virtual void hover (bool on); //call-in
  171. const CArmedInstance * getObj();
  172. void clickRight(tribool down, bool previousState);
  173. void clickLeft(tribool down, bool previousState);
  174. void activate();
  175. void deactivate();
  176. void show(SDL_Surface * to);
  177. CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg=0, const CCreature * Creature=NULL, int Count=0);
  178. ~CGarrisonSlot(); //d-tor
  179. };
  180. class CGarrisonInt :public CIntObject
  181. {
  182. public:
  183. int interx; //space between slots
  184. Point garOffset, //offset between garrisons (not used if only one hero)
  185. surOffset; //offset between garrison position on the bg surface and position on the screen
  186. CGarrisonSlot *highlighted; //chosen slot
  187. SDL_Surface *&sur; //bg surface
  188. int p2; //TODO: comment me
  189. bool ignoreEvent, update, active, splitting, pb,
  190. smallIcons; //true - 32x32 imgs, false - 58x64
  191. const CCreatureSet *set1; //top set of creatures
  192. const CCreatureSet *set2; //bottom set of creatures
  193. std::vector<CGarrisonSlot*> *sup, *sdown; //slots of upper and lower garrison
  194. const CArmedInstance *oup, *odown; //upper and lower garrisons (heroes or towns)
  195. void activate();
  196. void deactivate();
  197. void show(SDL_Surface * to);
  198. void activeteSlots();
  199. void deactiveteSlots();
  200. void deleteSlots();
  201. void createSlots();
  202. void recreateSlots();
  203. void splitClick(); //handles click on split button
  204. void splitStacks(int am2); //TODO: comment me
  205. CGarrisonInt(int x, int y, int inx, const Point &garsOffset, SDL_Surface *&pomsur, const Point &SurOffset, const CArmedInstance *s1, const CArmedInstance *s2=NULL, bool smallImgs = false); //c-tor
  206. ~CGarrisonInt(); //d-tor
  207. };
  208. class CStatusBar
  209. : public CIntObject, public IStatusBar
  210. {
  211. public:
  212. SDL_Surface * bg; //background
  213. int middlex, middley; //middle of statusbar
  214. std::string current; //text currently printed
  215. CStatusBar(int x, int y, std::string name="ADROLLVR.bmp", int maxw=-1); //c-tor
  216. ~CStatusBar(); //d-tor
  217. void print(const std::string & text); //prints text and refreshes statusbar
  218. void clear();//clears statusbar and refreshes
  219. void show(SDL_Surface * to); //shows statusbar (with current text)
  220. std::string getCurrent(); //getter for current
  221. };
  222. class CList : public CIntObject
  223. {
  224. public:
  225. SDL_Surface * bg; //background bitmap
  226. CDefHandler *arrup, *arrdo; //button arrows for scrolling list
  227. SDL_Surface *empty, *selection;
  228. SDL_Rect arrupp, arrdop; //positions of arrows
  229. int posw, posh; //position width/height
  230. int selected, //id of selected position, <0 if none
  231. from;
  232. const int SIZE; //size of list
  233. tribool pressed; //true=up; false=down; indeterminate=none
  234. CList(int Size = 5); //c-tor
  235. void clickLeft(tribool down, bool previousState);
  236. void activate();
  237. void deactivate();
  238. virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; //call-in
  239. virtual void genList()=0;
  240. virtual void select(int which)=0;
  241. virtual void draw(SDL_Surface * to)=0;
  242. };
  243. class CHeroList
  244. : public CList
  245. {
  246. public:
  247. CDefHandler *mobile, *mana; //mana and movement indicators
  248. int posmobx, posporx, posmanx, posmoby, pospory, posmany;
  249. std::vector<const CGHeroInstance *> &heroes; //points to LOCPLINT->wandering heroes
  250. CHeroList(int Size); //c-tor
  251. int getPosOfHero(const CGHeroInstance* h); //hero's position on list
  252. void genList();
  253. void select(int which); //call-in
  254. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  255. void clickLeft(tribool down, bool previousState); //call-in
  256. void clickRight(tribool down, bool previousState); //call-in
  257. void hover (bool on); //call-in
  258. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  259. void updateHList(const CGHeroInstance *toRemove=NULL); //removes specific hero from the list or recreates it
  260. void updateMove(const CGHeroInstance* which); //draws move points bar
  261. void draw(SDL_Surface * to);
  262. void show(SDL_Surface * to);
  263. void init();
  264. };
  265. class CTownList
  266. : public CList
  267. {
  268. public:
  269. boost::function<void()> fun; //function called on selection change
  270. std::vector<const CGTownInstance*> items; //towns on list
  271. int posporx,pospory;
  272. CTownList(int Size, int x, int y, std::string arrupg, std::string arrdog); //c-tor
  273. ~CTownList(); //d-tor
  274. void genList();
  275. void select(int which); //call-in
  276. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  277. void clickLeft(tribool down, bool previousState); //call-in
  278. void clickRight(tribool down, bool previousState); //call-in
  279. void hover (bool on); //call-in
  280. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  281. void draw(SDL_Surface * to);
  282. void show(SDL_Surface * to);
  283. };
  284. class CCreaturePic //draws picture with creature on background, use nextFrame=true to get animation
  285. {
  286. public:
  287. const CCreature *c; //which creature's picture
  288. bool big; //big => 100x130; !big => 100x120
  289. CCreatureAnimation *anim; //displayed animation
  290. CCreaturePic(const CCreature *cre, bool Big=true); //c-tor
  291. ~CCreaturePic(); //d-tor
  292. int blitPic(SDL_Surface *to, int x, int y, bool nextFrame); //prints creature on screen
  293. SDL_Surface * getPic(bool nextFrame); //returns frame of animation
  294. };
  295. class CRecruitmentWindow : public CIntObject
  296. {
  297. public:
  298. static const int SPACE_BETWEEN = 8;
  299. static const int CREATURE_WIDTH = 102;
  300. static const int TOTAL_CREATURE_WIDTH = SPACE_BETWEEN + CREATURE_WIDTH;
  301. struct creinfo
  302. {
  303. SDL_Rect pos;
  304. CCreaturePic *pic; //creature's animation
  305. int ID, amount; //creature ID and available amount
  306. std::vector<std::pair<int,int> > res; //res_id - cost_per_unit
  307. };
  308. std::vector<int> amounts; //how many creatures we can afford
  309. std::vector<creinfo> creatures; //recruitable creatures
  310. boost::function<void(int,int)> recruit; //void (int ID, int amount) <-- call to recruit creatures
  311. CSlider *slider; //for selecting amount
  312. AdventureMapButton *max, *buy, *cancel;
  313. SDL_Surface *bitmap; //background
  314. CStatusBar *bar;
  315. int which; //which creature is active
  316. const CGDwelling *dwelling;
  317. int level;
  318. const CArmedInstance *dst;
  319. void close();
  320. void Max();
  321. void Buy();
  322. void Cancel();
  323. void sliderMoved(int to);
  324. void clickLeft(tribool down, bool previousState);
  325. void clickRight(tribool down, bool previousState);
  326. void activate();
  327. void deactivate();
  328. void show(SDL_Surface * to);
  329. void showAll(SDL_Surface * to){show(to);};
  330. void cleanCres();
  331. void initCres();
  332. CRecruitmentWindow(const CGDwelling *Dwelling, int Level, const CArmedInstance *Dst, const boost::function<void(int,int)> & Recruit); //creatures - pairs<creature_ID,amount> //c-tor
  333. ~CRecruitmentWindow(); //d-tor
  334. };
  335. class CSplitWindow : public CIntObject
  336. {
  337. public:
  338. CGarrisonInt *gar;
  339. CSlider *slider;
  340. CCreaturePic *anim; //creature's animation
  341. AdventureMapButton *ok, *cancel;
  342. SDL_Surface *bitmap; //background
  343. int a1, a2, c; //TODO: comment me
  344. bool which; //which creature is selected
  345. int last; //0/1/2 - at least one creature must be in the src/dst/both stacks; -1 - no restrictions
  346. CSplitWindow(int cid, int max, CGarrisonInt *Owner, int Last = -1, int val=0); //c-tor; val - initial amount of second stack
  347. ~CSplitWindow(); //d-tor
  348. void activate();
  349. void split();
  350. void close();
  351. void deactivate();
  352. void show(SDL_Surface * to);
  353. void clickLeft(tribool down, bool previousState); //call-in
  354. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  355. void sliderMoved(int to);
  356. };
  357. class CCreInfoWindow : public CIntObject
  358. {
  359. public:
  360. //bool active; //TODO: comment me
  361. int type;//0 - rclick popup; 1 - normal window
  362. SDL_Surface *bitmap; //background
  363. char anf; //animation counter
  364. std::string count; //creature count in text format
  365. boost::function<void()> dsm; //dismiss button callback
  366. CCreaturePic *anim; //related creature's animation
  367. CCreature *c; //related creature
  368. std::vector<SComponent*> upgResCost; //cost of upgrade (if not possible then empty)
  369. AdventureMapButton *dismiss, *upgrade, *ok;
  370. CCreInfoWindow(int Cid, int Type, int creatureCount, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm, UpgradeInfo *ui); //c-tor
  371. ~CCreInfoWindow(); //d-tor
  372. void activate();
  373. void close();
  374. void clickRight(tribool down, bool previousState); //call-in
  375. void dismissF();
  376. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  377. void deactivate();
  378. void show(SDL_Surface * to);
  379. };
  380. class CLevelWindow : public CIntObject
  381. {
  382. public:
  383. int heroType;
  384. SDL_Surface *bitmap; //background
  385. std::vector<CSelectableComponent *> comps; //skills to select
  386. AdventureMapButton *ok;
  387. boost::function<void(ui32)> cb;
  388. void close();
  389. CLevelWindow(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback); //c-tor
  390. ~CLevelWindow(); //d-tor
  391. void activate();
  392. void deactivate();
  393. void selectionChanged(unsigned to);
  394. void show(SDL_Surface * to);
  395. };
  396. class CMinorResDataBar : public CIntObject
  397. {
  398. public:
  399. SDL_Surface *bg; //background bitmap
  400. void show(SDL_Surface * to);
  401. CMinorResDataBar(); //c-tor
  402. ~CMinorResDataBar(); //d-tor
  403. };
  404. class CMarketplaceWindow : public CIntObject
  405. {
  406. public:
  407. class CTradeableItem : public CIntObject
  408. {
  409. public:
  410. int type; //0 - res, 1 - artif big, 2 - artif small, 3 - player flag
  411. int id;
  412. bool left;
  413. CFunctionList<void()> callback;
  414. void activate();
  415. void deactivate();
  416. void show(SDL_Surface * to);
  417. void clickLeft(tribool down, bool previousState);
  418. SDL_Surface *getSurface();
  419. CTradeableItem(int Type, int ID, bool Left);
  420. };
  421. SDL_Surface *bg; //background
  422. std::vector<CTradeableItem*> left, right;
  423. std::vector<std::string> rSubs; //offer caption
  424. CTradeableItem *hLeft, *hRight; //highlighted items (NULL if no highlight)
  425. int mode,//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact
  426. r1, r2; //suggested amounts of traded resources
  427. AdventureMapButton *ok, *max, *deal;
  428. CSlider *slider; //for choosing amount to be exchanged
  429. void activate();
  430. void deactivate();
  431. void show(SDL_Surface * to);
  432. void setMax();
  433. void sliderMoved(int to);
  434. void makeDeal();
  435. void selectionChanged(bool side); //true == left
  436. CMarketplaceWindow(int Mode=0); //c-tor
  437. ~CMarketplaceWindow(); //d-tor
  438. void setMode(int mode); //mode setter
  439. void clear();
  440. };
  441. class CSystemOptionsWindow : public CIntObject
  442. {
  443. private:
  444. SDL_Surface * background; //background of window
  445. AdventureMapButton *load, *save, *restart, *mainMenu, * quitGame, * backToMap; //load, restart and main menu are not used yet
  446. CHighlightableButtonsGroup * heroMoveSpeed;
  447. CHighlightableButtonsGroup * mapScrollSpeed;
  448. CHighlightableButtonsGroup * musicVolume, * effectsVolume;
  449. public:
  450. CSystemOptionsWindow(const SDL_Rect & pos, CPlayerInterface * owner); //c-tor
  451. ~CSystemOptionsWindow(); //d-tor
  452. //functions bound to buttons
  453. void bsavef(); //save game
  454. void bquitf(); //quit game
  455. void breturnf(); //return to game
  456. void activate();
  457. void deactivate();
  458. void show(SDL_Surface * to);
  459. };
  460. class CTavernWindow : public CIntObject
  461. {
  462. public:
  463. class HeroPortrait : public CIntObject
  464. {
  465. public:
  466. std::string hoverName;
  467. vstd::assigner<int,int> as;
  468. const CGHeroInstance *h;
  469. void activate();
  470. void deactivate();
  471. void clickLeft(tribool down, bool previousState);
  472. void clickRight(tribool down, bool previousState);
  473. void hover (bool on);
  474. HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H);
  475. void show(SDL_Surface * to);
  476. char descr[100]; // "XXX is a level Y ZZZ with N artifacts"
  477. } h1, h2; //recruitable heroes
  478. SDL_Surface *bg; //background
  479. CStatusBar *bar; //tavern's internal status bar
  480. int selected;//0 (left) or 1 (right)
  481. int oldSelected;//0 (left) or 1 (right)
  482. AdventureMapButton *thiefGuild, *cancel, *recruit;
  483. CTavernWindow(const CGHeroInstance *H1, const CGHeroInstance *H2, const std::string &gossip); //c-tor
  484. ~CTavernWindow(); //d-tor
  485. void recruitb();
  486. void close();
  487. void activate();
  488. void deactivate();
  489. void show(SDL_Surface * to);
  490. };
  491. class CInGameConsole : public CIntObject
  492. {
  493. private:
  494. std::list< std::pair< std::string, int > > texts; //<text to show, time of add>
  495. boost::mutex texts_mx; // protects texts
  496. std::vector< std::string > previouslyEntered; //previously entered texts, for up/down arrows to work
  497. int prevEntDisp; //displayed entry from previouslyEntered - if none it's -1
  498. int defaultTimeout; //timeout for new texts (in ms)
  499. int maxDisplayedTexts; //hiw many texts can be displayed simultaneously
  500. public:
  501. std::string enteredText;
  502. void activate();
  503. void deactivate();
  504. void show(SDL_Surface * to);
  505. void print(const std::string &txt);
  506. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  507. void startEnteringText();
  508. void endEnteringText(bool printEnteredText);
  509. void refreshEnteredText();
  510. CInGameConsole(); //c-tor
  511. };
  512. class LClickableArea: public virtual CIntObject
  513. {
  514. public:
  515. virtual void clickLeft(tribool down, bool previousState);
  516. virtual void activate();
  517. virtual void deactivate();
  518. };
  519. class RClickableArea: public virtual CIntObject
  520. {
  521. public:
  522. virtual void clickRight(tribool down, bool previousState);
  523. virtual void activate();
  524. virtual void deactivate();
  525. };
  526. class LClickableAreaHero : public LClickableArea
  527. {
  528. public:
  529. int id;
  530. CHeroWindow * owner;
  531. virtual void clickLeft(tribool down, bool previousState);
  532. };
  533. class LRClickableAreaWText: public LClickableArea, public RClickableArea
  534. {
  535. public:
  536. std::string text, hoverText;
  537. virtual void activate();
  538. virtual void deactivate();
  539. virtual void clickLeft(tribool down, bool previousState);
  540. virtual void clickRight(tribool down, bool previousState);
  541. virtual void hover(bool on);
  542. };
  543. class LRClickableAreaWTextComp: public LClickableArea, public RClickableArea
  544. {
  545. public:
  546. std::string text, hoverText;
  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. virtual void hover(bool on);
  554. };
  555. class CArtPlace: public LRClickableAreaWTextComp
  556. {
  557. private:
  558. bool active;
  559. public:
  560. //bool spellBook, warMachine1, warMachine2, warMachine3, warMachine4,
  561. // misc1, misc2, misc3, misc4, misc5, feet, lRing, rRing, torso,
  562. // lHand, rHand, neck, shoulders, head; //my types
  563. 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
  564. bool clicked;
  565. CArtifactsOfHero * ourOwner;
  566. const CArtifact * ourArt;
  567. CArtPlace(const CArtifact * Art); //c-tor
  568. void clickLeft(tribool down, bool previousState);
  569. void clickRight(tribool down, bool previousState);
  570. void activate();
  571. void deactivate();
  572. void show(SDL_Surface * to);
  573. bool fitsHere(const CArtifact * art); //returns true if given artifact can be placed here
  574. ~CArtPlace(); //d-tor
  575. };
  576. class CArtifactsOfHero : public CIntObject
  577. {
  578. const CGHeroInstance * curHero;
  579. 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
  580. std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!)
  581. int backpackPos; //unmber of first art visible in backpack (in hero's vector)
  582. public:
  583. struct SCommonPart
  584. {
  585. CArtPlace * activeArtPlace;
  586. } * 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
  587. AdventureMapButton * leftArtRoll, * rightArtRoll;
  588. void activate();
  589. void deactivate();
  590. void show(SDL_Surface * to);
  591. void setHero(const CGHeroInstance * hero);
  592. void dispose(); //free resources not needed after closing windows and reset state
  593. void scrollBackpack(int dir); //dir==-1 => to left; dir==-2 => to right
  594. CArtifactsOfHero(const SDL_Rect & position); //c-tor
  595. ~CArtifactsOfHero(); //d-tor
  596. friend class CArtPlace;
  597. };
  598. class CGarrisonWindow : public CWindowWithGarrison
  599. {
  600. public:
  601. SDL_Surface *bg; //background surface
  602. AdventureMapButton *split, *quit;
  603. void close();
  604. void activate();
  605. void deactivate();
  606. void show(SDL_Surface * to);
  607. void showAll(SDL_Surface * to){show(to);};
  608. CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down); //c-tor
  609. ~CGarrisonWindow(); //d-tor
  610. };
  611. class CExchangeWindow : public CWindowWithGarrison
  612. {
  613. CStatusBar * ourBar; //internal statusbar
  614. SDL_Surface *bg; //background
  615. AdventureMapButton * quit, * questlogButton[2], * splitButton[2];
  616. std::vector<LRClickableAreaWTextComp *> secSkillAreas[2], primSkillAreas;
  617. LRClickableAreaWTextComp *morale[2], *luck[2];
  618. public:
  619. const CGHeroInstance * heroInst[2];
  620. CArtifactsOfHero * artifs[2];
  621. void close();
  622. void activate();
  623. void deactivate();
  624. void show(SDL_Surface * to);
  625. void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right
  626. void prepareBackground(); //prepares or redraws bg
  627. CExchangeWindow(si32 hero1, si32 hero2); //c-tor
  628. ~CExchangeWindow(); //d-tor
  629. };
  630. class CShipyardWindow : public CIntObject
  631. {
  632. public:
  633. CStatusBar *bar;
  634. SDL_Surface *bg; //background
  635. AdventureMapButton *build, *quit;
  636. unsigned char frame; //frame of the boat animation
  637. void activate();
  638. void deactivate();
  639. void show(SDL_Surface * to);
  640. CShipyardWindow(const std::vector<si32> &cost, int state, const boost::function<void()> &onBuy);
  641. ~CShipyardWindow();
  642. };
  643. #endif //__GUICLASSES_H__