CAdvmapInterface.h 7.3 KB

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