CPlayerInterface.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. #pragma once
  2. #include "global.h"
  3. #include "CGameInterface.h"
  4. #include "SDL.h"
  5. #include "SDL_framerate.h"
  6. class CDefEssential;
  7. class CDefHandler;
  8. struct HeroMoveDetails;
  9. class CDefEssential;
  10. class CGHeroInstance;
  11. class CAdvMapInt;
  12. class CCastleInterface;
  13. class CStack;
  14. class IShowable
  15. {
  16. public:
  17. virtual void show(SDL_Surface * to = NULL)=0;
  18. };
  19. class IStatusBar
  20. {
  21. public:
  22. virtual ~IStatusBar(){}; //d-tor
  23. virtual void print(std::string text)=0; //prints text and refreshes statusbar
  24. virtual void clear()=0;//clears statusbar and refreshes
  25. virtual void show()=0; //shows statusbar (with current text)
  26. virtual std::string getCurrent()=0;
  27. };
  28. class IActivable
  29. {
  30. public:
  31. virtual void activate()=0;
  32. virtual void deactivate()=0;
  33. virtual ~IActivable(){};
  34. };
  35. class CIntObject //interface object
  36. {
  37. public:
  38. SDL_Rect pos;
  39. int ID;
  40. };
  41. class CSimpleWindow : public virtual CIntObject, public IShowable
  42. {
  43. public:
  44. SDL_Surface * bitmap;
  45. CIntObject * owner;
  46. virtual void show(SDL_Surface * to = NULL);
  47. CSimpleWindow():bitmap(NULL),owner(NULL){};
  48. virtual ~CSimpleWindow();
  49. };
  50. class CButtonBase : public virtual CIntObject, public IShowable, public IActivable //basic buttton class
  51. {
  52. public:
  53. int bitmapOffset;
  54. int type; //advmapbutton=2
  55. bool abs;
  56. bool active;
  57. bool notFreeButton;
  58. CIntObject * ourObj; // "owner"
  59. int state;
  60. std::vector< std::vector<SDL_Surface*> > imgs;
  61. int curimg;
  62. virtual void show(SDL_Surface * to = NULL);
  63. virtual void activate()=0;
  64. virtual void deactivate()=0;
  65. CButtonBase();
  66. virtual ~CButtonBase();
  67. };
  68. class ClickableL : public virtual CIntObject //for left-clicks
  69. {
  70. public:
  71. bool pressedL;
  72. ClickableL();
  73. virtual ~ClickableL(){};
  74. virtual void clickLeft (tribool down)=0;
  75. virtual void activate()=0;
  76. virtual void deactivate()=0;
  77. };
  78. class ClickableR : public virtual CIntObject //for right-clicks
  79. {
  80. public:
  81. bool pressedR;
  82. ClickableR();
  83. virtual ~ClickableR(){};
  84. virtual void clickRight (tribool down)=0;
  85. virtual void activate()=0;
  86. virtual void deactivate()=0;
  87. };
  88. class Hoverable : public virtual CIntObject
  89. {
  90. public:
  91. Hoverable(){hovered=false;}
  92. virtual ~Hoverable(){};
  93. bool hovered;
  94. virtual void hover (bool on)=0;
  95. virtual void activate()=0;
  96. virtual void deactivate()=0;
  97. };
  98. class KeyInterested : public virtual CIntObject
  99. {
  100. public:
  101. virtual ~KeyInterested(){};
  102. virtual void keyPressed (SDL_KeyboardEvent & key)=0;
  103. virtual void activate()=0;
  104. virtual void deactivate()=0;
  105. };
  106. class MotionInterested: public virtual CIntObject
  107. {
  108. public:
  109. virtual ~MotionInterested(){};
  110. virtual void mouseMoved (SDL_MouseMotionEvent & sEvent)=0;
  111. virtual void activate()=0;
  112. virtual void deactivate()=0;
  113. };
  114. class TimeInterested: public virtual CIntObject
  115. {
  116. public:
  117. virtual ~TimeInterested(){};
  118. int toNextTick;
  119. virtual void tick()=0;
  120. virtual void activate();
  121. virtual void deactivate();
  122. };
  123. template <typename T> class CSCButton: public CButtonBase, public ClickableL //prosty guzik, ktory tylko zmienia obrazek
  124. {
  125. public:
  126. int3 posr; //position in the bitmap
  127. int state;
  128. T* delg;
  129. void(T::*func)(tribool);
  130. CSCButton(CDefHandler * img, CIntObject * obj, void(T::*poin)(tribool), T* Delg=NULL);
  131. void clickLeft (tribool down);
  132. void activate();
  133. void deactivate();
  134. void show(SDL_Surface * to = NULL);
  135. };
  136. class CInfoWindow : public CSimpleWindow //text + comp. + ok button
  137. { //okno usuwa swoje komponenty w chwili zamkniecia
  138. public:
  139. CSCButton<CInfoWindow> okb;
  140. std::vector<SComponent*> components;
  141. virtual void okClicked(tribool down);
  142. virtual void close();
  143. CInfoWindow();
  144. virtual ~CInfoWindow();
  145. };
  146. class CSelWindow : public CInfoWindow //component selection window
  147. { //uwaga - to okno nie usuwa swoich komponentow przy usuwaniu, moga sie one jeszcze przydac skryptowi - tak wiec skrypt korzystajacyz tego okna musi je usunac
  148. public:
  149. void selectionChange(CSelectableComponent * to);
  150. void okClicked(tribool down);
  151. void close();
  152. CSelWindow(){};
  153. };
  154. class CRClickPopup : public IShowable, public ClickableR
  155. {
  156. public:
  157. virtual void activate();
  158. virtual void deactivate();
  159. virtual void close()=0;
  160. void clickRight (tribool down);
  161. virtual ~CRClickPopup(){};
  162. };
  163. class CInfoPopup : public CRClickPopup
  164. {
  165. public:
  166. bool free;
  167. SDL_Surface * bitmap;
  168. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false);
  169. void close();
  170. void show(SDL_Surface * to = NULL);
  171. CInfoPopup(){free=false;bitmap=NULL;}
  172. ~CInfoPopup(){};
  173. };
  174. class SComponent : public ClickableR
  175. {
  176. public:
  177. enum Etype
  178. {
  179. primskill, secskill, resource, creature, artifact, experience
  180. } type;
  181. int subtype;
  182. int val;
  183. std::string description; //r-click
  184. std::string subtitle;
  185. SComponent(Etype Type, int Subtype, int Val);
  186. //SComponent(const & SComponent r);
  187. void clickRight (tribool down);
  188. virtual SDL_Surface * getImg();
  189. virtual void activate();
  190. virtual void deactivate();
  191. };
  192. class CSelectableComponent : public SComponent, public ClickableL
  193. {
  194. public:
  195. bool selected;
  196. bool customB;
  197. SDL_Surface * border, *myBitmap;
  198. CSelWindow * owner;
  199. void clickLeft(tribool down);
  200. CSelectableComponent(Etype Type, int Sub, int Val, CSelWindow * Owner=NULL, SDL_Surface * Border=NULL);
  201. ~CSelectableComponent();
  202. void activate();
  203. void deactivate();
  204. void select(bool on);
  205. SDL_Surface * getImg();
  206. };
  207. class CGarrisonInt;
  208. class CGarrisonSlot : public ClickableL, public ClickableR, public Hoverable
  209. {
  210. public:
  211. CGarrisonInt *owner;
  212. const CCreature * creature;
  213. int count;
  214. int upg; //0 - up garrison, 1 - down garrison
  215. virtual void hover (bool on);
  216. void clickRight (tribool down);
  217. void clickLeft(tribool down);
  218. void activate();
  219. void deactivate();
  220. void show();
  221. CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg=0, const CCreature * Creature=NULL, int Count=0);
  222. };
  223. class CGarrisonInt :public CIntObject
  224. {
  225. public:
  226. int interx, intery;
  227. CGarrisonSlot *highlighted;
  228. SDL_Surface *sur;
  229. int offx, offy;
  230. bool ignoreEvent, update;
  231. const CCreatureSet *set1;
  232. const CCreatureSet *set2;
  233. std::vector<CGarrisonSlot*> *sup, *sdown;
  234. const CGObjectInstance *oup, *odown;
  235. void activate();
  236. void deactivate();
  237. void show();
  238. void activeteSlots();
  239. void deactiveteSlots();
  240. void deleteSlots();
  241. void createSlots();
  242. void recreateSlots();
  243. CGarrisonInt(int x, int y, int inx, int iny, SDL_Surface *pomsur, int OX, int OY, const CGObjectInstance *s1, const CGObjectInstance *s2=NULL);
  244. ~CGarrisonInt();
  245. };
  246. class CPlayerInterface : public CGameInterface
  247. {
  248. public:
  249. bool makingTurn;
  250. SDL_Event * current;
  251. IActivable *curint;
  252. CAdvMapInt * adventureInt;
  253. CCastleInterface * castleInt;
  254. FPSmanager * mainFPSmng;
  255. IStatusBar *statusbar;
  256. //TODO: town interace, battle interface, other interfaces
  257. CCallback * cb;
  258. std::vector<ClickableL*> lclickable;
  259. std::vector<ClickableR*> rclickable;
  260. std::vector<Hoverable*> hoverable;
  261. std::vector<KeyInterested*> keyinterested;
  262. std::vector<MotionInterested*> motioninterested;
  263. std::vector<TimeInterested*> timeinterested;
  264. std::vector<IShowable*> objsToBlit;
  265. SDL_Surface * hInfo, *tInfo;
  266. std::vector<std::pair<int, int> > slotsPos;
  267. CDefEssential *luck22, *luck30, *luck42, *luck82,
  268. *morale22, *morale30, *morale42, *morale82,
  269. *halls, *forts, *bigTownPic;
  270. std::map<int,SDL_Surface*> heroWins;
  271. std::map<int,SDL_Surface*> townWins;
  272. //overloaded funcs from Interface
  273. void yourTurn();
  274. void heroMoved(const HeroMoveDetails & details);
  275. void tileRevealed(int3 pos);
  276. void tileHidden(int3 pos);
  277. void heroKilled(const CGHeroInstance* hero);
  278. void heroCreated(const CGHeroInstance* hero);
  279. void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val);
  280. void receivedResource(int type, int val);
  281. void showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID);
  282. void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town);
  283. void garrisonChanged(const CGObjectInstance * obj);
  284. //battles
  285. void battleStart(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, tribool side); //called by engine when battle starts; side=0 - left, side=1 - right
  286. void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning
  287. void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
  288. void actionStarted(Action action);//occurs BEFORE every action taken by any stack or by the hero
  289. void actionFinished(Action action);//occurs AFTER every action taken by any stack or by the hero
  290. void activeStack(int stackID); //called when it's turn of that stack
  291. void battleEnd(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2, std::vector<int> capturedArtifacts, int expForWinner, bool winner);
  292. //-------------//
  293. void showComp(SComponent comp);
  294. void openTownWindow(const CGTownInstance * town); //shows townscreen
  295. void openHeroWindow(const CGHeroInstance * hero); //shows hero window with given hero
  296. SDL_Surface * infoWin(const CGObjectInstance * specific); //specific=0 => draws info about selected town/hero //TODO - gdy sie dorobi sensowna hierarchie klas ins. to wywalic tego brzydkiego void*
  297. void handleEvent(SDL_Event * sEvent);
  298. void handleKeyDown(SDL_Event *sEvent);
  299. void handleKeyUp(SDL_Event *sEvent);
  300. void handleMouseMotion(SDL_Event *sEvent);
  301. void init(ICallback * CB);
  302. int3 repairScreenPos(int3 pos);
  303. void showInfoDialog(std::string text, std::vector<SComponent*> & components);
  304. void removeObjToBlit(IShowable* obj);
  305. SDL_Surface * drawHeroInfoWin(const CGHeroInstance * curh);
  306. SDL_Surface * drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from=0, int to=PRIMARY_SKILLS);
  307. SDL_Surface * drawTownInfoWin(const CGTownInstance * curh);
  308. CPlayerInterface(int Player, int serial);
  309. };
  310. class CStatusBar
  311. : public CIntObject, public IStatusBar
  312. {
  313. public:
  314. SDL_Surface * bg; //background
  315. int middlex, middley; //middle of statusbar
  316. std::string current; //text currently printed
  317. CStatusBar(int x, int y, std::string name="ADROLLVR.bmp", int maxw=-1); //c-tor
  318. ~CStatusBar(); //d-tor
  319. void print(std::string text); //prints text and refreshes statusbar
  320. void clear();//clears statusbar and refreshes
  321. void show(); //shows statusbar (with current text)
  322. std::string getCurrent();
  323. };
  324. class CList
  325. : public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public virtual CIntObject, public MotionInterested
  326. {
  327. public:
  328. SDL_Surface * bg;
  329. CDefHandler *arrup, *arrdo;
  330. SDL_Surface *empty, *selection;
  331. SDL_Rect arrupp, arrdop; //positions of arrows
  332. int posw, posh; //position width/height
  333. int selected, //id of selected position, <0 if none
  334. from;
  335. const int SIZE;
  336. tribool pressed; //true=up; false=down; indeterminate=none
  337. CList(int Size = 5);
  338. void clickLeft(tribool down);
  339. void activate();
  340. void deactivate();
  341. virtual void mouseMoved (SDL_MouseMotionEvent & sEvent)=0;
  342. virtual void genList()=0;
  343. virtual void select(int which)=0;
  344. virtual void draw()=0;
  345. };
  346. class CHeroList
  347. : public CList
  348. {
  349. public:
  350. CDefHandler *mobile, *mana;
  351. std::vector<std::pair<const CGHeroInstance*, CPath *> > items;
  352. int posmobx, posporx, posmanx, posmoby, pospory, posmany;
  353. CHeroList(int Size = 5);
  354. void genList();
  355. void select(int which);
  356. void mouseMoved (SDL_MouseMotionEvent & sEvent);
  357. void clickLeft(tribool down);
  358. void clickRight(tribool down);
  359. void hover (bool on);
  360. void keyPressed (SDL_KeyboardEvent & key);
  361. void updateHList();
  362. void updateMove(const CGHeroInstance* which); //draws move points bar
  363. void redrawAllOne(int which);
  364. void draw();
  365. void init();
  366. };
  367. template<typename T>
  368. class CTownList
  369. : public CList
  370. {
  371. public:
  372. T* owner;
  373. void(T::*fun)();
  374. std::vector<const CGTownInstance*> items;
  375. int posporx,pospory;
  376. CTownList(int Size, SDL_Rect * Pos, int arupx, int arupy, int ardox, int ardoy);
  377. ~CTownList();
  378. void genList();
  379. void select(int which);
  380. void mouseMoved (SDL_MouseMotionEvent & sEvent);
  381. void clickLeft(tribool down);
  382. void clickRight(tribool down);
  383. void hover (bool on);
  384. void keyPressed (SDL_KeyboardEvent & key);
  385. void draw();
  386. };