CAdvMapInt.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. #include "CTerrainRect.h"
  15. #include "CResDataBar.h"
  16. #include "CList.h"
  17. #include "CInfoBar.h"
  18. #include "CMinimap.h"
  19. VCMI_LIB_NAMESPACE_BEGIN
  20. class CGObjectInstance;
  21. class CGHeroInstance;
  22. class CGTownInstance;
  23. class CArmedInstance;
  24. class IShipyard;
  25. struct CGPathNode;
  26. struct ObjectPosInfo;
  27. VCMI_LIB_NAMESPACE_END
  28. class CButton;
  29. class IImage;
  30. class CAnimImage;
  31. class CGStatusBar;
  32. class CAdvMapPanel;
  33. class CAdvMapWorldViewPanel;
  34. class CAnimation;
  35. struct MapDrawingInfo;
  36. enum class EAdvMapMode
  37. {
  38. NORMAL,
  39. WORLD_VIEW
  40. };
  41. /// That's a huge class which handles general adventure map actions and
  42. /// shows the right menu(questlog, spellbook, end turn,..) from where you
  43. /// can get to the towns and heroes.
  44. class CAdvMapInt : public CIntObject
  45. {
  46. //Return object that must be active at this tile (=clickable)
  47. const CGObjectInstance *getActiveObject(const int3 &tile);
  48. boost::optional<Point> keyToMoveDirection(const SDL_Keycode & key);
  49. public:
  50. CAdvMapInt();
  51. int3 position; //top left corner of visible map part
  52. PlayerColor player;
  53. bool duringAITurn;
  54. enum{LEFT=1, RIGHT=2, UP=4, DOWN=8};
  55. ui8 scrollingDir; //uses enum: LEFT RIGHT, UP, DOWN
  56. bool scrollingState;
  57. bool swipeEnabled;
  58. bool swipeMovementRequested;
  59. int3 swipeTargetPosition;
  60. enum{NA, INGAME, WAITING} state;
  61. bool updateScreen;
  62. ui8 anim, animValHitCount; //animation frame
  63. ui8 heroAnim, heroAnimValHitCount; //animation frame
  64. EAdvMapMode mode;
  65. float worldViewScale;
  66. struct WorldViewOptions
  67. {
  68. bool showAllTerrain; //for expert viewEarth
  69. std::vector<ObjectPosInfo> iconPositions;
  70. WorldViewOptions();
  71. void clear();
  72. void adjustDrawingInfo(MapDrawingInfo & info);
  73. };
  74. WorldViewOptions worldViewOptions;
  75. std::shared_ptr<IImage> bg;
  76. std::shared_ptr<IImage> bgWorldView;
  77. std::vector<std::shared_ptr<CAnimImage>> gems;
  78. CMinimap minimap;
  79. std::shared_ptr<CGStatusBar> statusbar;
  80. std::shared_ptr<CButton> kingOverview;
  81. std::shared_ptr<CButton> underground;
  82. std::shared_ptr<CButton> questlog;
  83. std::shared_ptr<CButton> sleepWake;
  84. std::shared_ptr<CButton> moveHero;
  85. std::shared_ptr<CButton> spellbook;
  86. std::shared_ptr<CButton> advOptions;
  87. std::shared_ptr<CButton> sysOptions;
  88. std::shared_ptr<CButton> nextHero;
  89. std::shared_ptr<CButton> endTurn;
  90. std::shared_ptr<CButton> worldViewUnderground;
  91. CTerrainRect terrain; //visible terrain
  92. CResDataBar resdatabar;
  93. CHeroList heroList;
  94. CTownList townList;
  95. CInfoBar infoBar;
  96. std::shared_ptr<CAdvMapPanel> panelMain; // panel that holds all right-side buttons in normal view
  97. std::shared_ptr<CAdvMapWorldViewPanel> panelWorldView; // panel that holds all buttons and other ui in world view
  98. std::shared_ptr<CAdvMapPanel> activeMapPanel; // currently active panel (either main or world view, depending on current mode)
  99. std::shared_ptr<CAnimation> worldViewIcons;// images for world view overlay
  100. const CSpell *spellBeingCasted; //nullptr if none
  101. const CArmedInstance *selection; //currently selected town/hero
  102. //functions bound to buttons
  103. void fshowOverview();
  104. void fworldViewBack();
  105. void fworldViewScale1x();
  106. void fworldViewScale2x();
  107. void fworldViewScale4x();
  108. void fswitchLevel();
  109. void fshowQuestlog();
  110. void fsleepWake();
  111. void fmoveHero();
  112. void fshowSpellbok();
  113. void fadventureOPtions();
  114. void fsystemOptions();
  115. void fnextHero();
  116. void fendTurn();
  117. void activate() override;
  118. void deactivate() override;
  119. void show(SDL_Surface * to) override; //redraws terrain
  120. void showAll(SDL_Surface * to) override; //shows and activates adv. map interface
  121. void select(const CArmedInstance *sel, bool centerView = true);
  122. void selectionChanged();
  123. void centerOn(int3 on, bool fade = false);
  124. void centerOn(const CGObjectInstance *obj, bool fade = false);
  125. int3 verifyPos(int3 ver);
  126. void handleRightClick(std::string text, tribool down);
  127. void keyPressed(const SDL_Keycode & key) override;
  128. void keyReleased(const SDL_Keycode & key) override;
  129. void mouseMoved (const Point & cursorPosition) override;
  130. bool isActive();
  131. bool isHeroSleeping(const CGHeroInstance *hero);
  132. void setHeroSleeping(const CGHeroInstance *hero, bool sleep);
  133. int getNextHeroIndex(int startIndex); //for Next Hero button - cycles awake heroes with movement only
  134. void setPlayer(PlayerColor Player);
  135. void startHotSeatWait(PlayerColor Player);
  136. void startTurn();
  137. void endingTurn();
  138. void aiTurnStarted();
  139. void adjustActiveness(bool aiTurnStart); //should be called every time at AI/human turn transition; blocks GUI during AI turn
  140. void quickCombatLock(); //should be called when quick battle started
  141. void quickCombatUnlock();
  142. void tileLClicked(const int3 &mapPos);
  143. void tileHovered(const int3 &mapPos);
  144. void tileRClicked(const int3 &mapPos);
  145. void enterCastingMode(const CSpell * sp);
  146. void leaveCastingMode(bool cast = false, int3 dest = int3(-1, -1, -1));
  147. const CGHeroInstance * curHero() const;
  148. const CGTownInstance * curTown() const;
  149. const IShipyard * ourInaccessibleShipyard(const CGObjectInstance *obj) const; //checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or nullptr else
  150. //button updates
  151. void updateSleepWake(const CGHeroInstance *h);
  152. void updateMoveHero(const CGHeroInstance *h, tribool hasPath = boost::logic::indeterminate);
  153. void updateSpellbook(const CGHeroInstance *h);
  154. void updateNextHero(const CGHeroInstance *h);
  155. /// changes current adventure map mode; used to switch between default view and world view; scale is ignored if EAdvMapMode == NORMAL
  156. void changeMode(EAdvMapMode newMode, float newScale = 0.36f);
  157. void handleMapScrollingUpdate();
  158. void handleSwipeUpdate();
  159. private:
  160. void ShowMoveDetailsInStatusbar(const CGHeroInstance & hero, const CGPathNode & pathNode);
  161. };
  162. extern std::shared_ptr<CAdvMapInt> adventureInt;