CPlayerInterface.h 23 KB

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