CPlayerInterface.h 11 KB

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