CAdvmapInterface.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. enum EMode {NOTHING = -1, NEW_DAY, NEW_WEEK1, NEW_WEEK2, NEW_WEEK3, NEW_WEEK4, ____, SHOW_COMPONENT, ENEMY_TURN};
  120. CDefHandler *day, *week1, *week2, *week3, *week4, *hourglass, *hourglassSand;
  121. CComponent * current;
  122. int pom;
  123. SDL_Surface *selInfoWin; //info box for selection
  124. CDefHandler * getAnim(EMode mode);
  125. struct EnemyTurn
  126. {
  127. ui8 color;
  128. double progress; //0-1
  129. EnemyTurn()
  130. {
  131. color = 255;
  132. progress = 0.;
  133. }
  134. } enemyTurnInfo;
  135. public:
  136. EMode mode;
  137. const CGHeroInstance * curSel;
  138. CInfoBar();
  139. ~CInfoBar();
  140. void newDay(int Day); //start showing new day/week animation
  141. void showComp(const CComponent * comp, int time=5000);
  142. void enemyTurn(ui8 color, double progress);
  143. void tick();
  144. void showAll(SDL_Surface * to); // if specific==0 function draws info about selected hero/town
  145. void blitAnim(EMode mode);//0 - day, 1 - week
  146. void show(SDL_Surface * to);
  147. void activate();
  148. void deactivate();
  149. void updateSelection(const CGObjectInstance *obj);
  150. };
  151. /// That's a huge class which handles general adventure map actions and
  152. /// shows the right menu(questlog, spellbook, end turn,..) from where you
  153. /// can get to the towns and heroes.
  154. class CAdvMapInt : public CIntObject
  155. {
  156. //get top selectable object at tile
  157. const CGObjectInstance *getBlockingObject(const int3 &tile);
  158. public:
  159. CAdvMapInt();
  160. ~CAdvMapInt();
  161. int3 position; //top left corner of visible map part
  162. int player;
  163. bool duringAITurn;
  164. enum{LEFT=1, RIGHT=2, UP=4, DOWN=8};
  165. ui8 scrollingDir; //uses enum: LEFT RIGHT, UP, DOWN
  166. enum{NA, INGAME, WAITING} state;
  167. bool updateScreen, updateMinimap ;
  168. ui8 anim, animValHitCount; //animation frame
  169. ui8 heroAnim, heroAnimValHitCount; //animation frame
  170. SDL_Surface * bg;
  171. std::vector<CDefHandler *> gems;
  172. CMinimap minimap;
  173. CStatusBar statusbar;
  174. CAdventureMapButton kingOverview,//- kingdom overview
  175. underground,//- underground switch
  176. questlog,//- questlog
  177. sleepWake, //- sleep/wake hero
  178. moveHero, //- move hero
  179. spellbook,//- spellbook
  180. advOptions, //- adventure options
  181. sysOptions,//- system options
  182. nextHero, //- next hero
  183. endTurn;//- end turn
  184. CTerrainRect terrain; //visible terrain
  185. CResDataBar resdatabar;
  186. CHeroList heroList;
  187. CTownList townList;
  188. CInfoBar infoBar;
  189. const CSpell *spellBeingCasted; //NULL if none
  190. const CArmedInstance *selection; //currently selected town/hero
  191. //functions bound to buttons
  192. void fshowOverview();
  193. void fswitchLevel();
  194. void fshowQuestlog();
  195. void fsleepWake();
  196. void fmoveHero();
  197. void fshowSpellbok();
  198. void fadventureOPtions();
  199. void fsystemOptions();
  200. void fnextHero();
  201. void fendTurn();
  202. void activate();
  203. void deactivate();
  204. void show(SDL_Surface * to); //redraws terrain
  205. void showAll(SDL_Surface * to); //shows and activates adv. map interface
  206. void select(const CArmedInstance *sel, bool centerView = true);
  207. void selectionChanged();
  208. void centerOn(int3 on);
  209. void centerOn(const CGObjectInstance *obj);
  210. int3 verifyPos(int3 ver);
  211. void handleRightClick(std::string text, tribool down);
  212. void keyPressed(const SDL_KeyboardEvent & key);
  213. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  214. bool isActive();
  215. bool isHeroSleeping(const CGHeroInstance *hero);
  216. void setHeroSleeping(const CGHeroInstance *hero, bool sleep);
  217. int getNextHeroIndex(int startIndex); //for Next Hero button - cycles awake heroes with movement only
  218. void setPlayer(int Player);
  219. void startHotSeatWait(int Player);
  220. void startTurn();
  221. void endingTurn();
  222. void aiTurnStarted();
  223. void adjustActiveness(bool aiTurnStart); //should be called everytime at AI/human turn transition; blocks GUI during AI turn
  224. void tileLClicked(const int3 &mapPos);
  225. void tileHovered(const int3 &mapPos);
  226. void tileRClicked(const int3 &mapPos);
  227. void enterCastingMode(const CSpell * sp);
  228. void leaveCastingMode(bool cast = false, int3 dest = int3(-1, -1, -1));
  229. const CGHeroInstance * curHero() const;
  230. const CGTownInstance * curTown() const;
  231. const IShipyard * ourInaccessibleShipyard(const CGObjectInstance *obj) const; //checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or NULL else
  232. //button updates
  233. void updateSleepWake(const CGHeroInstance *h);
  234. void updateMoveHero(const CGHeroInstance *h, tribool hasPath = tribool::indeterminate_value);
  235. void updateNextHero(const CGHeroInstance *h);
  236. };
  237. extern CAdvMapInt *adventureInt;