GUIClasses.h 24 KB

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