CPlayerInterface.h 6.4 KB

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