CPlayerInterface.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  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. void madeChoice(); //looks for selected component and calls callback
  345. 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
  346. CSelWindow(){}; //c-tor
  347. //notification - this class inherits important destructor from CInfoWindow
  348. };
  349. class CRClickPopup : public IShowable, public ClickableR //popup displayed on R-click
  350. {
  351. public:
  352. virtual void activate();
  353. virtual void deactivate();
  354. virtual void close()=0;
  355. void clickRight (boost::logic::tribool down);
  356. virtual ~CRClickPopup(){}; //d-tor
  357. };
  358. class CInfoPopup : public CRClickPopup
  359. {
  360. public:
  361. bool free; //TODO: comment me
  362. SDL_Surface * bitmap; //popup background
  363. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false); //c-tor
  364. void close();
  365. void show(SDL_Surface * to = NULL);
  366. CInfoPopup(){free=false;bitmap=NULL;} //default c-tor
  367. ~CInfoPopup(){}; //d-tor
  368. };
  369. class SComponent : public ClickableR //common popup window component
  370. {
  371. public:
  372. enum Etype
  373. {
  374. primskill, secskill, resource, creature, artifact, experience, secskill44, spell, morale, luck
  375. } type; //component type
  376. int subtype; //TODO: comment me
  377. int val; //TODO: comment me
  378. std::string description; //r-click
  379. std::string subtitle; //TODO: comment me
  380. void init(Etype Type, int Subtype, int Val);
  381. SComponent(Etype Type, int Subtype, int Val); //c-tor
  382. SComponent(const Component &c); //c-tor
  383. SComponent(){}; //c-tor
  384. virtual ~SComponent(){}; //d-tor
  385. void clickRight (boost::logic::tribool down); //call-in
  386. virtual SDL_Surface * getImg();
  387. virtual void show(SDL_Surface * to = NULL);
  388. virtual void activate();
  389. virtual void deactivate();
  390. };
  391. class CCustomImgComponent : public SComponent
  392. {
  393. public:
  394. bool free; //should surface be freed on delete
  395. SDL_Surface *bmp; //our image
  396. SDL_Surface * getImg();
  397. CCustomImgComponent(Etype Type, int Subtype, int Val, SDL_Surface *sur, bool freeSur); //c-tor
  398. ~CCustomImgComponent(); //d-tor
  399. };
  400. class CSelectableComponent : public SComponent, public KeyShortcut
  401. {
  402. public:
  403. bool selected; //if true, this component is selected
  404. bool customB; //TODO: comment me
  405. SDL_Surface * border, *myBitmap;
  406. boost::function<void()> onSelect; //function called on selection change
  407. void clickLeft(boost::logic::tribool down); //call-in
  408. void init(SDL_Surface * Border);
  409. CSelectableComponent(Etype Type, int Sub, int Val, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
  410. CSelectableComponent(const Component &c, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
  411. ~CSelectableComponent(); //d-tor
  412. virtual void show(SDL_Surface * to = NULL);
  413. void activate();
  414. void deactivate();
  415. void select(bool on);
  416. SDL_Surface * getImg(); //returns myBitmap
  417. };
  418. class CGarrisonInt;
  419. class CGarrisonSlot : public ClickableL, public ClickableR, public Hoverable
  420. {
  421. public:
  422. CGarrisonInt *owner;
  423. const CCreature * creature; //creature in slot
  424. int count; //number of creatures
  425. int upg; //0 - up garrison, 1 - down garrison
  426. bool active; //TODO: comment me
  427. virtual void hover (bool on); //call-in
  428. const CArmedInstance * getObj();
  429. void clickRight (boost::logic::tribool down);
  430. void clickLeft(boost::logic::tribool down);
  431. void activate();
  432. void deactivate();
  433. void show();
  434. CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg=0, const CCreature * Creature=NULL, int Count=0);
  435. ~CGarrisonSlot();
  436. };
  437. class CGarrisonInt :public CIntObject
  438. {
  439. public:
  440. int interx, intery; //intervals between slots
  441. CGarrisonSlot *highlighted; //choosen slot
  442. SDL_Surface *&sur; //TODO: comment me
  443. int offx, offy, p2; //TODO: comment me
  444. bool ignoreEvent, update, active, splitting, pb;
  445. const CCreatureSet *set1; //top set of creatures
  446. const CCreatureSet *set2; //bottom set of creatures
  447. std::vector<CGarrisonSlot*> *sup, *sdown; //TODO: comment me
  448. const CArmedInstance *oup, *odown; //TODO: comment me
  449. void activate();
  450. void deactivate();
  451. void show();
  452. void activeteSlots();
  453. void deactiveteSlots();
  454. void deleteSlots();
  455. void createSlots();
  456. void recreateSlots();
  457. void splitClick(); //handles click on split button
  458. void splitStacks(int am2); //TODO: comment me
  459. 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
  460. ~CGarrisonInt(); //d-tor
  461. };
  462. class CPlayerInterface : public CGameInterface
  463. {
  464. public:
  465. //minor interfaces
  466. CondSh<bool> *showingDialog; //indicates if dialog box is displayed
  467. boost::recursive_mutex *pim; //locks read/write of this
  468. bool makingTurn; //indicates if player is already making his turn
  469. int heroMoveSpeed; //speed of player's hero movement
  470. void setHeroMoveSpeed(int newSpeed) {heroMoveSpeed = newSpeed;} //set for the member above
  471. int mapScrollingSpeed; //map scrolling speed
  472. void setMapScrollingSpeed(int newSpeed) {mapScrollingSpeed = newSpeed;} //set the member above
  473. SDL_Event * current; //current event
  474. CMainInterface *curint;
  475. CAdvMapInt * adventureInt;
  476. CCastleInterface * castleInt;
  477. CBattleInterface * battleInt;
  478. CInGameConsole * cingconsole;
  479. FPSmanager * mainFPSmng;
  480. IStatusBar *statusbar; //advmap statusbar; should it be used by other windows with statusbar?
  481. //to commucate with engine
  482. CCallback * cb;
  483. const BattleAction *curAction;
  484. bool stillMoveHero;
  485. std::list<CInfoWindow *> dialogs;
  486. //GUI elements
  487. std::list<ClickableL*> lclickable;
  488. std::list<ClickableR*> rclickable;
  489. std::list<Hoverable*> hoverable;
  490. std::list<KeyInterested*> keyinterested;
  491. std::list<MotionInterested*> motioninterested;
  492. std::list<TimeInterested*> timeinterested;
  493. std::vector<IShowable*> objsToBlit;
  494. //overloaded funcs from CGameInterface
  495. void buildChanged(const CGTownInstance *town, int buildingID, int what); //what: 1 - built, 2 - demolished
  496. void garrisonChanged(const CGObjectInstance * obj);
  497. void heroArtifactSetChanged(const CGHeroInstance*hero);
  498. void heroCreated(const CGHeroInstance* hero);
  499. void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback);
  500. void heroInGarrisonChange(const CGTownInstance *town);
  501. void heroKilled(const CGHeroInstance* hero);
  502. void heroMoved(const HeroMoveDetails & details);
  503. void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val);
  504. void heroManaPointsChanged(const CGHeroInstance * hero);
  505. void heroMovePointsChanged(const CGHeroInstance * hero);
  506. void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town);
  507. void receivedResource(int type, int val);
  508. void showInfoDialog(const std::string &text, const std::vector<Component*> &components);
  509. //void showSelDialog(const std::string &text, const std::vector<Component*> &components, ui32 askID);
  510. //void showYesNoDialog(const std::string &text, const std::vector<Component*> &components, ui32 askID);
  511. 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.
  512. void tileHidden(const std::set<int3> &pos);
  513. void tileRevealed(const std::set<int3> &pos);
  514. void yourTurn();
  515. void availableCreaturesChanged(const CGTownInstance *town);
  516. void heroBonusChanged(const CGHeroInstance *hero, const HeroBonus &bonus, bool gain);//if gain hero received bonus, else he lost it
  517. void serialize(COSer<CSaveFile> &h, const int version); //saving
  518. void serialize(CISer<CLoadFile> &h, const int version); //loading
  519. //for battles
  520. void actionFinished(const BattleAction* action);//occurs AFTER action taken by active stack or by the hero
  521. void actionStarted(const BattleAction* action);//occurs BEFORE action taken by active stack or by the hero
  522. BattleAction activeStack(int stackID); //called when it's turn of that stack
  523. void battleAttack(BattleAttack *ba); //stack performs attack
  524. void battleEnd(BattleResult *br); //end of battle
  525. void battleResultQuited();
  526. void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
  527. void battleStackMoved(int ID, int dest, int distance, bool end);
  528. void battleSpellCasted(SpellCasted *sc);
  529. void battleStacksEffectsSet(SetStackEffect & sse); //called when a specific effect is set to stacks
  530. void battleStacksAttacked(std::set<BattleStackAttacked> & bsa);
  531. 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
  532. void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning
  533. //-------------//
  534. bool shiftPressed() const;
  535. void redrawHeroWin(const CGHeroInstance * hero);
  536. void updateWater();
  537. void showComp(SComponent comp); //TODO: comment me
  538. void openTownWindow(const CGTownInstance * town); //shows townscreen
  539. void openHeroWindow(const CGHeroInstance * hero); //shows hero window with given hero
  540. SDL_Surface * infoWin(const CGObjectInstance * specific); //specific=0 => draws info about selected town/hero
  541. void handleEvent(SDL_Event * sEvent);
  542. void handleKeyDown(SDL_Event *sEvent);
  543. void handleKeyUp(SDL_Event *sEvent);
  544. void handleMouseMotion(SDL_Event *sEvent);
  545. void init(ICallback * CB);
  546. int3 repairScreenPos(int3 pos); //returns position closest to pos we can center screen on
  547. void removeObjToBlit(IShowable* obj);
  548. void showInfoDialog(const std::string &text, const std::vector<SComponent*> & components, bool deactivateCur=true);
  549. 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
  550. bool moveHero(const CGHeroInstance *h, CPath * path);
  551. CPlayerInterface(int Player, int serial);//c-tor
  552. ~CPlayerInterface();//d-tor
  553. //////////////////////////////////////////////////////////////////////////
  554. template <typename Handler> void serializeTempl(Handler &h, const int version);
  555. };
  556. class CStatusBar
  557. : public CIntObject, public IStatusBar
  558. {
  559. public:
  560. SDL_Surface * bg; //background
  561. int middlex, middley; //middle of statusbar
  562. std::string current; //text currently printed
  563. CStatusBar(int x, int y, std::string name="ADROLLVR.bmp", int maxw=-1); //c-tor
  564. ~CStatusBar(); //d-tor
  565. void print(const std::string & text); //prints text and refreshes statusbar
  566. void clear();//clears statusbar and refreshes
  567. void show(); //shows statusbar (with current text)
  568. std::string getCurrent(); //getter for current
  569. };
  570. class CList
  571. : public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public virtual CIntObject, public MotionInterested
  572. {
  573. public:
  574. SDL_Surface * bg; //background bitmap
  575. CDefHandler *arrup, *arrdo; //button arrows for scrolling list
  576. SDL_Surface *empty, *selection;
  577. SDL_Rect arrupp, arrdop; //positions of arrows
  578. int posw, posh; //position width/height
  579. int selected, //id of selected position, <0 if none
  580. from;
  581. const int SIZE; //size of list
  582. boost::logic::tribool pressed; //true=up; false=down; indeterminate=none
  583. CList(int Size = 5); //c-tor
  584. void clickLeft(boost::logic::tribool down);
  585. void activate();
  586. void deactivate();
  587. virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; //call-in
  588. virtual void genList()=0;
  589. virtual void select(int which)=0;
  590. virtual void draw()=0;
  591. };
  592. class CHeroList
  593. : public CList
  594. {
  595. public:
  596. CDefHandler *mobile, *mana; //mana and movement indicators
  597. std::vector<std::pair<const CGHeroInstance*, CPath *> > items;
  598. int posmobx, posporx, posmanx, posmoby, pospory, posmany;
  599. CHeroList(int Size); //c-tor
  600. int getPosOfHero(const CArmedInstance* h); //hero's position on list
  601. void genList();
  602. void select(int which); //call-in
  603. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  604. void clickLeft(boost::logic::tribool down); //call-in
  605. void clickRight(boost::logic::tribool down); //call-in
  606. void hover (bool on); //call-in
  607. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  608. void updateHList(const CGHeroInstance *toRemove=NULL); //removes specific hero from the list or recreates it
  609. void updateMove(const CGHeroInstance* which); //draws move points bar
  610. void redrawAllOne(int which); //not imeplemented
  611. void draw();
  612. void init();
  613. };
  614. class CTownList
  615. : public CList
  616. {
  617. public:
  618. boost::function<void()> fun; //function called on selection change
  619. std::vector<const CGTownInstance*> items; //towns on list
  620. int posporx,pospory;
  621. CTownList(int Size, int x, int y, std::string arrupg, std::string arrdog); //c-tor
  622. ~CTownList(); //d-tor
  623. void genList();
  624. void select(int which); //call-in
  625. void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
  626. void clickLeft(boost::logic::tribool down); //call-in
  627. void clickRight(boost::logic::tribool down); //call-in
  628. void hover (bool on); //call-in
  629. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  630. void draw();
  631. };
  632. class CCreaturePic //draws picture with creature on background, use nextFrame=true to get animation
  633. {
  634. public:
  635. bool big; //big => 100x130; !big => 100x120
  636. CCreature *c; //which creature's picture
  637. CCreatureAnimation *anim; //displayed animation
  638. CCreaturePic(CCreature *cre, bool Big=true); //c-tor
  639. ~CCreaturePic(); //d-tor
  640. int blitPic(SDL_Surface *to, int x, int y, bool nextFrame); //prints creature on screen
  641. SDL_Surface * getPic(bool nextFrame); //returns frame of animation
  642. };
  643. class CRecrutationWindow : public IShowable, public ClickableL, public ClickableR
  644. {
  645. public:
  646. struct creinfo
  647. {
  648. SDL_Rect pos;
  649. CCreaturePic *pic; //creature's animation
  650. int ID, amount; //creature ID and available amount
  651. std::vector<std::pair<int,int> > res; //res_id - cost_per_unit
  652. };
  653. std::vector<int> amounts; //how many creatures we can afford
  654. std::vector<creinfo> creatures; //recruitable creatures
  655. boost::function<void(int,int)> recruit; //void (int ID, int amount) <-- call to recruit creatures
  656. CSlider *slider; //for selecting amount
  657. AdventureMapButton *max, *buy, *cancel;
  658. SDL_Surface *bitmap; //background
  659. CStatusBar *bar;
  660. int which; //which creature is active
  661. void close();
  662. void Max();
  663. void Buy();
  664. void Cancel();
  665. void sliderMoved(int to);
  666. void clickLeft(boost::logic::tribool down);
  667. void clickRight(boost::logic::tribool down);
  668. void activate();
  669. void deactivate();
  670. void show(SDL_Surface * to = NULL);
  671. CRecrutationWindow(const std::vector<std::pair<int,int> > & Creatures, const boost::function<void(int,int)> & Recruit); //creatures - pairs<creature_ID,amount> //c-tor
  672. ~CRecrutationWindow(); //d-tor
  673. };
  674. class CSplitWindow : public IShowable, public KeyInterested, public ClickableL
  675. {
  676. public:
  677. CGarrisonInt *gar;
  678. CSlider *slider;
  679. CCreaturePic *anim; //creature's animation
  680. AdventureMapButton *ok, *cancel;
  681. SDL_Surface *bitmap; //background
  682. int a1, a2, c; //TODO: comment me
  683. bool which; //TODO: comment me
  684. int last; //0/1/2 - at least one creature must be in the src/dst/both stacks; -1 - no restrictions
  685. CSplitWindow(int cid, int max, CGarrisonInt *Owner, int Last = -1, int val=0); //c-tor; val - initial amount of second stack
  686. ~CSplitWindow(); //d-tor
  687. void activate();
  688. void split();
  689. void close();
  690. void deactivate();
  691. void show(SDL_Surface * to = NULL);
  692. void clickLeft(boost::logic::tribool down); //call-in
  693. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  694. void sliderMoved(int to);
  695. };
  696. class CCreInfoWindow : public IShowable, public KeyInterested, public ClickableR
  697. {
  698. public:
  699. bool active; //TODO: comment me
  700. int type;//0 - rclick popup; 1 - normal window
  701. SDL_Surface *bitmap; //background
  702. char anf; //TODO: comment me
  703. std::string count; //creature count in text format
  704. boost::function<void()> dsm; //TODO: comment me
  705. CCreaturePic *anim;
  706. CCreature *c;
  707. CInfoWindow *dependant; //it may be dialog asking whther upgrade/dismiss stack (if opened)
  708. std::vector<SComponent*> upgResCost; //cost of upgrade (if not possible then empty)
  709. AdventureMapButton *dismiss, *upgrade, *ok;
  710. CCreInfoWindow(int Cid, int Type, int creatureCount, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm, UpgradeInfo *ui); //c-tor
  711. ~CCreInfoWindow(); //d-tor
  712. void activate();
  713. void close();
  714. void clickRight(boost::logic::tribool down); //call-in
  715. void dismissF();
  716. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  717. void deactivate();
  718. void show(SDL_Surface * to = NULL);
  719. void onUpgradeYes();
  720. void onUpgradeNo();
  721. };
  722. class CLevelWindow : public IShowable, public CIntObject
  723. {
  724. public:
  725. int heroType;
  726. SDL_Surface *bitmap; //background
  727. std::vector<CSelectableComponent *> comps; //skills to select
  728. AdventureMapButton *ok;
  729. boost::function<void(ui32)> cb;
  730. void close();
  731. CLevelWindow(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback); //c-tor
  732. ~CLevelWindow(); //d-tor
  733. void activate();
  734. void deactivate();
  735. void selectionChanged(unsigned to);
  736. void show(SDL_Surface * to = NULL);
  737. };
  738. class CMinorResDataBar : public IShowable, public CIntObject
  739. {
  740. public:
  741. SDL_Surface *bg; //background bitmap
  742. void show(SDL_Surface * to=NULL);
  743. CMinorResDataBar(); //c-tor
  744. ~CMinorResDataBar(); //d-tor
  745. };
  746. class CMarketplaceWindow : public IShowActivable, public CIntObject
  747. {
  748. public:
  749. class CTradeableItem : public ClickableL
  750. {
  751. public:
  752. int type; //0 - res, 1 - artif big, 2 - artif small, 3 - player flag
  753. int id;
  754. bool left;
  755. CFunctionList<void()> callback;
  756. void activate();
  757. void deactivate();
  758. void show(SDL_Surface * to=NULL);
  759. void clickLeft(boost::logic::tribool down);
  760. SDL_Surface *getSurface();
  761. CTradeableItem(int Type, int ID, bool Left);
  762. };
  763. SDL_Surface *bg; //background
  764. std::vector<CTradeableItem*> left, right;
  765. std::vector<std::string> rSubs; //offer caption
  766. CTradeableItem *hLeft, *hRight; //highlighted items (NULL if no highlight)
  767. int mode,//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact
  768. r1, r2; //TODO: comment me
  769. AdventureMapButton *ok, *max, *deal;
  770. CSlider *slider;
  771. void activate();
  772. void deactivate();
  773. void show(SDL_Surface * to=NULL);
  774. void setMax();
  775. void sliderMoved(int to);
  776. void makeDeal();
  777. void selectionChanged(bool side); //true == left
  778. CMarketplaceWindow(int Mode=0); //c-tor
  779. ~CMarketplaceWindow(); //d-tor
  780. void setMode(int mode); //mode setter
  781. void clear();
  782. };
  783. class CSystemOptionsWindow : public IShowActivable, public CIntObject
  784. {
  785. private:
  786. SDL_Surface * background; //background of window
  787. AdventureMapButton *load, *save, *restart, *mainMenu, * quitGame, * backToMap; //load, restart and main menu are not used yet
  788. CHighlightableButtonsGroup * heroMoveSpeed;
  789. CHighlightableButtonsGroup * mapScrollSpeed;
  790. public:
  791. CSystemOptionsWindow(const SDL_Rect & pos, CPlayerInterface * owner); //c-tor
  792. ~CSystemOptionsWindow(); //d-tor
  793. //functions bound to buttons
  794. void bsavef(); //save game
  795. void bquitf(); //quit game
  796. void breturnf(); //return to game
  797. void activate();
  798. void deactivate();
  799. void show(SDL_Surface * to = NULL);
  800. };
  801. class CTavernWindow : public IShowActivable, public CIntObject
  802. {
  803. public:
  804. class HeroPortrait : public ClickableL, public ClickableR, public Hoverable
  805. {
  806. public:
  807. std::string hoverName;
  808. vstd::assigner<int,int> as;
  809. const CGHeroInstance *h;
  810. void activate();
  811. void deactivate();
  812. void clickLeft(boost::logic::tribool down);
  813. void clickRight(boost::logic::tribool down);
  814. void hover (bool on);
  815. HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H);
  816. void show(SDL_Surface * to = NULL);
  817. } h1, h2; //recruitable heroes
  818. SDL_Surface *bg; //background
  819. CStatusBar *bar;
  820. int selected;//0 (left) or 1 (right)
  821. AdventureMapButton *thiefGuild, *cancel, *recruit;
  822. CTavernWindow(const CGHeroInstance *H1, const CGHeroInstance *H2, const std::string &gossip); //c-tor
  823. ~CTavernWindow(); //d-tor
  824. void recruitb();
  825. void close();
  826. void activate();
  827. void deactivate();
  828. void show(SDL_Surface * to = NULL);
  829. };
  830. class CInGameConsole : public IShowActivable, public KeyInterested
  831. {
  832. private:
  833. std::list< std::pair< std::string, int > > texts; //<text to show, time of add>
  834. std::vector< std::string > previouslyEntered; //previously entered texts, for up/down arrows to work
  835. int prevEntDisp; //displayed entry from previouslyEntered - if none it's -1
  836. int defaultTimeout; //timeout for new texts (in ms)
  837. int maxDisplayedTexts; //hiw many texts can be displayed simultaneously
  838. public:
  839. std::string enteredText;
  840. void activate();
  841. void deactivate();
  842. void show(SDL_Surface * to = NULL);
  843. void print(const std::string &txt);
  844. void keyPressed (const SDL_KeyboardEvent & key); //call-in
  845. void startEnteringText();
  846. void endEnteringText(bool printEnteredText);
  847. void refreshEnteredText();
  848. CInGameConsole(); //c-tor
  849. };
  850. extern CPlayerInterface * LOCPLINT;
  851. #endif // __CPLAYERINTERFACE_H__