CAdvmapInterface.h 7.3 KB

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