GUIClasses.h 23 KB

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