CAdvmapInterface.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. #ifndef __CADVMAPINTERFACE_H__
  2. #define __CADVMAPINTERFACE_H__
  3. #include <typeinfo>
  4. #include "../global.h"
  5. #include "SDL.h"
  6. #include <map>
  7. #include "AdventureMapButton.h"
  8. #include "GUIClasses.h"
  9. class CDefHandler;
  10. class CCallback;
  11. struct CGPath;
  12. class CAdvMapInt;
  13. class CGHeroInstance;
  14. class CGTownInstance;
  15. class CHeroWindow;
  16. class CSpell;
  17. class IShipyard;
  18. /*****************************/
  19. /*
  20. * CAdcmapInterface.h, part of VCMI engine
  21. *
  22. * Authors: listed in file AUTHORS in main folder
  23. *
  24. * License: GNU General Public License v2.0 or later
  25. * Full text of license available in license.txt file, in main folder
  26. *
  27. */
  28. /// Adventure options dialogue where you can view the world, dig, play the replay of the last turn,...
  29. class CAdventureOptions : public CIntObject
  30. {
  31. public:
  32. CPicture *bg;
  33. AdventureMapButton *exit, *viewWorld, *puzzle, *dig, *scenInfo, *replay;
  34. CAdventureOptions();
  35. ~CAdventureOptions();
  36. static void showScenarioInfo();
  37. };
  38. class CMinimapSurfacesRef {
  39. public:
  40. CMinimapSurfacesRef();
  41. std::vector< SDL_Surface* > &map();
  42. std::vector< SDL_Surface* > &FoW();
  43. std::vector< SDL_Surface* > &flObjs();
  44. void free();
  45. private:
  46. void redraw(int level=-1);// (level==-1) => redraw all levels
  47. void initMap(int level=-1);// (level==-1) => redraw all levels
  48. void initFoW(int level=-1);// (level==-1) => redraw all levels
  49. void initFlaggableObjs(int level=-1);// (level==-1) => redraw all levels
  50. void showVisibleTiles(int level=-1);// (level==-1) => redraw all levels
  51. private:
  52. std::vector< SDL_Surface* > map_, FoW_, flObjs_; //one bitmap for each level (terrain, Fog of War, flaggable objects) (one for underworld, one for surface)
  53. bool ready;
  54. };
  55. /// Minimap which is displayed at the right upper corner of adventure map
  56. class CMinimap : public CIntObject
  57. {
  58. public:
  59. CPicture *aiShield; //the graphic displayed during AI turn
  60. SDL_Surface * temps;
  61. std::map<int,SDL_Color> colors;
  62. std::map<int,SDL_Color> colorsBlocked;
  63. std::map<int, CMinimapSurfacesRef> surfs;
  64. std::string statusbarTxt, rcText;
  65. CMinimap();
  66. ~CMinimap();
  67. void draw(SDL_Surface * to);
  68. void updateRadar();
  69. void clickRight(tribool down, bool previousState);
  70. void clickLeft(tribool down, bool previousState);
  71. void hover (bool on);
  72. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  73. void activate(); // makes button active
  74. void deactivate(); // makes button inactive (but don't deletes)
  75. void hideTile(const int3 &pos); //puts FoW
  76. void showTile(const int3 &pos); //removes FoW
  77. };
  78. /// Holds information about which tiles of the terrain are shown/not shown at the screen
  79. class CTerrainRect
  80. : public CIntObject
  81. {
  82. public:
  83. int tilesw, tilesh; //width and height of terrain to blit in tiles
  84. int3 curHoveredTile;
  85. int moveX, moveY; //shift between actual position of screen and the one we wil blit; ranges from -31 to 31 (in pixels)
  86. CTerrainRect();
  87. ~CTerrainRect();
  88. CGPath * currentPath;
  89. void activate();
  90. void deactivate();
  91. void clickLeft(tribool down, bool previousState);
  92. void clickRight(tribool down, bool previousState);
  93. void hover(bool on);
  94. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  95. void show(SDL_Surface * to);
  96. void showPath(const SDL_Rect * extRect, SDL_Surface * to);
  97. int3 whichTileIsIt(const int & x, const int & y); //x,y are cursor position
  98. int3 whichTileIsIt(); //uses current cursor pos
  99. };
  100. /// Resources bar which shows information about how many gold, crystals,... you have
  101. /// Current date is displayed too
  102. class CResDataBar
  103. : public CIntObject
  104. {
  105. public:
  106. SDL_Surface * bg;
  107. std::vector<std::pair<int,int> > txtpos;
  108. std::string datetext;
  109. void clickRight(tribool down, bool previousState);
  110. void activate();
  111. void deactivate();
  112. CResDataBar();
  113. CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist);
  114. ~CResDataBar();
  115. void draw(SDL_Surface * to);
  116. void show(SDL_Surface * to);
  117. void showAll(SDL_Surface * to);
  118. };
  119. /// Info box which shows next week/day information, hold the current date
  120. class CInfoBar : public CIntObject
  121. {
  122. CDefHandler *day, *week1, *week2, *week3, *week4;
  123. SComponent * current;
  124. int pom;
  125. SDL_Surface *selInfoWin; //info box for selection
  126. CDefHandler * getAnim(int mode);
  127. public:
  128. int mode;
  129. const CGHeroInstance * curSel;
  130. CInfoBar();
  131. ~CInfoBar();
  132. void newDay(int Day); //start showing new day/week animation
  133. void showComp(SComponent * comp, int time=5000);
  134. void tick();
  135. void showAll(SDL_Surface * to); // if specific==0 function draws info about selected hero/town
  136. void blitAnim(int mode);//0 - day, 1 - week
  137. void show(SDL_Surface * to);
  138. void activate();
  139. void deactivate();
  140. void updateSelection(const CGObjectInstance *obj);
  141. };
  142. /// That's a huge class which handles general adventure map actions and
  143. /// shows the right menu(questlog, spellbook, end turn,..) from where you
  144. /// can get to the towns and heroes.
  145. class CAdvMapInt : public CIntObject
  146. {
  147. public:
  148. CAdvMapInt();
  149. ~CAdvMapInt();
  150. int3 position; //top left corner of visible map part
  151. int player;
  152. enum{LEFT=1, RIGHT=2, UP=4, DOWN=8};
  153. ui8 scrollingDir; //uses enum: LEFT RIGHT, UP, DOWN
  154. enum{NA, INGAME, WAITING} state;
  155. bool updateScreen, updateMinimap ;
  156. unsigned char anim, animValHitCount; //animation frame
  157. unsigned char heroAnim, heroAnimValHitCount; //animation frame
  158. SDL_Surface * bg;
  159. std::vector<CDefHandler *> gems;
  160. CMinimap minimap;
  161. CStatusBar statusbar;
  162. AdventureMapButton kingOverview,//- kingdom overview
  163. underground,//- underground switch
  164. questlog,//- questlog
  165. sleepWake, //- sleep/wake hero
  166. moveHero, //- move hero
  167. spellbook,//- spellbook
  168. advOptions, //- adventure options
  169. sysOptions,//- system options
  170. nextHero, //- next hero
  171. endTurn;//- end turn
  172. CTerrainRect terrain; //visible terrain
  173. CResDataBar resdatabar;
  174. CHeroList heroList;
  175. CTownList townList;
  176. CInfoBar infoBar;
  177. const CSpell *spellBeingCasted; //NULL if none
  178. const CArmedInstance *selection; //currently selected town/hero
  179. //functions bound to buttons
  180. void fshowOverview();
  181. void fswitchLevel();
  182. void fshowQuestlog();
  183. void fsleepWake();
  184. void fmoveHero();
  185. void fshowSpellbok();
  186. void fadventureOPtions();
  187. void fsystemOptions();
  188. void fnextHero();
  189. void fendTurn();
  190. void activate();
  191. void deactivate();
  192. void show(SDL_Surface * to); //redraws terrain
  193. void showAll(SDL_Surface * to); //shows and activates adv. map interface
  194. void select(const CArmedInstance *sel, bool centerView = true);
  195. void selectionChanged();
  196. void centerOn(int3 on);
  197. void centerOn(const CGObjectInstance *obj);
  198. int3 verifyPos(int3 ver);
  199. void handleRightClick(std::string text, tribool down);
  200. void keyPressed(const SDL_KeyboardEvent & key);
  201. void mouseMoved (const SDL_MouseMotionEvent & sEvent);
  202. bool isActive();
  203. bool isHeroSleeping(const CGHeroInstance *hero);
  204. void setHeroSleeping(const CGHeroInstance *hero, bool sleep);
  205. void setPlayer(int Player);
  206. void startHotSeatWait(int Player);
  207. void startTurn();
  208. void endingTurn();
  209. void tileLClicked(const int3 &mp);
  210. void tileHovered(const int3 &tile);
  211. void tileRClicked(const int3 &mp);
  212. void enterCastingMode(const CSpell * sp);
  213. void leaveCastingMode(bool cast = false, int3 dest = int3(-1, -1, -1));
  214. const CGHeroInstance * curHero() const;
  215. const CGTownInstance * curTown() const;
  216. const IShipyard * ourInaccessibleShipyard(const CGObjectInstance *obj) const; //checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or NULL else
  217. void updateSleepWake(const CGHeroInstance *h); //button update
  218. };
  219. extern CAdvMapInt *adventureInt;
  220. #endif // __CADVMAPINTERFACE_H__