AdventureMapInterface.h 5.9 KB

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