CPlayerInterface.h 28 KB

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