CPlayerInterface.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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 CRClickPopup : public IShowable, public ClickableR
  147. {
  148. public:
  149. virtual void activate()=0;
  150. virtual void deactivate()=0;
  151. virtual void close()=0;
  152. virtual ~CRClickPopup(){};
  153. };
  154. class CInfoPopup : public CRClickPopup
  155. {
  156. public:
  157. bool free;
  158. SDL_Surface * bitmap;
  159. CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false);
  160. void clickRight (tribool down);
  161. void activate();
  162. void deactivate();
  163. void close();
  164. void show(SDL_Surface * to = NULL);
  165. ~CInfoPopup(){};
  166. };
  167. class SComponent : public ClickableR
  168. {
  169. public:
  170. enum Etype
  171. {
  172. primskill, secskill, resource, creature, artifact, experience
  173. } type;
  174. int subtype;
  175. int val;
  176. std::string description; //r-click
  177. std::string subtitle;
  178. SComponent(Etype Type, int Subtype, int Val);
  179. //SComponent(const & SComponent r);
  180. void clickRight (tribool down);
  181. virtual SDL_Surface * getImg();
  182. virtual void activate();
  183. virtual void deactivate();
  184. };
  185. class CSelectableComponent : public SComponent, public ClickableL
  186. {
  187. public:
  188. bool selected;
  189. bool customB;
  190. SDL_Surface * border, *myBitmap;
  191. CSelWindow * owner;
  192. void clickLeft(tribool down);
  193. CSelectableComponent(Etype Type, int Sub, int Val, CSelWindow * Owner=NULL, SDL_Surface * Border=NULL);
  194. ~CSelectableComponent();
  195. void activate();
  196. void deactivate();
  197. void select(bool on);
  198. SDL_Surface * getImg();
  199. };
  200. class CGarrisonInt;
  201. class CGarrisonSlot : public ClickableL, public ClickableR, public Hoverable
  202. {
  203. public:
  204. CGarrisonInt *owner;
  205. const CCreature * creature;
  206. int count;
  207. int upg; //0 - up garrison, 1 - down garrison
  208. virtual void hover (bool on);
  209. void clickRight (tribool down);
  210. void clickLeft(tribool down);
  211. void activate();
  212. void deactivate();
  213. void show();
  214. CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg=0, const CCreature * Creature=NULL, int Count=0);
  215. };
  216. class CGarrisonInt :public CIntObject
  217. {
  218. public:
  219. int interx, intery;
  220. CGarrisonSlot *highlighted;
  221. SDL_Surface *sur;
  222. int offx, offy;
  223. bool ignoreEvent, update;
  224. const CCreatureSet *set1;
  225. const CCreatureSet *set2;
  226. std::vector<CGarrisonSlot*> *sup, *sdown;
  227. const CGObjectInstance *oup, *odown;
  228. void activate();
  229. void deactivate();
  230. void show();
  231. void activeteSlots();
  232. void deactiveteSlots();
  233. void deleteSlots();
  234. void createSlots();
  235. void recreateSlots();
  236. CGarrisonInt(int x, int y, int inx, int iny, SDL_Surface *pomsur, int OX, int OY, const CGObjectInstance *s1, const CGObjectInstance *s2=NULL);
  237. ~CGarrisonInt();
  238. };
  239. class CPlayerInterface : public CGameInterface
  240. {
  241. public:
  242. bool makingTurn;
  243. SDL_Event * current;
  244. IActivable *curint;
  245. CAdvMapInt * adventureInt;
  246. CCastleInterface * castleInt;
  247. FPSmanager * mainFPSmng;
  248. IStatusBar *statusbar;
  249. //TODO: town interace, battle interface, other interfaces
  250. CCallback * cb;
  251. std::vector<ClickableL*> lclickable;
  252. std::vector<ClickableR*> rclickable;
  253. std::vector<Hoverable*> hoverable;
  254. std::vector<KeyInterested*> keyinterested;
  255. std::vector<MotionInterested*> motioninterested;
  256. std::vector<TimeInterested*> timeinterested;
  257. std::vector<IShowable*> objsToBlit;
  258. SDL_Surface * hInfo, *tInfo;
  259. std::vector<std::pair<int, int> > slotsPos;
  260. CDefEssential *luck22, *luck30, *luck42, *luck82,
  261. *morale22, *morale30, *morale42, *morale82,
  262. *halls, *forts, *bigTownPic;
  263. std::map<int,SDL_Surface*> heroWins;
  264. std::map<int,SDL_Surface*> townWins;
  265. //overloaded funcs from Interface
  266. void yourTurn();
  267. void heroMoved(const HeroMoveDetails & details);
  268. void tileRevealed(int3 pos);
  269. void tileHidden(int3 pos);
  270. void heroKilled(const CGHeroInstance* hero);
  271. void heroCreated(const CGHeroInstance* hero);
  272. void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val);
  273. void receivedResource(int type, int val);
  274. void showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID);
  275. void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town);
  276. void garrisonChanged(const CGObjectInstance * obj);
  277. //battles
  278. void battleStart(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, tribool side); //called by engine when battle starts; side=0 - left, side=1 - right
  279. void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning
  280. void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
  281. void actionStarted(Action action);//occurs BEFORE every action taken by any stack or by the hero
  282. void actionFinished(Action action);//occurs AFTER every action taken by any stack or by the hero
  283. void activeStack(int stackID); //called when it's turn of that stack
  284. void battleEnd(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2, std::vector<int> capturedArtifacts, int expForWinner, bool winner);
  285. //-------------//
  286. void showComp(SComponent comp);
  287. void openTownWindow(const CGTownInstance * town); //shows townscreen
  288. void openHeroWindow(const CGHeroInstance * hero); //shows hero window with given hero
  289. 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*
  290. void handleEvent(SDL_Event * sEvent);
  291. void handleKeyDown(SDL_Event *sEvent);
  292. void handleKeyUp(SDL_Event *sEvent);
  293. void handleMouseMotion(SDL_Event *sEvent);
  294. void init(ICallback * CB);
  295. int3 repairScreenPos(int3 pos);
  296. void showInfoDialog(std::string text, std::vector<SComponent*> & components);
  297. void removeObjToBlit(IShowable* obj);
  298. SDL_Surface * drawHeroInfoWin(const CGHeroInstance * curh);
  299. SDL_Surface * drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from=0, int to=PRIMARY_SKILLS);
  300. SDL_Surface * drawTownInfoWin(const CGTownInstance * curh);
  301. CPlayerInterface(int Player, int serial);
  302. };
  303. class CStatusBar
  304. : public CIntObject, public IStatusBar
  305. {
  306. public:
  307. SDL_Surface * bg; //background
  308. int middlex, middley; //middle of statusbar
  309. std::string current; //text currently printed
  310. CStatusBar(int x, int y, std::string name="ADROLLVR.bmp", int maxw=-1); //c-tor
  311. ~CStatusBar(); //d-tor
  312. void print(std::string text); //prints text and refreshes statusbar
  313. void clear();//clears statusbar and refreshes
  314. void show(); //shows statusbar (with current text)
  315. std::string getCurrent();
  316. };
  317. class CList
  318. : public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public virtual CIntObject, public MotionInterested
  319. {
  320. public:
  321. SDL_Surface * bg;
  322. CDefHandler *arrup, *arrdo;
  323. SDL_Surface *empty, *selection;
  324. SDL_Rect arrupp, arrdop; //positions of arrows
  325. int posw, posh; //position width/height
  326. int selected, //id of selected position, <0 if none
  327. from;
  328. const int SIZE;
  329. tribool pressed; //true=up; false=down; indeterminate=none
  330. CList(int Size = 5);
  331. void clickLeft(tribool down);
  332. void activate();
  333. void deactivate();
  334. virtual void mouseMoved (SDL_MouseMotionEvent & sEvent)=0;
  335. virtual void genList()=0;
  336. virtual void select(int which)=0;
  337. virtual void draw()=0;
  338. };
  339. class CHeroList
  340. : public CList
  341. {
  342. public:
  343. CDefHandler *mobile, *mana;
  344. std::vector<std::pair<const CGHeroInstance*, CPath *> > items;
  345. int posmobx, posporx, posmanx, posmoby, pospory, posmany;
  346. CHeroList(int Size = 5);
  347. void genList();
  348. void select(int which);
  349. void mouseMoved (SDL_MouseMotionEvent & sEvent);
  350. void clickLeft(tribool down);
  351. void clickRight(tribool down);
  352. void hover (bool on);
  353. void keyPressed (SDL_KeyboardEvent & key);
  354. void updateHList();
  355. void updateMove(const CGHeroInstance* which); //draws move points bar
  356. void redrawAllOne(int which);
  357. void draw();
  358. void init();
  359. };
  360. template<typename T>
  361. class CTownList
  362. : public CList
  363. {
  364. public:
  365. T* owner;
  366. void(T::*fun)();
  367. std::vector<const CGTownInstance*> items;
  368. int posporx,pospory;
  369. CTownList(int Size, SDL_Rect * Pos, int arupx, int arupy, int ardox, int ardoy);
  370. ~CTownList();
  371. void genList();
  372. void select(int which);
  373. void mouseMoved (SDL_MouseMotionEvent & sEvent);
  374. void clickLeft(tribool down);
  375. void clickRight(tribool down);
  376. void hover (bool on);
  377. void keyPressed (SDL_KeyboardEvent & key);
  378. void draw();
  379. };