CAdvMapInt.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. #include "../../lib/int3.h"
  13. #include "../../lib/GameConstants.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class CGObjectInstance;
  16. class CGHeroInstance;
  17. class CGTownInstance;
  18. class CArmedInstance;
  19. class IShipyard;
  20. struct CGPathNode;
  21. struct ObjectPosInfo;
  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. enum class EAdvMapMode
  39. {
  40. NORMAL,
  41. WORLD_VIEW
  42. };
  43. /// That's a huge class which handles general adventure map actions and
  44. /// shows the right menu(questlog, spellbook, end turn,..) from where you
  45. /// can get to the towns and heroes.
  46. class CAdvMapInt : public CIntObject
  47. {
  48. //TODO: remove
  49. friend class CPlayerInterface;
  50. private:
  51. enum EDirections {LEFT=1, RIGHT=2, UP=4, DOWN=8};
  52. enum EGameStates {NA, INGAME, WAITING};
  53. EGameStates state;
  54. EAdvMapMode mode;
  55. /// Currently selected object, can be town, hero or null
  56. const CArmedInstance *selection;
  57. /// currently acting player
  58. PlayerColor player;
  59. bool duringAITurn;
  60. /// uses EDirections enum
  61. ui8 scrollingDir;
  62. bool scrollingState;
  63. const CSpell *spellBeingCasted; //nullptr if none
  64. std::vector<std::shared_ptr<CAnimImage>> gems;
  65. std::shared_ptr<IImage> bg;
  66. std::shared_ptr<IImage> bgWorldView;
  67. std::shared_ptr<CButton> kingOverview;
  68. std::shared_ptr<CButton> sleepWake;
  69. std::shared_ptr<CButton> underground;
  70. std::shared_ptr<CButton> questlog;
  71. std::shared_ptr<CButton> moveHero;
  72. std::shared_ptr<CButton> spellbook;
  73. std::shared_ptr<CButton> advOptions;
  74. std::shared_ptr<CButton> sysOptions;
  75. std::shared_ptr<CButton> nextHero;
  76. std::shared_ptr<CButton> endTurn;
  77. std::shared_ptr<CButton> worldViewUnderground;
  78. std::shared_ptr<MapView> terrain;
  79. std::shared_ptr<CMinimap> minimap;
  80. std::shared_ptr<CHeroList> heroList;
  81. std::shared_ptr<CTownList> townList;
  82. std::shared_ptr<CInfoBar> infoBar;
  83. std::shared_ptr<CGStatusBar> statusbar;
  84. std::shared_ptr<CResDataBar> resdatabar;
  85. std::shared_ptr<CAdvMapPanel> panelMain; // panel that holds all right-side buttons in normal view
  86. std::shared_ptr<CAdvMapWorldViewPanel> panelWorldView; // panel that holds all buttons and other ui in world view
  87. std::shared_ptr<CAdvMapPanel> activeMapPanel; // currently active panel (either main or world view, depending on current mode)
  88. std::shared_ptr<CAnimation> worldViewIcons;// images for world view overlay
  89. std::shared_ptr<MapAudioPlayer> mapAudio;
  90. private:
  91. //functions bound to buttons
  92. void fshowOverview();
  93. void fworldViewBack();
  94. void fworldViewScale1x();
  95. void fworldViewScale2x();
  96. void fworldViewScale4x();
  97. void fswitchLevel();
  98. void fshowQuestlog();
  99. void fsleepWake();
  100. void fmoveHero();
  101. void fshowSpellbok();
  102. void fadventureOPtions();
  103. void fsystemOptions();
  104. void fnextHero();
  105. void fendTurn();
  106. void setScrollingCursor(ui8 direction) const;
  107. void selectionChanged();
  108. bool isActive();
  109. void adjustActiveness(bool aiTurnStart); //should be called every time at AI/human turn transition; blocks GUI during AI turn
  110. const IShipyard * ourInaccessibleShipyard(const CGObjectInstance *obj) const; //checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or nullptr else
  111. //button updates
  112. void updateSleepWake(const CGHeroInstance *h);
  113. void updateSpellbook(const CGHeroInstance *h);
  114. void handleMapScrollingUpdate();
  115. void showMoveDetailsInStatusbar(const CGHeroInstance & hero, const CGPathNode & pathNode);
  116. const CGObjectInstance *getActiveObject(const int3 &tile);
  117. std::optional<Point> keyToMoveDirection(const SDL_Keycode & key);
  118. public:
  119. CAdvMapInt();
  120. // CIntObject interface implementation
  121. void activate() override;
  122. void deactivate() override;
  123. void show(SDL_Surface * to) override;
  124. void showAll(SDL_Surface * to) override;
  125. void keyPressed(const SDL_Keycode & key) override;
  126. void keyReleased(const SDL_Keycode & key) override;
  127. void mouseMoved (const Point & cursorPosition) override;
  128. // public interface
  129. /// called by MapView whenever currently visible area changes
  130. /// visibleArea describen now visible map section measured in tiles
  131. void onMapViewMoved(const Rect & visibleArea, int mapLevel);
  132. /// Called when map audio should be paused, e.g. on combat or town scren access
  133. void onAudioPaused();
  134. /// Called when map audio should be resume, opposite to onPaused
  135. void onAudioResumed();
  136. void select(const CArmedInstance *sel, bool centerView = true);
  137. void centerOnTile(int3 on);
  138. void centerOnObject(const CGObjectInstance *obj);
  139. bool isHeroSleeping(const CGHeroInstance *hero);
  140. void setHeroSleeping(const CGHeroInstance *hero, bool sleep);
  141. int getNextHeroIndex(int startIndex); //for Next Hero button - cycles awake heroes with movement only
  142. void setPlayer(PlayerColor Player);
  143. void startHotSeatWait(PlayerColor Player);
  144. void startTurn();
  145. void initializeNewTurn();
  146. void endingTurn();
  147. void aiTurnStarted();
  148. void quickCombatLock(); //should be called when quick battle started
  149. void quickCombatUnlock();
  150. void onTileLeftClicked(const int3 & mapPos);
  151. void onTileHovered(const int3 & mapPos);
  152. void onTileRightClicked(const int3 & mapPos);
  153. void enterCastingMode(const CSpell * sp);
  154. void leaveCastingMode(bool cast = false, int3 dest = int3(-1, -1, -1));
  155. const CGHeroInstance * curHero() const;
  156. const CGTownInstance * curTown() const;
  157. const CArmedInstance * curArmy() const;
  158. void updateMoveHero(const CGHeroInstance *h, tribool hasPath = boost::logic::indeterminate);
  159. void updateNextHero(const CGHeroInstance *h);
  160. /// returns area of screen covered by terrain (main game area)
  161. Rect terrainAreaPixels() const;
  162. /// exits currently opened world view mode and returns to normal map
  163. void exitWorldView();
  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<CAdvMapInt> adventureInt;