GUIClasses.h 32 KB

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