CPlayerInterface.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. #ifndef __CPLAYERINTERFACE_H__
  2. #define __CPLAYERINTERFACE_H__
  3. #include "../global.h"
  4. #include "../CGameInterface.h"
  5. #include "SDL_framerate.h"
  6. #include <map>
  7. #include <list>
  8. #include <algorithm>
  9. #ifdef __GNUC__
  10. #define sprintf_s snprintf
  11. #endif
  12. #ifdef max
  13. #undef max
  14. #endif
  15. #ifdef min
  16. #undef min
  17. #endif
  18. /*
  19. * CPlayerInterface.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. class CDefEssential;
  28. class AdventureMapButton;
  29. class CHighlightableButtonsGroup;
  30. class CDefHandler;
  31. struct TryMoveHero;
  32. class CDefEssential;
  33. class CGHeroInstance;
  34. class CAdvMapInt;
  35. class CCastleInterface;
  36. class CBattleInterface;
  37. class CStack;
  38. class SComponent;
  39. class CCreature;
  40. struct SDL_Surface;
  41. struct CPath;
  42. class CCreatureAnimation;
  43. class CSelectableComponent;
  44. class CCreatureSet;
  45. class CGObjectInstance;
  46. class CSlider;
  47. struct UpgradeInfo;
  48. template <typename T> struct CondSh;
  49. class CInGameConsole;
  50. class CGarrisonInt;
  51. class CInGameConsole;
  52. union SDL_Event;
  53. class IStatusBar;
  54. class CInfoWindow;
  55. class IShowActivable;
  56. class ClickableL;
  57. class ClickableR;
  58. class Hoverable;
  59. class KeyInterested;
  60. class MotionInterested;
  61. class TimeInterested;
  62. class IShowable;
  63. namespace boost
  64. {
  65. class mutex;
  66. class recursive_mutex;
  67. };
  68. struct SystemOptions
  69. {
  70. ui8 heroMoveSpeed; //speed of player's hero movement
  71. //TODO: enemy hero speed
  72. ui8 mapScrollingSpeed; //map scrolling speed
  73. ui8 musicVolume, soundVolume;
  74. //TODO: rest of system options
  75. template <typename Handler> void serialize(Handler &h, const int version)
  76. {
  77. h & heroMoveSpeed & mapScrollingSpeed & musicVolume & soundVolume;
  78. }
  79. SystemOptions()
  80. {
  81. heroMoveSpeed = 2;
  82. mapScrollingSpeed = 2;
  83. musicVolume = 88;
  84. soundVolume = 88;
  85. }
  86. void setHeroMoveSpeed(int newSpeed); //set for the member above
  87. void setMapScrollingSpeed(int newSpeed); //set the member above
  88. void setMusicVolume(int newVolume);
  89. void setSoundVolume(int newVolume);
  90. void settingsChanged(); //updates file with "default" settings for next running of application
  91. void apply();
  92. };
  93. extern SystemOptions GDefaultOptions; //defined and inited in CMT.cpp, stores default settings loaded with application
  94. class CPlayerInterface : public CGameInterface
  95. {
  96. public:
  97. //minor interfaces
  98. CondSh<bool> *showingDialog; //indicates if dialog box is displayed
  99. boost::recursive_mutex *pim;
  100. bool makingTurn; //if player is already making his turn
  101. SystemOptions sysOpts;
  102. SDL_Event * current; //current event
  103. CAdvMapInt * adventureInt;
  104. CCastleInterface * castleInt; //NULL if castle window isn't opened
  105. CBattleInterface * battleInt; //NULL if no battle
  106. CInGameConsole * cingconsole;
  107. FPSmanager * mainFPSmng; //to keep const framerate
  108. IStatusBar *statusbar; //current statusbar - will be used to show hover tooltips
  109. CCallback * cb; //to communicate with engine
  110. const BattleAction *curAction; //during the battle - action currently performed by active stack (or NULL)
  111. std::list<CInfoWindow *> dialogs; //queue of dialogs awaiting to be shown (not currently shown!)
  112. std::list<IShowActivable *> listInt; //list of interfaces - front=foreground; back = background (includes adventure map, window interfaces, all kind of active dialogs, and so on)
  113. void totalRedraw(); //forces total redraw (using showAll)
  114. void popInt(IShowActivable *top); //removes given interface from the top and activates next
  115. void popIntTotally(IShowActivable *top); //deactivates, deletes, removes given interface from the top and activates next
  116. void pushInt(IShowActivable *newInt); //deactivate old top interface, activates this one and pushes to the top
  117. void popInts(int howMany); //pops one or more interfaces - deactivates top, deletes and removes given number of interfaces, activates new front
  118. IShowActivable *topInt(); //returns top interface
  119. std::vector<const CGHeroInstance *> wanderingHeroes; //our heroes on the adventure map (not the garrisoned ones)
  120. void recreateWanderingHeroes();
  121. const CGHeroInstance *getWHero(int pos); //returns NULL if position is not valid
  122. //GUI elements
  123. std::list<ClickableL*> lclickable;
  124. std::list<ClickableR*> rclickable;
  125. std::list<Hoverable*> hoverable;
  126. std::list<KeyInterested*> keyinterested;
  127. std::list<MotionInterested*> motioninterested;
  128. std::list<TimeInterested*> timeinterested;
  129. std::vector<IShowable*> objsToBlit;
  130. //overloaded funcs from CGameInterface
  131. void buildChanged(const CGTownInstance *town, int buildingID, int what); //what: 1 - built, 2 - demolished
  132. void garrisonChanged(const CGObjectInstance * obj);
  133. void heroArtifactSetChanged(const CGHeroInstance* hero);
  134. void heroCreated(const CGHeroInstance* hero);
  135. void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback);
  136. void heroInGarrisonChange(const CGTownInstance *town);
  137. void heroMoved(const TryMoveHero & details);
  138. void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val);
  139. void heroManaPointsChanged(const CGHeroInstance * hero);
  140. void heroMovePointsChanged(const CGHeroInstance * hero);
  141. void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town);
  142. void receivedResource(int type, int val);
  143. void showInfoDialog(const std::string &text, const std::vector<Component*> &components, int soundID);
  144. void showRecruitmentDialog(const CGDwelling *dwelling, const CArmedInstance *dst, int level);
  145. void showShipyardDialog(const IShipyard *obj); //obj may be town or shipyard;
  146. void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, int soundID, bool selection, bool cancel); //Show a dialog, player must take decision. If selection then he has to choose between one of given components, if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called with number of selected component (1 - n) or 0 for cancel (if allowed) and askID.
  147. void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, boost::function<void()> &onEnd);
  148. void tileHidden(const std::set<int3> &pos); //called when given tiles become hidden under fog of war
  149. void tileRevealed(const std::set<int3> &pos); //called when fog of war disappears from given tiles
  150. void newObject(const CGObjectInstance * obj);
  151. void yourTurn();
  152. void availableCreaturesChanged(const CGDwelling *town);
  153. void heroBonusChanged(const CGHeroInstance *hero, const HeroBonus &bonus, bool gain);//if gain hero received bonus, else he lost it
  154. void requestRealized(PackageApplied *pa);
  155. void heroExchangeStarted(si32 hero1, si32 hero2);
  156. void objectPropertyChanged(const SetObjectProperty * sop);
  157. void objectRemoved(const CGObjectInstance *obj);
  158. void serialize(COSer<CSaveFile> &h, const int version); //saving
  159. void serialize(CISer<CLoadFile> &h, const int version); //loading
  160. //for battles
  161. void actionFinished(const BattleAction* action);//occurs AFTER action taken by active stack or by the hero
  162. void actionStarted(const BattleAction* action);//occurs BEFORE action taken by active stack or by the hero
  163. BattleAction activeStack(int stackID); //called when it's turn of that stack
  164. void battleAttack(BattleAttack *ba); //stack performs attack
  165. void battleEnd(BattleResult *br); //end of battle
  166. //void battleResultQuited();
  167. void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
  168. void battleStackMoved(int ID, int dest, int distance, bool end);
  169. void battleSpellCast(SpellCast *sc);
  170. void battleStacksEffectsSet(SetStackEffect & sse); //called when a specific effect is set to stacks
  171. void battleStacksAttacked(std::set<BattleStackAttacked> & bsa);
  172. void battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side); //called by engine when battle starts; side=0 - left, side=1 - right
  173. void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning
  174. void battleStacksHealedRes(const std::vector<std::pair<ui32, ui32> > & healedStacks); //called when stacks are healed / resurrected
  175. void battleNewStackAppeared(int stackID); //not called at the beginning of a battle or by resurrection; called eg. when elemental is summoned
  176. //-------------//
  177. void heroKilled(const CGHeroInstance* hero);
  178. void waitWhileDialog();
  179. bool shiftPressed() const; //determines if shift key is pressed (left or right or both)
  180. void redrawHeroWin(const CGHeroInstance * hero);
  181. void updateWater();
  182. void showComp(SComponent comp); //TODO: comment me
  183. void openTownWindow(const CGTownInstance * town); //shows townscreen
  184. void openHeroWindow(const CGHeroInstance * hero); //shows hero window with given hero
  185. SDL_Surface * infoWin(const CGObjectInstance * specific); //specific=0 => draws info about selected town/hero
  186. void handleEvent(SDL_Event * sEvent);
  187. void handleKeyDown(SDL_Event *sEvent);
  188. void handleKeyUp(SDL_Event *sEvent);
  189. void handleMouseMotion(SDL_Event *sEvent);
  190. void init(ICallback * CB);
  191. int3 repairScreenPos(int3 pos); //returns position closest to pos we can center screen on
  192. void showInfoDialog(const std::string &text, const std::vector<SComponent*> & components = std::vector<SComponent*>(), int soundID = 0);
  193. void showYesNoDialog(const std::string &text, const std::vector<SComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool DelComps); //deactivateCur - whether current main interface should be deactivated; delComps - if components will be deleted on window close
  194. bool moveHero(const CGHeroInstance *h, CPath path);
  195. CPlayerInterface(int Player, int serial);//c-tor
  196. ~CPlayerInterface();//d-tor
  197. //////////////////////////////////////////////////////////////////////////
  198. template <typename Handler> void serializeTempl(Handler &h, const int version);
  199. };
  200. extern CPlayerInterface * LOCPLINT;
  201. #endif // __CPLAYERINTERFACE_H__