CAdvmapInterface.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. #ifndef CADVENTUREMAPINTERFACE_H
  2. #define CADVENTUREMAPINTERFACE_H
  3. #include <typeinfo>
  4. #include "global.h"
  5. #include "SDL.h"
  6. #include "CGameInterface.h"
  7. #include <boost/logic/tribool.hpp>
  8. #include <map>
  9. class CDefHandler;
  10. class CCallback;
  11. class CTownInstance;
  12. class CPath;
  13. class CGHeroInstance;
  14. class CGTownInstance;
  15. class AdventureMapButton
  16. : public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public CButtonBase
  17. {
  18. public:
  19. std::string name; //for status bar
  20. std::string helpBox; //for right-click help
  21. char key; //key shortcut
  22. void (CAdvMapInt::*function)(); //function in CAdvMapInt called when this button is pressed, different for each button
  23. void clickRight (tribool down);
  24. void clickLeft (tribool down);
  25. void hover (bool on);
  26. void keyPressed (SDL_KeyboardEvent & key);
  27. void activate(); // makes button active
  28. void deactivate(); // makes button inactive (but doesn't delete)
  29. AdventureMapButton(); //c-tor
  30. 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
  31. };
  32. /*****************************/
  33. class CList
  34. : public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public virtual CIntObject, public MotionInterested
  35. {
  36. public:
  37. SDL_Surface * bg;
  38. CDefHandler *arrup, *arrdo;
  39. SDL_Surface *empty, *selection;
  40. SDL_Rect arrupp, arrdop; //positions of arrows
  41. int posw, posh; //position width/height
  42. int selected, //id of selected position, <0 if none
  43. from;
  44. tribool pressed; //true=up; false=down; indeterminate=none
  45. void clickLeft(tribool down);
  46. void activate();
  47. void deactivate();
  48. virtual void mouseMoved (SDL_MouseMotionEvent & sEvent)=0;
  49. virtual void genList()=0;
  50. virtual void select(int which)=0;
  51. virtual void draw()=0;
  52. };
  53. class CHeroList
  54. : public CList
  55. {
  56. public:
  57. CDefHandler *mobile, *mana;
  58. std::vector<std::pair<const CGHeroInstance*, CPath *> > items;
  59. int posmobx, posporx, posmanx, posmoby, pospory, posmany;
  60. CHeroList();
  61. void genList();
  62. void select(int which);
  63. void mouseMoved (SDL_MouseMotionEvent & sEvent);
  64. void clickLeft(tribool down);
  65. void clickRight(tribool down);
  66. void hover (bool on);
  67. void keyPressed (SDL_KeyboardEvent & key);
  68. void updateHList();
  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, public CIntObject
  91. {
  92. SDL_Surface * bg;
  93. void clickRight(tribool down);
  94. void refresh();
  95. };
  96. class CDataBar
  97. :public ClickableR, public CIntObject
  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; //radar.def; TODO: radars for maps with custom dimensions
  121. SDL_Surface * temps;
  122. std::map<int,SDL_Color> colors;
  123. std::map<int,SDL_Color> colorsBlocked;
  124. std::vector<SDL_Surface *> map; //one bitmap for each level
  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. };
  138. class CTerrainRect
  139. : public ClickableL, public ClickableR, public Hoverable, public virtual CIntObject, public KeyInterested,
  140. public MotionInterested
  141. {
  142. public:
  143. int tilesw, tilesh;
  144. int3 curHoveredTile;
  145. CDefHandler * arrows;
  146. CTerrainRect();
  147. CPath * currentPath;
  148. void activate();
  149. void deactivate();
  150. void clickLeft(tribool down);
  151. void clickRight(tribool down);
  152. void hover(bool on);
  153. void mouseMoved (SDL_MouseMotionEvent & sEvent);
  154. void keyPressed (SDL_KeyboardEvent & key);
  155. void show();
  156. int3 whichTileIsIt(int x, int y); //x,y are cursor position
  157. int3 whichTileIsIt(); //uses current cursor pos
  158. };
  159. class CResDataBar
  160. :public ClickableR, public virtual CIntObject
  161. {
  162. public:
  163. SDL_Surface * bg;
  164. std::vector<std::pair<int,int> > txtpos;
  165. std::string datetext;
  166. void clickRight (tribool down);
  167. void activate();
  168. void deactivate();
  169. CResDataBar();
  170. ~CResDataBar();
  171. void draw();
  172. };
  173. class CInfoBar
  174. :public virtual CIntObject
  175. {
  176. public:
  177. CInfoBar();
  178. void draw(void * specific=NULL); // if specific==0 function draws info about selected hero/town
  179. };
  180. /*****************************/
  181. class CAdvMapInt //adventure map interface
  182. {
  183. public:
  184. CAdvMapInt(int Player);
  185. ~CAdvMapInt();
  186. int3 position; //top left corner of visible map part
  187. int player;
  188. std::vector<CDefHandler *> gems;
  189. bool scrollingLeft ;
  190. bool scrollingRight ;
  191. bool scrollingUp ;
  192. bool scrollingDown ;
  193. bool updateScreen, updateMinimap ;
  194. unsigned char anim, animValHitCount; //animation frame
  195. CMinimap minimap;
  196. SDL_Surface * bg;
  197. AdventureMapButton kingOverview,//- kingdom overview
  198. underground,//- underground switch
  199. questlog,//- questlog
  200. sleepWake, //- sleep/wake hero
  201. moveHero, //- move hero
  202. spellbook,//- spellbook
  203. advOptions, //- adventure options
  204. sysOptions,//- system options
  205. nextHero, //- next hero
  206. endTurn;//- end turn
  207. //CHeroList herolist;
  208. CTerrainRect terrain; //visible terrain
  209. CStatusBar statusbar;
  210. CResDataBar resdatabar;
  211. CHeroList heroList;
  212. CTownList townList;
  213. CInfoBar infoBar;
  214. struct CurrentSelection
  215. {
  216. int type; //0 - hero, 1 - town
  217. const void* selected;
  218. CurrentSelection(); //ctor
  219. } selection;
  220. //fuctions binded to buttons
  221. void fshowOverview();
  222. void fswitchLevel();
  223. void fshowQuestlog();
  224. void fsleepWake();
  225. void fmoveHero();
  226. void fshowSpellbok();
  227. void fadventureOPtions();
  228. void fsystemOptions();
  229. void fnextHero();
  230. void fendTurn();
  231. void show(); //shows and activates adv. map interface
  232. void hide(); //deactivates advmap interface
  233. void update(); //redraws terrain
  234. void centerOn(int3 on);
  235. int3 verifyPos(int3 ver);
  236. void handleRightClick(std::string text, tribool down, CIntObject * client);
  237. };
  238. #endif //CADVENTUREMAPINTERFACE_H