GUIClasses.h 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  1. #ifndef __GUICLASSES_H__
  2. #define __GUICLASSES_H__
  3. #include "../global.h"
  4. #include "../hch/CArtHandler.h"
  5. #include "SDL_framerate.h"
  6. #include "GUIBase.h"
  7. #include "FunctionList.h"
  8. #include <set>
  9. #include <list>
  10. #include <boost/thread/mutex.hpp>
  11. #ifdef max
  12. #undef max
  13. #endif
  14. #ifdef min
  15. #undef min
  16. #endif
  17. /*
  18. * GUIClasses.h, part of VCMI engine
  19. *
  20. * Authors: listed in file AUTHORS in main folder
  21. *
  22. * License: GNU General Public License v2.0 or later
  23. * Full text of license available in license.txt file, in main folder
  24. *
  25. */
  26. class CDefEssential;
  27. class AdventureMapButton;
  28. class CHighlightableButtonsGroup;
  29. class CDefHandler;
  30. struct HeroMoveDetails;
  31. class CDefEssential;
  32. class CGHeroInstance;
  33. class CAdvMapInt;
  34. class CCastleInterface;
  35. class CBattleInterface;
  36. class CStack;
  37. class SComponent;
  38. class CCreature;
  39. struct SDL_Surface;
  40. struct CPath;
  41. class CCreatureAnimation;
  42. class CSelectableComponent;
  43. class CCreatureSet;
  44. class CGObjectInstance;
  45. class CGDwelling;
  46. class CSlider;
  47. struct UpgradeInfo;
  48. template <typename T> struct CondSh;
  49. class CInGameConsole;
  50. class CGarrisonInt;
  51. class CInGameConsole;
  52. class Component;
  53. class CArmedInstance;
  54. class CGTownInstance;
  55. class StackState;
  56. class CPlayerInterface;
  57. class CHeroWindow;
  58. class CArtifact;
  59. class CArtifactsOfHero;
  60. class CResDataBar;
  61. struct SPuzzleInfo;
  62. class CGGarrison;
  63. class CStackInstance;
  64. class IMarket;
  65. class CTextBox;
  66. extern SDL_Color tytulowy, tlo, zwykly ;
  67. class CInfoWindow : public CSimpleWindow //text + comp. + ok button
  68. { //window able to delete its components when closed
  69. bool delComps; //whether comps will be deleted
  70. public:
  71. CTextBox *text;
  72. std::vector<AdventureMapButton *> buttons;
  73. std::vector<SComponent*> components;
  74. CSlider *slider;
  75. void setDelComps(bool DelComps);
  76. virtual void close();
  77. void show(SDL_Surface * to);
  78. void showAll(SDL_Surface * to);
  79. void sliderMoved(int to);
  80. CInfoWindow(std::string Text, int player, int charperline, const std::vector<SComponent*> &comps, std::vector<std::pair<std::string,CFunctionList<void()> > > &Buttons, bool delComps); //c-tor
  81. CInfoWindow(); //c-tor
  82. ~CInfoWindow(); //d-tor
  83. 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)
  84. static CInfoWindow *create(const std::string &text, int playerID = 1, const std::vector<SComponent*> *components = NULL);
  85. };
  86. class CSelWindow : public CInfoWindow //component selection window
  87. { //warning - this window deletes its components by closing!
  88. public:
  89. void selectionChange(unsigned to);
  90. void madeChoice(); //looks for selected component and calls callback
  91. 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
  92. CSelWindow(){}; //c-tor
  93. //notification - this class inherits important destructor from CInfoWindow
  94. };
  95. class CRClickPopup : public CIntObject //popup displayed on R-click
  96. {
  97. public:
  98. virtual void activate();
  99. virtual void deactivate();
  100. virtual void close();
  101. void clickRight(tribool down, bool previousState);
  102. CRClickPopup();
  103. virtual ~CRClickPopup(); //d-tor
  104. static void createAndPush(const std::string &txt);
  105. static void createAndPush(const CGObjectInstance *obj, const Point &p, EAlignment alignment = BOTTOMRIGHT);
  106. };
  107. class CRClickPopupInt : public CRClickPopup //popup displayed on R-click
  108. {
  109. public:
  110. IShowActivable *inner;
  111. bool delInner;
  112. void show(SDL_Surface * to);
  113. CRClickPopupInt(IShowActivable *our, bool deleteInt); //c-tor
  114. virtual ~CRClickPopupInt(); //d-tor
  115. };
  116. class CInfoPopup : public CRClickPopup
  117. {
  118. public:
  119. bool free; //TODO: comment me
  120. SDL_Surface * bitmap; //popup background
  121. void close();
  122. void show(SDL_Surface * to);
  123. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false); //c-tor
  124. CInfoPopup(SDL_Surface * Bitmap, const Point &p, EAlignment alignment, bool Free=false); //c-tor
  125. CInfoPopup(SDL_Surface *Bitmap = NULL, bool Free = false); //default c-tor
  126. void init(int x, int y);
  127. ~CInfoPopup(); //d-tor
  128. };
  129. class SComponent : public virtual CIntObject //common popup window component
  130. {
  131. public:
  132. enum Etype
  133. {
  134. primskill, secskill, resource, creature, artifact, experience, secskill44, spell, morale, luck, building, hero, flag
  135. } type; //component type
  136. int subtype; //TODO: comment me
  137. int val; //TODO: comment me
  138. std::string description; //r-click
  139. std::string subtitle; //TODO: comment me
  140. void init(Etype Type, int Subtype, int Val);
  141. SComponent(Etype Type, int Subtype, int Val); //c-tor
  142. SComponent(const Component &c); //c-tor
  143. SComponent(){}; //c-tor
  144. virtual ~SComponent(){}; //d-tor
  145. void clickRight(tribool down, bool previousState); //call-in
  146. virtual SDL_Surface * getImg();
  147. virtual void show(SDL_Surface * to);
  148. virtual void activate();
  149. virtual void deactivate();
  150. };
  151. class CCustomImgComponent : public SComponent
  152. {
  153. public:
  154. SDL_Surface *bmp; //our image
  155. bool free; //should surface be freed on delete
  156. SDL_Surface * getImg();
  157. CCustomImgComponent(Etype Type, int Subtype, int Val, SDL_Surface *sur, bool freeSur); //c-tor
  158. ~CCustomImgComponent(); //d-tor
  159. };
  160. class CSelectableComponent : public SComponent, public KeyShortcut
  161. {
  162. public:
  163. bool selected; //if true, this component is selected
  164. bool customB; //TODO: comment me
  165. SDL_Surface * border, *myBitmap;
  166. boost::function<void()> onSelect; //function called on selection change
  167. void clickLeft(tribool down, bool previousState); //call-in
  168. void init(SDL_Surface * Border);
  169. CSelectableComponent(Etype Type, int Sub, int Val, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
  170. CSelectableComponent(const Component &c, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
  171. ~CSelectableComponent(); //d-tor
  172. virtual void show(SDL_Surface * to);
  173. void activate();
  174. void deactivate();
  175. void select(bool on);
  176. SDL_Surface * getImg(); //returns myBitmap
  177. };
  178. class CGarrisonInt;
  179. class CGarrisonSlot : public CIntObject
  180. {
  181. public:
  182. CGarrisonInt *owner;
  183. const CStackInstance *myStack; //NULL if slot is empty
  184. const CCreature *creature;
  185. int count; //number of creatures
  186. int upg; //0 - up garrison, 1 - down garrison
  187. bool active; //TODO: comment me
  188. virtual void hover (bool on); //call-in
  189. const CArmedInstance * getObj();
  190. void clickRight(tribool down, bool previousState);
  191. void clickLeft(tribool down, bool previousState);
  192. void activate();
  193. void deactivate();
  194. void show(SDL_Surface * to);
  195. CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg=0, const CStackInstance * Creature=NULL);
  196. ~CGarrisonSlot(); //d-tor
  197. };
  198. class CGarrisonInt :public CIntObject
  199. {
  200. public:
  201. int interx; //space between slots
  202. Point garOffset, //offset between garrisons (not used if only one hero)
  203. surOffset, //offset between garrison position on the bg surface and position on the screen
  204. shiftPoint;//how last slots will be shifted (for second row, set shiftPoint for effect)
  205. CGarrisonSlot *highlighted; //chosen slot
  206. std::vector<AdventureMapButton *> splitButtons; //may be empty if no buttons
  207. SDL_Surface *&sur; //bg surface
  208. int p2, //TODO: comment me
  209. shiftPos;//1st slot of the second row, set shiftPoint for effect
  210. bool ignoreEvent, update, active, splitting, pb,
  211. smallIcons; //true - 32x32 imgs, false - 58x64
  212. bool removableUnits;
  213. const CCreatureSet *set1; //top set of creatures
  214. const CCreatureSet *set2; //bottom set of creatures
  215. std::vector<CGarrisonSlot*> *sup, *sdown; //slots of upper and lower garrison
  216. const CArmedInstance *oup, *odown; //upper and lower garrisons (heroes or towns)
  217. void activate();
  218. void deactivate();
  219. void show(SDL_Surface * to);
  220. void activeteSlots();
  221. void deactiveteSlots();
  222. void deleteSlots();
  223. void createSlots();
  224. void recreateSlots();
  225. void splitClick(); //handles click on split button
  226. void splitStacks(int am2); //TODO: comment me
  227. 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
  228. ~CGarrisonInt(); //d-tor
  229. };
  230. class CStatusBar
  231. : public CIntObject, public IStatusBar
  232. {
  233. public:
  234. SDL_Surface * bg; //background
  235. int middlex, middley; //middle of statusbar
  236. std::string current; //text currently printed
  237. CStatusBar(int x, int y, std::string name="ADROLLVR.bmp", int maxw=-1); //c-tor
  238. ~CStatusBar(); //d-tor
  239. void print(const std::string & text); //prints text and refreshes statusbar
  240. void clear();//clears statusbar and refreshes
  241. void show(SDL_Surface * to); //shows statusbar (with current text)
  242. std::string getCurrent(); //getter for current
  243. };
  244. class CLabel
  245. : public virtual CIntObject
  246. {
  247. public:
  248. EAlignment alignment;
  249. EFonts font;
  250. SDL_Color color;
  251. std::string text;
  252. CPicture *bg;
  253. bool autoRedraw; //whether control will redraw itself on setTxt
  254. Point textOffset; //text will be blitted at pos + textOffset with appropriate alignment
  255. bool ignoreLeadingWhitespace;
  256. virtual void setTxt(const std::string &Txt);
  257. void showAll(SDL_Surface * to); //shows statusbar (with current text)
  258. CLabel(int x=0, int y=0, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly, const std::string &Text = "");
  259. };
  260. //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
  261. class CTextBox
  262. : public CLabel
  263. {
  264. public:
  265. int maxW; //longest line of text in px
  266. int maxH; //total height needed to print all lines
  267. int sliderStyle;
  268. bool redrawParentOnScrolling;
  269. std::vector<std::string> lines;
  270. CSlider *slider;
  271. //CTextBox( std::string Text, const Point &Pos, int w, int h, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly);
  272. CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font = FONT_SMALL, EAlignment Align = TOPLEFT, const SDL_Color &Color = zwykly);
  273. void showAll(SDL_Surface * to); //shows statusbar (with current text)
  274. void setTxt(const std::string &Txt);
  275. void setBounds(int limitW, int limitH);
  276. void recalculateLines(const std::string &Txt);
  277. void sliderMoved(int to);
  278. };
  279. class CGStatusBar
  280. : public CLabel, public IStatusBar
  281. {
  282. void init();
  283. public:
  284. IStatusBar *oldStatusBar;
  285. //statusbar interface overloads
  286. void print(const std::string & Text); //prints text and refreshes statusbar
  287. void clear();//clears statusbar and refreshes
  288. std::string getCurrent(); //returns currently displayed text
  289. void show(SDL_Surface * to); //shows statusbar (with current text)
  290. CGStatusBar(int x, int y, EFonts Font = FONT_SMALL, EAlignment Align = CENTER, const SDL_Color &Color = zwykly, const std::string &Text = "");
  291. 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
  292. CGStatusBar(int x, int y, std::string name, int maxw=-1);
  293. ~CGStatusBar();
  294. void calcOffset();
  295. };
  296. class CFocusable
  297. : public virtual CIntObject
  298. {
  299. public:
  300. bool focus; //only one focusable control can have focus at one moment
  301. void giveFocus(); //captures focus
  302. void moveFocus(); //moves focus to next active control (may be used for tab switching)
  303. static std::list<CFocusable*> focusables; //all existing objs
  304. static CFocusable *inputWithFocus; //who has focus now
  305. CFocusable();
  306. ~CFocusable();
  307. };
  308. class CTextInput
  309. : public CLabel, public CFocusable
  310. {
  311. public:
  312. CFunctionList<void(const std::string &)> cb;
  313. void setText(const std::string &nText, bool callCb = false);
  314. CTextInput(const Rect &Pos, const Point &bgOffset, const std::string &bgName, const CFunctionList<void(const std::string &)> &CB);
  315. CTextInput(const Rect &Pos, SDL_Surface *srf);
  316. ~CTextInput();
  317. void showAll(SDL_Surface * to);
  318. void clickLeft(tribool down, bool previousState);
  319. void keyPressed(const SDL_KeyboardEvent & key);
  320. };
  321. class CList : public CIntObject
  322. {
  323. public:
  324. SDL_Surface * bg; //background bitmap
  325. CDefHandler *arrup, *arrdo; //button arrows for scrolling list
  326. SDL_Surface *empty, *selection;
  327. SDL_Rect arrupp, arrdop; //positions of arrows
  328. int posw, posh; //position width/height
  329. int selected, //id of selected position, <0 if none
  330. from;
  331. const int SIZE; //size of list
  332. tribool pressed; //true=up; false=down; indeterminate=none
  333. CList(int Size = 5); //c-tor
  334. void clickLeft(tribool down, bool previousState);
  335. void activate();
  336. void deactivate();
  337. virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; //call-in
  338. virtual void genList()=0;
  339. virtual void select(int which)=0;
  340. virtual void draw(SDL_Surface * to)=0;
  341. virtual int size() = 0; //how many elements do we have
  342. void fixPos(); //scrolls list, so the selection will be visible
  343. };
  344. class CHeroList
  345. : public CList
  346. {
  347. public:
  348. CDefHandler *mobile, *mana; //mana and movement indicators
  349. int posmobx, posporx, posmanx, posmoby, pospory, posmany;
  350. CHeroList(int Size); //c-tor
  351. int getPosOfHero(const CGHeroInstance* h); //hero's position on list
  352. void genList();
  353. void select(int which); //call-in
  354. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  355. void clickLeft(tribool down, bool previousState); //call-in
  356. void clickRight(tribool down, bool previousState); //call-in
  357. void hover (bool on); //call-in
  358. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  359. void updateHList(const CGHeroInstance *toRemove=NULL); //removes specific hero from the list or recreates it
  360. void updateMove(const CGHeroInstance* which); //draws move points bar
  361. void draw(SDL_Surface * to);
  362. void show(SDL_Surface * to);
  363. void init();
  364. int size(); //how many elements do we have
  365. };
  366. class CTownList
  367. : public CList
  368. {
  369. public:
  370. boost::function<void()> fun; //function called on selection change
  371. int posporx,pospory;
  372. CTownList(int Size, int x, int y, std::string arrupg, std::string arrdog); //c-tor
  373. ~CTownList(); //d-tor
  374. void genList();
  375. void select(int which); //call-in
  376. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  377. void clickLeft(tribool down, bool previousState); //call-in
  378. void clickRight(tribool down, bool previousState); //call-in
  379. void hover (bool on); //call-in
  380. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  381. void draw(SDL_Surface * to);
  382. void show(SDL_Surface * to);
  383. int size(); //how many elements do we have
  384. };
  385. class CCreaturePic //draws picture with creature on background, use nextFrame=true to get animation
  386. {
  387. public:
  388. const CCreature *c; //which creature's picture
  389. bool big; //big => 100x130; !big => 100x120
  390. CCreatureAnimation *anim; //displayed animation
  391. CCreaturePic(const CCreature *cre, bool Big=true); //c-tor
  392. ~CCreaturePic(); //d-tor
  393. int blitPic(SDL_Surface *to, int x, int y, bool nextFrame); //prints creature on screen
  394. SDL_Surface * getPic(bool nextFrame); //returns frame of animation
  395. };
  396. class CRecruitmentWindow : public CIntObject
  397. {
  398. public:
  399. static const int SPACE_BETWEEN = 18;
  400. static const int CREATURE_WIDTH = 102;
  401. static const int TOTAL_CREATURE_WIDTH = SPACE_BETWEEN + CREATURE_WIDTH;
  402. struct creinfo
  403. {
  404. SDL_Rect pos;
  405. CCreaturePic *pic; //creature's animation
  406. int ID, amount; //creature ID and available amount
  407. std::vector<std::pair<int,int> > res; //res_id - cost_per_unit
  408. };
  409. std::vector<int> amounts; //how many creatures we can afford
  410. std::vector<creinfo> creatures; //recruitable creatures
  411. boost::function<void(int,int)> recruit; //void (int ID, int amount) <-- call to recruit creatures
  412. CSlider *slider; //for selecting amount
  413. AdventureMapButton *max, *buy, *cancel;
  414. SDL_Surface *bitmap; //background
  415. CStatusBar *bar;
  416. int which; //which creature is active
  417. const CGDwelling *dwelling;
  418. int level;
  419. const CArmedInstance *dst;
  420. void close();
  421. void Max();
  422. void Buy();
  423. void Cancel();
  424. void sliderMoved(int to);
  425. void clickLeft(tribool down, bool previousState);
  426. void clickRight(tribool down, bool previousState);
  427. void activate();
  428. void deactivate();
  429. void show(SDL_Surface * to);
  430. void showAll(SDL_Surface * to){show(to);};
  431. void cleanCres();
  432. void initCres();
  433. 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
  434. ~CRecruitmentWindow(); //d-tor
  435. };
  436. class CSplitWindow : public CIntObject
  437. {
  438. public:
  439. CGarrisonInt *gar;
  440. CSlider *slider;
  441. CCreaturePic *anim; //creature's animation
  442. AdventureMapButton *ok, *cancel;
  443. SDL_Surface *bitmap; //background
  444. int a1, a2, c; //TODO: comment me
  445. bool which; //which creature is selected
  446. int last; //0/1/2 - at least one creature must be in the src/dst/both stacks; -1 - no restrictions
  447. CSplitWindow(int cid, int max, CGarrisonInt *Owner, int Last = -1, int val=0); //c-tor; val - initial amount of second stack
  448. ~CSplitWindow(); //d-tor
  449. void activate();
  450. void split();
  451. void close();
  452. void deactivate();
  453. void show(SDL_Surface * to);
  454. void clickLeft(tribool down, bool previousState); //call-in
  455. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  456. void sliderMoved(int to);
  457. };
  458. class CLevelWindow : public CIntObject
  459. {
  460. public:
  461. int heroPortrait;
  462. SDL_Surface *bitmap; //background
  463. std::vector<CSelectableComponent *> comps; //skills to select
  464. AdventureMapButton *ok;
  465. boost::function<void(ui32)> cb;
  466. void close();
  467. CLevelWindow(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback); //c-tor
  468. ~CLevelWindow(); //d-tor
  469. void activate();
  470. void deactivate();
  471. void selectionChanged(unsigned to);
  472. void show(SDL_Surface * to);
  473. };
  474. class CMinorResDataBar : public CIntObject
  475. {
  476. public:
  477. SDL_Surface *bg; //background bitmap
  478. void show(SDL_Surface * to);
  479. CMinorResDataBar(); //c-tor
  480. ~CMinorResDataBar(); //d-tor
  481. };
  482. class CObjectListWindow : public CIntObject
  483. {
  484. public:
  485. boost::function<void(int)> onSelect;//called when OK button is pressed, returns id of selected item.
  486. std::string title,descr;//text for title and description
  487. CPicture *bg; //background
  488. CSlider *slider;
  489. CPicture *titleImage;//title image (castle gate\town portal picture)
  490. AdventureMapButton *ok, *exit;
  491. std::vector<Rect> areas;//areas for each visible item
  492. std::vector<int> items;//id of all items present in list
  493. int selected;//currently selected item
  494. int length;//size of list (=9)
  495. bool init;//true = initialization completed
  496. /// Callback will be called when OK button is pressed, returns id of selected item. initState = initially selected item
  497. CObjectListWindow(const std::vector<int> &_items, CPicture * titlePic, std::string _title, std::string _descr,
  498. boost::function<void(int)> Callback, int initState=-1); //c-tor
  499. ~CObjectListWindow(); //d-tor
  500. void elementSelected();//call callback and exit
  501. void moveList(int which);//called when slider moves
  502. void clickLeft(tribool down, bool previousState); //call-in
  503. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  504. void show(SDL_Surface * to);
  505. void showAll(SDL_Surface * to);
  506. };
  507. class CTradeWindow : public CIntObject //base for markets and altar of sacrifice
  508. {
  509. public:
  510. enum EType
  511. {
  512. RESOURCE, PLAYER, ARTIFACT, CREATURE, CREATURE_PLACEHOLDER,ARTIFACT_PLACEHOLDER
  513. };
  514. class CTradeableItem : public CIntObject
  515. {
  516. public:
  517. EType type;
  518. int id;
  519. int serial;
  520. bool left;
  521. std::string subtitle; //empty if default
  522. CFunctionList<void()> callback;
  523. bool downSelection;
  524. void showAllAt(const Point &dstPos, const std::string &customSub, SDL_Surface * to);
  525. void clickRight(tribool down, bool previousState);
  526. void hover (bool on);
  527. void showAll(SDL_Surface * to);
  528. void clickLeft(tribool down, bool previousState);
  529. SDL_Surface *getSurface();
  530. CTradeableItem(EType Type, int ID, bool Left, int Serial);
  531. };
  532. const IMarket *market;
  533. const CGHeroInstance *hero;
  534. CPicture *bg; //background
  535. CArtifactsOfHero *arts;
  536. //all indexes: 1 = left, 0 = right
  537. std::vector<CTradeableItem*> items[2];
  538. CTradeableItem *hLeft, *hRight; //highlighted items (NULL if no highlight)
  539. EType itemsType[2];
  540. EMarketMode mode;//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact
  541. AdventureMapButton *ok, *max, *deal;
  542. CSlider *slider; //for choosing amount to be exchanged
  543. bool readyToTrade;
  544. CTradeWindow(const IMarket *Market, const CGHeroInstance *Hero, EMarketMode Mode); //c
  545. void showAll(SDL_Surface * to);
  546. void initSubs(bool Left);
  547. void initTypes();
  548. void initItems(bool Left);
  549. std::vector<int> *getItemsIds(bool Left); //NULL if default
  550. void getPositionsFor(std::vector<Rect> &poss, bool Left, EType type) const;
  551. void removeItems(const std::set<CTradeableItem *> &toRemove);
  552. void removeItem(CTradeableItem * t);
  553. void getEmptySlots(std::set<CTradeableItem *> &toRemove);
  554. void setMode(EMarketMode Mode); //mode setter
  555. virtual void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const = 0;
  556. virtual void selectionChanged(bool side) = 0; //true == left
  557. virtual Point selectionOffset(bool Left) const = 0;
  558. virtual std::string selectionSubtitle(bool Left) const = 0;
  559. virtual void garrisonChanged() = 0;
  560. virtual void artifactsChanged(bool left) = 0;
  561. };
  562. class CMarketplaceWindow : public CTradeWindow
  563. {
  564. bool printButtonFor(EMarketMode M) const;
  565. public:
  566. int r1, r2; //suggested amounts of traded resources
  567. void setMax();
  568. void sliderMoved(int to);
  569. void makeDeal();
  570. void selectionChanged(bool side); //true == left
  571. CMarketplaceWindow(const IMarket *Market, const CGHeroInstance *Hero = NULL, EMarketMode Mode = RESOURCE_RESOURCE); //c-tor
  572. ~CMarketplaceWindow(); //d-tor
  573. Point selectionOffset(bool Left) const;
  574. std::string selectionSubtitle(bool Left) const;
  575. void garrisonChanged(); //removes creatures with count 0 from the list (apparently whole stack has been sold)
  576. void artifactsChanged(bool left);
  577. void resourceChanged(int type, int val);
  578. void getBaseForPositions(EType type, int &dx, int &dy, int &x, int &y, int &h, int &w, bool Right, int &leftToRightOffset) const;
  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); //returns true if given artifact can be placed here
  777. bool locked () const;
  778. void userSelectedNo ();
  779. ~CArtPlace(); //d-tor
  780. };
  781. inline bool CArtPlace::locked () const
  782. {
  783. return ourArt && ourArt->id == 145;
  784. }
  785. class CArtifactsOfHero : public CIntObject
  786. {
  787. CGHeroInstance * curHero; //local copy of hero on which we operate
  788. 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
  789. std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!)
  790. int backpackPos; //number of first art visible in backpack (in hero's vector)
  791. public:
  792. struct SCommonPart
  793. {
  794. std::set<CArtifactsOfHero *> participants; // Needed to mark slots.
  795. const CArtifact * srcArtifact; // Held artifact.
  796. const CArtifactsOfHero * srcAOH; // Following two needed to uniquely identify the source.
  797. int srcSlotID; //
  798. const CArtifactsOfHero * destAOH; // For swapping. (i.e. changing what is held)
  799. int destSlotID; // Needed to determine what kind of action was last taken in setHero
  800. const CArtifact * destArtifact; // For swapping.
  801. void reset();
  802. } * 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
  803. bool updateState; // Whether the commonInfo should be updated on setHero or not.
  804. AdventureMapButton * leftArtRoll, * rightArtRoll;
  805. bool allowedAssembling;
  806. 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
  807. void setHero(const CGHeroInstance * hero);
  808. void dispose(); //free resources not needed after closing windows and reset state
  809. void scrollBackpack(int dir); //dir==-1 => to left; dir==1 => to right
  810. void safeRedraw();
  811. void markPossibleSlots (const CArtifact* art);
  812. void unmarkSlots ();
  813. void setSlotData (CArtPlace* artPlace, int slotID);
  814. void eraseSlotData (CArtPlace* artPlace, int slotID);
  815. CArtifactsOfHero(const Point& position); //c-tor
  816. ~CArtifactsOfHero(); //d-tor
  817. void updateParentWindow();
  818. friend class CArtPlace;
  819. };
  820. class CGarrisonWindow : public CWindowWithGarrison
  821. {
  822. public:
  823. SDL_Surface *bg; //background surface
  824. AdventureMapButton *quit;
  825. void close();
  826. void activate();
  827. void deactivate();
  828. void show(SDL_Surface * to);
  829. void showAll(SDL_Surface * to){show(to);};
  830. CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits); //c-tor
  831. ~CGarrisonWindow(); //d-tor
  832. };
  833. class CExchangeWindow : public CWindowWithGarrison
  834. {
  835. CStatusBar * ourBar; //internal statusbar
  836. SDL_Surface *bg; //background
  837. AdventureMapButton * quit, * questlogButton[2];
  838. std::vector<LRClickableAreaWTextComp *> secSkillAreas[2], primSkillAreas;
  839. MoraleLuckBox *morale[2], *luck[2];
  840. LRClickableAreaWText *speciality[2];
  841. LRClickableAreaWText *experience[2];
  842. LRClickableAreaWText *spellPoints[2];
  843. CHeroArea *portrait[2];
  844. public:
  845. const CGHeroInstance * heroInst[2];
  846. CArtifactsOfHero * artifs[2];
  847. void close();
  848. void activate();
  849. void deactivate();
  850. void show(SDL_Surface * to);
  851. void questlog(int whichHero); //questlog button callback; whichHero: 0 - left, 1 - right
  852. void prepareBackground(); //prepares or redraws bg
  853. CExchangeWindow(si32 hero1, si32 hero2); //c-tor
  854. ~CExchangeWindow(); //d-tor
  855. };
  856. class CShipyardWindow : public CIntObject
  857. {
  858. public:
  859. CStatusBar *bar;
  860. SDL_Surface *bg; //background
  861. AdventureMapButton *build, *quit;
  862. unsigned char frame; //frame of the boat animation
  863. int boat; //which boat graphic should be used
  864. void activate();
  865. void deactivate();
  866. void show(SDL_Surface * to);
  867. CShipyardWindow(const std::vector<si32> &cost, int state, int boatType, const boost::function<void()> &onBuy);
  868. ~CShipyardWindow();
  869. };
  870. class CPuzzleWindow : public CIntObject
  871. {
  872. private:
  873. SDL_Surface * background;
  874. AdventureMapButton * quitb;
  875. CResDataBar * resdatabar;
  876. std::vector<std::pair<SDL_Surface *, SPuzzleInfo *> > puzzlesToPullBack;
  877. ui8 animCount;
  878. public:
  879. void activate();
  880. void deactivate();
  881. void show(SDL_Surface * to);
  882. CPuzzleWindow(const int3 &grailPos, float discoveredRatio);
  883. ~CPuzzleWindow();
  884. };
  885. class CTransformerWindow : public CIntObject
  886. {
  887. public:
  888. class CItem : public CIntObject
  889. {
  890. public:
  891. int id;//position of creature in hero army
  892. bool left;//position of the item
  893. int size; //size of creature stack
  894. CTransformerWindow * parent;
  895. void move();
  896. void showAll(SDL_Surface * to);
  897. void clickLeft(tribool down, bool previousState);
  898. CItem(CTransformerWindow * _parent, int _size, int _id);
  899. ~CItem();
  900. };
  901. const CArmedInstance *army;//object with army for transforming (hero or town)
  902. const CGHeroInstance *hero;//only if we have hero in town
  903. const CGTownInstance *town;//market, town garrison is used if hero == NULL
  904. CPicture *bg; //background
  905. std::vector<CItem*> items;
  906. AdventureMapButton *all, *convert, *cancel;
  907. CGStatusBar *bar;
  908. void showAll(SDL_Surface * to);
  909. void makeDeal();
  910. void addAll();
  911. CTransformerWindow(const CGHeroInstance * _hero, const CGTownInstance * _town); //c-tor
  912. ~CTransformerWindow(); //d-tor
  913. };
  914. class CUniversityWindow : public CIntObject
  915. {
  916. class CItem : public CPicture
  917. {
  918. public:
  919. int ID;//id of selected skill
  920. CUniversityWindow * parent;
  921. void showAll(SDL_Surface * to);
  922. void clickLeft(tribool down, bool previousState);
  923. void clickRight(tribool down, bool previousState);
  924. void hover(bool on);
  925. int state();//0=can't learn, 1=learned, 2=can learn
  926. CItem(CUniversityWindow * _parent, int _ID, int X, int Y);
  927. };
  928. public:
  929. const CGHeroInstance *hero;
  930. const IMarket * market;
  931. SDL_Surface * red,
  932. * green,//colored bars near skills
  933. * yellow;
  934. CPicture *bg; //background
  935. std::vector<CItem*> items;
  936. AdventureMapButton *cancel;
  937. CGStatusBar *bar;
  938. CUniversityWindow(const CGHeroInstance * _hero, const IMarket * _market); //c-tor
  939. ~CUniversityWindow(); //d-tor
  940. };
  941. class CUnivConfirmWindow : public CIntObject//Confirmation window for University
  942. {
  943. public:
  944. CUniversityWindow * parent;
  945. CPicture * bg;
  946. CGStatusBar *bar;
  947. AdventureMapButton *confirm, *cancel;
  948. CUnivConfirmWindow(CUniversityWindow * PARENT, int SKILL, bool available); //c-tor
  949. void makeDeal(int skill);
  950. };
  951. class CHillFortWindow : public CWindowWithGarrison
  952. {
  953. public:
  954. int slotsCount;//=7;
  955. CGStatusBar * bar;
  956. CDefEssential *resources;
  957. CPicture *bg; //background surface
  958. CHeroArea *heroPic;//clickable hero image
  959. AdventureMapButton *quit,//closes window
  960. *upgradeAll,//upgrade all creatures
  961. *upgrade[7];//upgrade single creature
  962. const CGObjectInstance * fort;
  963. const CGHeroInstance * hero;
  964. std::vector<int> currState;//current state of slot - to avoid calls to getState or updating buttons
  965. std::vector<std::map<int,int> > costs;// costs [slot ID] [resource ID] = resource count for upgrade
  966. std::vector<int> totalSumm; // totalSum[resource ID] = value
  967. CHillFortWindow(const CGHeroInstance *visitor, const CGObjectInstance *object); //c-tor
  968. ~CHillFortWindow(); //d-tor
  969. void activate();
  970. void deactivate();
  971. void showAll (SDL_Surface *to);
  972. std::string getDefForSlot(int slot);
  973. void makeDeal(int slot);//-1 for upgrading all creatures
  974. int getState(int slot); //-1 = no creature 0=can't upgrade, 1=upgraded, 2=can upgrade
  975. void updateGarrisons();//update buttons after garrison changes
  976. };
  977. class CThievesGuildWindow : public CIntObject
  978. {
  979. const CGObjectInstance * owner;
  980. CGStatusBar * statusBar;
  981. AdventureMapButton * exitb;
  982. SDL_Surface * background;
  983. CMinorResDataBar * resdatabar;
  984. public:
  985. void activate();
  986. void show(SDL_Surface * to);
  987. void bexitf();
  988. CThievesGuildWindow(const CGObjectInstance * _owner);
  989. ~CThievesGuildWindow();
  990. };
  991. #endif //__GUICLASSES_H__