CAdvMapInt.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. struct Component;
  23. VCMI_LIB_NAMESPACE_END
  24. class CButton;
  25. class IImage;
  26. class CAnimImage;
  27. class CGStatusBar;
  28. class CAdvMapPanel;
  29. class CAdvMapWorldViewPanel;
  30. class CAnimation;
  31. class MapView;
  32. class CResDataBar;
  33. class CHeroList;
  34. class CTownList;
  35. class CInfoBar;
  36. class CMinimap;
  37. class MapAudioPlayer;
  38. struct MapDrawingInfo;
  39. enum class EAdvMapMode
  40. {
  41. NORMAL,
  42. WORLD_VIEW
  43. };
  44. /// That's a huge class which handles general adventure map actions and
  45. /// shows the right menu(questlog, spellbook, end turn,..) from where you
  46. /// can get to the towns and heroes.
  47. class CAdvMapInt : public CIntObject
  48. {
  49. private:
  50. enum EDirections {LEFT=1, RIGHT=2, UP=4, DOWN=8};
  51. enum class EGameStates {NA, INGAME, WAITING};
  52. EGameStates state;
  53. EAdvMapMode mode;
  54. /// Currently selected object, can be town, hero or null
  55. const CArmedInstance *selection;
  56. /// currently acting player
  57. PlayerColor player;
  58. bool duringAITurn;
  59. /// uses EDirections enum
  60. ui8 scrollingDir;
  61. bool scrollingState;
  62. const CSpell *spellBeingCasted; //nullptr if none
  63. std::vector<std::shared_ptr<CAnimImage>> gems;
  64. std::shared_ptr<IImage> bg;
  65. std::shared_ptr<IImage> bgWorldView;
  66. std::shared_ptr<CButton> kingOverview;
  67. std::shared_ptr<CButton> sleepWake;
  68. std::shared_ptr<CButton> underground;
  69. std::shared_ptr<CButton> questlog;
  70. std::shared_ptr<CButton> moveHero;
  71. std::shared_ptr<CButton> spellbook;
  72. std::shared_ptr<CButton> advOptions;
  73. std::shared_ptr<CButton> sysOptions;
  74. std::shared_ptr<CButton> nextHero;
  75. std::shared_ptr<CButton> endTurn;
  76. std::shared_ptr<CButton> worldViewUnderground;
  77. std::shared_ptr<MapView> terrain;
  78. std::shared_ptr<CMinimap> minimap;
  79. std::shared_ptr<CHeroList> heroList;
  80. std::shared_ptr<CTownList> townList;
  81. std::shared_ptr<CInfoBar> infoBar;
  82. std::shared_ptr<CGStatusBar> statusbar;
  83. std::shared_ptr<CResDataBar> resdatabar;
  84. std::shared_ptr<CAdvMapPanel> panelMain; // panel that holds all right-side buttons in normal view
  85. std::shared_ptr<CAdvMapWorldViewPanel> panelWorldView; // panel that holds all buttons and other ui in world view
  86. std::shared_ptr<CAdvMapPanel> activeMapPanel; // currently active panel (either main or world view, depending on current mode)
  87. std::shared_ptr<CAnimation> worldViewIcons;// images for world view overlay
  88. std::shared_ptr<MapAudioPlayer> mapAudio;
  89. private:
  90. //functions bound to buttons
  91. void fshowOverview();
  92. void fworldViewBack();
  93. void fworldViewScale1x();
  94. void fworldViewScale2x();
  95. void fworldViewScale4x();
  96. void fswitchLevel();
  97. void fshowQuestlog();
  98. void fsleepWake();
  99. void fmoveHero();
  100. void fshowSpellbok();
  101. void fadventureOPtions();
  102. void fsystemOptions();
  103. void fnextHero();
  104. void fendTurn();
  105. void setScrollingCursor(ui8 direction) const;
  106. void selectionChanged();
  107. bool isActive();
  108. void adjustActiveness(bool aiTurnStart); //should be called every time at AI/human turn transition; blocks GUI during AI turn
  109. const IShipyard * ourInaccessibleShipyard(const CGObjectInstance *obj) const; //checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or nullptr else
  110. //button updates
  111. void updateSleepWake(const CGHeroInstance *h);
  112. void updateSpellbook(const CGHeroInstance *h);
  113. void handleMapScrollingUpdate();
  114. void showMoveDetailsInStatusbar(const CGHeroInstance & hero, const CGPathNode & pathNode);
  115. const CGObjectInstance *getActiveObject(const int3 &tile);
  116. std::optional<Point> keyToMoveDirection(const SDL_Keycode & key);
  117. bool isHeroSleeping(const CGHeroInstance *hero);
  118. void setHeroSleeping(const CGHeroInstance *hero, bool sleep);
  119. int getNextHeroIndex(int startIndex); //for Next Hero button - cycles awake heroes with movement only
  120. void endingTurn();
  121. public:
  122. CAdvMapInt();
  123. // CIntObject interface implementation
  124. void activate() override;
  125. void deactivate() override;
  126. void show(SDL_Surface * to) override;
  127. void showAll(SDL_Surface * to) override;
  128. void keyPressed(const SDL_Keycode & key) override;
  129. void keyReleased(const SDL_Keycode & key) override;
  130. void mouseMoved (const Point & cursorPosition) override;
  131. // public interface
  132. void startHotSeatWait(PlayerColor Player);
  133. void startTurn();
  134. void initializeNewTurn();
  135. void aiTurnStarted();
  136. /// Called by PlayerInterface when hero is forced to wake up, e.g. on moving sleeping hero
  137. void onHeroWokeUp(const CGHeroInstance * hero);
  138. /// Called by PlayerInterface when current player changes in hotseat
  139. void onCurrentPlayerChanged(PlayerColor Player);
  140. /// Called by PlayerInterface when specific map tile changed and must be updated on minimap
  141. void onMapTileChanged(const int3 & mapPosition);
  142. /// Called by PlayerInterface when unknown number of tiles changed and minimap should redraw
  143. void onMapTilesChanged();
  144. /// Called by PlayerInterface when hero state changed and hero list must be updated
  145. void onHeroChanged(const CGHeroInstance * hero);
  146. /// Called by PlayerInterface when town state changed and town list must be updated
  147. void onTownChanged(const CGTownInstance * town);
  148. /// Called when map audio should be paused, e.g. on combat or town scren access
  149. void onAudioPaused();
  150. /// Called when map audio should be resume, opposite to onPaused
  151. void onAudioResumed();
  152. /// Requests to display provided information inside infobox
  153. void showInfoBoxMessage(const std::vector<Component> & components, std::string message, int timer);
  154. /// Changes currently selected object
  155. void setSelection(const CArmedInstance *sel, bool centerView = true);
  156. /// Changes position on map to center selected location
  157. void centerOnTile(int3 on);
  158. void centerOnObject(const CGObjectInstance *obj);
  159. /// called by MapView whenever currently visible area changes
  160. /// visibleArea describes now visible map section measured in tiles
  161. void onMapViewMoved(const Rect & visibleArea, int mapLevel);
  162. /// called by MapView whenever tile is clicked
  163. void onTileLeftClicked(const int3 & mapPos);
  164. /// called by MapView whenever tile is hovered
  165. void onTileHovered(const int3 & mapPos);
  166. /// called by MapView whenever tile is clicked
  167. void onTileRightClicked(const int3 & mapPos);
  168. void enterCastingMode(const CSpell * sp);
  169. void leaveCastingMode(bool cast = false, int3 dest = int3(-1, -1, -1));
  170. const CGHeroInstance * getCurrentHero() const;
  171. const CGTownInstance * getCurrentTown() const;
  172. const CArmedInstance * getCurrentArmy() const;
  173. /// returns area of screen covered by terrain (main game area)
  174. Rect terrainAreaPixels() const;
  175. /// exits currently opened world view mode and returns to normal map
  176. void exitWorldView();
  177. /// opens world view at default scale
  178. void openWorldView();
  179. /// opens world view at specific scale
  180. void openWorldView(int tileSize);
  181. /// opens world view with specific info, e.g. after View Earth/Air is shown
  182. void openWorldView(const std::vector<ObjectPosInfo>& objectPositions, bool showTerrain);
  183. };
  184. extern std::shared_ptr<CAdvMapInt> adventureInt;