CAdvMapInt.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * CAdvMapInt.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 "../gui/CIntObject.h"
  12. #include "../../lib/int3.h"
  13. #include "../../lib/GameConstants.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class CGObjectInstance;
  16. class CGHeroInstance;
  17. class CGTownInstance;
  18. class CArmedInstance;
  19. class IShipyard;
  20. struct CGPathNode;
  21. struct ObjectPosInfo;
  22. VCMI_LIB_NAMESPACE_END
  23. class CButton;
  24. class IImage;
  25. class CAnimImage;
  26. class CGStatusBar;
  27. class CAdvMapPanel;
  28. class CAdvMapWorldViewPanel;
  29. class CAnimation;
  30. class CTerrainRect;
  31. class CResDataBar;
  32. class CHeroList;
  33. class CTownList;
  34. class CInfoBar;
  35. class CMinimap;
  36. struct MapDrawingInfo;
  37. enum class EAdvMapMode
  38. {
  39. NORMAL,
  40. WORLD_VIEW
  41. };
  42. /// That's a huge class which handles general adventure map actions and
  43. /// shows the right menu(questlog, spellbook, end turn,..) from where you
  44. /// can get to the towns and heroes.
  45. class CAdvMapInt : public CIntObject
  46. {
  47. //Return object that must be active at this tile (=clickable)
  48. const CGObjectInstance *getActiveObject(const int3 &tile);
  49. boost::optional<Point> keyToMoveDirection(const SDL_Keycode & key);
  50. public:
  51. CAdvMapInt();
  52. int3 position; //top left corner of visible map part
  53. PlayerColor player;
  54. bool duringAITurn;
  55. enum{LEFT=1, RIGHT=2, UP=4, DOWN=8};
  56. ui8 scrollingDir; //uses enum: LEFT RIGHT, UP, DOWN
  57. bool scrollingState;
  58. bool swipeEnabled;
  59. bool swipeMovementRequested;
  60. int3 swipeTargetPosition;
  61. enum{NA, INGAME, WAITING} state;
  62. bool updateScreen;
  63. ui8 anim, animValHitCount; //animation frame
  64. ui8 heroAnim, heroAnimValHitCount; //animation frame
  65. EAdvMapMode mode;
  66. float worldViewScale;
  67. struct WorldViewOptions
  68. {
  69. bool showAllTerrain; //for expert viewEarth
  70. std::vector<ObjectPosInfo> iconPositions;
  71. WorldViewOptions();
  72. void clear();
  73. void adjustDrawingInfo(MapDrawingInfo & info);
  74. };
  75. WorldViewOptions worldViewOptions;
  76. std::shared_ptr<IImage> bg;
  77. std::shared_ptr<IImage> bgWorldView;
  78. std::vector<std::shared_ptr<CAnimImage>> gems;
  79. std::shared_ptr<CMinimap> minimap;
  80. std::shared_ptr<CGStatusBar> statusbar;
  81. std::shared_ptr<CButton> kingOverview;
  82. std::shared_ptr<CButton> underground;
  83. std::shared_ptr<CButton> questlog;
  84. std::shared_ptr<CButton> sleepWake;
  85. std::shared_ptr<CButton> moveHero;
  86. std::shared_ptr<CButton> spellbook;
  87. std::shared_ptr<CButton> advOptions;
  88. std::shared_ptr<CButton> sysOptions;
  89. std::shared_ptr<CButton> nextHero;
  90. std::shared_ptr<CButton> endTurn;
  91. std::shared_ptr<CButton> worldViewUnderground;
  92. std::shared_ptr<CTerrainRect> terrain; //visible terrain
  93. std::shared_ptr<CResDataBar> resdatabar;
  94. std::shared_ptr<CHeroList> heroList;
  95. std::shared_ptr<CTownList> townList;
  96. std::shared_ptr<CInfoBar> infoBar;
  97. std::shared_ptr<CAdvMapPanel> panelMain; // panel that holds all right-side buttons in normal view
  98. std::shared_ptr<CAdvMapWorldViewPanel> panelWorldView; // panel that holds all buttons and other ui in world view
  99. std::shared_ptr<CAdvMapPanel> activeMapPanel; // currently active panel (either main or world view, depending on current mode)
  100. std::shared_ptr<CAnimation> worldViewIcons;// images for world view overlay
  101. const CSpell *spellBeingCasted; //nullptr if none
  102. const CArmedInstance *selection; //currently selected town/hero
  103. //functions bound to buttons
  104. void fshowOverview();
  105. void fworldViewBack();
  106. void fworldViewScale1x();
  107. void fworldViewScale2x();
  108. void fworldViewScale4x();
  109. void fswitchLevel();
  110. void fshowQuestlog();
  111. void fsleepWake();
  112. void fmoveHero();
  113. void fshowSpellbok();
  114. void fadventureOPtions();
  115. void fsystemOptions();
  116. void fnextHero();
  117. void fendTurn();
  118. void activate() override;
  119. void deactivate() override;
  120. void show(SDL_Surface * to) override; //redraws terrain
  121. void showAll(SDL_Surface * to) override; //shows and activates adv. map interface
  122. void select(const CArmedInstance *sel, bool centerView = true);
  123. void selectionChanged();
  124. void centerOn(int3 on, bool fade = false);
  125. void centerOn(const CGObjectInstance *obj, bool fade = false);
  126. int3 verifyPos(int3 ver);
  127. void keyPressed(const SDL_Keycode & key) override;
  128. void keyReleased(const SDL_Keycode & key) override;
  129. void mouseMoved (const Point & cursorPosition) override;
  130. bool isActive();
  131. bool isHeroSleeping(const CGHeroInstance *hero);
  132. void setHeroSleeping(const CGHeroInstance *hero, bool sleep);
  133. int getNextHeroIndex(int startIndex); //for Next Hero button - cycles awake heroes with movement only
  134. void setPlayer(PlayerColor Player);
  135. void startHotSeatWait(PlayerColor Player);
  136. void startTurn();
  137. void endingTurn();
  138. void aiTurnStarted();
  139. void adjustActiveness(bool aiTurnStart); //should be called every time at AI/human turn transition; blocks GUI during AI turn
  140. void quickCombatLock(); //should be called when quick battle started
  141. void quickCombatUnlock();
  142. void tileLClicked(const int3 &mapPos);
  143. void tileHovered(const int3 &mapPos);
  144. void tileRClicked(const int3 &mapPos);
  145. void enterCastingMode(const CSpell * sp);
  146. void leaveCastingMode(bool cast = false, int3 dest = int3(-1, -1, -1));
  147. const CGHeroInstance * curHero() const;
  148. const CGTownInstance * curTown() const;
  149. const IShipyard * ourInaccessibleShipyard(const CGObjectInstance *obj) const; //checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or nullptr else
  150. //button updates
  151. void updateSleepWake(const CGHeroInstance *h);
  152. void updateMoveHero(const CGHeroInstance *h, tribool hasPath = boost::logic::indeterminate);
  153. void updateSpellbook(const CGHeroInstance *h);
  154. void updateNextHero(const CGHeroInstance *h);
  155. /// changes current adventure map mode; used to switch between default view and world view; scale is ignored if EAdvMapMode == NORMAL
  156. void changeMode(EAdvMapMode newMode, float newScale = 0.36f);
  157. void handleMapScrollingUpdate();
  158. void handleSwipeUpdate();
  159. private:
  160. void showMoveDetailsInStatusbar(const CGHeroInstance & hero, const CGPathNode & pathNode);
  161. };
  162. extern std::shared_ptr<CAdvMapInt> adventureInt;