CAdvMapInt.h 6.2 KB

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