CAdvmapInterface.h 6.5 KB

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