AdventureMapInterface.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * AdventureMapInterface.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 AdventureMapWidget;
  28. class AdventureMapShortcuts;
  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. enum class EAdventureState;
  38. struct MapDrawingInfo;
  39. /// That's a huge class which handles general adventure map actions and
  40. /// shows the right menu(questlog, spellbook, end turn,..) from where you
  41. /// can get to the towns and heroes.
  42. class AdventureMapInterface : public CIntObject
  43. {
  44. private:
  45. /// currently acting player
  46. PlayerColor currentPlayerID;
  47. /// if true, cursor was changed to scrolling and must be reset back once scroll is over
  48. bool scrollingWasActive;
  49. /// if true, then scrolling was blocked via ctrl and should not restart until player move cursor outside scrolling area
  50. bool scrollingWasBlocked;
  51. /// spell for which player is selecting target, or nullptr if none
  52. const CSpell *spellBeingCasted;
  53. std::shared_ptr<MapAudioPlayer> mapAudio;
  54. std::shared_ptr<AdventureMapWidget> widget;
  55. std::shared_ptr<AdventureMapShortcuts> shortcuts;
  56. private:
  57. void setState(EAdventureState state);
  58. /// updates active state of game window whenever game state changes
  59. void adjustActiveness();
  60. /// checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or nullptr else
  61. const IShipyard * ourInaccessibleShipyard(const CGObjectInstance *obj) const;
  62. /// check and if necessary reacts on scrolling by moving cursor to screen edge
  63. void handleMapScrollingUpdate();
  64. void showMoveDetailsInStatusbar(const CGHeroInstance & hero, const CGPathNode & pathNode);
  65. const CGObjectInstance *getActiveObject(const int3 &tile);
  66. /// exits currently opened world view mode and returns to normal map
  67. void exitCastingMode();
  68. /// casts current spell at specified location
  69. void performSpellcasting(const int3 & castTarget);
  70. protected:
  71. /// CIntObject interface implementation
  72. void activate() override;
  73. void deactivate() override;
  74. void show(SDL_Surface * to) override;
  75. void showAll(SDL_Surface * to) override;
  76. void keyPressed(EShortcut key) override;
  77. void onScreenResize() override;
  78. public:
  79. AdventureMapInterface();
  80. void hotkeyAbortCastingMode();
  81. void hotkeyExitWorldView();
  82. void hotkeyEndingTurn();
  83. void hotkeyNextTown();
  84. void hotkeySwitchMapLevel();
  85. /// Called by PlayerInterface when specified player is ready to start his turn
  86. void onHotseatWaitStarted(PlayerColor playerID);
  87. /// Called by PlayerInterface when AI or remote human player starts his turn
  88. void onEnemyTurnStarted(PlayerColor playerID);
  89. /// Called by PlayerInterface when local human player starts his turn
  90. void onPlayerTurnStarted(PlayerColor playerID);
  91. /// Called by PlayerInterface when interface should be switched to specified player without starting turn
  92. void onCurrentPlayerChanged(PlayerColor playerID);
  93. /// Called by PlayerInterface when specific map tile changed and must be updated on minimap
  94. void onMapTilesChanged(boost::optional<std::unordered_set<int3>> positions);
  95. /// Called by PlayerInterface when hero starts movement
  96. void onHeroMovementStarted(const CGHeroInstance * hero);
  97. /// Called by PlayerInterface when hero state changed and hero list must be updated
  98. void onHeroChanged(const CGHeroInstance * hero);
  99. /// Called by PlayerInterface when town state changed and town list must be updated
  100. void onTownChanged(const CGTownInstance * town);
  101. /// Called when currently selected object changes
  102. void onSelectionChanged(const CArmedInstance *sel);
  103. /// Called when map audio should be paused, e.g. on combat or town screen access
  104. void onAudioPaused();
  105. /// Called when map audio should be resume, opposite to onPaused
  106. void onAudioResumed();
  107. /// Requests to display provided information inside infobox
  108. void showInfoBoxMessage(const std::vector<Component> & components, std::string message, int timer);
  109. /// Changes position on map to center selected location
  110. void centerOnTile(int3 on);
  111. void centerOnObject(const CGObjectInstance *obj);
  112. /// called by MapView whenever currently visible area changes
  113. /// visibleArea describes now visible map section measured in tiles
  114. void onMapViewMoved(const Rect & visibleArea, int mapLevel);
  115. /// called by MapView whenever tile is clicked
  116. void onTileLeftClicked(const int3 & mapPos);
  117. /// called by MapView whenever tile is hovered
  118. void onTileHovered(const int3 & mapPos);
  119. /// called by MapView whenever tile is clicked
  120. void onTileRightClicked(const int3 & mapPos);
  121. /// called by spell window when spell to cast has been selected
  122. void enterCastingMode(const CSpell * sp);
  123. /// returns area of screen covered by terrain (main game area)
  124. Rect terrainAreaPixels() const;
  125. /// opens world view at default scale
  126. void openWorldView();
  127. /// opens world view at specific scale
  128. void openWorldView(int tileSize);
  129. /// opens world view with specific info, e.g. after View Earth/Air is shown
  130. void openWorldView(const std::vector<ObjectPosInfo>& objectPositions, bool showTerrain);
  131. };
  132. extern std::shared_ptr<AdventureMapInterface> adventureInt;