GUIClasses.h 26 KB

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