CAdvmapInterface.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #ifndef __CADVMAPINTERFACE_H__
  2. #define __CADVMAPINTERFACE_H__
  3. #include <typeinfo>
  4. #include "../global.h"
  5. #include "SDL.h"
  6. #include <map>
  7. #include "AdventureMapButton.h"
  8. #include "GUIClasses.h"
  9. class CDefHandler;
  10. class CCallback;
  11. struct CGPath;
  12. class CAdvMapInt;
  13. class CGHeroInstance;
  14. class CGTownInstance;
  15. class CHeroWindow;
  16. class CSpell;
  17. class IShipyard;
  18. /*****************************/
  19. /*
  20. * CAdcmapInterface.h, part of VCMI engine
  21. *
  22. * Authors: listed in file AUTHORS in main folder
  23. *
  24. * License: GNU General Public License v2.0 or later
  25. * Full text of license available in license.txt file, in main folder
  26. *
  27. */
  28. /// Adventure options dialogue where you can view the world, dig, play the replay of the last turn,...
  29. class CAdventureOptions : public CIntObject
  30. {
  31. public:
  32. CPicture *bg;
  33. AdventureMapButton *exit, *viewWorld, *puzzle, *dig, *scenInfo, *replay;
  34. CAdventureOptions();
  35. ~CAdventureOptions();
  36. static void showScenarioInfo();
  37. };
  38. /// Minimap which is displayed at the right upper corner of adventure map
  39. class CMinimap : public CIntObject
  40. {
  41. public:
  42. SDL_Surface * temps;
  43. std::map<int,SDL_Color> colors;
  44. std::map<int,SDL_Color> colorsBlocked;
  45. std::vector<SDL_Surface *> map, FoW, flObjs; //one bitmap for each level (terrain, Fog of War, flaggable objects)
  46. std::string statusbarTxt, rcText;
  47. CMinimap(bool draw=true);
  48. ~CMinimap();
  49. void show(SDL_Surface * to);
  50. void draw(SDL_Surface * to);
  51. void redraw(int level=-1);// (level==-1) => redraw all levels
  52. void initMap(int level=-1);// (level==-1) => redraw all levels
  53. void initFoW(int level=-1);// (level==-1) => redraw all levels
  54. void initFlaggableObjs(int level=-1);// (level==-1) => redraw all levels
  55. void updateRadar();
  56. void clickRight(tribool down, bool previousState);
  57. void clickLeft(tribool down, bool previousState);
  58. void hover (bool on);
  59. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  60. void activate(); // makes button active
  61. void deactivate(); // makes button inactive (but don't deletes)
  62. void hideTile(const int3 &pos); //puts FoW
  63. void showTile(const int3 &pos); //removes FoW
  64. void showVisibleTiles(int level=-1);// (level==-1) => redraw all levels
  65. };
  66. /// Holds information about which tiles of the terrain are shown/not shown at the screen
  67. class CTerrainRect
  68. : public CIntObject
  69. {
  70. public:
  71. int tilesw, tilesh; //width and height of terrain to blit in tiles
  72. int3 curHoveredTile;
  73. int moveX, moveY; //shift between actual position of screen and the one we wil blit; ranges from -31 to 31 (in pixels)
  74. CTerrainRect();
  75. ~CTerrainRect();
  76. CGPath * currentPath;
  77. void activate();
  78. void deactivate();
  79. void clickLeft(tribool down, bool previousState);
  80. void clickRight(tribool down, bool previousState);
  81. void hover(bool on);
  82. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  83. void show(SDL_Surface * to);
  84. void showPath(const SDL_Rect * extRect, SDL_Surface * to);
  85. int3 whichTileIsIt(const int & x, const int & y); //x,y are cursor position
  86. int3 whichTileIsIt(); //uses current cursor pos
  87. };
  88. /// Resources bar which shows information about how many gold, crystals,... you have
  89. /// Current date is displayed too
  90. class CResDataBar
  91. : public CIntObject
  92. {
  93. public:
  94. SDL_Surface * bg;
  95. std::vector<std::pair<int,int> > txtpos;
  96. std::string datetext;
  97. void clickRight(tribool down, bool previousState);
  98. void activate();
  99. void deactivate();
  100. CResDataBar();
  101. CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist);
  102. ~CResDataBar();
  103. void draw(SDL_Surface * to);
  104. void show(SDL_Surface * to);
  105. void showAll(SDL_Surface * to);
  106. };
  107. /// Info box which shows next week/day information, hold the current date
  108. class CInfoBar : public CIntObject
  109. {
  110. CDefHandler *day, *week1, *week2, *week3, *week4;
  111. SComponent * current;
  112. int pom;
  113. SDL_Surface *selInfoWin; //info box for selection
  114. CDefHandler * getAnim(int mode);
  115. public:
  116. int mode;
  117. const CGHeroInstance * curSel;
  118. CInfoBar();
  119. ~CInfoBar();
  120. void newDay(int Day); //start showing new day/week animation
  121. void showComp(SComponent * comp, int time=5000);
  122. void tick();
  123. void showAll(SDL_Surface * to); // if specific==0 function draws info about selected hero/town
  124. void blitAnim(int mode);//0 - day, 1 - week
  125. void show(SDL_Surface * to);
  126. void activate();
  127. void deactivate();
  128. void updateSelection(const CGObjectInstance *obj);
  129. };
  130. /// That's a huge class which handles general adventure map actions and
  131. /// shows the right menu(questlog, spellbook, end turn,..) from where you
  132. /// can get to the towns and heroes.
  133. class CAdvMapInt : public CIntObject
  134. {
  135. public:
  136. CAdvMapInt();
  137. ~CAdvMapInt();
  138. int3 position; //top left corner of visible map part
  139. int player;
  140. enum{LEFT=1, RIGHT=2, UP=4, DOWN=8};
  141. ui8 scrollingDir; //uses enum: LEFT RIGHT, UP, DOWN
  142. enum{NA, INGAME, WAITING} state;
  143. bool updateScreen, updateMinimap ;
  144. unsigned char anim, animValHitCount; //animation frame
  145. unsigned char heroAnim, heroAnimValHitCount; //animation frame
  146. SDL_Surface * bg;
  147. std::vector<CDefHandler *> gems;
  148. CMinimap minimap;
  149. CStatusBar statusbar;
  150. AdventureMapButton kingOverview,//- kingdom overview
  151. underground,//- underground switch
  152. questlog,//- questlog
  153. sleepWake, //- sleep/wake hero
  154. moveHero, //- move hero
  155. spellbook,//- spellbook
  156. advOptions, //- adventure options
  157. sysOptions,//- system options
  158. nextHero, //- next hero
  159. endTurn;//- end turn
  160. CTerrainRect terrain; //visible terrain
  161. CResDataBar resdatabar;
  162. CHeroList heroList;
  163. CTownList townList;
  164. CInfoBar infoBar;
  165. const CSpell *spellBeingCasted; //NULL if none
  166. const CArmedInstance *selection; //currently selected town/hero
  167. //functions bound to buttons
  168. void fshowOverview();
  169. void fswitchLevel();
  170. void fshowQuestlog();
  171. void fsleepWake();
  172. void fmoveHero();
  173. void fshowSpellbok();
  174. void fadventureOPtions();
  175. void fsystemOptions();
  176. void fnextHero();
  177. void fendTurn();
  178. void activate();
  179. void deactivate();
  180. void show(SDL_Surface * to); //redraws terrain
  181. void showAll(SDL_Surface * to); //shows and activates adv. map interface
  182. void select(const CArmedInstance *sel, bool centerView = true);
  183. void selectionChanged();
  184. void centerOn(int3 on);
  185. void centerOn(const CGObjectInstance *obj);
  186. int3 verifyPos(int3 ver);
  187. void handleRightClick(std::string text, tribool down);
  188. void keyPressed(const SDL_KeyboardEvent & key);
  189. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  190. bool isActive();
  191. void setPlayer(int Player);
  192. void startHotSeatWait(int Player);
  193. void startTurn();
  194. void tileLClicked(const int3 &mp);
  195. void tileHovered(const int3 &tile);
  196. void tileRClicked(const int3 &mp);
  197. void enterCastingMode(const CSpell * sp);
  198. void leaveCastingMode(bool cast = false, int3 dest = int3(-1, -1, -1));
  199. const CGHeroInstance * curHero() const;
  200. const CGTownInstance * curTown() const;
  201. const IShipyard * ourInaccessibleShipyard(const CGObjectInstance *obj) const; //checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or NULL else
  202. };
  203. extern CAdvMapInt *adventureInt;
  204. #endif // __CADVMAPINTERFACE_H__