GUIClasses.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068
  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 CGGarrison;
  63. class CStackInstance;
  64. class IMarket;
  65. class CTextBox;
  66. extern SDL_Color tytulowy, tlo, zwykly ;
  67. class CInfoWindow : public CSimpleWindow //text + comp. + ok button
  68. { //window able to delete its components when closed
  69. public:
  70. CTextBox *text;
  71. std::vector<AdventureMapButton *> buttons;
  72. bool delComps; //whether comps will be deleted
  73. std::vector<SComponent*> components;
  74. virtual void close();
  75. void show(SDL_Surface * to);
  76. void showAll(SDL_Surface * to);
  77. 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
  78. CInfoWindow(); //c-tor
  79. ~CInfoWindow(); //d-tor
  80. static void showYesNoDialog( const std::string & text, const std::vector<SComponent*> *components, const CFunctionList<void( ) > &onYes, const CFunctionList<void()> &onNo, bool DelComps = true, int player = 1); //use only before the game starts! (showYesNoDialog in LOCPLINT must be used then)
  81. static CInfoWindow *create(const std::string &text, int playerID = 1, const std::vector<SComponent*> *components = NULL);
  82. };
  83. class CSelWindow : public CInfoWindow //component selection window
  84. { //warning - this window deletes its components by closing!
  85. public:
  86. void selectionChange(unsigned to);
  87. void madeChoice(); //looks for selected component and calls callback
  88. 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
  89. CSelWindow(){}; //c-tor
  90. //notification - this class inherits important destructor from CInfoWindow
  91. };
  92. class CRClickPopup : public CIntObject //popup displayed on R-click
  93. {
  94. public:
  95. virtual void activate();
  96. virtual void deactivate();
  97. virtual void close();
  98. void clickRight(tribool down, bool previousState);
  99. CRClickPopup();
  100. virtual ~CRClickPopup(); //d-tor
  101. static void createAndPush(const std::string &txt);
  102. static void createAndPush(const CGObjectInstance *obj, const Point &p, EAlignment alignment = BOTTOMRIGHT);
  103. };
  104. class CRClickPopupInt : public CRClickPopup //popup displayed on R-click
  105. {
  106. public:
  107. IShowActivable *inner;
  108. bool delInner;
  109. void show(SDL_Surface * to);
  110. CRClickPopupInt(IShowActivable *our, bool deleteInt); //c-tor
  111. virtual ~CRClickPopupInt(); //d-tor
  112. };
  113. class CInfoPopup : public CRClickPopup
  114. {
  115. public:
  116. bool free; //TODO: comment me
  117. SDL_Surface * bitmap; //popup background
  118. void close();
  119. void show(SDL_Surface * to);
  120. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false); //c-tor
  121. CInfoPopup(SDL_Surface * Bitmap, const Point &p, EAlignment alignment, bool Free=false); //c-tor
  122. CInfoPopup(SDL_Surface *Bitmap = NULL, bool Free = false); //default c-tor
  123. void init(int x, int y);
  124. ~CInfoPopup(); //d-tor
  125. };
  126. class SComponent : public virtual CIntObject //common popup window component
  127. {
  128. public:
  129. enum Etype
  130. {
  131. primskill, secskill, resource, creature, artifact, experience, secskill44, spell, morale, luck, building, hero, flag
  132. } type; //component type
  133. int subtype; //TODO: comment me
  134. int val; //TODO: comment me
  135. std::string description; //r-click
  136. std::string subtitle; //TODO: comment me
  137. void init(Etype Type, int Subtype, int Val);
  138. SComponent(Etype Type, int Subtype, int Val); //c-tor
  139. SComponent(const Component &c); //c-tor
  140. SComponent(){}; //c-tor
  141. virtual ~SComponent(){}; //d-tor
  142. void clickRight(tribool down, bool previousState); //call-in
  143. virtual SDL_Surface * getImg();
  144. virtual void show(SDL_Surface * to);
  145. virtual void activate();
  146. virtual void deactivate();
  147. };
  148. class CCustomImgComponent : public SComponent
  149. {
  150. public:
  151. SDL_Surface *bmp; //our image
  152. bool free; //should surface be freed on delete
  153. SDL_Surface * getImg();
  154. CCustomImgComponent(Etype Type, int Subtype, int Val, SDL_Surface *sur, bool freeSur); //c-tor
  155. ~CCustomImgComponent(); //d-tor
  156. };
  157. class CSelectableComponent : public SComponent, public KeyShortcut
  158. {
  159. public:
  160. bool selected; //if true, this component is selected
  161. bool customB; //TODO: comment me
  162. SDL_Surface * border, *myBitmap;
  163. boost::function<void()> onSelect; //function called on selection change
  164. void clickLeft(tribool down, bool previousState); //call-in
  165. void init(SDL_Surface * Border);
  166. CSelectableComponent(Etype Type, int Sub, int Val, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
  167. CSelectableComponent(const Component &c, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
  168. ~CSelectableComponent(); //d-tor
  169. virtual void show(SDL_Surface * to);
  170. void activate();
  171. void deactivate();
  172. void select(bool on);
  173. SDL_Surface * getImg(); //returns myBitmap
  174. };
  175. class CGarrisonInt;
  176. class CGarrisonSlot : public CIntObject
  177. {
  178. public:
  179. CGarrisonInt *owner;
  180. const CStackInstance *myStack; //NULL if slot is empty
  181. const CCreature *creature;
  182. int count; //number of creatures
  183. int upg; //0 - up garrison, 1 - down garrison
  184. bool active; //TODO: comment me
  185. virtual void hover (bool on); //call-in
  186. const CArmedInstance * getObj();
  187. void clickRight(tribool down, bool previousState);
  188. void clickLeft(tribool down, bool previousState);
  189. void activate();
  190. void deactivate();
  191. void show(SDL_Surface * to);
  192. CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg=0, const CStackInstance * Creature=NULL);
  193. ~CGarrisonSlot(); //d-tor
  194. };
  195. class CGarrisonInt :public CIntObject
  196. {
  197. public:
  198. int interx; //space between slots
  199. Point garOffset, //offset between garrisons (not used if only one hero)
  200. surOffset, //offset between garrison position on the bg surface and position on the screen
  201. shiftPoint;//how last slots will be shifted (for second row, set shiftPoint for effect)
  202. CGarrisonSlot *highlighted; //chosen slot
  203. std::vector<AdventureMapButton *> splitButtons; //may be empty if no buttons
  204. SDL_Surface *&sur; //bg surface
  205. int p2, //TODO: comment me
  206. shiftPos;//1st slot of the second row, set shiftPoint for effect
  207. bool ignoreEvent, update, active, splitting, pb,
  208. smallIcons; //true - 32x32 imgs, false - 58x64
  209. bool removableUnits;
  210. const CCreatureSet *set1; //top set of creatures
  211. const CCreatureSet *set2; //bottom set of creatures
  212. std::vector<CGarrisonSlot*> *sup, *sdown; //slots of upper and lower garrison
  213. const CArmedInstance *oup, *odown; //upper and lower garrisons (heroes or towns)
  214. void activate();
  215. void deactivate();
  216. void show(SDL_Surface * to);
  217. void activeteSlots();
  218. void deactiveteSlots();
  219. void deleteSlots();
  220. void createSlots();
  221. void recreateSlots();
  222. void splitClick(); //handles click on split button
  223. void splitStacks(int am2); //TODO: comment me
  224. 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
  225. ~CGarrisonInt(); //d-tor
  226. };
  227. class CStatusBar
  228. : public CIntObject, public IStatusBar
  229. {
  230. public:
  231. SDL_Surface * bg; //background
  232. int middlex, middley; //middle of statusbar
  233. std::string current; //text currently printed
  234. CStatusBar(int x, int y, std::string name="ADROLLVR.bmp", int maxw=-1); //c-tor
  235. ~CStatusBar(); //d-tor
  236. void print(const std::string & text); //prints text and refreshes statusbar
  237. void clear();//clears statusbar and refreshes
  238. void show(SDL_Surface * to); //shows statusbar (with current text)
  239. std::string getCurrent(); //getter for current
  240. };
  241. class CLabel
  242. : public virtual CIntObject
  243. {
  244. public:
  245. EAlignment alignment;
  246. EFonts font;
  247. SDL_Color color;
  248. std::string text;
  249. CPicture *bg;
  250. bool autoRedraw; //whether control will redraw itself on setTxt
  251. Point textOffset; //text will be blitted at pos + textOffset with appropriate alignment
  252. bool ignoreLeadingWhitespace;
  253. virtual void setTxt(const std::string &Txt);
  254. void showAll(SDL_Surface * to); //shows statusbar (with current text)
  255. CLabel(int x=0, int y=0, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly, const std::string &Text = "");
  256. };
  257. //a multi-line label that tries to fit text with given available width and height; if not possible, it creates a slider for scrolling text
  258. class CTextBox
  259. : public CLabel
  260. {
  261. public:
  262. int maxW; //longest line of text in px
  263. int maxH; //total height needed to print all lines
  264. int sliderStyle;
  265. bool redrawParentOnScrolling;
  266. std::vector<std::string> lines;
  267. CSlider *slider;
  268. //CTextBox( std::string Text, const Point &Pos, int w, int h, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly);
  269. CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly);
  270. void showAll(SDL_Surface * to); //shows statusbar (with current text)
  271. void setTxt(const std::string &Txt);
  272. void setBounds(int limitW, int limitH);
  273. void recalculateLines(const std::string &Txt);
  274. void sliderMoved(int to);
  275. };
  276. class CGStatusBar
  277. : public CLabel, public IStatusBar
  278. {
  279. void init();
  280. public:
  281. IStatusBar *oldStatusBar;
  282. //statusbar interface overloads
  283. void print(const std::string & Text); //prints text and refreshes statusbar
  284. void clear();//clears statusbar and refreshes
  285. std::string getCurrent(); //returns currently displayed text
  286. void show(SDL_Surface * to); //shows statusbar (with current text)
  287. CGStatusBar(int x, int y, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = zwykly, const std::string &Text = "");
  288. CGStatusBar(CPicture *BG, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = zwykly); //given CPicture will be captured by created sbar and it's pos will be used as pos for sbar
  289. CGStatusBar(int x, int y, std::string name, int maxw=-1);
  290. ~CGStatusBar();
  291. void calcOffset();
  292. };
  293. class CFocusable
  294. : public virtual CIntObject
  295. {
  296. public:
  297. bool focus; //only one focusable control can have focus at one moment
  298. void giveFocus(); //captures focus
  299. void moveFocus(); //moves focus to next active control (may be used for tab switching)
  300. static std::list<CFocusable*> focusables; //all existing objs
  301. static CFocusable *inputWithFocus; //who has focus now
  302. CFocusable();
  303. ~CFocusable();
  304. };
  305. class CTextInput
  306. : public CLabel, public CFocusable
  307. {
  308. public:
  309. CFunctionList<void(const std::string &)> cb;
  310. void setText(const std::string &nText, bool callCb = false);
  311. CTextInput(const Rect &Pos, const Point &bgOffset, const std::string &bgName, const CFunctionList<void(const std::string &)> &CB);
  312. CTextInput(const Rect &Pos, SDL_Surface *srf);
  313. ~CTextInput();
  314. void showAll(SDL_Surface * to);
  315. void clickLeft(tribool down, bool previousState);
  316. void keyPressed(const SDL_KeyboardEvent & key);
  317. };
  318. class CList : public CIntObject
  319. {
  320. public:
  321. SDL_Surface * bg; //background bitmap
  322. CDefHandler *arrup, *arrdo; //button arrows for scrolling list
  323. SDL_Surface *empty, *selection;
  324. SDL_Rect arrupp, arrdop; //positions of arrows
  325. int posw, posh; //position width/height
  326. int selected, //id of selected position, <0 if none
  327. from;
  328. const int SIZE; //size of list
  329. tribool pressed; //true=up; false=down; indeterminate=none
  330. CList(int Size = 5); //c-tor
  331. void clickLeft(tribool down, bool previousState);
  332. void activate();
  333. void deactivate();
  334. virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; //call-in
  335. virtual void genList()=0;
  336. virtual void select(int which)=0;
  337. virtual void draw(SDL_Surface * to)=0;
  338. virtual int size() = 0; //how many elements do we have
  339. void fixPos(); //scrolls list, so the selection will be visible
  340. };
  341. class CHeroList
  342. : public CList
  343. {
  344. public:
  345. CDefHandler *mobile, *mana; //mana and movement indicators
  346. int posmobx, posporx, posmanx, posmoby, pospory, posmany;
  347. CHeroList(int Size); //c-tor
  348. int getPosOfHero(const CGHeroInstance* h); //hero's position on list
  349. void genList();
  350. void select(int which); //call-in
  351. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  352. void clickLeft(tribool down, bool previousState); //call-in
  353. void clickRight(tribool down, bool previousState); //call-in
  354. void hover (bool on); //call-in
  355. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  356. void updateHList(const CGHeroInstance *toRemove=NULL); //removes specific hero from the list or recreates it
  357. void updateMove(const CGHeroInstance* which); //draws move points bar
  358. void draw(SDL_Surface * to);
  359. void show(SDL_Surface * to);
  360. void init();
  361. int size(); //how many elements do we have
  362. };
  363. class CTownList
  364. : public CList
  365. {
  366. public:
  367. boost::function<void()> fun; //function called on selection change
  368. int posporx,pospory;
  369. CTownList(int Size, int x, int y, std::string arrupg, std::string arrdog); //c-tor
  370. ~CTownList(); //d-tor
  371. void genList();
  372. void select(int which); //call-in
  373. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  374. void clickLeft(tribool down, bool previousState); //call-in
  375. void clickRight(tribool down, bool previousState); //call-in
  376. void hover (bool on); //call-in
  377. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  378. void draw(SDL_Surface * to);
  379. void show(SDL_Surface * to);
  380. int size(); //how many elements do we have
  381. };
  382. class CCreaturePic //draws picture with creature on background, use nextFrame=true to get animation
  383. {
  384. public:
  385. const CCreature *c; //which creature's picture
  386. bool big; //big => 100x130; !big => 100x120
  387. CCreatureAnimation *anim; //displayed animation
  388. CCreaturePic(const CCreature *cre, bool Big=true); //c-tor
  389. ~CCreaturePic(); //d-tor
  390. int blitPic(SDL_Surface *to, int x, int y, bool nextFrame); //prints creature on screen
  391. SDL_Surface * getPic(bool nextFrame); //returns frame of animation
  392. };
  393. class CRecruitmentWindow : public CIntObject
  394. {
  395. public:
  396. static const int SPACE_BETWEEN = 18;
  397. static const int CREATURE_WIDTH = 102;
  398. static const int TOTAL_CREATURE_WIDTH = SPACE_BETWEEN + CREATURE_WIDTH;
  399. struct creinfo
  400. {
  401. SDL_Rect pos;
  402. CCreaturePic *pic; //creature's animation
  403. int ID, amount; //creature ID and available amount
  404. std::vector<std::pair<int,int> > res; //res_id - cost_per_unit
  405. };
  406. std::vector<int> amounts; //how many creatures we can afford
  407. std::vector<creinfo> creatures; //recruitable creatures
  408. boost::function<void(int,int)> recruit; //void (int ID, int amount) <-- call to recruit creatures
  409. CSlider *slider; //for selecting amount
  410. AdventureMapButton *max, *buy, *cancel;
  411. SDL_Surface *bitmap; //background
  412. CStatusBar *bar;
  413. int which; //which creature is active
  414. const CGDwelling *dwelling;
  415. int level;
  416. const CArmedInstance *dst;
  417. void close();
  418. void Max();
  419. void Buy();
  420. void Cancel();
  421. void sliderMoved(int to);
  422. void clickLeft(tribool down, bool previousState);
  423. void clickRight(tribool down, bool previousState);
  424. void activate();
  425. void deactivate();
  426. void show(SDL_Surface * to);
  427. void showAll(SDL_Surface * to){show(to);};
  428. void cleanCres();
  429. void initCres();
  430. CRecruitmentWindow(const CGDwelling *Dwelling, int Level, const CArmedInstance *Dst, const boost::function<void(int,int)> & Recruit, int y_offset = 0); //creatures - pairs<creature_ID,amount> //c-tor
  431. ~CRecruitmentWindow(); //d-tor
  432. };
  433. class CSplitWindow : public CIntObject
  434. {
  435. public:
  436. CGarrisonInt *gar;
  437. CSlider *slider;
  438. CCreaturePic *anim; //creature's animation
  439. AdventureMapButton *ok, *cancel;
  440. SDL_Surface *bitmap; //background
  441. int a1, a2, c; //TODO: comment me
  442. bool which; //which creature is selected
  443. int last; //0/1/2 - at least one creature must be in the src/dst/both stacks; -1 - no restrictions
  444. CSplitWindow(int cid, int max, CGarrisonInt *Owner, int Last = -1, int val=0); //c-tor; val - initial amount of second stack
  445. ~CSplitWindow(); //d-tor
  446. void activate();
  447. void split();
  448. void close();
  449. void deactivate();
  450. void show(SDL_Surface * to);
  451. void clickLeft(tribool down, bool previousState); //call-in
  452. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  453. void sliderMoved(int to);
  454. };
  455. class CLevelWindow : public CIntObject
  456. {
  457. public:
  458. int heroPortrait;
  459. SDL_Surface *bitmap; //background
  460. std::vector<CSelectableComponent *> comps; //skills to select
  461. AdventureMapButton *ok;
  462. boost::function<void(ui32)> cb;
  463. void close();
  464. CLevelWindow(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback); //c-tor
  465. ~CLevelWindow(); //d-tor
  466. void activate();
  467. void deactivate();
  468. void selectionChanged(unsigned to);
  469. void show(SDL_Surface * to);
  470. };
  471. class CMinorResDataBar : public CIntObject
  472. {
  473. public:
  474. SDL_Surface *bg; //background bitmap
  475. void show(SDL_Surface * to);
  476. CMinorResDataBar(); //c-tor
  477. ~CMinorResDataBar(); //d-tor
  478. };
  479. class CObjectListWindow : public CIntObject
  480. {
  481. public:
  482. boost::function<void(int)> onSelect;//called when OK button is pressed, returns id of selected item.
  483. std::string title,descr;//text for title and description
  484. CPicture *bg; //background
  485. CSlider *slider;
  486. CPicture *titleImage;//title image (castle gate\town portal picture)
  487. AdventureMapButton *ok, *exit;
  488. std::vector<Rect> areas;//areas for each visible item
  489. std::vector<int> items;//id of all items present in list
  490. int selected;//currently selected item
  491. int length;//size of list (=9)
  492. bool init;//true = initialization completed
  493. /// Callback will be called when OK button is pressed, returns id of selected item. initState = initially selected item
  494. CObjectListWindow(const std::vector<int> &_items, CPicture * titlePic, std::string _title, std::string _descr,
  495. boost::function<void(int)> Callback, int initState=-1); //c-tor
  496. ~CObjectListWindow(); //d-tor
  497. void elementSelected();//call callback and exit
  498. void moveList(int which);//called when slider moves
  499. void clickLeft(tribool down, bool previousState); //call-in
  500. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  501. void show(SDL_Surface * to);
  502. void showAll(SDL_Surface * to);
  503. };
  504. class CMarketplaceWindow : public CIntObject
  505. {
  506. bool printButtonFor(EMarketMode M) const;
  507. public:
  508. enum EType
  509. {
  510. RESOURCE, PLAYER, ARTIFACT, CREATURE
  511. };
  512. class CTradeableItem : public CIntObject
  513. {
  514. public:
  515. EType type;
  516. int id;
  517. int serial;
  518. bool left;
  519. CFunctionList<void()> callback;
  520. void show(SDL_Surface * to);
  521. void clickLeft(tribool down, bool previousState);
  522. SDL_Surface *getSurface();
  523. CTradeableItem(EType Type, int ID, bool Left, int Serial);
  524. };
  525. const IMarket *market;
  526. const CGHeroInstance *hero;
  527. CPicture *bg; //background
  528. std::vector<CTradeableItem*> left, right;
  529. std::vector<std::string> rSubs; //offer caption
  530. CTradeableItem *hLeft, *hRight; //highlighted items (NULL if no highlight)
  531. EType ltype, rtype;
  532. EMarketMode mode;//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact
  533. int r1, r2; //suggested amounts of traded resources
  534. AdventureMapButton *ok, *max, *deal;
  535. CSlider *slider; //for choosing amount to be exchanged
  536. bool readyToTrade;
  537. void showAll(SDL_Surface * to);
  538. void setMax();
  539. void sliderMoved(int to);
  540. void makeDeal();
  541. void selectionChanged(bool side); //true == left
  542. CMarketplaceWindow(const IMarket *Market, const CGHeroInstance *Hero = NULL, EMarketMode Mode = RESOURCE_RESOURCE); //c-tor
  543. ~CMarketplaceWindow(); //d-tor
  544. void setMode(EMarketMode Mode); //mode setter
  545. void getPositionsFor(std::vector<Rect> &poss, bool Right, EType type) const;
  546. void garrisonChanged(); //removes creatures with count 0 from the list (apparently whole stack has been sold)
  547. void artifactsChanged(bool left);
  548. };
  549. class CSystemOptionsWindow : public CIntObject
  550. {
  551. private:
  552. SDL_Surface * background; //background of window
  553. AdventureMapButton *load, *save, *restart, *mainMenu, *quitGame, *backToMap; //load and restart are not used yet
  554. CHighlightableButtonsGroup * heroMoveSpeed;
  555. CHighlightableButtonsGroup * mapScrollSpeed;
  556. CHighlightableButtonsGroup * musicVolume, * effectsVolume;
  557. public:
  558. CSystemOptionsWindow(const SDL_Rect & pos, CPlayerInterface * owner); //c-tor
  559. ~CSystemOptionsWindow(); //d-tor
  560. //functions bound to buttons
  561. void bsavef(); //save game
  562. void bquitf(); //quit game
  563. void breturnf(); //return to game
  564. void bmainmenuf(); //return to main menu
  565. void pushSDLEvent(int type, int usercode);
  566. void activate();
  567. void deactivate();
  568. void show(SDL_Surface * to);
  569. };
  570. class CTavernWindow : public CIntObject
  571. {
  572. public:
  573. class HeroPortrait : public CIntObject
  574. {
  575. public:
  576. std::string hoverName;
  577. vstd::assigner<int,int> as;
  578. const CGHeroInstance *h;
  579. char descr[100]; // "XXX is a level Y ZZZ with N artifacts"
  580. void clickLeft(tribool down, bool previousState);
  581. void clickRight(tribool down, bool previousState);
  582. void hover (bool on);
  583. HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H);
  584. void show(SDL_Surface * to);
  585. } *h1, *h2; //recruitable heroes
  586. CPicture *bg; //background
  587. CGStatusBar *bar; //tavern's internal status bar
  588. int selected;//0 (left) or 1 (right)
  589. int oldSelected;//0 (left) or 1 (right)
  590. AdventureMapButton *thiefGuild, *cancel, *recruit;
  591. const CGObjectInstance *tavernObj;
  592. CTavernWindow(const CGObjectInstance *TavernObj); //c-tor
  593. ~CTavernWindow(); //d-tor
  594. void recruitb();
  595. void close();
  596. void thievesguildb();
  597. void show(SDL_Surface * to);
  598. };
  599. class CInGameConsole : public CIntObject
  600. {
  601. private:
  602. std::list< std::pair< std::string, int > > texts; //<text to show, time of add>
  603. boost::mutex texts_mx; // protects texts
  604. std::vector< std::string > previouslyEntered; //previously entered texts, for up/down arrows to work
  605. int prevEntDisp; //displayed entry from previouslyEntered - if none it's -1
  606. int defaultTimeout; //timeout for new texts (in ms)
  607. int maxDisplayedTexts; //hiw many texts can be displayed simultaneously
  608. public:
  609. std::string enteredText;
  610. void activate();
  611. void deactivate();
  612. void show(SDL_Surface * to);
  613. void print(const std::string &txt);
  614. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  615. void startEnteringText();
  616. void endEnteringText(bool printEnteredText);
  617. void refreshEnteredText();
  618. CInGameConsole(); //c-tor
  619. };
  620. class HoverableArea: public virtual CIntObject
  621. {
  622. public:
  623. std::string hoverText;
  624. virtual void hover (bool on);
  625. virtual void activate();
  626. virtual void deactivate();
  627. };
  628. class LClickableArea: public virtual CIntObject
  629. {
  630. public:
  631. virtual void clickLeft(tribool down, bool previousState);
  632. virtual void activate();
  633. virtual void deactivate();
  634. };
  635. class RClickableArea: public virtual CIntObject
  636. {
  637. public:
  638. virtual void clickRight(tribool down, bool previousState);
  639. virtual void activate();
  640. virtual void deactivate();
  641. };
  642. class LClickableAreaHero : public LClickableArea
  643. {
  644. public:
  645. int id;
  646. CHeroWindow * owner;
  647. virtual void clickLeft(tribool down, bool previousState);
  648. };
  649. class LRClickableAreaWText: public LClickableArea, public RClickableArea, public HoverableArea
  650. {
  651. public:
  652. std::string text;
  653. virtual void activate();
  654. virtual void deactivate();
  655. virtual void clickLeft(tribool down, bool previousState);
  656. virtual void clickRight(tribool down, bool previousState);
  657. };
  658. class LRClickableAreaWTextComp: public LClickableArea, public RClickableArea, public HoverableArea
  659. {
  660. public:
  661. std::string text;
  662. int baseType;
  663. int bonus, type;
  664. virtual void activate();
  665. virtual void deactivate();
  666. virtual void clickLeft(tribool down, bool previousState);
  667. virtual void clickRight(tribool down, bool previousState);
  668. };
  669. class MoraleLuckBox : public LRClickableAreaWTextComp
  670. {
  671. public:
  672. void set(bool morale, const CGHeroInstance *hero);
  673. };
  674. class LRClickableAreaOpenHero: public LRClickableAreaWTextComp
  675. {
  676. public:
  677. const CGHeroInstance * hero;
  678. void clickLeft(tribool down, bool previousState);
  679. void clickRight(tribool down, bool previousState);
  680. };
  681. class LRClickableAreaOpenTown: public LRClickableAreaWTextComp
  682. {
  683. public:
  684. const CGTownInstance * town;
  685. void clickLeft(tribool down, bool previousState);
  686. void clickRight(tribool down, bool previousState);
  687. };
  688. class CCreInfoWindow : public CIntObject
  689. {
  690. public:
  691. //bool active; //TODO: comment me
  692. int type;//0 - rclick popup; 1 - normal window
  693. CPicture *bitmap; //background
  694. char anf; //animation counter
  695. std::string count; //creature count in text format
  696. boost::function<void()> dsm; //dismiss button callback
  697. CCreaturePic *anim; //related creature's animation
  698. const CCreature *c; //related creature
  699. std::vector<SComponent*> upgResCost; //cost of upgrade (if not possible then empty)
  700. //MoraleLuckBox *luck, *morale;
  701. AdventureMapButton *dismiss, *upgrade, *ok;
  702. CCreInfoWindow(const CStackInstance &st, int Type = 0, boost::function<void()> Upg = 0, boost::function<void()> Dsm = 0, UpgradeInfo *ui = NULL); //c-tor
  703. CCreInfoWindow(int Cid, int Type, int creatureCount); //c-tor
  704. void init(const CCreature *cre, const CStackInstance *stack, int creatureCount);
  705. void printLine(int nr, const std::string &text, int baseVal, int val=-1, bool range=false);
  706. ~CCreInfoWindow(); //d-tor
  707. void activate();
  708. void close();
  709. void clickRight(tribool down, bool previousState); //call-in
  710. void dismissF();
  711. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  712. void deactivate();
  713. void show(SDL_Surface * to);
  714. };
  715. class CArtPlace: public LRClickableAreaWTextComp
  716. {
  717. private:
  718. bool active;
  719. public:
  720. //bool spellBook, warMachine1, warMachine2, warMachine3, warMachine4,
  721. // misc1, misc2, misc3, misc4, misc5, feet, lRing, rRing, torso,
  722. // lHand, rHand, neck, shoulders, head; //my types
  723. 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
  724. bool marked;
  725. bool selectedNo;
  726. CArtifactsOfHero * ourOwner;
  727. const CArtifact * ourArt;
  728. CArtPlace(const CArtifact * Art); //c-tor
  729. void clickLeft(tribool down, bool previousState);
  730. void clickRight(tribool down, bool previousState);
  731. void select ();
  732. void deselect ();
  733. void activate();
  734. void deactivate();
  735. void show(SDL_Surface * to);
  736. bool fitsHere (const CArtifact * art); //returns true if given artifact can be placed here
  737. bool locked () const;
  738. void userSelectedNo ();
  739. ~CArtPlace(); //d-tor
  740. };
  741. inline bool CArtPlace::locked () const
  742. {
  743. return ourArt && ourArt->id == 145;
  744. }
  745. class CArtifactsOfHero : public CIntObject
  746. {
  747. const CGHeroInstance * curHero;
  748. 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
  749. std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!)
  750. int backpackPos; //number of first art visible in backpack (in hero's vector)
  751. public:
  752. struct SCommonPart
  753. {
  754. std::set<CArtifactsOfHero *> participants; // Needed to mark slots.
  755. const CArtifact * srcArtifact; // Held artifact.
  756. const CArtifactsOfHero * srcAOH; // Following two needed to uniquely identify the source.
  757. int srcSlotID; //
  758. const CArtifactsOfHero * destAOH; // For swapping. (i.e. changing what is held)
  759. int destSlotID; // Needed to determine what kind of action was last taken in setHero
  760. const CArtifact * destArtifact; // For swapping.
  761. } * 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
  762. bool updateState; // Whether the commonInfo should be updated on setHero or not.
  763. AdventureMapButton * leftArtRoll, * rightArtRoll;
  764. void activate();
  765. void deactivate();
  766. void show(SDL_Surface * to);
  767. void setHero(const CGHeroInstance * hero);
  768. void dispose(); //free resources not needed after closing windows and reset state
  769. void rollback();
  770. void scrollBackpack(int dir); //dir==-1 => to left; dir==1 => to right
  771. void markPossibleSlots (const CArtifact* art);
  772. void unmarkSlots ();
  773. void setSlotData (CArtPlace* artPlace, int slotID);
  774. void eraseSlotData (CArtPlace* artPlace, int slotID);
  775. CArtifactsOfHero(const SDL_Rect & position); //c-tor
  776. ~CArtifactsOfHero(); //d-tor
  777. friend class CArtPlace;
  778. };
  779. class CGarrisonWindow : public CWindowWithGarrison
  780. {
  781. public:
  782. SDL_Surface *bg; //background surface
  783. AdventureMapButton *quit;
  784. void close();
  785. void activate();
  786. void deactivate();
  787. void show(SDL_Surface * to);
  788. void showAll(SDL_Surface * to){show(to);};
  789. CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits); //c-tor
  790. ~CGarrisonWindow(); //d-tor
  791. };
  792. class CExchangeWindow : public CWindowWithGarrison
  793. {
  794. CStatusBar * ourBar; //internal statusbar
  795. SDL_Surface *bg; //background
  796. AdventureMapButton * quit, * questlogButton[2];
  797. std::vector<LRClickableAreaWTextComp *> secSkillAreas[2], primSkillAreas;
  798. MoraleLuckBox *morale[2], *luck[2];
  799. LRClickableAreaWText *speciality[2];
  800. LRClickableAreaWText *experience[2];
  801. LRClickableAreaWText *spellPoints[2];
  802. LRClickableAreaOpenHero *portrait[2];
  803. public:
  804. const CGHeroInstance * heroInst[2];
  805. CArtifactsOfHero * artifs[2];
  806. void close();
  807. void activate();
  808. void deactivate();
  809. void show(SDL_Surface * to);
  810. void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right
  811. void prepareBackground(); //prepares or redraws bg
  812. CExchangeWindow(si32 hero1, si32 hero2); //c-tor
  813. ~CExchangeWindow(); //d-tor
  814. };
  815. class CShipyardWindow : public CIntObject
  816. {
  817. public:
  818. CStatusBar *bar;
  819. SDL_Surface *bg; //background
  820. AdventureMapButton *build, *quit;
  821. unsigned char frame; //frame of the boat animation
  822. int boat; //which boat graphic should be used
  823. void activate();
  824. void deactivate();
  825. void show(SDL_Surface * to);
  826. CShipyardWindow(const std::vector<si32> &cost, int state, int boatType, const boost::function<void()> &onBuy);
  827. ~CShipyardWindow();
  828. };
  829. class CPuzzleWindow : public CIntObject
  830. {
  831. private:
  832. SDL_Surface * background;
  833. AdventureMapButton * quitb;
  834. CResDataBar * resdatabar;
  835. std::vector<std::pair<SDL_Surface *, SPuzzleInfo *> > puzzlesToPullBack;
  836. ui8 animCount;
  837. public:
  838. void activate();
  839. void deactivate();
  840. void show(SDL_Surface * to);
  841. CPuzzleWindow(const int3 &grailPos, float discoveredRatio);
  842. ~CPuzzleWindow();
  843. };
  844. class CTransformerWindow : public CIntObject
  845. {
  846. public:
  847. class CItem : public CIntObject
  848. {
  849. public:
  850. int id;//position of creature in hero army
  851. bool left;//position of the item
  852. int size; //size of creature stack
  853. CTransformerWindow * parent;
  854. void move();
  855. void showAll(SDL_Surface * to);
  856. void clickLeft(tribool down, bool previousState);
  857. CItem(CTransformerWindow * _parent, int _size, int _id);
  858. ~CItem();
  859. };
  860. const CArmedInstance *army;//object with army for transforming (hero or town)
  861. const CGHeroInstance *hero;//only if we have hero in town
  862. const CGTownInstance *town;//market, town garrison is used if hero == NULL
  863. CPicture *bg; //background
  864. std::vector<CItem*> items;
  865. AdventureMapButton *all, *convert, *cancel;
  866. CGStatusBar *bar;
  867. void showAll(SDL_Surface * to);
  868. void makeDeal();
  869. void addAll();
  870. CTransformerWindow(const CGHeroInstance * _hero, const CGTownInstance * _town); //c-tor
  871. ~CTransformerWindow(); //d-tor
  872. };
  873. class CShopWindow : public CIntObject
  874. {
  875. public:
  876. std::map<ui16, Component> available, chosen, bought;
  877. bool swapItem (ui16 which, bool choose);
  878. virtual void Buy() {};
  879. };
  880. class CArtMerchantWindow : public CShopWindow
  881. {
  882. public:
  883. void activate();
  884. void deactivate();
  885. void show(SDL_Surface * to);
  886. void Buy();
  887. CArtMerchantWindow();
  888. ~CArtMerchantWindow();
  889. };
  890. class CUniversityWindow : public CShopWindow
  891. {};
  892. class CAltarWindow : public CShopWindow
  893. {};
  894. class CRefugeeCampWindow : public CShopWindow
  895. {};
  896. class CWarMachineWindow : public CShopWindow
  897. {};
  898. class CFreelancersWindow : public CShopWindow
  899. {};
  900. class CHillFortWindow : public CIntObject //garrison dialog? shop?
  901. {};
  902. class CThievesGuildWindow : public CIntObject
  903. {
  904. const CGObjectInstance * owner;
  905. CGStatusBar * statusBar;
  906. AdventureMapButton * exitb;
  907. SDL_Surface * background;
  908. CMinorResDataBar * resdatabar;
  909. public:
  910. void activate();
  911. void show(SDL_Surface * to);
  912. void bexitf();
  913. CThievesGuildWindow(const CGObjectInstance * _owner);
  914. ~CThievesGuildWindow();
  915. };
  916. #endif //__GUICLASSES_H__