CPlayerInterface.h 29 KB

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