CAdvmapInterface.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. #pragma once
  2. #include "../widgets/AdventureMapClasses.h"
  3. #include "CWindowObject.h"
  4. #include "../widgets/TextControls.h"
  5. #include "../widgets/Buttons.h"
  6. class CDefHandler;
  7. class CCallback;
  8. struct CGPath;
  9. class CAdvMapInt;
  10. class CGHeroInstance;
  11. class CGTownInstance;
  12. class CHeroWindow;
  13. class CSpell;
  14. class IShipyard;
  15. enum class EMapAnimRedrawStatus;
  16. class CFadeAnimation;
  17. /*****************************/
  18. /*
  19. * CAdvmapInterface.h, part of VCMI engine
  20. *
  21. * Authors: listed in file AUTHORS in main folder
  22. *
  23. * License: GNU General Public License v2.0 or later
  24. * Full text of license available in license.txt file, in main folder
  25. *
  26. */
  27. enum class EAdvMapMode
  28. {
  29. NORMAL,
  30. WORLD_VIEW
  31. };
  32. /// Adventure options dialogue where you can view the world, dig, play the replay of the last turn,...
  33. class CAdventureOptions : public CWindowObject
  34. {
  35. public:
  36. CButton *exit, *viewWorld, *puzzle, *dig, *scenInfo, *replay;
  37. CAdventureOptions();
  38. static void showScenarioInfo();
  39. };
  40. /// Holds information about which tiles of the terrain are shown/not shown at the screen
  41. class CTerrainRect
  42. : public CIntObject
  43. {
  44. SDL_Surface * fadeSurface;
  45. EMapAnimRedrawStatus lastRedrawStatus;
  46. CFadeAnimation * fadeAnim;
  47. public:
  48. int tilesw, tilesh; //width and height of terrain to blit in tiles
  49. int3 curHoveredTile;
  50. int moveX, moveY; //shift between actual position of screen and the one we wil blit; ranges from -31 to 31 (in pixels)
  51. CTerrainRect();
  52. virtual ~CTerrainRect();
  53. CGPath * currentPath;
  54. void deactivate();
  55. void clickLeft(tribool down, bool previousState);
  56. void clickRight(tribool down, bool previousState);
  57. void hover(bool on);
  58. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  59. void show(SDL_Surface * to);
  60. void showAll(SDL_Surface * to);
  61. void showAnim(SDL_Surface * to);
  62. void showPath(const SDL_Rect * extRect, SDL_Surface * to);
  63. int3 whichTileIsIt(const int & x, const int & y); //x,y are cursor position
  64. int3 whichTileIsIt(); //uses current cursor pos
  65. /// @returns number of visible tiles on screen respecting current map scaling
  66. int3 tileCountOnScreen();
  67. /// animates view by caching current surface and crossfading it with normal screen
  68. void fadeFromCurrentView();
  69. bool needsAnimUpdate();
  70. };
  71. /// Resources bar which shows information about how many gold, crystals,... you have
  72. /// Current date is displayed too
  73. class CResDataBar : public CIntObject
  74. {
  75. public:
  76. SDL_Surface * bg;
  77. std::vector<std::pair<int,int> > txtpos;
  78. std::string datetext;
  79. void clickRight(tribool down, bool previousState);
  80. CResDataBar();
  81. CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist);
  82. ~CResDataBar();
  83. void draw(SDL_Surface * to);
  84. void show(SDL_Surface * to);
  85. void showAll(SDL_Surface * to);
  86. };
  87. /// That's a huge class which handles general adventure map actions and
  88. /// shows the right menu(questlog, spellbook, end turn,..) from where you
  89. /// can get to the towns and heroes.
  90. class CAdvMapInt : public CIntObject
  91. {
  92. //Return object that must be active at this tile (=clickable)
  93. const CGObjectInstance *getActiveObject(const int3 &tile);
  94. public:
  95. CAdvMapInt();
  96. ~CAdvMapInt();
  97. int3 position; //top left corner of visible map part
  98. PlayerColor player;
  99. bool duringAITurn;
  100. enum{LEFT=1, RIGHT=2, UP=4, DOWN=8};
  101. ui8 scrollingDir; //uses enum: LEFT RIGHT, UP, DOWN
  102. enum{NA, INGAME, WAITING} state;
  103. bool updateScreen;
  104. ui8 anim, animValHitCount; //animation frame
  105. ui8 heroAnim, heroAnimValHitCount; //animation frame
  106. EAdvMapMode mode;
  107. float worldViewScale;
  108. SDL_Surface * bg;
  109. SDL_Surface * bgWorldView;
  110. std::vector<CDefHandler *> gems;
  111. CMinimap minimap;
  112. CGStatusBar statusbar;
  113. CButton * kingOverview;
  114. CButton * underground;
  115. CButton * questlog;
  116. CButton * sleepWake;
  117. CButton * moveHero;
  118. CButton * spellbook;
  119. CButton * advOptions;
  120. CButton * sysOptions;
  121. CButton * nextHero;
  122. CButton * endTurn;
  123. CButton * worldViewUnderground;
  124. CTerrainRect terrain; //visible terrain
  125. CResDataBar resdatabar;
  126. CHeroList heroList;
  127. CTownList townList;
  128. CInfoBar infoBar;
  129. CAdvMapPanel *panelMain; // panel that holds all right-side buttons in normal view
  130. CAdvMapWorldViewPanel *panelWorldView; // panel that holds all buttons and other ui in world view
  131. CAdvMapPanel *activeMapPanel; // currently active panel (either main or world view, depending on current mode)
  132. CDefHandler * worldViewIconsDef; // images for world view overlay
  133. const CSpell *spellBeingCasted; //nullptr if none
  134. const CArmedInstance *selection; //currently selected town/hero
  135. //functions bound to buttons
  136. void fshowOverview();
  137. void fworldViewBack();
  138. void fworldViewScale1x();
  139. void fworldViewScale2x();
  140. void fworldViewScale4x();
  141. void fswitchLevel();
  142. void fshowQuestlog();
  143. void fsleepWake();
  144. void fmoveHero();
  145. void fshowSpellbok();
  146. void fadventureOPtions();
  147. void fsystemOptions();
  148. void fnextHero();
  149. void fendTurn();
  150. void activate();
  151. void deactivate();
  152. void show(SDL_Surface * to); //redraws terrain
  153. void showAll(SDL_Surface * to); //shows and activates adv. map interface
  154. void select(const CArmedInstance *sel, bool centerView = true);
  155. void selectionChanged();
  156. void centerOn(int3 on, bool fade = false);
  157. void centerOn(const CGObjectInstance *obj, bool fade = false);
  158. int3 verifyPos(int3 ver);
  159. void handleRightClick(std::string text, tribool down);
  160. void keyPressed(const SDL_KeyboardEvent & key);
  161. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  162. bool isActive();
  163. bool isHeroSleeping(const CGHeroInstance *hero);
  164. void setHeroSleeping(const CGHeroInstance *hero, bool sleep);
  165. int getNextHeroIndex(int startIndex); //for Next Hero button - cycles awake heroes with movement only
  166. void setPlayer(PlayerColor Player);
  167. void startHotSeatWait(PlayerColor Player);
  168. void startTurn();
  169. void endingTurn();
  170. void aiTurnStarted();
  171. void adjustActiveness(bool aiTurnStart); //should be called every time at AI/human turn transition; blocks GUI during AI turn
  172. void tileLClicked(const int3 &mapPos);
  173. void tileHovered(const int3 &mapPos);
  174. void tileRClicked(const int3 &mapPos);
  175. void enterCastingMode(const CSpell * sp);
  176. void leaveCastingMode(bool cast = false, int3 dest = int3(-1, -1, -1));
  177. const CGHeroInstance * curHero() const;
  178. const CGTownInstance * curTown() const;
  179. const IShipyard * ourInaccessibleShipyard(const CGObjectInstance *obj) const; //checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or nullptr else
  180. //button updates
  181. void updateSleepWake(const CGHeroInstance *h);
  182. void updateMoveHero(const CGHeroInstance *h, tribool hasPath = boost::logic::indeterminate);
  183. void updateNextHero(const CGHeroInstance *h);
  184. /// changes current adventure map mode; used to switch between default view and world view; scale is ignored if EAdvMapMode == NORMAL
  185. void changeMode(EAdvMapMode newMode, float newScale = 0.36f);
  186. };
  187. extern CAdvMapInt *adventureInt;