CAdvmapInterface.h 8.2 KB

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