CPlayerInterface.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. #ifndef __CPLAYERINTERFACE_H__
  2. #define __CPLAYERINTERFACE_H__
  3. #include "global.h"
  4. #include "CGameInterface.h"
  5. #include "SDL_framerate.h"
  6. #include <map>
  7. #include <list>
  8. #include <algorithm>
  9. #ifdef __GNUC__
  10. #define sprintf_s snprintf
  11. #endif
  12. #ifdef max
  13. #undef max
  14. #endif
  15. #ifdef min
  16. #undef min
  17. #endif
  18. /*
  19. * CPlayerInterface.h, part of VCMI engine
  20. *
  21. * Authors: listed in file AUTHORS in main folder
  22. *
  23. * License: GNU General Public License v2.0 or later
  24. * Full text of license available in license.txt file, in main folder
  25. *
  26. */
  27. class CDefEssential;
  28. class AdventureMapButton;
  29. class CHighlightableButtonsGroup;
  30. class CDefHandler;
  31. struct HeroMoveDetails;
  32. class CDefEssential;
  33. class CGHeroInstance;
  34. class CAdvMapInt;
  35. class CCastleInterface;
  36. class CBattleInterface;
  37. class CStack;
  38. class SComponent;
  39. class CCreature;
  40. struct SDL_Surface;
  41. struct CPath;
  42. class CCreatureAnimation;
  43. class CSelectableComponent;
  44. class CCreatureSet;
  45. class CGObjectInstance;
  46. class CSlider;
  47. struct UpgradeInfo;
  48. template <typename T> struct CondSh;
  49. class CInGameConsole;
  50. class CGarrisonInt;
  51. namespace boost
  52. {
  53. class mutex;
  54. class recursive_mutex;
  55. };
  56. struct Point
  57. {
  58. int x, y;
  59. //constructors
  60. Point(){};
  61. Point(int X, int Y)
  62. :x(X),y(Y)
  63. {};
  64. Point(const int3 &a)
  65. :x(a.x),y(a.y)
  66. {}
  67. Point operator+(const Point &b) const
  68. {
  69. return Point(x+b.x,y+b.y);
  70. }
  71. Point& operator+=(const Point &b)
  72. {
  73. x += b.x;
  74. y += b.y;
  75. return *this;
  76. }
  77. Point operator-(const Point &b) const
  78. {
  79. return Point(x+b.x,y+b.y);
  80. }
  81. Point& operator-=(const Point &b)
  82. {
  83. x -= b.x;
  84. y -= b.y;
  85. return *this;
  86. }
  87. bool operator<(const Point &b) const //product order
  88. {
  89. return x < b.x && y < b.y;
  90. }
  91. };
  92. struct Rect : public SDL_Rect
  93. {
  94. Rect()//default c-tor
  95. {
  96. x = y = w = h = -1;
  97. }
  98. Rect(int X, int Y, int W, int H) //c-tor
  99. {
  100. x = X;
  101. y = Y;
  102. w = W;
  103. h = H;
  104. }
  105. Rect(const SDL_Rect & r) //c-tor
  106. {
  107. x = r.x;
  108. y = r.y;
  109. w = r.w;
  110. h = r.h;
  111. }
  112. bool isIn(int qx, int qy) const //determines if given point lies inside rect
  113. {
  114. if (qx > x && qx<x+w && qy>y && qy<y+h)
  115. return true;
  116. return false;
  117. }
  118. bool isIn(const Point &q) const //determines if given point lies inside rect
  119. {
  120. return isIn(q.x,q.y);
  121. }
  122. Point topLeft() const //top left corner of this rect
  123. {
  124. return Point(x,y);
  125. }
  126. Point topRight() const //top right corner of this rect
  127. {
  128. return Point(x+w,y);
  129. }
  130. Point bottomLeft() const //bottom left corner of this rect
  131. {
  132. return Point(x,y+h);
  133. }
  134. Point bottomRight() const //bottom right corner of this rect
  135. {
  136. return Point(x+w,y+h);
  137. }
  138. Rect operator+(const Rect &p) const //moves this rect by p's rect position
  139. {
  140. return Rect(x+p.x,y+p.y,w,h);
  141. }
  142. Rect operator+(const Point &p) const //moves this rect by p's point position
  143. {
  144. return Rect(x+p.x,y+p.y,w,h);
  145. }
  146. Rect& operator=(const Rect &p) //assignment operator
  147. {
  148. x = p.x;
  149. y = p.y;
  150. w = p.w;
  151. h = p.h;
  152. return *this;
  153. }
  154. Rect& operator+=(const Rect &p) //works as operator+
  155. {
  156. x += p.x;
  157. y += p.y;
  158. return *this;
  159. }
  160. Rect operator&(const Rect &p) const //rect intersection
  161. {
  162. bool intersect = true;
  163. if(p.topLeft().y < y && p.bottomLeft().y < y) //rect p is above *this
  164. {
  165. intersect = false;
  166. }
  167. else if(p.topLeft().y > y+h && p.bottomLeft().y > y+h) //rect p is below *this
  168. {
  169. intersect = false;
  170. }
  171. else if(p.topLeft().x > x+w && p.topRight().x > x+w) //rect p is on the right hand side of this
  172. {
  173. intersect = false;
  174. }
  175. else if(p.topLeft().x < x && p.topRight().x < x) //rect p is on the left hand side of this
  176. {
  177. intersect = false;
  178. }
  179. if(intersect)
  180. {
  181. Rect ret;
  182. ret.x = std::max(this->x, p.x);
  183. ret.y = std::max(this->y, p.y);
  184. Point bR; //bottomRight point of returned rect
  185. bR.x = std::min(this->w+this->x, p.w+p.x);
  186. bR.y = std::min(this->h+this->y, p.h+p.y);
  187. ret.w = bR.x - ret.x;
  188. ret.h = bR.y - ret.y;
  189. return ret;
  190. }
  191. else
  192. {
  193. return Rect();
  194. }
  195. }
  196. };
  197. class IShowable
  198. {
  199. public:
  200. virtual void show(SDL_Surface * to)=0;
  201. virtual void showAll(SDL_Surface * to)
  202. {
  203. show(to);
  204. }
  205. virtual ~IShowable(){};
  206. };
  207. class IStatusBar
  208. {
  209. public:
  210. virtual ~IStatusBar(){}; //d-tor
  211. virtual void print(const std::string & text)=0; //prints text and refreshes statusbar
  212. virtual void clear()=0;//clears statusbar and refreshes
  213. virtual void show(SDL_Surface * to)=0; //shows statusbar (with current text)
  214. virtual std::string getCurrent()=0; //returns currently displayed text
  215. };
  216. class IActivable
  217. {
  218. public:
  219. virtual void activate()=0;
  220. virtual void deactivate()=0;
  221. virtual ~IActivable(){};
  222. };
  223. class IShowActivable : public IShowable, public IActivable
  224. {
  225. public:
  226. enum {WITH_GARRISON = 1};
  227. int type; //bin flags using etype
  228. IShowActivable();
  229. virtual ~IShowActivable(){};
  230. };
  231. class CWindowWithGarrison : public IShowActivable
  232. {
  233. public:
  234. CGarrisonInt *garr;
  235. CWindowWithGarrison();
  236. };
  237. class CMainInterface : public IShowActivable
  238. {
  239. public:
  240. IShowActivable *subInt;
  241. };
  242. class CIntObject //interface object
  243. {
  244. public:
  245. Rect pos; //position of object on the screen
  246. int ID; //object uniqe ID, rarely (if at all) used
  247. //virtual bool isIn(int x, int y)
  248. //{
  249. // return pos.isIn(x,y);
  250. //}
  251. virtual ~CIntObject(){}; //d-tor
  252. };
  253. class CSimpleWindow : public IShowActivable, public virtual CIntObject
  254. {
  255. public:
  256. SDL_Surface * bitmap;
  257. CIntObject * owner; //who made this window
  258. virtual void show(SDL_Surface * to);
  259. CSimpleWindow():bitmap(NULL),owner(NULL){}; //c-tor
  260. virtual ~CSimpleWindow(); //d-tor
  261. void activate(){};
  262. void deactivate(){};
  263. };
  264. class CButtonBase : public virtual CIntObject, public IShowable, public IActivable //basic buttton class
  265. {
  266. public:
  267. int bitmapOffset; //TODO: comment me
  268. int type; //advmapbutton=2 //TODO: comment me
  269. bool abs;//TODO: comment me
  270. bool active; //if true, this button is active and can be pressed
  271. bool notFreeButton; //TODO: comment me
  272. CIntObject * ourObj; // "owner"
  273. int state; //TODO: comment me
  274. std::vector< std::vector<SDL_Surface*> > imgs; //images for this button
  275. int curimg; //curently displayed image from imgs
  276. virtual void show(SDL_Surface * to);
  277. virtual void activate()=0;
  278. virtual void deactivate()=0;
  279. CButtonBase(); //c-tor
  280. virtual ~CButtonBase(); //d-tor
  281. };
  282. class ClickableL : public virtual CIntObject //for left-clicks
  283. {
  284. public:
  285. bool pressedL; //for determining if object is L-pressed
  286. ClickableL(); //c-tor
  287. virtual ~ClickableL();//{};
  288. virtual void clickLeft (boost::logic::tribool down)=0;
  289. virtual void activate();
  290. virtual void deactivate();
  291. };
  292. class ClickableR : public virtual CIntObject //for right-clicks
  293. {
  294. public:
  295. bool pressedR; //for determining if object is R-pressed
  296. ClickableR(); //c-tor
  297. virtual ~ClickableR();//{};
  298. virtual void clickRight (boost::logic::tribool down)=0;
  299. virtual void activate()=0;
  300. virtual void deactivate()=0;
  301. };
  302. class Hoverable : public virtual CIntObject
  303. {
  304. public:
  305. Hoverable() : hovered(false){} //c-tor
  306. virtual ~Hoverable();//{}; //d-tor
  307. bool hovered; //for determining if object is hovered
  308. virtual void hover (bool on)=0;
  309. virtual void activate()=0;
  310. virtual void deactivate()=0;
  311. };
  312. class KeyInterested : public virtual CIntObject
  313. {
  314. public:
  315. bool captureAllKeys; //if true, only this object should get info about pressed keys
  316. KeyInterested(): captureAllKeys(false){}
  317. virtual ~KeyInterested();//{};
  318. virtual void keyPressed(const SDL_KeyboardEvent & key)=0;
  319. virtual void activate()=0;
  320. virtual void deactivate()=0;
  321. };
  322. class KeyShortcut : public KeyInterested, public ClickableL
  323. {
  324. public:
  325. std::set<int> assignedKeys;
  326. KeyShortcut(){}; //c-tor
  327. KeyShortcut(int key){assignedKeys.insert(key);}; //c-tor
  328. KeyShortcut(std::set<int> Keys):assignedKeys(Keys){}; //c-tor
  329. virtual void keyPressed(const SDL_KeyboardEvent & key); //call-in
  330. };
  331. class MotionInterested: public virtual CIntObject
  332. {
  333. public:
  334. bool strongInterest; //if true - report all mouse movements, if not - only when hovered
  335. MotionInterested(){strongInterest=false;};
  336. virtual ~MotionInterested(){};
  337. virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0;
  338. virtual void activate()=0;
  339. virtual void deactivate()=0;
  340. };
  341. class TimeInterested: public virtual CIntObject
  342. {
  343. public:
  344. virtual ~TimeInterested(){}; //d-tor
  345. int toNextTick;
  346. virtual void tick()=0;
  347. virtual void activate();
  348. virtual void deactivate();
  349. };
  350. class CInfoWindow : public CSimpleWindow //text + comp. + ok button
  351. { //window able to delete its components when closed
  352. public:
  353. bool delComps; //whether comps will be deleted
  354. std::vector<AdventureMapButton *> buttons;
  355. std::vector<SComponent*> components;
  356. virtual void close();
  357. virtual void show(SDL_Surface * to);
  358. void activate();
  359. void deactivate();
  360. CInfoWindow(std::string text, int player, int charperline, const std::vector<SComponent*> &comps, std::vector<std::pair<std::string,CFunctionList<void()> > > &Buttons); //c-tor
  361. CInfoWindow(); //c-tor
  362. ~CInfoWindow(); //d-tor
  363. };
  364. class CSelWindow : public CInfoWindow //component selection window
  365. { //warning - this window deletes its components by closing!
  366. public:
  367. void selectionChange(unsigned to);
  368. void madeChoice(); //looks for selected component and calls callback
  369. 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
  370. CSelWindow(){}; //c-tor
  371. //notification - this class inherits important destructor from CInfoWindow
  372. };
  373. class CRClickPopup : public IShowActivable, public ClickableR //popup displayed on R-click
  374. {
  375. public:
  376. virtual void activate();
  377. virtual void deactivate();
  378. virtual void close();
  379. void clickRight (boost::logic::tribool down);
  380. virtual ~CRClickPopup(){}; //d-tor
  381. };
  382. class CRClickPopupInt : public CRClickPopup //popup displayed on R-click
  383. {
  384. public:
  385. IShowActivable *inner;
  386. bool delInner;
  387. void show(SDL_Surface * to);
  388. CRClickPopupInt(IShowActivable *our, bool deleteInt);
  389. virtual ~CRClickPopupInt(); //d-tor
  390. };
  391. class CInfoPopup : public CRClickPopup
  392. {
  393. public:
  394. bool free; //TODO: comment me
  395. SDL_Surface * bitmap; //popup background
  396. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false); //c-tor
  397. void close();
  398. void show(SDL_Surface * to);
  399. CInfoPopup(){free=false;bitmap=NULL;} //default c-tor
  400. ~CInfoPopup(){}; //d-tor
  401. };
  402. class SComponent : public ClickableR //common popup window component
  403. {
  404. public:
  405. enum Etype
  406. {
  407. primskill, secskill, resource, creature, artifact, experience, secskill44, spell, morale, luck
  408. } type; //component type
  409. int subtype; //TODO: comment me
  410. int val; //TODO: comment me
  411. std::string description; //r-click
  412. std::string subtitle; //TODO: comment me
  413. void init(Etype Type, int Subtype, int Val);
  414. SComponent(Etype Type, int Subtype, int Val); //c-tor
  415. SComponent(const Component &c); //c-tor
  416. SComponent(){}; //c-tor
  417. virtual ~SComponent(){}; //d-tor
  418. void clickRight (boost::logic::tribool down); //call-in
  419. virtual SDL_Surface * getImg();
  420. virtual void show(SDL_Surface * to);
  421. virtual void activate();
  422. virtual void deactivate();
  423. };
  424. class CCustomImgComponent : public SComponent
  425. {
  426. public:
  427. SDL_Surface *bmp; //our image
  428. bool free; //should surface be freed on delete
  429. SDL_Surface * getImg();
  430. CCustomImgComponent(Etype Type, int Subtype, int Val, SDL_Surface *sur, bool freeSur); //c-tor
  431. ~CCustomImgComponent(); //d-tor
  432. };
  433. class CSelectableComponent : public SComponent, public KeyShortcut
  434. {
  435. public:
  436. bool selected; //if true, this component is selected
  437. bool customB; //TODO: comment me
  438. SDL_Surface * border, *myBitmap;
  439. boost::function<void()> onSelect; //function called on selection change
  440. void clickLeft(boost::logic::tribool down); //call-in
  441. void init(SDL_Surface * Border);
  442. CSelectableComponent(Etype Type, int Sub, int Val, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
  443. CSelectableComponent(const Component &c, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
  444. ~CSelectableComponent(); //d-tor
  445. virtual void show(SDL_Surface * to);
  446. void activate();
  447. void deactivate();
  448. void select(bool on);
  449. SDL_Surface * getImg(); //returns myBitmap
  450. };
  451. class CGarrisonInt;
  452. class CGarrisonSlot : public ClickableL, public ClickableR, public Hoverable
  453. {
  454. public:
  455. CGarrisonInt *owner;
  456. const CCreature * creature; //creature in slot
  457. int count; //number of creatures
  458. int upg; //0 - up garrison, 1 - down garrison
  459. bool active; //TODO: comment me
  460. virtual void hover (bool on); //call-in
  461. const CArmedInstance * getObj();
  462. void clickRight (boost::logic::tribool down);
  463. void clickLeft(boost::logic::tribool down);
  464. void activate();
  465. void deactivate();
  466. void show(SDL_Surface * to);
  467. CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg=0, const CCreature * Creature=NULL, int Count=0);
  468. ~CGarrisonSlot();
  469. };
  470. class CGarrisonInt :public CIntObject
  471. {
  472. public:
  473. int interx, intery; //intervals between slots
  474. CGarrisonSlot *highlighted; //choosen slot
  475. SDL_Surface *&sur; //TODO: comment me
  476. int offx, offy, p2; //TODO: comment me
  477. bool ignoreEvent, update, active, splitting, pb;
  478. const CCreatureSet *set1; //top set of creatures
  479. const CCreatureSet *set2; //bottom set of creatures
  480. std::vector<CGarrisonSlot*> *sup, *sdown; //TODO: comment me
  481. const CArmedInstance *oup, *odown; //TODO: comment me
  482. void activate();
  483. void deactivate();
  484. void show(SDL_Surface * to);
  485. void activeteSlots();
  486. void deactiveteSlots();
  487. void deleteSlots();
  488. void createSlots();
  489. void recreateSlots();
  490. void splitClick(); //handles click on split button
  491. void splitStacks(int am2); //TODO: comment me
  492. CGarrisonInt(int x, int y, int inx, int iny, SDL_Surface *&pomsur, int OX, int OY, const CArmedInstance *s1, const CArmedInstance *s2=NULL); //c-tor
  493. ~CGarrisonInt(); //d-tor
  494. };
  495. class CPlayerInterface : public CGameInterface
  496. {
  497. public:
  498. //minor interfaces
  499. CondSh<bool> *showingDialog; //indicates if dialog box is displayed
  500. boost::recursive_mutex *pim;
  501. bool makingTurn; //if player is already making his turn
  502. //TODO: exclude to some kind Settings struct
  503. int heroMoveSpeed; //speed of player's hero movement
  504. void setHeroMoveSpeed(int newSpeed) {heroMoveSpeed = newSpeed;} //set for the member above
  505. int mapScrollingSpeed; //map scrolling speed
  506. void setMapScrollingSpeed(int newSpeed) {mapScrollingSpeed = newSpeed;} //set the member above
  507. SDL_Event * current; //current event
  508. //CMainInterface *curint;
  509. CAdvMapInt * adventureInt;
  510. CCastleInterface * castleInt; //NULL if castle window isn't opened
  511. CBattleInterface * battleInt; //NULL if no battle
  512. CInGameConsole * cingconsole;
  513. FPSmanager * mainFPSmng; //to keep const framerate
  514. IStatusBar *statusbar; //current statusbar - will be used to show hover tooltips
  515. CCallback * cb; //to communicate with engine
  516. const BattleAction *curAction; //during the battle - action currently performed by active stack (or NULL)
  517. bool stillMoveHero; //during hero movement - setting this flag to false will stop movement
  518. std::list<CInfoWindow *> dialogs; //queue of dialogs awaiting to be shown (not currently shown!)
  519. std::list<IShowActivable *> listInt; //list of interfaces - front=foreground; back = background (includes adventure map, window interfaces, all kind of active dialogs, and so on)
  520. void totalRedraw(); //forces total redraw (using showAll)
  521. void popInt(IShowActivable *top); //removes given interface from the top and activates next
  522. void popIntTotally(IShowActivable *top); //deactivates, deletes, removes given interface from the top and activates next
  523. void pushInt(IShowActivable *newInt); //deactivate old top interface, activates this one and pushes to the top
  524. void popInts(int howMany); //pops one or more interfaces - deactivates top, deletes and removes given number of interfaces, activates new front
  525. IShowActivable *topInt(); //returns top interface
  526. //GUI elements
  527. std::list<ClickableL*> lclickable;
  528. std::list<ClickableR*> rclickable;
  529. std::list<Hoverable*> hoverable;
  530. std::list<KeyInterested*> keyinterested;
  531. std::list<MotionInterested*> motioninterested;
  532. std::list<TimeInterested*> timeinterested;
  533. std::vector<IShowable*> objsToBlit;
  534. //overloaded funcs from CGameInterface
  535. void buildChanged(const CGTownInstance *town, int buildingID, int what); //what: 1 - built, 2 - demolished
  536. void garrisonChanged(const CGObjectInstance * obj);
  537. void heroArtifactSetChanged(const CGHeroInstance*hero);
  538. void heroCreated(const CGHeroInstance* hero);
  539. void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback);
  540. void heroInGarrisonChange(const CGTownInstance *town);
  541. void heroKilled(const CGHeroInstance* hero);
  542. void heroMoved(const HeroMoveDetails & details);
  543. void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val);
  544. void heroManaPointsChanged(const CGHeroInstance * hero);
  545. void heroMovePointsChanged(const CGHeroInstance * hero);
  546. void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town);
  547. void receivedResource(int type, int val);
  548. void showInfoDialog(const std::string &text, const std::vector<Component*> &components);
  549. //void showSelDialog(const std::string &text, const std::vector<Component*> &components, ui32 askID);
  550. //void showYesNoDialog(const std::string &text, const std::vector<Component*> &components, ui32 askID);
  551. void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, bool selection, bool cancel); //Show a dialog, player must take decision. If selection then he has to choose between one of given components, if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called with number of selected component (1 - n) or 0 for cancel (if allowed) and askID.
  552. void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, boost::function<void()> &onEnd);
  553. void tileHidden(const std::set<int3> &pos);
  554. void tileRevealed(const std::set<int3> &pos);
  555. void yourTurn();
  556. void availableCreaturesChanged(const CGTownInstance *town);
  557. void heroBonusChanged(const CGHeroInstance *hero, const HeroBonus &bonus, bool gain);//if gain hero received bonus, else he lost it
  558. void serialize(COSer<CSaveFile> &h, const int version); //saving
  559. void serialize(CISer<CLoadFile> &h, const int version); //loading
  560. //for battles
  561. void actionFinished(const BattleAction* action);//occurs AFTER action taken by active stack or by the hero
  562. void actionStarted(const BattleAction* action);//occurs BEFORE action taken by active stack or by the hero
  563. BattleAction activeStack(int stackID); //called when it's turn of that stack
  564. void battleAttack(BattleAttack *ba); //stack performs attack
  565. void battleEnd(BattleResult *br); //end of battle
  566. //void battleResultQuited();
  567. void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
  568. void battleStackMoved(int ID, int dest, int distance, bool end);
  569. void battleSpellCasted(SpellCasted *sc);
  570. void battleStacksEffectsSet(SetStackEffect & sse); //called when a specific effect is set to stacks
  571. void battleStacksAttacked(std::set<BattleStackAttacked> & bsa);
  572. void battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side); //called by engine when battle starts; side=0 - left, side=1 - right
  573. void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning
  574. //-------------//
  575. bool shiftPressed() const;
  576. void redrawHeroWin(const CGHeroInstance * hero);
  577. void updateWater();
  578. void showComp(SComponent comp); //TODO: comment me
  579. void openTownWindow(const CGTownInstance * town); //shows townscreen
  580. void openHeroWindow(const CGHeroInstance * hero); //shows hero window with given hero
  581. SDL_Surface * infoWin(const CGObjectInstance * specific); //specific=0 => draws info about selected town/hero
  582. void handleEvent(SDL_Event * sEvent);
  583. void handleKeyDown(SDL_Event *sEvent);
  584. void handleKeyUp(SDL_Event *sEvent);
  585. void handleMouseMotion(SDL_Event *sEvent);
  586. void init(ICallback * CB);
  587. int3 repairScreenPos(int3 pos); //returns position closest to pos we can center screen on
  588. void showInfoDialog(const std::string &text, const std::vector<SComponent*> & components);
  589. void showYesNoDialog(const std::string &text, const std::vector<SComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool DelComps); //deactivateCur - whether current main interface should be deactivated; delComps - if components will be deleted on window close
  590. bool moveHero(const CGHeroInstance *h, CPath * path);
  591. CPlayerInterface(int Player, int serial);//c-tor
  592. ~CPlayerInterface();//d-tor
  593. //////////////////////////////////////////////////////////////////////////
  594. template <typename Handler> void serializeTempl(Handler &h, const int version);
  595. };
  596. class CStatusBar
  597. : public CIntObject, public IStatusBar
  598. {
  599. public:
  600. SDL_Surface * bg; //background
  601. int middlex, middley; //middle of statusbar
  602. std::string current; //text currently printed
  603. CStatusBar(int x, int y, std::string name="ADROLLVR.bmp", int maxw=-1); //c-tor
  604. ~CStatusBar(); //d-tor
  605. void print(const std::string & text); //prints text and refreshes statusbar
  606. void clear();//clears statusbar and refreshes
  607. void show(SDL_Surface * to); //shows statusbar (with current text)
  608. std::string getCurrent(); //getter for current
  609. };
  610. class CList
  611. : public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public virtual CIntObject, public MotionInterested
  612. {
  613. public:
  614. SDL_Surface * bg; //background bitmap
  615. CDefHandler *arrup, *arrdo; //button arrows for scrolling list
  616. SDL_Surface *empty, *selection;
  617. SDL_Rect arrupp, arrdop; //positions of arrows
  618. int posw, posh; //position width/height
  619. int selected, //id of selected position, <0 if none
  620. from;
  621. const int SIZE; //size of list
  622. boost::logic::tribool pressed; //true=up; false=down; indeterminate=none
  623. CList(int Size = 5); //c-tor
  624. void clickLeft(boost::logic::tribool down);
  625. void activate();
  626. void deactivate();
  627. virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; //call-in
  628. virtual void genList()=0;
  629. virtual void select(int which)=0;
  630. virtual void draw(SDL_Surface * to)=0;
  631. };
  632. class CHeroList
  633. : public CList
  634. {
  635. public:
  636. CDefHandler *mobile, *mana; //mana and movement indicators
  637. std::vector<std::pair<const CGHeroInstance*, CPath *> > items;
  638. int posmobx, posporx, posmanx, posmoby, pospory, posmany;
  639. CHeroList(int Size); //c-tor
  640. int getPosOfHero(const CArmedInstance* h); //hero's position on list
  641. void genList();
  642. void select(int which); //call-in
  643. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  644. void clickLeft(boost::logic::tribool down); //call-in
  645. void clickRight(boost::logic::tribool down); //call-in
  646. void hover (bool on); //call-in
  647. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  648. void updateHList(const CGHeroInstance *toRemove=NULL); //removes specific hero from the list or recreates it
  649. void updateMove(const CGHeroInstance* which); //draws move points bar
  650. void redrawAllOne(int which); //not imeplemented
  651. void draw(SDL_Surface * to);
  652. void init();
  653. };
  654. class CTownList
  655. : public CList
  656. {
  657. public:
  658. boost::function<void()> fun; //function called on selection change
  659. std::vector<const CGTownInstance*> items; //towns on list
  660. int posporx,pospory;
  661. CTownList(int Size, int x, int y, std::string arrupg, std::string arrdog); //c-tor
  662. ~CTownList(); //d-tor
  663. void genList();
  664. void select(int which); //call-in
  665. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  666. void clickLeft(boost::logic::tribool down); //call-in
  667. void clickRight(boost::logic::tribool down); //call-in
  668. void hover (bool on); //call-in
  669. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  670. void draw(SDL_Surface * to);
  671. };
  672. class CCreaturePic //draws picture with creature on background, use nextFrame=true to get animation
  673. {
  674. public:
  675. CCreature *c; //which creature's picture
  676. bool big; //big => 100x130; !big => 100x120
  677. CCreatureAnimation *anim; //displayed animation
  678. CCreaturePic(CCreature *cre, bool Big=true); //c-tor
  679. ~CCreaturePic(); //d-tor
  680. int blitPic(SDL_Surface *to, int x, int y, bool nextFrame); //prints creature on screen
  681. SDL_Surface * getPic(bool nextFrame); //returns frame of animation
  682. };
  683. class CRecrutationWindow : public IShowActivable, public ClickableL, public ClickableR
  684. {
  685. public:
  686. struct creinfo
  687. {
  688. SDL_Rect pos;
  689. CCreaturePic *pic; //creature's animation
  690. int ID, amount; //creature ID and available amount
  691. std::vector<std::pair<int,int> > res; //res_id - cost_per_unit
  692. };
  693. std::vector<int> amounts; //how many creatures we can afford
  694. std::vector<creinfo> creatures; //recruitable creatures
  695. boost::function<void(int,int)> recruit; //void (int ID, int amount) <-- call to recruit creatures
  696. CSlider *slider; //for selecting amount
  697. AdventureMapButton *max, *buy, *cancel;
  698. SDL_Surface *bitmap; //background
  699. CStatusBar *bar;
  700. int which; //which creature is active
  701. void close();
  702. void Max();
  703. void Buy();
  704. void Cancel();
  705. void sliderMoved(int to);
  706. void clickLeft(boost::logic::tribool down);
  707. void clickRight(boost::logic::tribool down);
  708. void activate();
  709. void deactivate();
  710. void show(SDL_Surface * to);
  711. CRecrutationWindow(const std::vector<std::pair<int,int> > & Creatures, const boost::function<void(int,int)> & Recruit); //creatures - pairs<creature_ID,amount> //c-tor
  712. ~CRecrutationWindow(); //d-tor
  713. };
  714. class CSplitWindow : public IShowActivable, public KeyInterested, public ClickableL
  715. {
  716. public:
  717. CGarrisonInt *gar;
  718. CSlider *slider;
  719. CCreaturePic *anim; //creature's animation
  720. AdventureMapButton *ok, *cancel;
  721. SDL_Surface *bitmap; //background
  722. int a1, a2, c; //TODO: comment me
  723. bool which; //TODO: comment me
  724. int last; //0/1/2 - at least one creature must be in the src/dst/both stacks; -1 - no restrictions
  725. CSplitWindow(int cid, int max, CGarrisonInt *Owner, int Last = -1, int val=0); //c-tor; val - initial amount of second stack
  726. ~CSplitWindow(); //d-tor
  727. void activate();
  728. void split();
  729. void close();
  730. void deactivate();
  731. void show(SDL_Surface * to);
  732. void clickLeft(boost::logic::tribool down); //call-in
  733. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  734. void sliderMoved(int to);
  735. };
  736. class CCreInfoWindow : public IShowActivable, public KeyInterested, public ClickableR
  737. {
  738. public:
  739. //bool active; //TODO: comment me
  740. int type;//0 - rclick popup; 1 - normal window
  741. SDL_Surface *bitmap; //background
  742. char anf; //TODO: comment me
  743. std::string count; //creature count in text format
  744. boost::function<void()> dsm; //TODO: comment me
  745. CCreaturePic *anim;
  746. CCreature *c;
  747. std::vector<SComponent*> upgResCost; //cost of upgrade (if not possible then empty)
  748. AdventureMapButton *dismiss, *upgrade, *ok;
  749. CCreInfoWindow(int Cid, int Type, int creatureCount, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm, UpgradeInfo *ui); //c-tor
  750. ~CCreInfoWindow(); //d-tor
  751. void activate();
  752. void close();
  753. void clickRight(boost::logic::tribool down); //call-in
  754. void dismissF();
  755. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  756. void deactivate();
  757. void show(SDL_Surface * to);
  758. };
  759. class CLevelWindow : public IShowActivable, public CIntObject
  760. {
  761. public:
  762. int heroType;
  763. SDL_Surface *bitmap; //background
  764. std::vector<CSelectableComponent *> comps; //skills to select
  765. AdventureMapButton *ok;
  766. boost::function<void(ui32)> cb;
  767. void close();
  768. CLevelWindow(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback); //c-tor
  769. ~CLevelWindow(); //d-tor
  770. void activate();
  771. void deactivate();
  772. void selectionChanged(unsigned to);
  773. void show(SDL_Surface * to);
  774. };
  775. class CMinorResDataBar : public IShowable, public CIntObject
  776. {
  777. public:
  778. SDL_Surface *bg; //background bitmap
  779. void show(SDL_Surface * to);
  780. CMinorResDataBar(); //c-tor
  781. ~CMinorResDataBar(); //d-tor
  782. };
  783. class CMarketplaceWindow : public IShowActivable, public CIntObject
  784. {
  785. public:
  786. class CTradeableItem : public ClickableL
  787. {
  788. public:
  789. int type; //0 - res, 1 - artif big, 2 - artif small, 3 - player flag
  790. int id;
  791. bool left;
  792. CFunctionList<void()> callback;
  793. void activate();
  794. void deactivate();
  795. void show(SDL_Surface * to);
  796. void clickLeft(boost::logic::tribool down);
  797. SDL_Surface *getSurface();
  798. CTradeableItem(int Type, int ID, bool Left);
  799. };
  800. SDL_Surface *bg; //background
  801. std::vector<CTradeableItem*> left, right;
  802. std::vector<std::string> rSubs; //offer caption
  803. CTradeableItem *hLeft, *hRight; //highlighted items (NULL if no highlight)
  804. int mode,//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact
  805. r1, r2; //TODO: comment me
  806. AdventureMapButton *ok, *max, *deal;
  807. CSlider *slider;
  808. void activate();
  809. void deactivate();
  810. void show(SDL_Surface * to);
  811. void setMax();
  812. void sliderMoved(int to);
  813. void makeDeal();
  814. void selectionChanged(bool side); //true == left
  815. CMarketplaceWindow(int Mode=0); //c-tor
  816. ~CMarketplaceWindow(); //d-tor
  817. void setMode(int mode); //mode setter
  818. void clear();
  819. };
  820. class CSystemOptionsWindow : public IShowActivable, public CIntObject
  821. {
  822. private:
  823. SDL_Surface * background; //background of window
  824. AdventureMapButton *load, *save, *restart, *mainMenu, * quitGame, * backToMap; //load, restart and main menu are not used yet
  825. CHighlightableButtonsGroup * heroMoveSpeed;
  826. CHighlightableButtonsGroup * mapScrollSpeed;
  827. public:
  828. CSystemOptionsWindow(const SDL_Rect & pos, CPlayerInterface * owner); //c-tor
  829. ~CSystemOptionsWindow(); //d-tor
  830. //functions bound to buttons
  831. void bsavef(); //save game
  832. void bquitf(); //quit game
  833. void breturnf(); //return to game
  834. void activate();
  835. void deactivate();
  836. void show(SDL_Surface * to);
  837. };
  838. class CTavernWindow : public IShowActivable, public CIntObject
  839. {
  840. public:
  841. class HeroPortrait : public ClickableL, public ClickableR, public Hoverable
  842. {
  843. public:
  844. std::string hoverName;
  845. vstd::assigner<int,int> as;
  846. const CGHeroInstance *h;
  847. void activate();
  848. void deactivate();
  849. void clickLeft(boost::logic::tribool down);
  850. void clickRight(boost::logic::tribool down);
  851. void hover (bool on);
  852. HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H);
  853. void show(SDL_Surface * to);
  854. } h1, h2; //recruitable heroes
  855. SDL_Surface *bg; //background
  856. CStatusBar *bar;
  857. int selected;//0 (left) or 1 (right)
  858. AdventureMapButton *thiefGuild, *cancel, *recruit;
  859. CTavernWindow(const CGHeroInstance *H1, const CGHeroInstance *H2, const std::string &gossip); //c-tor
  860. ~CTavernWindow(); //d-tor
  861. void recruitb();
  862. void close();
  863. void activate();
  864. void deactivate();
  865. void show(SDL_Surface * to);
  866. };
  867. class CInGameConsole : public IShowActivable, public KeyInterested
  868. {
  869. private:
  870. std::list< std::pair< std::string, int > > texts; //<text to show, time of add>
  871. std::vector< std::string > previouslyEntered; //previously entered texts, for up/down arrows to work
  872. int prevEntDisp; //displayed entry from previouslyEntered - if none it's -1
  873. int defaultTimeout; //timeout for new texts (in ms)
  874. int maxDisplayedTexts; //hiw many texts can be displayed simultaneously
  875. public:
  876. std::string enteredText;
  877. void activate();
  878. void deactivate();
  879. void show(SDL_Surface * to);
  880. void print(const std::string &txt);
  881. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  882. void startEnteringText();
  883. void endEnteringText(bool printEnteredText);
  884. void refreshEnteredText();
  885. CInGameConsole(); //c-tor
  886. };
  887. class CGarrisonWindow : public CWindowWithGarrison, public CIntObject
  888. {
  889. public:
  890. SDL_Surface *bg;
  891. AdventureMapButton *split, *quit;
  892. void close();
  893. void activate();
  894. void deactivate();
  895. void show(SDL_Surface * to);
  896. CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down);
  897. ~CGarrisonWindow();
  898. };
  899. extern CPlayerInterface * LOCPLINT;
  900. #endif // __CPLAYERINTERFACE_H__