CAdvMapInt.h 6.0 KB

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