AdventureMapInterface.h 5.9 KB

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