CAdventureMapInterface.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. VCMI_LIB_NAMESPACE_BEGIN
  13. class CGObjectInstance;
  14. class CGHeroInstance;
  15. class CGTownInstance;
  16. class CArmedInstance;
  17. class IShipyard;
  18. struct CGPathNode;
  19. struct ObjectPosInfo;
  20. struct Component;
  21. class int3;
  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 MapView;
  31. class CResDataBar;
  32. class CHeroList;
  33. class CTownList;
  34. class CInfoBar;
  35. class CMinimap;
  36. class MapAudioPlayer;
  37. struct MapDrawingInfo;
  38. /// That's a huge class which handles general adventure map actions and
  39. /// shows the right menu(questlog, spellbook, end turn,..) from where you
  40. /// can get to the towns and heroes.
  41. class CAdventureMapInterface : public CIntObject
  42. {
  43. private:
  44. enum class EGameState
  45. {
  46. NOT_INITIALIZED,
  47. HOTSEAT_WAIT,
  48. MAKING_TURN,
  49. ENEMY_TURN,
  50. WORLD_VIEW
  51. };
  52. EGameState state;
  53. /// currently acting player
  54. PlayerColor currentPlayerID;
  55. /// uses EDirections enum
  56. bool scrollingCursorSet;
  57. const CSpell *spellBeingCasted; //nullptr if none
  58. std::vector<std::shared_ptr<CAnimImage>> gems;
  59. std::shared_ptr<IImage> bg;
  60. std::shared_ptr<IImage> bgWorldView;
  61. std::shared_ptr<CButton> kingOverview;
  62. std::shared_ptr<CButton> sleepWake;
  63. std::shared_ptr<CButton> underground;
  64. std::shared_ptr<CButton> questlog;
  65. std::shared_ptr<CButton> moveHero;
  66. std::shared_ptr<CButton> spellbook;
  67. std::shared_ptr<CButton> advOptions;
  68. std::shared_ptr<CButton> sysOptions;
  69. std::shared_ptr<CButton> nextHero;
  70. std::shared_ptr<CButton> endTurn;
  71. std::shared_ptr<CButton> worldViewUnderground;
  72. std::shared_ptr<MapView> terrain;
  73. std::shared_ptr<CMinimap> minimap;
  74. std::shared_ptr<CHeroList> heroList;
  75. std::shared_ptr<CTownList> townList;
  76. std::shared_ptr<CInfoBar> infoBar;
  77. std::shared_ptr<CGStatusBar> statusbar;
  78. std::shared_ptr<CResDataBar> resdatabar;
  79. std::shared_ptr<CAdvMapPanel> panelMain; // panel that holds all right-side buttons in normal view
  80. std::shared_ptr<CAdvMapWorldViewPanel> panelWorldView; // panel that holds all buttons and other ui in world view
  81. std::shared_ptr<CAdvMapPanel> activeMapPanel; // currently active panel (either main or world view, depending on current mode)
  82. std::shared_ptr<CAnimation> worldViewIcons;// images for world view overlay
  83. std::shared_ptr<MapAudioPlayer> mapAudio;
  84. private:
  85. //functions bound to buttons
  86. void fshowOverview();
  87. void fworldViewBack();
  88. void fworldViewScale1x();
  89. void fworldViewScale2x();
  90. void fworldViewScale4x();
  91. void fswitchLevel();
  92. void fshowQuestlog();
  93. void fsleepWake();
  94. void fmoveHero();
  95. void fshowSpellbok();
  96. void fadventureOPtions();
  97. void fsystemOptions();
  98. void fnextHero();
  99. void fendTurn();
  100. bool isActive();
  101. void adjustActiveness(bool aiTurnStart); //should be called every time at AI/human turn transition; blocks GUI during AI turn
  102. const IShipyard * ourInaccessibleShipyard(const CGObjectInstance *obj) const; //checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or nullptr else
  103. // update locked state of buttons
  104. void updateButtons();
  105. void handleMapScrollingUpdate();
  106. void showMoveDetailsInStatusbar(const CGHeroInstance & hero, const CGPathNode & pathNode);
  107. const CGObjectInstance *getActiveObject(const int3 &tile);
  108. std::optional<Point> keyToMoveDirection(const SDL_Keycode & key);
  109. void endingTurn();
  110. /// exits currently opened world view mode and returns to normal map
  111. void exitWorldView();
  112. void exitCastingMode();
  113. void leaveCastingMode(const int3 & castTarget);
  114. void abortCastingMode();
  115. protected:
  116. // CIntObject interface implementation
  117. void activate() override;
  118. void deactivate() override;
  119. void show(SDL_Surface * to) override;
  120. void showAll(SDL_Surface * to) override;
  121. void keyPressed(const SDL_Keycode & key) override;
  122. public:
  123. CAdventureMapInterface();
  124. /// Called by PlayerInterface when specified player is ready to start his turn
  125. void onHotseatWaitStarted(PlayerColor playerID);
  126. /// Called by PlayerInterface when AI or remote human player starts his turn
  127. void onEnemyTurnStarted(PlayerColor playerID);
  128. /// Called by PlayerInterface when local human player starts his turn
  129. void onPlayerTurnStarted(PlayerColor playerID);
  130. /// Called by PlayerInterface when interface should be switched to specified player without starting turn
  131. void onCurrentPlayerChanged(PlayerColor playerID);
  132. /// Called by PlayerInterface when specific map tile changed and must be updated on minimap
  133. void onMapTilesChanged(boost::optional<std::unordered_set<int3>> positions);
  134. /// Called by PlayerInterface when hero starts movement
  135. void onHeroMovementStarted(const CGHeroInstance * hero);
  136. /// Called by PlayerInterface when hero state changed and hero list must be updated
  137. void onHeroChanged(const CGHeroInstance * hero);
  138. /// Called by PlayerInterface when town state changed and town list must be updated
  139. void onTownChanged(const CGTownInstance * town);
  140. /// Called when currently selected object changes
  141. void onSelectionChanged(const CArmedInstance *sel);
  142. /// Called when map audio should be paused, e.g. on combat or town screen access
  143. void onAudioPaused();
  144. /// Called when map audio should be resume, opposite to onPaused
  145. void onAudioResumed();
  146. /// Requests to display provided information inside infobox
  147. void showInfoBoxMessage(const std::vector<Component> & components, std::string message, int timer);
  148. /// Changes position on map to center selected location
  149. void centerOnTile(int3 on);
  150. void centerOnObject(const CGObjectInstance *obj);
  151. /// called by MapView whenever currently visible area changes
  152. /// visibleArea describes now visible map section measured in tiles
  153. void onMapViewMoved(const Rect & visibleArea, int mapLevel);
  154. /// called by MapView whenever tile is clicked
  155. void onTileLeftClicked(const int3 & mapPos);
  156. /// called by MapView whenever tile is hovered
  157. void onTileHovered(const int3 & mapPos);
  158. /// called by MapView whenever tile is clicked
  159. void onTileRightClicked(const int3 & mapPos);
  160. /// called by spell window when spell to cast has been selected
  161. void enterCastingMode(const CSpell * sp);
  162. /// returns area of screen covered by terrain (main game area)
  163. Rect terrainAreaPixels() const;
  164. /// opens world view at default scale
  165. void openWorldView();
  166. /// opens world view at specific scale
  167. void openWorldView(int tileSize);
  168. /// opens world view with specific info, e.g. after View Earth/Air is shown
  169. void openWorldView(const std::vector<ObjectPosInfo>& objectPositions, bool showTerrain);
  170. };
  171. extern std::shared_ptr<CAdventureMapInterface> adventureInt;