GUIClasses.h 38 KB

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