CAdvmapInterface.h 8.2 KB

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