CPlayerInterface.h 8.7 KB

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