CAdvMapInt.h 5.9 KB

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