CPlayerInterface.h 32 KB

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