CPlayerInterface.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. {
  119. public:
  120. CSCButton<CInfoWindow> okb;
  121. std::vector<SComponent*> components;
  122. virtual void okClicked(tribool down);
  123. virtual void close();
  124. CInfoWindow();
  125. ~CInfoWindow();
  126. };
  127. class CSelWindow : public CInfoWindow //component selection window
  128. {
  129. void selectionChange(SComponent * to);
  130. void okClicked(tribool down);
  131. void close();
  132. };
  133. class SComponent : public ClickableR
  134. {
  135. public:
  136. enum Etype
  137. {
  138. primskill, secskill, resource, creature, artifact
  139. } type;
  140. int subtype;
  141. int val;
  142. std::string description; //r-click
  143. std::string subtitle;
  144. SComponent(Etype Type, int Subtype, int Val);
  145. //SComponent(const & SComponent r);
  146. void clickRight (tribool down);
  147. virtual SDL_Surface * getImg();
  148. virtual void activate();
  149. virtual void deactivate();
  150. };
  151. class CSelectableComponent : public SComponent, public ClickableL
  152. {
  153. public:
  154. bool selected;
  155. SDL_Surface * border, *myBitmap;
  156. void clickLeft(tribool down);
  157. CSelectableComponent(Etype Type, int Sub, int Val, SDL_Surface * Border=NULL);
  158. void activate();
  159. void deactivate();
  160. void select(bool on);
  161. SDL_Surface * getImg();
  162. };
  163. class CPlayerInterface : public CGameInterface
  164. {
  165. public:
  166. bool makingTurn;
  167. SDL_Event * current;
  168. CAdvMapInt * adventureInt;
  169. FPSmanager * mainFPSmng;
  170. //TODO: town interace, battle interface, other interfaces
  171. CCallback * cb;
  172. std::vector<ClickableL*> lclickable;
  173. std::vector<ClickableR*> rclickable;
  174. std::vector<Hoverable*> hoverable;
  175. std::vector<KeyInterested*> keyinterested;
  176. std::vector<MotionInterested*> motioninterested;
  177. std::vector<TimeInterested*> timeinterested;
  178. std::vector<IShowable*> objsToBlit;
  179. SDL_Surface * hInfo;
  180. std::vector<std::pair<int, int> > slotsPos;
  181. CDefEssential *luck22, *luck30, *luck42, *luck82,
  182. *morale22, *morale30, *morale42, *morale82;
  183. std::map<int,SDL_Surface*> heroWins;
  184. //std::map<int,SDL_Surface*> townWins;
  185. //overloaded funcs from Interface
  186. void yourTurn();
  187. void heroMoved(const HeroMoveDetails & details);
  188. void tileRevealed(int3 pos);
  189. void tileHidden(int3 pos);
  190. void heroKilled(const CGHeroInstance* hero);
  191. void heroCreated(const CGHeroInstance* hero);
  192. void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val);
  193. void receivedResource(int type, int val);
  194. 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*
  195. void handleEvent(SDL_Event * sEvent);
  196. void init(ICallback * CB);
  197. int3 repairScreenPos(int3 pos);
  198. void showInfoDialog(std::string text, std::vector<SComponent*> & components);
  199. void removeObjToBlit(IShowable* obj);
  200. SDL_Surface * drawHeroInfoWin(const CGHeroInstance * curh);
  201. SDL_Surface * drawTownInfoWin(const CGTownInstance * curh);
  202. CPlayerInterface(int Player, int serial);
  203. };