2
0

GUIClasses.h 38 KB

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