GUIClasses.h 25 KB

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