CAdvmapInterface.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. #ifndef CADVENTUREMAPINTERFACE_H
  2. #define CADVENTUREMAPINTERFACE_H
  3. #include <typeinfo>
  4. #include "global.h"
  5. #include "SDL.h"
  6. #include "CPlayerInterface.h"
  7. #include <map>
  8. class CDefHandler;
  9. class CCallback;
  10. class CTownInstance;
  11. class CPath;
  12. class CAdvMapInt;
  13. class CGHeroInstance;
  14. class CGTownInstance;
  15. template <typename T=CAdvMapInt>
  16. class AdventureMapButton
  17. : public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public CButtonBase
  18. {
  19. public:
  20. std::string name; //for status bar
  21. std::string helpBox; //for right-click help
  22. char key; //key shortcut
  23. T* owner;
  24. void (T::*function)(); //function in CAdvMapInt called when this button is pressed, different for each button
  25. void clickRight (tribool down);
  26. void clickLeft (tribool down);
  27. void hover (bool on);
  28. void keyPressed (SDL_KeyboardEvent & key);
  29. void activate(); // makes button active
  30. void deactivate(); // makes button inactive (but doesn't delete)
  31. AdventureMapButton(); //c-tor
  32. AdventureMapButton( std::string Name, std::string HelpBox, void(T::*Function)(), int x, int y, std::string defName, T* Owner, bool activ=false, std::vector<std::string> * add = NULL );//c-tor
  33. };
  34. /*****************************/
  35. class CList
  36. : public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public virtual CIntObject, public MotionInterested
  37. {
  38. public:
  39. SDL_Surface * bg;
  40. CDefHandler *arrup, *arrdo;
  41. SDL_Surface *empty, *selection;
  42. SDL_Rect arrupp, arrdop; //positions of arrows
  43. int posw, posh; //position width/height
  44. int selected, //id of selected position, <0 if none
  45. from;
  46. tribool pressed; //true=up; false=down; indeterminate=none
  47. void clickLeft(tribool down);
  48. void activate();
  49. void deactivate();
  50. virtual void mouseMoved (SDL_MouseMotionEvent & sEvent)=0;
  51. virtual void genList()=0;
  52. virtual void select(int which)=0;
  53. virtual void draw()=0;
  54. };
  55. class CHeroList
  56. : public CList
  57. {
  58. public:
  59. CDefHandler *mobile, *mana;
  60. std::vector<std::pair<const CGHeroInstance*, CPath *> > items;
  61. int posmobx, posporx, posmanx, posmoby, pospory, posmany;
  62. CHeroList();
  63. void genList();
  64. void select(int which);
  65. void mouseMoved (SDL_MouseMotionEvent & sEvent);
  66. void clickLeft(tribool down);
  67. void clickRight(tribool down);
  68. void hover (bool on);
  69. void keyPressed (SDL_KeyboardEvent & key);
  70. void updateHList();
  71. void updateMove(const CGHeroInstance* which); //draws move points bar
  72. void redrawAllOne(int which);
  73. void draw();
  74. void init();
  75. };
  76. class CTownList
  77. : public CList
  78. {
  79. public:
  80. std::vector<const CGTownInstance*> items;
  81. int posporx,pospory;
  82. CTownList();
  83. void genList();
  84. void select(int which);
  85. void mouseMoved (SDL_MouseMotionEvent & sEvent);
  86. void clickLeft(tribool down);
  87. void clickRight(tribool down);
  88. void hover (bool on);
  89. void keyPressed (SDL_KeyboardEvent & key);
  90. void draw();
  91. };
  92. class CStatusBar
  93. : public CIntObject
  94. {
  95. public:
  96. SDL_Surface * bg; //background
  97. int middlex, middley; //middle of statusbar
  98. std::string current; //text currently printed
  99. CStatusBar(int x, int y); //c-tor
  100. ~CStatusBar(); //d-tor
  101. void print(std::string text); //prints text and refreshes statusbar
  102. void clear();//clears statusbar and refreshes
  103. void show(); //shows statusbar (with current text)
  104. };
  105. class CMinimap
  106. : public ClickableL, public ClickableR, public Hoverable, public MotionInterested, public virtual CIntObject
  107. {
  108. public:
  109. SDL_Surface * radar;
  110. SDL_Surface * temps;
  111. std::map<int,SDL_Color> colors;
  112. std::map<int,SDL_Color> colorsBlocked;
  113. std::vector<SDL_Surface *> map, FoW; //one bitmap for each level (terrain, Fog of War)
  114. //TODO flagged buildings
  115. std::string statusbarTxt, rcText;
  116. CMinimap(bool draw=true);
  117. void draw();
  118. void redraw(int level=-1);// (level==-1) => redraw all levels
  119. void updateRadar();
  120. void clickRight (tribool down);
  121. void clickLeft (tribool down);
  122. void hover (bool on);
  123. void mouseMoved (SDL_MouseMotionEvent & sEvent);
  124. void activate(); // makes button active
  125. void deactivate(); // makes button inactive (but don't deletes)
  126. void hideTile(int3 pos); //puts FoW
  127. void showTile(int3 pos); //removes FoW
  128. };
  129. class CTerrainRect
  130. : public ClickableL, public ClickableR, public Hoverable, public virtual CIntObject, public KeyInterested,
  131. public MotionInterested
  132. {
  133. public:
  134. int tilesw, tilesh;
  135. int3 curHoveredTile;
  136. CDefHandler * arrows;
  137. CTerrainRect();
  138. CPath * currentPath;
  139. void activate();
  140. void deactivate();
  141. void clickLeft(tribool down);
  142. void clickRight(tribool down);
  143. void hover(bool on);
  144. void mouseMoved (SDL_MouseMotionEvent & sEvent);
  145. void keyPressed (SDL_KeyboardEvent & key);
  146. void show();
  147. void showPath();
  148. int3 whichTileIsIt(int x, int y); //x,y are cursor position
  149. int3 whichTileIsIt(); //uses current cursor pos
  150. };
  151. class CResDataBar
  152. :public ClickableR, public virtual CIntObject
  153. {
  154. public:
  155. SDL_Surface * bg;
  156. std::vector<std::pair<int,int> > txtpos;
  157. std::string datetext;
  158. void clickRight (tribool down);
  159. void activate();
  160. void deactivate();
  161. CResDataBar();
  162. ~CResDataBar();
  163. void draw();
  164. };
  165. class CInfoBar
  166. :public virtual CIntObject, public TimeInterested
  167. {
  168. public:
  169. CDefHandler *day, *week1, *week2, *week3, *week4;
  170. SComponent * current;
  171. int mode;
  172. int pom;
  173. CInfoBar();
  174. ~CInfoBar();
  175. void newDay(int Day);
  176. void showComp(SComponent * comp, int time=5000);
  177. void tick();
  178. void draw(const CGObjectInstance * specific=NULL); // if specific==0 function draws info about selected hero/town
  179. void blitAnim(int mode);//0 - day, 1 - week
  180. CDefHandler * getAnim(int mode);
  181. };
  182. /*****************************/
  183. class CAdvMapInt //adventure map interface
  184. {
  185. public:
  186. CAdvMapInt(int Player);
  187. ~CAdvMapInt();
  188. int3 position; //top left corner of visible map part
  189. int player;
  190. std::vector<CDefHandler *> gems;
  191. bool scrollingLeft ;
  192. bool scrollingRight ;
  193. bool scrollingUp ;
  194. bool scrollingDown ;
  195. bool updateScreen, updateMinimap ;
  196. unsigned char anim, animValHitCount; //animation frame
  197. unsigned char heroAnim, heroAnimValHitCount; //animation frame
  198. CMinimap minimap;
  199. SDL_Surface * bg;
  200. AdventureMapButton<> kingOverview,//- kingdom overview
  201. underground,//- underground switch
  202. questlog,//- questlog
  203. sleepWake, //- sleep/wake hero
  204. moveHero, //- move hero
  205. spellbook,//- spellbook
  206. advOptions, //- adventure options
  207. sysOptions,//- system options
  208. nextHero, //- next hero
  209. endTurn;//- end turn
  210. //CHeroList herolist;
  211. CTerrainRect terrain; //visible terrain
  212. CStatusBar statusbar;
  213. CResDataBar resdatabar;
  214. CHeroList heroList;
  215. CTownList townList;
  216. CInfoBar infoBar;
  217. struct CurrentSelection
  218. {
  219. int type; //0 - hero, 1 - town
  220. const void* selected;
  221. CurrentSelection(); //ctor
  222. } selection;
  223. //fuctions binded to buttons
  224. void fshowOverview();
  225. void fswitchLevel();
  226. void fshowQuestlog();
  227. void fsleepWake();
  228. void fmoveHero();
  229. void fshowSpellbok();
  230. void fadventureOPtions();
  231. void fsystemOptions();
  232. void fnextHero();
  233. void fendTurn();
  234. void show(); //shows and activates adv. map interface
  235. void hide(); //deactivates advmap interface
  236. void update(); //redraws terrain
  237. void centerOn(int3 on);
  238. int3 verifyPos(int3 ver);
  239. void handleRightClick(std::string text, tribool down, CIntObject * client);
  240. };
  241. #endif //CADVENTUREMAPINTERFACE_H