GUIClasses.h 27 KB

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