CAdvmapInterface.h 8.8 KB

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