CAdvmapInterface.h 7.8 KB

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