CAdvmapInterface.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. int3 swipeInitialMapPos;
  49. int3 swipeInitialRealPos;
  50. bool isSwiping;
  51. static constexpr float SwipeTouchSlop = 16.0f;
  52. void handleHover(const SDL_MouseMotionEvent &sEvent);
  53. #ifdef VCMI_ANDROID
  54. void handleSwipeMove(const SDL_MouseMotionEvent &sEvent);
  55. #endif // VCMI_ANDROID
  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 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{LEFT=1, RIGHT=2, UP=4, DOWN=8};
  110. ui8 scrollingDir; //uses enum: LEFT RIGHT, UP, DOWN
  111. bool scrollingState;
  112. #ifdef VCMI_ANDROID
  113. bool swipeEnabled;
  114. bool swipeMovementRequested;
  115. int3 swipeTargetPosition;
  116. #endif // !VCMI_ANDROID
  117. enum{NA, INGAME, WAITING} state;
  118. bool updateScreen;
  119. ui8 anim, animValHitCount; //animation frame
  120. ui8 heroAnim, heroAnimValHitCount; //animation frame
  121. EAdvMapMode mode;
  122. float worldViewScale;
  123. struct WorldViewOptions
  124. {
  125. bool showAllTerrain; //for expert viewEarth
  126. std::vector<ObjectPosInfo> iconPositions;
  127. WorldViewOptions();
  128. void clear();
  129. void adjustDrawingInfo(MapDrawingInfo & info);
  130. };
  131. WorldViewOptions worldViewOptions;
  132. SDL_Surface * bg;
  133. SDL_Surface * bgWorldView;
  134. std::vector<CAnimImage *> gems;
  135. CMinimap minimap;
  136. CGStatusBar statusbar;
  137. CButton * kingOverview;
  138. CButton * underground;
  139. CButton * questlog;
  140. CButton * sleepWake;
  141. CButton * moveHero;
  142. CButton * spellbook;
  143. CButton * advOptions;
  144. CButton * sysOptions;
  145. CButton * nextHero;
  146. CButton * endTurn;
  147. CButton * worldViewUnderground;
  148. CTerrainRect terrain; //visible terrain
  149. CResDataBar resdatabar;
  150. CHeroList heroList;
  151. CTownList townList;
  152. CInfoBar infoBar;
  153. CAdvMapPanel *panelMain; // panel that holds all right-side buttons in normal view
  154. CAdvMapWorldViewPanel *panelWorldView; // panel that holds all buttons and other ui in world view
  155. CAdvMapPanel *activeMapPanel; // currently active panel (either main or world view, depending on current mode)
  156. std::shared_ptr<CAnimation> worldViewIcons;// images for world view overlay
  157. const CSpell *spellBeingCasted; //nullptr if none
  158. const CArmedInstance *selection; //currently selected town/hero
  159. //functions bound to buttons
  160. void fshowOverview();
  161. void fworldViewBack();
  162. void fworldViewScale1x();
  163. void fworldViewScale2x();
  164. void fworldViewScale4x();
  165. void fswitchLevel();
  166. void fshowQuestlog();
  167. void fsleepWake();
  168. void fmoveHero();
  169. void fshowSpellbok();
  170. void fadventureOPtions();
  171. void fsystemOptions();
  172. void fnextHero();
  173. void fendTurn();
  174. void activate() override;
  175. void deactivate() override;
  176. void show(SDL_Surface * to) override; //redraws terrain
  177. void showAll(SDL_Surface * to) override; //shows and activates adv. map interface
  178. void select(const CArmedInstance *sel, bool centerView = true);
  179. void selectionChanged();
  180. void centerOn(int3 on, bool fade = false);
  181. void centerOn(const CGObjectInstance *obj, bool fade = false);
  182. int3 verifyPos(int3 ver);
  183. void handleRightClick(std::string text, tribool down);
  184. void keyPressed(const SDL_KeyboardEvent & key) override;
  185. void mouseMoved (const SDL_MouseMotionEvent & sEvent) override;
  186. bool isActive();
  187. bool isHeroSleeping(const CGHeroInstance *hero);
  188. void setHeroSleeping(const CGHeroInstance *hero, bool sleep);
  189. int getNextHeroIndex(int startIndex); //for Next Hero button - cycles awake heroes with movement only
  190. void setPlayer(PlayerColor Player);
  191. void startHotSeatWait(PlayerColor Player);
  192. void startTurn();
  193. void endingTurn();
  194. void aiTurnStarted();
  195. void adjustActiveness(bool aiTurnStart); //should be called every time at AI/human turn transition; blocks GUI during AI turn
  196. void quickCombatLock(); //should be called when quick battle started
  197. void quickCombatUnlock();
  198. void tileLClicked(const int3 &mapPos);
  199. void tileHovered(const int3 &mapPos);
  200. void tileRClicked(const int3 &mapPos);
  201. void enterCastingMode(const CSpell * sp);
  202. void leaveCastingMode(bool cast = false, int3 dest = int3(-1, -1, -1));
  203. const CGHeroInstance * curHero() const;
  204. const CGTownInstance * curTown() const;
  205. const IShipyard * ourInaccessibleShipyard(const CGObjectInstance *obj) const; //checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or nullptr else
  206. //button updates
  207. void updateSleepWake(const CGHeroInstance *h);
  208. void updateMoveHero(const CGHeroInstance *h, tribool hasPath = boost::logic::indeterminate);
  209. void updateSpellbook(const CGHeroInstance *h);
  210. void updateNextHero(const CGHeroInstance *h);
  211. /// changes current adventure map mode; used to switch between default view and world view; scale is ignored if EAdvMapMode == NORMAL
  212. void changeMode(EAdvMapMode newMode, float newScale = 0.36f);
  213. void handleMapScrollingUpdate();
  214. #ifdef VCMI_ANDROID
  215. void handleSwipeUpdate();
  216. #endif
  217. };
  218. extern CAdvMapInt *adventureInt;