CAdvMapInt.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. //TODO: remove
  48. friend class CPlayerInterface;
  49. friend class CTerrainRect;
  50. private:
  51. enum EDirections {LEFT=1, RIGHT=2, UP=4, DOWN=8};
  52. enum EGameStates {NA, INGAME, WAITING};
  53. struct WorldViewOptions
  54. {
  55. bool showAllTerrain; //for expert viewEarth
  56. std::vector<ObjectPosInfo> iconPositions;
  57. WorldViewOptions();
  58. void clear();
  59. };
  60. bool swipeEnabled;
  61. bool swipeMovementRequested;
  62. Point swipeTargetPosition;
  63. EGameStates state;
  64. EAdvMapMode mode;
  65. WorldViewOptions worldViewOptions;
  66. /// Currently selected object, can be town, hero or null
  67. const CArmedInstance *selection;
  68. /// currently acting player
  69. PlayerColor player;
  70. bool duringAITurn;
  71. /// uses EDirections enum
  72. ui8 scrollingDir;
  73. bool scrollingState;
  74. const CSpell *spellBeingCasted; //nullptr if none
  75. std::vector<std::shared_ptr<CAnimImage>> gems;
  76. std::shared_ptr<IImage> bg;
  77. std::shared_ptr<IImage> bgWorldView;
  78. std::shared_ptr<CButton> kingOverview;
  79. std::shared_ptr<CButton> sleepWake;
  80. std::shared_ptr<CButton> underground;
  81. std::shared_ptr<CButton> questlog;
  82. std::shared_ptr<CButton> moveHero;
  83. std::shared_ptr<CButton> spellbook;
  84. std::shared_ptr<CButton> advOptions;
  85. std::shared_ptr<CButton> sysOptions;
  86. std::shared_ptr<CButton> nextHero;
  87. std::shared_ptr<CButton> endTurn;
  88. std::shared_ptr<CButton> worldViewUnderground;
  89. std::shared_ptr<CTerrainRect> terrain;
  90. std::shared_ptr<CMinimap> minimap;
  91. std::shared_ptr<CHeroList> heroList;
  92. std::shared_ptr<CTownList> townList;
  93. std::shared_ptr<CInfoBar> infoBar;
  94. std::shared_ptr<CGStatusBar> statusbar;
  95. std::shared_ptr<CResDataBar> resdatabar;
  96. std::shared_ptr<CAdvMapPanel> panelMain; // panel that holds all right-side buttons in normal view
  97. std::shared_ptr<CAdvMapWorldViewPanel> panelWorldView; // panel that holds all buttons and other ui in world view
  98. std::shared_ptr<CAdvMapPanel> activeMapPanel; // currently active panel (either main or world view, depending on current mode)
  99. std::shared_ptr<CAnimation> worldViewIcons;// images for world view overlay
  100. private:
  101. //functions bound to buttons
  102. void fshowOverview();
  103. void fworldViewBack();
  104. void fworldViewScale1x();
  105. void fworldViewScale2x();
  106. void fworldViewScale4x();
  107. void fswitchLevel();
  108. void fshowQuestlog();
  109. void fsleepWake();
  110. void fmoveHero();
  111. void fshowSpellbok();
  112. void fadventureOPtions();
  113. void fsystemOptions();
  114. void fnextHero();
  115. void fendTurn();
  116. void setScrollingCursor(ui8 direction) const;
  117. void selectionChanged();
  118. bool isActive();
  119. void adjustActiveness(bool aiTurnStart); //should be called every time at AI/human turn transition; blocks GUI during AI turn
  120. const IShipyard * ourInaccessibleShipyard(const CGObjectInstance *obj) const; //checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or nullptr else
  121. //button updates
  122. void updateSleepWake(const CGHeroInstance *h);
  123. void updateSpellbook(const CGHeroInstance *h);
  124. void handleMapScrollingUpdate();
  125. void handleSwipeUpdate();
  126. void showMoveDetailsInStatusbar(const CGHeroInstance & hero, const CGPathNode & pathNode);
  127. const CGObjectInstance *getActiveObject(const int3 &tile);
  128. boost::optional<Point> keyToMoveDirection(const SDL_Keycode & key);
  129. public:
  130. CAdvMapInt();
  131. // CIntObject interface implementation
  132. void activate() override;
  133. void deactivate() override;
  134. void show(SDL_Surface * to) override;
  135. void showAll(SDL_Surface * to) override;
  136. void keyPressed(const SDL_Keycode & key) override;
  137. void keyReleased(const SDL_Keycode & key) override;
  138. void mouseMoved (const Point & cursorPosition) override;
  139. // public interface
  140. void select(const CArmedInstance *sel, bool centerView = true);
  141. void centerOn(int3 on, bool fade = false);
  142. void centerOn(const CGObjectInstance *obj, bool fade = false);
  143. bool isHeroSleeping(const CGHeroInstance *hero);
  144. void setHeroSleeping(const CGHeroInstance *hero, bool sleep);
  145. int getNextHeroIndex(int startIndex); //for Next Hero button - cycles awake heroes with movement only
  146. void setPlayer(PlayerColor Player);
  147. void startHotSeatWait(PlayerColor Player);
  148. void startTurn();
  149. void initializeNewTurn();
  150. void endingTurn();
  151. void aiTurnStarted();
  152. void quickCombatLock(); //should be called when quick battle started
  153. void quickCombatUnlock();
  154. void tileLClicked(const int3 &mapPos);
  155. void tileHovered(const int3 &mapPos);
  156. void tileRClicked(const int3 &mapPos);
  157. void enterCastingMode(const CSpell * sp);
  158. void leaveCastingMode(bool cast = false, int3 dest = int3(-1, -1, -1));
  159. const CGHeroInstance * curHero() const;
  160. const CGTownInstance * curTown() const;
  161. const CArmedInstance * curArmy() const;
  162. void updateMoveHero(const CGHeroInstance *h, tribool hasPath = boost::logic::indeterminate);
  163. void updateNextHero(const CGHeroInstance *h);
  164. /// returns area of screen covered by terrain (main game area)
  165. Rect terrainAreaPixels() const;
  166. /// returs visible section of game map, in tiles
  167. Rect terrainAreaTiles() const;
  168. /// changes current adventure map mode; used to switch between default view and world view; scale is ignored if EAdvMapMode == NORMAL
  169. void changeMode(EAdvMapMode newMode);
  170. void changeMode(EAdvMapMode newMode, int tileSize);
  171. };
  172. extern std::shared_ptr<CAdvMapInt> adventureInt;