CAdvmapInterface.h 8.6 KB

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