CAdvmapInterface.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 redrawAllOne(int which);
  69. void draw();
  70. void init();
  71. };
  72. class CTownList
  73. : public CList
  74. {
  75. public:
  76. std::vector<const CGTownInstance*> items;
  77. int posporx,pospory;
  78. CTownList();
  79. void genList();
  80. void select(int which);
  81. void mouseMoved (SDL_MouseMotionEvent & sEvent);
  82. void clickLeft(tribool down);
  83. void clickRight(tribool down);
  84. void hover (bool on);
  85. void keyPressed (SDL_KeyboardEvent & key);
  86. void draw();
  87. };
  88. class CResourceBar
  89. :public ClickableR
  90. {
  91. SDL_Surface * bg;
  92. void clickRight(tribool down);
  93. void refresh();
  94. };
  95. class CDataBar
  96. :public ClickableR
  97. {
  98. SDL_Surface * bg;
  99. void clickRight(tribool down);
  100. void refresh();
  101. };
  102. class CStatusBar
  103. : public CIntObject
  104. {
  105. public:
  106. SDL_Surface * bg; //background
  107. int middlex, middley; //middle of statusbar
  108. std::string current; //text currently printed
  109. CStatusBar(int x, int y); //c-tor
  110. ~CStatusBar(); //d-tor
  111. void print(std::string text); //prints text and refreshes statusbar
  112. void clear();//clears statusbar and refreshes
  113. void show(); //shows statusbar (with current text)
  114. };
  115. class CMinimap
  116. : public ClickableL, public ClickableR, public Hoverable, public MotionInterested, public virtual CIntObject
  117. {
  118. public:
  119. SDL_Surface * radar;
  120. SDL_Surface * temps;
  121. std::map<int,SDL_Color> colors;
  122. std::map<int,SDL_Color> colorsBlocked;
  123. std::vector<SDL_Surface *> map; //one bitmap for each level
  124. //TODO flagged buildings
  125. std::string statusbarTxt, rcText;
  126. CMinimap(bool draw=true);
  127. void draw();
  128. void redraw(int level=-1);// (level==-1) => redraw all levels
  129. void updateRadar();
  130. void clickRight (tribool down);
  131. void clickLeft (tribool down);
  132. void hover (bool on);
  133. void mouseMoved (SDL_MouseMotionEvent & sEvent);
  134. void activate(); // makes button active
  135. void deactivate(); // makes button inactive (but don't deletes)
  136. };
  137. class CTerrainRect
  138. : public ClickableL, public ClickableR, public Hoverable, public virtual CIntObject, public KeyInterested,
  139. public MotionInterested
  140. {
  141. public:
  142. int tilesw, tilesh;
  143. int3 curHoveredTile;
  144. CDefHandler * arrows;
  145. CTerrainRect();
  146. CPath * currentPath;
  147. void activate();
  148. void deactivate();
  149. void clickLeft(tribool down);
  150. void clickRight(tribool down);
  151. void hover(bool on);
  152. void mouseMoved (SDL_MouseMotionEvent & sEvent);
  153. void keyPressed (SDL_KeyboardEvent & key);
  154. void show();
  155. int3 whichTileIsIt(int x, int y); //x,y are cursor position
  156. int3 whichTileIsIt(); //uses current cursor pos
  157. };
  158. class CResDataBar
  159. :public ClickableR, public virtual CIntObject
  160. {
  161. public:
  162. SDL_Surface * bg;
  163. std::vector<std::pair<int,int> > txtpos;
  164. std::string datetext;
  165. void clickRight (tribool down);
  166. void activate();
  167. void deactivate();
  168. CResDataBar();
  169. ~CResDataBar();
  170. void draw();
  171. };
  172. class CInfoBar
  173. :public virtual CIntObject
  174. {
  175. public:
  176. CInfoBar();
  177. void draw(void * specific=NULL); // if specific==0 function draws info about selected hero/town
  178. };
  179. /*****************************/
  180. class CAdvMapInt //adventure map interface
  181. {
  182. public:
  183. CAdvMapInt(int Player);
  184. ~CAdvMapInt();
  185. int3 position; //top left corner of visible map part
  186. int player;
  187. std::vector<CDefHandler *> gems;
  188. bool scrollingLeft ;
  189. bool scrollingRight ;
  190. bool scrollingUp ;
  191. bool scrollingDown ;
  192. bool updateScreen, updateMinimap ;
  193. unsigned char anim, animValHitCount; //animation frame
  194. CMinimap minimap;
  195. SDL_Surface * bg;
  196. AdventureMapButton kingOverview,//- kingdom overview
  197. underground,//- underground switch
  198. questlog,//- questlog
  199. sleepWake, //- sleep/wake hero
  200. moveHero, //- move hero
  201. spellbook,//- spellbook
  202. advOptions, //- adventure options
  203. sysOptions,//- system options
  204. nextHero, //- next hero
  205. endTurn;//- end turn
  206. //CHeroList herolist;
  207. CTerrainRect terrain; //visible terrain
  208. CStatusBar statusbar;
  209. CResDataBar resdatabar;
  210. CHeroList heroList;
  211. CTownList townList;
  212. CInfoBar infoBar;
  213. struct CurrentSelection
  214. {
  215. int type; //0 - hero, 1 - town
  216. const void* selected;
  217. CurrentSelection(); //ctor
  218. } selection;
  219. //fuctions binded to buttons
  220. void fshowOverview();
  221. void fswitchLevel();
  222. void fshowQuestlog();
  223. void fsleepWake();
  224. void fmoveHero();
  225. void fshowSpellbok();
  226. void fadventureOPtions();
  227. void fsystemOptions();
  228. void fnextHero();
  229. void fendTurn();
  230. void show(); //shows and activates adv. map interface
  231. void hide(); //deactivates advmap interface
  232. void update(); //redraws terrain
  233. void centerOn(int3 on);
  234. int3 verifyPos(int3 ver);
  235. void handleRightClick(std::string text, tribool down, CIntObject * client);
  236. };
  237. #endif //CADVENTUREMAPINTERFACE_H