CPlayerInterface.h 8.7 KB

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