CAdvmapInterface.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. CDefHandler * arrows;
  142. CTerrainRect();
  143. CPath * currentPath;
  144. void activate();
  145. void deactivate();
  146. void clickLeft(tribool down);
  147. void clickRight(tribool down);
  148. void hover(bool on);
  149. void mouseMoved (SDL_MouseMotionEvent & sEvent);
  150. void keyPressed (SDL_KeyboardEvent & key);
  151. void show();
  152. };
  153. class CResDataBar
  154. :public ClickableR, public virtual CIntObject
  155. {
  156. public:
  157. SDL_Surface * bg;
  158. std::vector<std::pair<int,int> > txtpos;
  159. std::string datetext;
  160. void clickRight (tribool down);
  161. void activate();
  162. void deactivate();
  163. CResDataBar();
  164. ~CResDataBar();
  165. void draw();
  166. };
  167. class CInfoBar
  168. :public virtual CIntObject
  169. {
  170. CInfoBar();
  171. void draw(void * specific=NULL); // if specific==0 function draws info about selected hero/town
  172. };
  173. /*****************************/
  174. class CAdvMapInt //adventure map interface
  175. {
  176. public:
  177. CAdvMapInt(int Player);
  178. ~CAdvMapInt();
  179. int3 position; //top left corner of visible map part
  180. int player;
  181. std::vector<CDefHandler *> gems;
  182. bool scrollingLeft ;
  183. bool scrollingRight ;
  184. bool scrollingUp ;
  185. bool scrollingDown ;
  186. bool updateScreen ;
  187. unsigned char anim, animValHitCount; //animation frame
  188. CMinimap minimap;
  189. SDL_Surface * bg;
  190. AdventureMapButton kingOverview,//- kingdom overview
  191. underground,//- underground switch
  192. questlog,//- questlog
  193. sleepWake, //- sleep/wake hero
  194. moveHero, //- move hero
  195. spellbook,//- spellbook
  196. advOptions, //- adventure options
  197. sysOptions,//- system options
  198. nextHero, //- next hero
  199. endTurn;//- end turn
  200. //CHeroList herolist;
  201. CTerrainRect terrain; //visible terrain
  202. CStatusBar statusbar;
  203. CResDataBar resdatabar;
  204. CHeroList heroList;
  205. CTownList townList;
  206. //fuctions binded to buttons
  207. void fshowOverview();
  208. void fswitchLevel();
  209. void fshowQuestlog();
  210. void fsleepWake();
  211. void fmoveHero();
  212. void fshowSpellbok();
  213. void fadventureOPtions();
  214. void fsystemOptions();
  215. void fnextHero();
  216. void fendTurn();
  217. void show(); //shows and activates adv. map interface
  218. void update(); //redraws terrain
  219. void centerOn(int3 on);
  220. struct CurrentSelection
  221. {
  222. int type; //0 - hero, 1 - town
  223. const void* selected;
  224. CurrentSelection(); //ctor
  225. } selection;
  226. };
  227. #endif //CADVENTUREMAPINTERFACE_H