CAdvmapInterface.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. #pragma once
  2. #include "../widgets/AdventureMapClasses.h"
  3. #include "CWindowObject.h"
  4. #include "../widgets/TextControls.h"
  5. #include "../widgets/Buttons.h"
  6. #include "../../lib/spells/ViewSpellInt.h"
  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. enum class EMapAnimRedrawStatus;
  16. class CFadeAnimation;
  17. struct MapDrawingInfo;
  18. /*****************************/
  19. /*
  20. * CAdvmapInterface.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. enum class EAdvMapMode
  29. {
  30. NORMAL,
  31. WORLD_VIEW
  32. };
  33. /// Adventure options dialogue where you can view the world, dig, play the replay of the last turn,...
  34. class CAdventureOptions : public CWindowObject
  35. {
  36. public:
  37. CButton *exit, *viewWorld, *puzzle, *dig, *scenInfo/*, *replay*/;
  38. CAdventureOptions();
  39. static void showScenarioInfo();
  40. };
  41. /// Holds information about which tiles of the terrain are shown/not shown at the screen
  42. class CTerrainRect
  43. : public CIntObject
  44. {
  45. SDL_Surface * fadeSurface;
  46. EMapAnimRedrawStatus lastRedrawStatus;
  47. CFadeAnimation * fadeAnim;
  48. public:
  49. int tilesw, tilesh; //width and height of terrain to blit in tiles
  50. int3 curHoveredTile;
  51. int moveX, moveY; //shift between actual position of screen and the one we wil blit; ranges from -31 to 31 (in pixels)
  52. CTerrainRect();
  53. virtual ~CTerrainRect();
  54. CGPath * currentPath;
  55. void deactivate() override;
  56. void clickLeft(tribool down, bool previousState) override;
  57. void clickRight(tribool down, bool previousState) override;
  58. void hover(bool on) override;
  59. void mouseMoved (const SDL_MouseMotionEvent & sEvent) override;
  60. void show(SDL_Surface * to) override;
  61. void showAll(SDL_Surface * to) override;
  62. void showAnim(SDL_Surface * to);
  63. void showPath(const SDL_Rect * extRect, SDL_Surface * to);
  64. int3 whichTileIsIt(const int x, const int y); //x,y are cursor position
  65. int3 whichTileIsIt(); //uses current cursor pos
  66. /// @returns number of visible tiles on screen respecting current map scaling
  67. int3 tileCountOnScreen();
  68. /// animates view by caching current surface and crossfading it with normal screen
  69. void fadeFromCurrentView();
  70. bool needsAnimUpdate();
  71. };
  72. /// Resources bar which shows information about how many gold, crystals,... you have
  73. /// Current date is displayed too
  74. class CResDataBar : public CIntObject
  75. {
  76. public:
  77. SDL_Surface * bg;
  78. std::vector<std::pair<int,int> > txtpos;
  79. std::string datetext;
  80. void clickRight(tribool down, bool previousState) override;
  81. CResDataBar();
  82. CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist);
  83. ~CResDataBar();
  84. void draw(SDL_Surface * to);
  85. void show(SDL_Surface * to) override;
  86. void showAll(SDL_Surface * to) override;
  87. };
  88. /// That's a huge class which handles general adventure map actions and
  89. /// shows the right menu(questlog, spellbook, end turn,..) from where you
  90. /// can get to the towns and heroes.
  91. class CAdvMapInt : public CIntObject
  92. {
  93. //Return object that must be active at this tile (=clickable)
  94. const CGObjectInstance *getActiveObject(const int3 &tile);
  95. public:
  96. CAdvMapInt();
  97. ~CAdvMapInt();
  98. int3 position; //top left corner of visible map part
  99. PlayerColor player;
  100. bool duringAITurn;
  101. enum{LEFT=1, RIGHT=2, UP=4, DOWN=8};
  102. ui8 scrollingDir; //uses enum: LEFT RIGHT, UP, DOWN
  103. bool scrollingState;
  104. enum{NA, INGAME, WAITING} state;
  105. bool updateScreen;
  106. ui8 anim, animValHitCount; //animation frame
  107. ui8 heroAnim, heroAnimValHitCount; //animation frame
  108. EAdvMapMode mode;
  109. float worldViewScale;
  110. struct WorldViewOptions
  111. {
  112. bool showAllTerrain; //for expert viewEarth
  113. std::vector<ObjectPosInfo> iconPositions;
  114. WorldViewOptions();
  115. void clear();
  116. void adjustDrawingInfo(MapDrawingInfo & info);
  117. };
  118. WorldViewOptions worldViewOptions;
  119. SDL_Surface * bg;
  120. SDL_Surface * bgWorldView;
  121. std::vector<CAnimImage *> gems;
  122. CMinimap minimap;
  123. CGStatusBar statusbar;
  124. CButton * kingOverview;
  125. CButton * underground;
  126. CButton * questlog;
  127. CButton * sleepWake;
  128. CButton * moveHero;
  129. CButton * spellbook;
  130. CButton * advOptions;
  131. CButton * sysOptions;
  132. CButton * nextHero;
  133. CButton * endTurn;
  134. CButton * worldViewUnderground;
  135. CTerrainRect terrain; //visible terrain
  136. CResDataBar resdatabar;
  137. CHeroList heroList;
  138. CTownList townList;
  139. CInfoBar infoBar;
  140. CAdvMapPanel *panelMain; // panel that holds all right-side buttons in normal view
  141. CAdvMapWorldViewPanel *panelWorldView; // panel that holds all buttons and other ui in world view
  142. CAdvMapPanel *activeMapPanel; // currently active panel (either main or world view, depending on current mode)
  143. std::shared_ptr<CAnimation> worldViewIcons;// images for world view overlay
  144. const CSpell *spellBeingCasted; //nullptr if none
  145. const CArmedInstance *selection; //currently selected town/hero
  146. //functions bound to buttons
  147. void fshowOverview();
  148. void fworldViewBack();
  149. void fworldViewScale1x();
  150. void fworldViewScale2x();
  151. void fworldViewScale4x();
  152. void fswitchLevel();
  153. void fshowQuestlog();
  154. void fsleepWake();
  155. void fmoveHero();
  156. void fshowSpellbok();
  157. void fadventureOPtions();
  158. void fsystemOptions();
  159. void fnextHero();
  160. void fendTurn();
  161. void activate() override;
  162. void deactivate() override;
  163. void show(SDL_Surface * to) override; //redraws terrain
  164. void showAll(SDL_Surface * to) override; //shows and activates adv. map interface
  165. void select(const CArmedInstance *sel, bool centerView = true);
  166. void selectionChanged();
  167. void centerOn(int3 on, bool fade = false);
  168. void centerOn(const CGObjectInstance *obj, bool fade = false);
  169. int3 verifyPos(int3 ver);
  170. void handleRightClick(std::string text, tribool down);
  171. void keyPressed(const SDL_KeyboardEvent & key) override;
  172. void mouseMoved (const SDL_MouseMotionEvent & sEvent) override;
  173. bool isActive();
  174. bool isHeroSleeping(const CGHeroInstance *hero);
  175. void setHeroSleeping(const CGHeroInstance *hero, bool sleep);
  176. int getNextHeroIndex(int startIndex); //for Next Hero button - cycles awake heroes with movement only
  177. void setPlayer(PlayerColor Player);
  178. void startHotSeatWait(PlayerColor Player);
  179. void startTurn();
  180. void endingTurn();
  181. void aiTurnStarted();
  182. void adjustActiveness(bool aiTurnStart); //should be called every time at AI/human turn transition; blocks GUI during AI turn
  183. void quickCombatLock(); //should be called when quick battle started
  184. void quickCombatUnlock();
  185. void tileLClicked(const int3 &mapPos);
  186. void tileHovered(const int3 &mapPos);
  187. void tileRClicked(const int3 &mapPos);
  188. void enterCastingMode(const CSpell * sp);
  189. void leaveCastingMode(bool cast = false, int3 dest = int3(-1, -1, -1));
  190. const CGHeroInstance * curHero() const;
  191. const CGTownInstance * curTown() const;
  192. const IShipyard * ourInaccessibleShipyard(const CGObjectInstance *obj) const; //checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or nullptr else
  193. //button updates
  194. void updateSleepWake(const CGHeroInstance *h);
  195. void updateMoveHero(const CGHeroInstance *h, tribool hasPath = boost::logic::indeterminate);
  196. void updateSpellbook(const CGHeroInstance *h);
  197. void updateNextHero(const CGHeroInstance *h);
  198. /// changes current adventure map mode; used to switch between default view and world view; scale is ignored if EAdvMapMode == NORMAL
  199. void changeMode(EAdvMapMode newMode, float newScale = 0.36f);
  200. };
  201. extern CAdvMapInt *adventureInt;