CAdvmapInterface.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. public:
  157. CAdvMapInt();
  158. ~CAdvMapInt();
  159. int3 position; //top left corner of visible map part
  160. int player;
  161. bool duringAITurn;
  162. enum{LEFT=1, RIGHT=2, UP=4, DOWN=8};
  163. ui8 scrollingDir; //uses enum: LEFT RIGHT, UP, DOWN
  164. enum{NA, INGAME, WAITING} state;
  165. bool updateScreen, updateMinimap ;
  166. ui8 anim, animValHitCount; //animation frame
  167. ui8 heroAnim, heroAnimValHitCount; //animation frame
  168. SDL_Surface * bg;
  169. std::vector<CDefHandler *> gems;
  170. CMinimap minimap;
  171. CStatusBar statusbar;
  172. CAdventureMapButton kingOverview,//- kingdom overview
  173. underground,//- underground switch
  174. questlog,//- questlog
  175. sleepWake, //- sleep/wake hero
  176. moveHero, //- move hero
  177. spellbook,//- spellbook
  178. advOptions, //- adventure options
  179. sysOptions,//- system options
  180. nextHero, //- next hero
  181. endTurn;//- end turn
  182. CTerrainRect terrain; //visible terrain
  183. CResDataBar resdatabar;
  184. CHeroList heroList;
  185. CTownList townList;
  186. CInfoBar infoBar;
  187. const CSpell *spellBeingCasted; //NULL if none
  188. const CArmedInstance *selection; //currently selected town/hero
  189. //functions bound to buttons
  190. void fshowOverview();
  191. void fswitchLevel();
  192. void fshowQuestlog();
  193. void fsleepWake();
  194. void fmoveHero();
  195. void fshowSpellbok();
  196. void fadventureOPtions();
  197. void fsystemOptions();
  198. void fnextHero();
  199. void fendTurn();
  200. void activate();
  201. void deactivate();
  202. void show(SDL_Surface * to); //redraws terrain
  203. void showAll(SDL_Surface * to); //shows and activates adv. map interface
  204. void select(const CArmedInstance *sel, bool centerView = true);
  205. void selectionChanged();
  206. void centerOn(int3 on);
  207. void centerOn(const CGObjectInstance *obj);
  208. int3 verifyPos(int3 ver);
  209. void handleRightClick(std::string text, tribool down);
  210. void keyPressed(const SDL_KeyboardEvent & key);
  211. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  212. bool isActive();
  213. bool isHeroSleeping(const CGHeroInstance *hero);
  214. void setHeroSleeping(const CGHeroInstance *hero, bool sleep);
  215. int getNextHeroIndex(int startIndex); //for Next Hero button - cycles awake heroes with movement only
  216. void setPlayer(int Player);
  217. void startHotSeatWait(int Player);
  218. void startTurn();
  219. void endingTurn();
  220. void aiTurnStarted();
  221. void adjustActiveness(bool aiTurnStart); //should be called everytime at AI/human turn transition; blocks GUI during AI turn
  222. void tileLClicked(const int3 &mp);
  223. void tileHovered(const int3 &tile);
  224. void tileRClicked(const int3 &mp);
  225. void enterCastingMode(const CSpell * sp);
  226. void leaveCastingMode(bool cast = false, int3 dest = int3(-1, -1, -1));
  227. const CGHeroInstance * curHero() const;
  228. const CGTownInstance * curTown() const;
  229. const IShipyard * ourInaccessibleShipyard(const CGObjectInstance *obj) const; //checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or NULL else
  230. //button updates
  231. void updateSleepWake(const CGHeroInstance *h);
  232. void updateMoveHero(const CGHeroInstance *h, tribool hasPath = tribool::indeterminate_value);
  233. void updateNextHero(const CGHeroInstance *h);
  234. };
  235. extern CAdvMapInt *adventureInt;