CAdvmapInterface.h 6.8 KB

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