CAdventureMapInterface.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * CAdventureMapInterface.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 CAdventureMapWidget;
  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. 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. /// currently acting player
  45. PlayerColor currentPlayerID;
  46. /// uses EDirections enum
  47. bool scrollingCursorSet;
  48. const CSpell *spellBeingCasted; //nullptr if none
  49. std::shared_ptr<MapAudioPlayer> mapAudio;
  50. std::shared_ptr<CAdventureMapWidget> widget;
  51. std::shared_ptr<AdventureMapShortcuts> shortcuts;
  52. private:
  53. bool isActive();
  54. void adjustActiveness(bool aiTurnStart); //should be called every time at AI/human turn transition; blocks GUI during AI turn
  55. const IShipyard * ourInaccessibleShipyard(const CGObjectInstance *obj) const; //checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or nullptr else
  56. void handleMapScrollingUpdate();
  57. void showMoveDetailsInStatusbar(const CGHeroInstance & hero, const CGPathNode & pathNode);
  58. const CGObjectInstance *getActiveObject(const int3 &tile);
  59. /// exits currently opened world view mode and returns to normal map
  60. void exitCastingMode();
  61. void performSpellcasting(const int3 & castTarget);
  62. protected:
  63. // CIntObject interface implementation
  64. void activate() override;
  65. void deactivate() override;
  66. void show(SDL_Surface * to) override;
  67. void showAll(SDL_Surface * to) override;
  68. void keyPressed(EShortcut key) override;
  69. void onScreenResize() override;
  70. public:
  71. CAdventureMapInterface();
  72. void hotkeyAbortCastingMode();
  73. void hotkeyExitWorldView();
  74. void hotkeyEndingTurn();
  75. void hotkeyNextTown();
  76. void hotkeySwitchMapLevel();
  77. /// Called by PlayerInterface when specified player is ready to start his turn
  78. void onHotseatWaitStarted(PlayerColor playerID);
  79. /// Called by PlayerInterface when AI or remote human player starts his turn
  80. void onEnemyTurnStarted(PlayerColor playerID);
  81. /// Called by PlayerInterface when local human player starts his turn
  82. void onPlayerTurnStarted(PlayerColor playerID);
  83. /// Called by PlayerInterface when interface should be switched to specified player without starting turn
  84. void onCurrentPlayerChanged(PlayerColor playerID);
  85. /// Called by PlayerInterface when specific map tile changed and must be updated on minimap
  86. void onMapTilesChanged(boost::optional<std::unordered_set<int3>> positions);
  87. /// Called by PlayerInterface when hero starts movement
  88. void onHeroMovementStarted(const CGHeroInstance * hero);
  89. /// Called by PlayerInterface when hero state changed and hero list must be updated
  90. void onHeroChanged(const CGHeroInstance * hero);
  91. /// Called by PlayerInterface when town state changed and town list must be updated
  92. void onTownChanged(const CGTownInstance * town);
  93. /// Called when currently selected object changes
  94. void onSelectionChanged(const CArmedInstance *sel);
  95. /// Called when map audio should be paused, e.g. on combat or town screen access
  96. void onAudioPaused();
  97. /// Called when map audio should be resume, opposite to onPaused
  98. void onAudioResumed();
  99. /// Requests to display provided information inside infobox
  100. void showInfoBoxMessage(const std::vector<Component> & components, std::string message, int timer);
  101. /// Changes position on map to center selected location
  102. void centerOnTile(int3 on);
  103. void centerOnObject(const CGObjectInstance *obj);
  104. /// called by MapView whenever currently visible area changes
  105. /// visibleArea describes now visible map section measured in tiles
  106. void onMapViewMoved(const Rect & visibleArea, int mapLevel);
  107. /// called by MapView whenever tile is clicked
  108. void onTileLeftClicked(const int3 & mapPos);
  109. /// called by MapView whenever tile is hovered
  110. void onTileHovered(const int3 & mapPos);
  111. /// called by MapView whenever tile is clicked
  112. void onTileRightClicked(const int3 & mapPos);
  113. /// called by spell window when spell to cast has been selected
  114. void enterCastingMode(const CSpell * sp);
  115. /// returns area of screen covered by terrain (main game area)
  116. Rect terrainAreaPixels() const;
  117. /// opens world view at default scale
  118. void openWorldView();
  119. /// opens world view at specific scale
  120. void openWorldView(int tileSize);
  121. /// opens world view with specific info, e.g. after View Earth/Air is shown
  122. void openWorldView(const std::vector<ObjectPosInfo>& objectPositions, bool showTerrain);
  123. };
  124. extern std::shared_ptr<CAdventureMapInterface> adventureInt;