CAdvmapInterface.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #pragma once
  2. #include <typeinfo>
  3. #include "SDL.h"
  4. #include "UIFramework/CIntObjectClasses.h"
  5. #include "GUIClasses.h"
  6. #include "AdventureMapClasses.h"
  7. class CDefHandler;
  8. class CCallback;
  9. struct CGPath;
  10. class CAdvMapInt;
  11. class CGHeroInstance;
  12. class CGTownInstance;
  13. class CHeroWindow;
  14. class CSpell;
  15. class IShipyard;
  16. /*****************************/
  17. /*
  18. * CAdvmapInterface.h, part of VCMI engine
  19. *
  20. * Authors: listed in file AUTHORS in main folder
  21. *
  22. * License: GNU General Public License v2.0 or later
  23. * Full text of license available in license.txt file, in main folder
  24. *
  25. */
  26. /// Adventure options dialogue where you can view the world, dig, play the replay of the last turn,...
  27. class CAdventureOptions : public CWindowObject
  28. {
  29. public:
  30. CAdventureMapButton *exit, *viewWorld, *puzzle, *dig, *scenInfo, *replay;
  31. CAdventureOptions();
  32. static void showScenarioInfo();
  33. };
  34. /// Holds information about which tiles of the terrain are shown/not shown at the screen
  35. class CTerrainRect
  36. : public CIntObject
  37. {
  38. public:
  39. int tilesw, tilesh; //width and height of terrain to blit in tiles
  40. int3 curHoveredTile;
  41. int moveX, moveY; //shift between actual position of screen and the one we wil blit; ranges from -31 to 31 (in pixels)
  42. CTerrainRect();
  43. CGPath * currentPath;
  44. void deactivate();
  45. void clickLeft(tribool down, bool previousState);
  46. void clickRight(tribool down, bool previousState);
  47. void hover(bool on);
  48. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  49. void show();
  50. void showPath(const SDL_Rect * extRect, SDL_Surface * to);
  51. int3 whichTileIsIt(const int & x, const int & y); //x,y are cursor position
  52. int3 whichTileIsIt(); //uses current cursor pos
  53. };
  54. /// Resources bar which shows information about how many gold, crystals,... you have
  55. /// Current date is displayed too
  56. class CResDataBar : public CIntObject
  57. {
  58. public:
  59. SDL_Surface * bg;
  60. std::vector<std::pair<int,int> > txtpos;
  61. std::string datetext;
  62. void clickRight(tribool down, bool previousState);
  63. CResDataBar();
  64. CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist);
  65. ~CResDataBar();
  66. void draw(SDL_Surface * to);
  67. void show();
  68. void showAll();
  69. };
  70. /// That's a huge class which handles general adventure map actions and
  71. /// shows the right menu(questlog, spellbook, end turn,..) from where you
  72. /// can get to the towns and heroes.
  73. class CAdvMapInt : public CIntObject
  74. {
  75. //get top selectable object at tile
  76. const CGObjectInstance *getBlockingObject(const int3 &tile);
  77. public:
  78. CAdvMapInt();
  79. ~CAdvMapInt();
  80. int3 position; //top left corner of visible map part
  81. PlayerColor player;
  82. bool duringAITurn;
  83. enum{LEFT=1, RIGHT=2, UP=4, DOWN=8};
  84. ui8 scrollingDir; //uses enum: LEFT RIGHT, UP, DOWN
  85. enum{NA, INGAME, WAITING} state;
  86. bool updateScreen;
  87. ui8 anim, animValHitCount; //animation frame
  88. ui8 heroAnim, heroAnimValHitCount; //animation frame
  89. SDL_Surface * bg;
  90. std::vector<CDefHandler *> gems;
  91. CMinimap minimap;
  92. CGStatusBar statusbar;
  93. CAdventureMapButton kingOverview,//- kingdom overview
  94. underground,//- underground switch
  95. questlog,//- questlog
  96. sleepWake, //- sleep/wake hero
  97. moveHero, //- move hero
  98. spellbook,//- spellbook
  99. advOptions, //- adventure options
  100. sysOptions,//- system options
  101. nextHero, //- next hero
  102. endTurn;//- end turn
  103. CTerrainRect terrain; //visible terrain
  104. CResDataBar resdatabar;
  105. CHeroList heroList;
  106. CTownList townList;
  107. CInfoBar infoBar;
  108. const CSpell *spellBeingCasted; //NULL if none
  109. const CArmedInstance *selection; //currently selected town/hero
  110. //functions bound to buttons
  111. void fshowOverview();
  112. void fswitchLevel();
  113. void fshowQuestlog();
  114. void fsleepWake();
  115. void fmoveHero();
  116. void fshowSpellbok();
  117. void fadventureOPtions();
  118. void fsystemOptions();
  119. void fnextHero();
  120. void fendTurn();
  121. void activate();
  122. void deactivate();
  123. void show(); //redraws terrain
  124. void showAll(); //shows and activates adv. map interface
  125. void select(const CArmedInstance *sel, bool centerView = true);
  126. void selectionChanged();
  127. void centerOn(int3 on);
  128. void centerOn(const CGObjectInstance *obj);
  129. int3 verifyPos(int3 ver);
  130. void handleRightClick(std::string text, tribool down);
  131. void keyPressed(const SDL_KeyboardEvent & key);
  132. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  133. bool isActive();
  134. bool isHeroSleeping(const CGHeroInstance *hero);
  135. void setHeroSleeping(const CGHeroInstance *hero, bool sleep);
  136. int getNextHeroIndex(int startIndex); //for Next Hero button - cycles awake heroes with movement only
  137. void setPlayer(PlayerColor Player);
  138. void startHotSeatWait(PlayerColor Player);
  139. void startTurn();
  140. void endingTurn();
  141. void aiTurnStarted();
  142. void adjustActiveness(bool aiTurnStart); //should be called everytime at AI/human turn transition; blocks GUI during AI turn
  143. void tileLClicked(const int3 &mapPos);
  144. void tileHovered(const int3 &mapPos);
  145. void tileRClicked(const int3 &mapPos);
  146. void enterCastingMode(const CSpell * sp);
  147. void leaveCastingMode(bool cast = false, int3 dest = int3(-1, -1, -1));
  148. const CGHeroInstance * curHero() const;
  149. const CGTownInstance * curTown() const;
  150. const IShipyard * ourInaccessibleShipyard(const CGObjectInstance *obj) const; //checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or NULL else
  151. //button updates
  152. void updateSleepWake(const CGHeroInstance *h);
  153. void updateMoveHero(const CGHeroInstance *h, tribool hasPath = tribool::indeterminate_value);
  154. void updateNextHero(const CGHeroInstance *h);
  155. };
  156. extern CAdvMapInt *adventureInt;