CPlayerInterface.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  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. bool stillMoveHero;
  420. std::list<CInfoWindow *> dialogs;
  421. //GUI elements
  422. std::list<ClickableL*> lclickable;
  423. std::list<ClickableR*> rclickable;
  424. std::list<Hoverable*> hoverable;
  425. std::list<KeyInterested*> keyinterested;
  426. std::list<MotionInterested*> motioninterested;
  427. std::list<TimeInterested*> timeinterested;
  428. std::vector<IShowable*> objsToBlit;
  429. //overloaded funcs from CGameInterface
  430. void buildChanged(const CGTownInstance *town, int buildingID, int what); //what: 1 - built, 2 - demolished
  431. void garrisonChanged(const CGObjectInstance * obj);
  432. void heroArtifactSetChanged(const CGHeroInstance*hero);
  433. void heroCreated(const CGHeroInstance* hero);
  434. void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback);
  435. void heroInGarrisonChange(const CGTownInstance *town);
  436. void heroKilled(const CGHeroInstance* hero);
  437. void heroMoved(const HeroMoveDetails & details);
  438. void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val);
  439. void heroManaPointsChanged(const CGHeroInstance * hero);
  440. void heroMovePointsChanged(const CGHeroInstance * hero);
  441. void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town);
  442. void receivedResource(int type, int val);
  443. void showInfoDialog(std::string &text, const std::vector<Component*> &components);
  444. void showSelDialog(std::string &text, const std::vector<Component*> &components, ui32 askID);
  445. void showYesNoDialog(std::string &text, const std::vector<Component*> &components, ui32 askID);
  446. void tileHidden(const std::set<int3> &pos);
  447. void tileRevealed(const std::set<int3> &pos);
  448. void yourTurn();
  449. void availableCreaturesChanged(const CGTownInstance *town);
  450. void heroBonusChanged(const CGHeroInstance *hero, const HeroBonus &bonus, bool gain);//if gain hero received bonus, else he lost it
  451. //for battles
  452. void actionFinished(const BattleAction* action);//occurs AFTER action taken by active stack or by the hero
  453. void actionStarted(const BattleAction* action);//occurs BEFORE action taken by active stack or by the hero
  454. BattleAction activeStack(int stackID); //called when it's turn of that stack
  455. void battleAttack(BattleAttack *ba); //stack performs attack
  456. void battleEnd(BattleResult *br);
  457. void battleResultQuited();
  458. void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
  459. void battleStackMoved(int ID, int dest, int distance);
  460. void battleSpellCasted(SpellCasted *sc);
  461. void battleStackAttacked(BattleStackAttacked * bsa);
  462. 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
  463. void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning
  464. //-------------//
  465. void redrawHeroWin(const CGHeroInstance * hero);
  466. void updateWater();
  467. void showComp(SComponent comp);
  468. void openTownWindow(const CGTownInstance * town); //shows townscreen
  469. void openHeroWindow(const CGHeroInstance * hero); //shows hero window with given hero
  470. SDL_Surface * infoWin(const CGObjectInstance * specific); //specific=0 => draws info about selected town/hero
  471. void handleEvent(SDL_Event * sEvent);
  472. void handleKeyDown(SDL_Event *sEvent);
  473. void handleKeyUp(SDL_Event *sEvent);
  474. void handleMouseMotion(SDL_Event *sEvent);
  475. void init(ICallback * CB);
  476. int3 repairScreenPos(int3 pos);
  477. void removeObjToBlit(IShowable* obj);
  478. void showInfoDialog(std::string &text, const std::vector<SComponent*> & components);
  479. 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
  480. bool moveHero(const CGHeroInstance *h, CPath * path);
  481. CPlayerInterface(int Player, int serial);//c-tor
  482. ~CPlayerInterface();//d-tor
  483. };
  484. class CStatusBar
  485. : public CIntObject, public IStatusBar
  486. {
  487. public:
  488. SDL_Surface * bg; //background
  489. int middlex, middley; //middle of statusbar
  490. std::string current; //text currently printed
  491. CStatusBar(int x, int y, std::string name="ADROLLVR.bmp", int maxw=-1); //c-tor
  492. ~CStatusBar(); //d-tor
  493. void print(const std::string & text); //prints text and refreshes statusbar
  494. void clear();//clears statusbar and refreshes
  495. void show(); //shows statusbar (with current text)
  496. std::string getCurrent();
  497. };
  498. class CList
  499. : public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public virtual CIntObject, public MotionInterested
  500. {
  501. public:
  502. SDL_Surface * bg;
  503. CDefHandler *arrup, *arrdo;
  504. SDL_Surface *empty, *selection;
  505. SDL_Rect arrupp, arrdop; //positions of arrows
  506. int posw, posh; //position width/height
  507. int selected, //id of selected position, <0 if none
  508. from;
  509. const int SIZE;
  510. boost::logic::tribool pressed; //true=up; false=down; indeterminate=none
  511. CList(int Size = 5);
  512. void clickLeft(boost::logic::tribool down);
  513. void activate();
  514. void deactivate();
  515. virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0;
  516. virtual void genList()=0;
  517. virtual void select(int which)=0;
  518. virtual void draw()=0;
  519. };
  520. class CHeroList
  521. : public CList
  522. {
  523. public:
  524. CDefHandler *mobile, *mana;
  525. std::vector<std::pair<const CGHeroInstance*, CPath *> > items;
  526. int posmobx, posporx, posmanx, posmoby, pospory, posmany;
  527. CHeroList(int Size);
  528. int getPosOfHero(const CArmedInstance* h);
  529. void genList();
  530. void select(int which);
  531. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  532. void clickLeft(boost::logic::tribool down);
  533. void clickRight(boost::logic::tribool down);
  534. void hover (bool on);
  535. void keyPressed (const SDL_KeyboardEvent & key);
  536. void updateHList();
  537. void updateMove(const CGHeroInstance* which); //draws move points bar
  538. void redrawAllOne(int which);
  539. void draw();
  540. void init();
  541. };
  542. class CTownList
  543. : public CList
  544. {
  545. public:
  546. boost::function<void()> fun;
  547. std::vector<const CGTownInstance*> items;
  548. int posporx,pospory;
  549. CTownList(int Size, int x, int y, std::string arrupg, std::string arrdog);
  550. ~CTownList();
  551. void genList();
  552. void select(int which);
  553. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  554. void clickLeft(boost::logic::tribool down);
  555. void clickRight(boost::logic::tribool down);
  556. void hover (bool on);
  557. void keyPressed (const SDL_KeyboardEvent & key);
  558. void draw();
  559. };
  560. class CCreaturePic //draws picture with creature on background, use nextFrame=true to get animation
  561. {
  562. public:
  563. bool big; //big => 100x130; !big => 100x120
  564. CCreature *c;
  565. CCreatureAnimation *anim;
  566. CCreaturePic(CCreature *cre, bool Big=true);
  567. ~CCreaturePic();
  568. int blitPic(SDL_Surface *to, int x, int y, bool nextFrame);
  569. SDL_Surface * getPic(bool nextFrame);
  570. };
  571. class CRecrutationWindow : public IShowable, public ClickableL, public ClickableR
  572. {
  573. public:
  574. struct creinfo
  575. {
  576. SDL_Rect pos;
  577. CCreaturePic *pic;
  578. int ID, amount; //creature ID and available amount
  579. std::vector<std::pair<int,int> > res; //res_id - cost_per_unit
  580. };
  581. std::vector<int> amounts; //how many creatures we can afford
  582. std::vector<creinfo> creatures;
  583. boost::function<void(int,int)> recruit; //void (int ID, int amount) <-- call to recruit creatures
  584. CSlider *slider;
  585. AdventureMapButton *max, *buy, *cancel;
  586. SDL_Surface *bitmap;
  587. CStatusBar *bar;
  588. int which; //which creature is active
  589. void close();
  590. void Max();
  591. void Buy();
  592. void Cancel();
  593. void sliderMoved(int to);
  594. void clickLeft(boost::logic::tribool down);
  595. void clickRight(boost::logic::tribool down);
  596. void activate();
  597. void deactivate();
  598. void show(SDL_Surface * to = NULL);
  599. CRecrutationWindow(const std::vector<std::pair<int,int> > & Creatures, const boost::function<void(int,int)> & Recruit); //creatures - pairs<creature_ID,amount>
  600. ~CRecrutationWindow();
  601. };
  602. class CSplitWindow : public IShowable, public KeyInterested, public ClickableL
  603. {
  604. public:
  605. CGarrisonInt *gar;
  606. CSlider *slider;
  607. CCreaturePic *anim;
  608. AdventureMapButton *ok, *cancel;
  609. SDL_Surface *bitmap;
  610. int a1, a2, c;
  611. bool which;
  612. CSplitWindow(int cid, int max, CGarrisonInt *Owner);
  613. ~CSplitWindow();
  614. void activate();
  615. void split();
  616. void close();
  617. void deactivate();
  618. void show(SDL_Surface * to = NULL);
  619. void clickLeft(boost::logic::tribool down);
  620. void keyPressed (const SDL_KeyboardEvent & key);
  621. void sliderMoved(int to);
  622. };
  623. class CCreInfoWindow : public IShowable, public KeyInterested, public ClickableR
  624. {
  625. public:
  626. bool active;
  627. int type;//0 - rclick popup; 1 - normal window
  628. SDL_Surface *bitmap;
  629. char anf;
  630. std::string count; //creature count in text format
  631. boost::function<void()> dsm;
  632. CCreaturePic *anim;
  633. CCreature *c;
  634. CInfoWindow *dependant; //it may be dialog asking whther upgrade/dismiss stack (if opened)
  635. std::vector<SComponent*> upgResCost; //cost of upgrade (if not possible then empty)
  636. AdventureMapButton *dismiss, *upgrade, *ok;
  637. CCreInfoWindow(int Cid, int Type, int creatureCount, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm, UpgradeInfo *ui);
  638. ~CCreInfoWindow();
  639. void activate();
  640. void close();
  641. void clickRight(boost::logic::tribool down);
  642. void dismissF();
  643. void keyPressed (const SDL_KeyboardEvent & key);
  644. void deactivate();
  645. void show(SDL_Surface * to = NULL);
  646. void onUpgradeYes();
  647. void onUpgradeNo();
  648. };
  649. class CLevelWindow : public IShowable, public CIntObject
  650. {
  651. public:
  652. int heroType;
  653. SDL_Surface *bitmap;
  654. std::vector<CSelectableComponent *> comps; //skills to select
  655. AdventureMapButton *ok;
  656. boost::function<void(ui32)> cb;
  657. void close();
  658. CLevelWindow(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback);
  659. ~CLevelWindow();
  660. void activate();
  661. void deactivate();
  662. void selectionChanged(unsigned to);
  663. void show(SDL_Surface * to = NULL);
  664. };
  665. class CMinorResDataBar : public IShowable, public CIntObject
  666. {
  667. public:
  668. SDL_Surface *bg;
  669. void show(SDL_Surface * to=NULL);
  670. CMinorResDataBar();
  671. ~CMinorResDataBar();
  672. };
  673. class CMarketplaceWindow : public IShowActivable, public CIntObject
  674. {
  675. public:
  676. class CTradeableItem : public ClickableL
  677. {
  678. public:
  679. int type; //0 - res, 1 - artif big, 2 - artif small, 3 - player flag
  680. int id;
  681. bool left;
  682. CFunctionList<void()> callback;
  683. void activate();
  684. void deactivate();
  685. void show(SDL_Surface * to=NULL);
  686. void clickLeft(boost::logic::tribool down);
  687. SDL_Surface *getSurface();
  688. CTradeableItem(int Type, int ID, bool Left);
  689. };
  690. SDL_Surface *bg;
  691. std::vector<CTradeableItem*> left, right;
  692. std::vector<std::string> rSubs;
  693. CTradeableItem *hLeft, *hRight; //highlighted items (NULL if no highlight)
  694. int mode,//0 - res<->res; 1 - res<->plauer; 2 - buy artifact; 3 - sell artifact
  695. r1, r2;
  696. AdventureMapButton *ok, *max, *deal;
  697. CSlider *slider;
  698. void activate();
  699. void deactivate();
  700. void show(SDL_Surface * to=NULL);
  701. void setMax();
  702. void sliderMoved(int to);
  703. void makeDeal();
  704. void selectionChanged(bool side); //true == left
  705. CMarketplaceWindow(int Mode=0);
  706. ~CMarketplaceWindow();
  707. void setMode(int mode);
  708. void clear();
  709. };
  710. class CSystemOptionsWindow : public IShowActivable, public CIntObject
  711. {
  712. private:
  713. SDL_Surface * background; //background of window
  714. AdventureMapButton * quitGame, * backToMap;
  715. CHighlightableButtonsGroup * heroMoveSpeed;
  716. CHighlightableButtonsGroup * mapScrollSpeed;
  717. public:
  718. CSystemOptionsWindow(const SDL_Rect & pos, CPlayerInterface * owner); //c-tor
  719. ~CSystemOptionsWindow(); //d-tor
  720. //functions for butons
  721. void bquitf(); //quit game
  722. void breturnf(); //return to game
  723. void activate();
  724. void deactivate();
  725. void show(SDL_Surface * to = NULL);
  726. };
  727. class CTavernWindow : public IShowActivable, public CIntObject
  728. {
  729. public:
  730. class HeroPortrait : public ClickableL, public ClickableR, public Hoverable
  731. {
  732. public:
  733. std::string hoverName;
  734. vstd::assigner<int,int> as;
  735. const CGHeroInstance *h;
  736. void activate();
  737. void deactivate();
  738. void clickLeft(boost::logic::tribool down);
  739. void clickRight(boost::logic::tribool down);
  740. void hover (bool on);
  741. HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H);
  742. void show(SDL_Surface * to = NULL);
  743. } h1, h2;
  744. SDL_Surface *bg;
  745. CStatusBar *bar;
  746. int selected;//0 (left) or 1 (right)
  747. AdventureMapButton *thiefGuild, *cancel, *recruit;
  748. CTavernWindow(const CGHeroInstance *H1, const CGHeroInstance *H2, const std::string &gossip); //c-tor
  749. ~CTavernWindow(); //d-tor
  750. void recruitb();
  751. void close();
  752. void activate();
  753. void deactivate();
  754. void show(SDL_Surface * to = NULL);
  755. };
  756. extern CPlayerInterface * LOCPLINT;
  757. #endif // __CPLAYERINTERFACE_H__