CPlayerInterface.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. class CPlayerInterface : public CGameInterface
  69. {
  70. public:
  71. //minor interfaces
  72. CondSh<bool> *showingDialog; //indicates if dialog box is displayed
  73. boost::recursive_mutex *pim;
  74. bool makingTurn; //if player is already making his turn
  75. //TODO: exclude to some kind Settings struct
  76. int heroMoveSpeed; //speed of player's hero movement
  77. void setHeroMoveSpeed(int newSpeed) {heroMoveSpeed = newSpeed;} //set for the member above
  78. int mapScrollingSpeed; //map scrolling speed
  79. void setMapScrollingSpeed(int newSpeed) {mapScrollingSpeed = newSpeed;} //set the member above
  80. SDL_Event * current; //current event
  81. CAdvMapInt * adventureInt;
  82. CCastleInterface * castleInt; //NULL if castle window isn't opened
  83. CBattleInterface * battleInt; //NULL if no battle
  84. CInGameConsole * cingconsole;
  85. FPSmanager * mainFPSmng; //to keep const framerate
  86. IStatusBar *statusbar; //current statusbar - will be used to show hover tooltips
  87. CCallback * cb; //to communicate with engine
  88. const BattleAction *curAction; //during the battle - action currently performed by active stack (or NULL)
  89. std::list<CInfoWindow *> dialogs; //queue of dialogs awaiting to be shown (not currently shown!)
  90. std::list<IShowActivable *> listInt; //list of interfaces - front=foreground; back = background (includes adventure map, window interfaces, all kind of active dialogs, and so on)
  91. void totalRedraw(); //forces total redraw (using showAll)
  92. void popInt(IShowActivable *top); //removes given interface from the top and activates next
  93. void popIntTotally(IShowActivable *top); //deactivates, deletes, removes given interface from the top and activates next
  94. void pushInt(IShowActivable *newInt); //deactivate old top interface, activates this one and pushes to the top
  95. void popInts(int howMany); //pops one or more interfaces - deactivates top, deletes and removes given number of interfaces, activates new front
  96. IShowActivable *topInt(); //returns top interface
  97. std::vector<const CGHeroInstance *> wanderingHeroes; //our heroes on the adventure map (not the garrisoned ones)
  98. void recreateWanderingHeroes();
  99. const CGHeroInstance *getWHero(int pos); //returns NULL if position is not valid
  100. //GUI elements
  101. std::list<ClickableL*> lclickable;
  102. std::list<ClickableR*> rclickable;
  103. std::list<Hoverable*> hoverable;
  104. std::list<KeyInterested*> keyinterested;
  105. std::list<MotionInterested*> motioninterested;
  106. std::list<TimeInterested*> timeinterested;
  107. std::vector<IShowable*> objsToBlit;
  108. //overloaded funcs from CGameInterface
  109. void buildChanged(const CGTownInstance *town, int buildingID, int what); //what: 1 - built, 2 - demolished
  110. void garrisonChanged(const CGObjectInstance * obj);
  111. void heroArtifactSetChanged(const CGHeroInstance* hero);
  112. void heroCreated(const CGHeroInstance* hero);
  113. void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback);
  114. void heroInGarrisonChange(const CGTownInstance *town);
  115. void heroKilled(const CGHeroInstance* hero);
  116. void heroMoved(const TryMoveHero & details);
  117. void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val);
  118. void heroManaPointsChanged(const CGHeroInstance * hero);
  119. void heroMovePointsChanged(const CGHeroInstance * hero);
  120. void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town);
  121. void receivedResource(int type, int val);
  122. void showInfoDialog(const std::string &text, const std::vector<Component*> &components, int soundID);
  123. //void showSelDialog(const std::string &text, const std::vector<Component*> &components, ui32 askID);
  124. //void showYesNoDialog(const std::string &text, const std::vector<Component*> &components, ui32 askID);
  125. 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.
  126. void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, boost::function<void()> &onEnd);
  127. void tileHidden(const std::set<int3> &pos); //called when given tiles become hidden under fog of war
  128. void tileRevealed(const std::set<int3> &pos); //called when fog of war disappears from given tiles
  129. void yourTurn();
  130. void availableCreaturesChanged(const CGTownInstance *town);
  131. void heroBonusChanged(const CGHeroInstance *hero, const HeroBonus &bonus, bool gain);//if gain hero received bonus, else he lost it
  132. void requestRealized(PackageApplied *pa);
  133. void heroExchangeStarted(si32 hero1, si32 hero2);
  134. void serialize(COSer<CSaveFile> &h, const int version); //saving
  135. void serialize(CISer<CLoadFile> &h, const int version); //loading
  136. //for battles
  137. void actionFinished(const BattleAction* action);//occurs AFTER action taken by active stack or by the hero
  138. void actionStarted(const BattleAction* action);//occurs BEFORE action taken by active stack or by the hero
  139. BattleAction activeStack(int stackID); //called when it's turn of that stack
  140. void battleAttack(BattleAttack *ba); //stack performs attack
  141. void battleEnd(BattleResult *br); //end of battle
  142. //void battleResultQuited();
  143. void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
  144. void battleStackMoved(int ID, int dest, int distance, bool end);
  145. void battleSpellCast(SpellCast *sc);
  146. void battleStacksEffectsSet(SetStackEffect & sse); //called when a specific effect is set to stacks
  147. void battleStacksAttacked(std::set<BattleStackAttacked> & bsa);
  148. 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
  149. void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning
  150. //-------------//
  151. bool shiftPressed() const; //determines if shift key is pressed (left or right or both)
  152. void redrawHeroWin(const CGHeroInstance * hero);
  153. void updateWater();
  154. void showComp(SComponent comp); //TODO: comment me
  155. void openTownWindow(const CGTownInstance * town); //shows townscreen
  156. void openHeroWindow(const CGHeroInstance * hero); //shows hero window with given hero
  157. SDL_Surface * infoWin(const CGObjectInstance * specific); //specific=0 => draws info about selected town/hero
  158. void handleEvent(SDL_Event * sEvent);
  159. void handleKeyDown(SDL_Event *sEvent);
  160. void handleKeyUp(SDL_Event *sEvent);
  161. void handleMouseMotion(SDL_Event *sEvent);
  162. void init(ICallback * CB);
  163. int3 repairScreenPos(int3 pos); //returns position closest to pos we can center screen on
  164. void showInfoDialog(const std::string &text, const std::vector<SComponent*> & components, int soundID);
  165. 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
  166. bool moveHero(const CGHeroInstance *h, CPath path);
  167. CPlayerInterface(int Player, int serial);//c-tor
  168. ~CPlayerInterface();//d-tor
  169. //////////////////////////////////////////////////////////////////////////
  170. template <typename Handler> void serializeTempl(Handler &h, const int version);
  171. };
  172. extern CPlayerInterface * LOCPLINT;
  173. #endif // __CPLAYERINTERFACE_H__