CPlayerInterface.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 IActivable
  20. {
  21. public:
  22. virtual void activate()=0;
  23. virtual void deactivate()=0;
  24. };
  25. class CIntObject //interface object
  26. {
  27. public:
  28. SDL_Rect pos;
  29. int ID;
  30. };
  31. class CSimpleWindow : public virtual CIntObject, public IShowable
  32. {
  33. public:
  34. SDL_Surface * bitmap;
  35. CIntObject * owner;
  36. virtual void show(SDL_Surface * to = NULL);
  37. CSimpleWindow():bitmap(NULL),owner(NULL){};
  38. virtual ~CSimpleWindow();
  39. };
  40. class CButtonBase : public virtual CIntObject, public IShowable, public IActivable //basic buttton class
  41. {
  42. public:
  43. int bitmapOffset;
  44. int type; //advmapbutton=2
  45. bool abs;
  46. bool active;
  47. CIntObject * ourObj; // "owner"
  48. int state;
  49. std::vector< std::vector<SDL_Surface*> > imgs;
  50. int curimg;
  51. virtual void show(SDL_Surface * to = NULL);
  52. virtual void activate()=0;
  53. virtual void deactivate()=0;
  54. CButtonBase();
  55. virtual ~CButtonBase(){};
  56. };
  57. class ClickableL : public virtual CIntObject //for left-clicks
  58. {
  59. public:
  60. bool pressedL;
  61. ClickableL();
  62. virtual void clickLeft (tribool down)=0;
  63. virtual void activate()=0;
  64. virtual void deactivate()=0;
  65. };
  66. class ClickableR : public virtual CIntObject //for right-clicks
  67. {
  68. public:
  69. bool pressedR;
  70. ClickableR();
  71. virtual void clickRight (tribool down)=0;
  72. virtual void activate()=0;
  73. virtual void deactivate()=0;
  74. };
  75. class Hoverable : public virtual CIntObject
  76. {
  77. public:
  78. Hoverable(){hovered=false;}
  79. bool hovered;
  80. virtual void hover (bool on)=0;
  81. virtual void activate()=0;
  82. virtual void deactivate()=0;
  83. };
  84. class KeyInterested : public virtual CIntObject
  85. {
  86. public:
  87. virtual void keyPressed (SDL_KeyboardEvent & key)=0;
  88. virtual void activate()=0;
  89. virtual void deactivate()=0;
  90. };
  91. class MotionInterested: public virtual CIntObject
  92. {
  93. public:
  94. virtual void mouseMoved (SDL_MouseMotionEvent & sEvent)=0;
  95. virtual void activate()=0;
  96. virtual void deactivate()=0;
  97. };
  98. class TimeInterested: public virtual CIntObject
  99. {
  100. public:
  101. int toNextTick;
  102. virtual void tick()=0;
  103. virtual void activate();
  104. virtual void deactivate();
  105. };
  106. template <typename T> class CSCButton: public CButtonBase, public ClickableL //prosty guzik, ktory tylko zmienia obrazek
  107. {
  108. public:
  109. int3 posr; //position in the bitmap
  110. int state;
  111. T* delg;
  112. void(T::*func)(tribool);
  113. CSCButton(CDefHandler * img, CIntObject * obj, void(T::*poin)(tribool), T* Delg=NULL);
  114. void clickLeft (tribool down);
  115. void activate();
  116. void deactivate();
  117. void show(SDL_Surface * to = NULL);
  118. };
  119. class CInfoWindow : public CSimpleWindow //text + comp. + ok button
  120. { //okno usuwa swoje komponenty w chwili zamkniecia
  121. public:
  122. CSCButton<CInfoWindow> okb;
  123. std::vector<SComponent*> components;
  124. virtual void okClicked(tribool down);
  125. virtual void close();
  126. CInfoWindow();
  127. virtual ~CInfoWindow();
  128. };
  129. class CSelWindow : public CInfoWindow //component selection window
  130. { //uwaga - to okno nie usuwa swoich komponentow przy usuwaniu, moga sie one jeszcze przydac skryptowi - tak wiec skrypt korzystajacyz tego okna musi je usunac
  131. public:
  132. void selectionChange(CSelectableComponent * to);
  133. void okClicked(tribool down);
  134. void close();
  135. CSelWindow(){};
  136. };
  137. class SComponent : public ClickableR
  138. {
  139. public:
  140. enum Etype
  141. {
  142. primskill, secskill, resource, creature, artifact, experience
  143. } type;
  144. int subtype;
  145. int val;
  146. std::string description; //r-click
  147. std::string subtitle;
  148. SComponent(Etype Type, int Subtype, int Val);
  149. //SComponent(const & SComponent r);
  150. void clickRight (tribool down);
  151. virtual SDL_Surface * getImg();
  152. virtual void activate();
  153. virtual void deactivate();
  154. };
  155. class CSelectableComponent : public SComponent, public ClickableL
  156. {
  157. public:
  158. bool selected;
  159. bool customB;
  160. SDL_Surface * border, *myBitmap;
  161. CSelWindow * owner;
  162. void clickLeft(tribool down);
  163. CSelectableComponent(Etype Type, int Sub, int Val, CSelWindow * Owner=NULL, SDL_Surface * Border=NULL);
  164. ~CSelectableComponent();
  165. void activate();
  166. void deactivate();
  167. void select(bool on);
  168. SDL_Surface * getImg();
  169. };
  170. class CPlayerInterface : public CGameInterface
  171. {
  172. public:
  173. bool makingTurn;
  174. SDL_Event * current;
  175. IActivable *curint;
  176. CAdvMapInt * adventureInt;
  177. CCastleInterface * castleInt;
  178. FPSmanager * mainFPSmng;
  179. //TODO: town interace, battle interface, other interfaces
  180. CCallback * cb;
  181. std::vector<ClickableL*> lclickable;
  182. std::vector<ClickableR*> rclickable;
  183. std::vector<Hoverable*> hoverable;
  184. std::vector<KeyInterested*> keyinterested;
  185. std::vector<MotionInterested*> motioninterested;
  186. std::vector<TimeInterested*> timeinterested;
  187. std::vector<IShowable*> objsToBlit;
  188. SDL_Surface * hInfo;
  189. std::vector<std::pair<int, int> > slotsPos;
  190. CDefEssential *luck22, *luck30, *luck42, *luck82,
  191. *morale22, *morale30, *morale42, *morale82;
  192. std::map<int,SDL_Surface*> heroWins;
  193. //std::map<int,SDL_Surface*> townWins;
  194. //overloaded funcs from Interface
  195. void yourTurn();
  196. void heroMoved(const HeroMoveDetails & details);
  197. void tileRevealed(int3 pos);
  198. void tileHidden(int3 pos);
  199. void heroKilled(const CGHeroInstance* hero);
  200. void heroCreated(const CGHeroInstance* hero);
  201. void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val);
  202. void receivedResource(int type, int val);
  203. void showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID);
  204. void showComp(SComponent comp);
  205. void openTownWindow(const CGTownInstance * town); //shows townscreen
  206. void openHeroWindow(const CGHeroInstance * hero); //shows hero window with given hero
  207. 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*
  208. void handleEvent(SDL_Event * sEvent);
  209. void handleKeyDown(SDL_Event *sEvent);
  210. void handleKeyUp(SDL_Event *sEvent);
  211. void handleMouseMotion(SDL_Event *sEvent);
  212. void init(ICallback * CB);
  213. int3 repairScreenPos(int3 pos);
  214. void showInfoDialog(std::string text, std::vector<SComponent*> & components);
  215. void removeObjToBlit(IShowable* obj);
  216. SDL_Surface * drawHeroInfoWin(const CGHeroInstance * curh);
  217. SDL_Surface * drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from=0, int to=PRIMARY_SKILLS);
  218. SDL_Surface * drawTownInfoWin(const CGTownInstance * curh);
  219. CPlayerInterface(int Player, int serial);
  220. };