2011-12-14 00:23:17 +03:00
# pragma once
2013-11-30 13:08:38 +03:00
# include "../lib/FunctionList.h"
2011-12-14 00:23:17 +03:00
# include "../lib/CGameInterface.h"
2014-07-15 10:14:49 +03:00
# include "../lib/NetPacksBase.h"
2013-04-07 14:52:07 +03:00
# include "gui/CIntObject.h"
2014-07-15 10:14:49 +03:00
//#include "../lib/CGameState.h"
2009-02-20 15:06:20 +02:00
# ifdef __GNUC__
2012-09-15 22:16:16 +03:00
# define sprintf_s snprintf
2009-02-20 15:06:20 +02:00
# endif
2009-03-21 19:22:16 +02:00
# ifdef max
# undef max
# endif
# ifdef min
# undef min
# endif
2009-04-15 17:03:31 +03:00
/*
* CPlayerInterface . h , part of VCMI engine
*
* Authors : listed in file AUTHORS in main folder
*
* License : GNU General Public License v2 .0 or later
* Full text of license available in license . txt file , in main folder
*
*/
2009-02-20 15:06:20 +02:00
class CDefEssential ;
2014-08-03 14:16:19 +03:00
class CButton ;
class CToggleGroup ;
2009-02-20 15:06:20 +02:00
class CDefHandler ;
2009-07-03 22:57:14 +03:00
struct TryMoveHero ;
2009-02-20 15:06:20 +02:00
class CDefEssential ;
class CGHeroInstance ;
class CAdvMapInt ;
class CCastleInterface ;
class CBattleInterface ;
class CStack ;
2011-12-22 16:05:19 +03:00
class CComponent ;
2009-02-20 15:06:20 +02:00
class CCreature ;
struct SDL_Surface ;
2009-09-07 05:29:44 +03:00
struct CGPath ;
2009-02-20 15:06:20 +02:00
class CCreatureAnimation ;
class CSelectableComponent ;
class CCreatureSet ;
class CGObjectInstance ;
class CSlider ;
struct UpgradeInfo ;
template < typename T > struct CondSh ;
2009-04-03 18:55:26 +03:00
class CInGameConsole ;
2009-04-14 15:47:09 +03:00
class CGarrisonInt ;
2009-05-19 21:23:04 +03:00
class CInGameConsole ;
union SDL_Event ;
class CInfoWindow ;
2011-12-17 21:59:59 +03:00
class IShowActivatable ;
2009-05-19 21:23:04 +03:00
class ClickableL ;
class ClickableR ;
class Hoverable ;
class KeyInterested ;
class MotionInterested ;
class TimeInterested ;
class IShowable ;
2009-08-30 15:47:40 +03:00
struct CPathsInfo ;
2009-02-20 15:06:20 +02:00
namespace boost
{
class mutex ;
class recursive_mutex ;
2012-09-15 22:16:16 +03:00
}
2009-02-20 15:06:20 +02:00
2012-09-15 22:16:16 +03:00
enum
2012-09-11 17:25:19 +03:00
{
2012-05-18 20:35:46 +03:00
/*CHANGE_SCREEN_RESOLUTION = 1,*/
RETURN_TO_MAIN_MENU = 2 ,
STOP_CLIENT = 3 ,
RESTART_GAME ,
2012-09-11 17:25:19 +03:00
RETURN_TO_MENU_LOAD ,
2013-12-16 21:39:56 +03:00
FULLSCREEN_TOGGLED ,
2015-06-21 19:30:19 +02:00
PREPARE_RESTART_CAMPAIGN ,
FORCE_QUIT //quit client without question
2012-09-11 17:25:19 +03:00
} ;
2012-04-08 05:29:11 +03:00
2011-02-22 13:52:36 +02:00
/// Central class for managing user interface logic
2015-06-22 20:53:47 +02:00
class CPlayerInterface : public CGameInterface , public IUpdateable
2009-02-20 15:06:20 +02:00
{
2014-09-21 16:42:08 +03:00
const CArmedInstance * currentSelection ;
2009-02-20 15:06:20 +02:00
public :
2010-12-23 02:33:48 +02:00
bool observerInDuelMode ;
2015-03-08 16:17:24 +02:00
ObjectInstanceID destinationTeleport ; //contain -1 or object id if teleportation
2010-12-23 02:33:48 +02:00
2009-02-20 15:06:20 +02:00
//minor interfaces
2009-03-22 18:04:46 +02:00
CondSh < bool > * showingDialog ; //indicates if dialog box is displayed
2009-04-14 15:47:09 +03:00
2011-02-24 15:57:47 +02:00
static boost : : recursive_mutex * pim ;
2009-04-14 15:47:09 +03:00
bool makingTurn ; //if player is already making his turn
2009-12-28 06:08:24 +02:00
int firstCall ; // -1 - just loaded game; 1 - just started game; 0 otherwise
int autosaveCount ;
static const int SAVES_COUNT = 5 ;
2010-05-27 00:59:58 +03:00
static int howManyPeople ;
2009-04-14 15:47:09 +03:00
2013-06-26 14:18:27 +03:00
CCastleInterface * castleInt ; //nullptr if castle window isn't opened
static CBattleInterface * battleInt ; //nullptr if no battle
2009-08-07 01:36:51 +03:00
CInGameConsole * cingconsole ;
2012-09-15 22:16:16 +03:00
2013-06-22 17:47:20 +03:00
shared_ptr < CCallback > cb ; //to communicate with engine
2013-06-26 14:18:27 +03:00
const BattleAction * curAction ; //during the battle - action currently performed by active stack (or nullptr)
2009-04-14 15:47:09 +03:00
std : : list < CInfoWindow * > dialogs ; //queue of dialogs awaiting to be shown (not currently shown!)
2009-08-07 01:36:51 +03:00
2009-06-11 20:21:06 +03:00
std : : vector < const CGHeroInstance * > wanderingHeroes ; //our heroes on the adventure map (not the garrisoned ones)
2012-06-13 16:04:06 +03:00
std : : vector < const CGTownInstance * > towns ; //our towns on the adventure map
2010-02-20 15:24:38 +02:00
std : : map < const CGHeroInstance * , CGPath > paths ; //maps hero => selected path in adventure map
2011-10-04 22:43:49 +03:00
std : : vector < const CGHeroInstance * > sleepingHeroes ; //if hero is in here, he's sleeping
2009-12-28 06:08:24 +02:00
2013-06-23 14:25:48 +03:00
//During battle is quick combat mode is used
shared_ptr < CBattleGameInterface > autofightingAI ; //AI that makes decisions
bool isAutoFightOn ; //Flag, switch it to stop quick combat. Don't touch if there is no battle interface.
2014-09-21 16:42:08 +03:00
const CArmedInstance * getSelection ( ) ;
void setSelection ( const CArmedInstance * obj ) ;
2013-06-23 14:25:48 +03:00
2010-07-21 13:09:29 +03:00
struct SpellbookLastSetting
{
int spellbookLastPageBattle , spellbokLastPageAdvmap ; //on which page we left spellbook
int spellbookLastTabBattle , spellbookLastTabAdvmap ; //on which page we left spellbook
SpellbookLastSetting ( ) ;
template < typename Handler > void serialize ( Handler & h , const int version )
{
h & spellbookLastPageBattle & spellbokLastPageAdvmap & spellbookLastTabBattle & spellbookLastTabAdvmap ;
}
} spellbookSettings ;
2014-07-03 21:05:59 +03:00
void update ( ) override ;
2012-06-13 16:04:06 +03:00
void initializeHeroTownList ( ) ;
2009-12-28 06:08:24 +02:00
int getLastIndex ( std : : string namePrefix ) ;
2009-06-11 20:21:06 +03:00
2010-12-23 22:18:10 +02:00
//overridden funcs from CGameInterface
2013-06-26 14:18:27 +03:00
void buildChanged ( const CGTownInstance * town , BuildingID buildingID , int what ) override ; //what: 1 - built, 2 - demolished
void stackChagedCount ( const StackLocation & location , const TQuantity & change , bool isAbsolute ) override ; //if absolute, change is the new count; otherwise count was modified by adding change
void stackChangedType ( const StackLocation & location , const CCreature & newType ) override ; //used eg. when upgrading creatures
void stacksErased ( const StackLocation & location ) override ; //stack removed from previously filled slot
void stacksSwapped ( const StackLocation & loc1 , const StackLocation & loc2 ) override ;
void newStackInserted ( const StackLocation & location , const CStackInstance & stack ) override ; //new stack inserted at given (previously empty position)
void stacksRebalanced ( const StackLocation & src , const StackLocation & dst , TQuantity count ) override ; //moves creatures from src stack to dst slot, may be used for merging/splittint/moving stacks
2011-01-06 22:00:19 +02:00
void artifactPut ( const ArtifactLocation & al ) ;
void artifactRemoved ( const ArtifactLocation & al ) ;
void artifactMoved ( const ArtifactLocation & src , const ArtifactLocation & dst ) ;
2011-01-22 05:43:20 +02:00
void artifactAssembled ( const ArtifactLocation & al ) ;
void artifactDisassembled ( const ArtifactLocation & al ) ;
2011-01-06 22:00:19 +02:00
2013-06-26 14:18:27 +03:00
void heroCreated ( const CGHeroInstance * hero ) override ;
void heroGotLevel ( const CGHeroInstance * hero , PrimarySkill : : PrimarySkill pskill , std : : vector < SecondarySkill > & skills , QueryID queryID ) override ;
void commanderGotLevel ( const CCommanderInstance * commander , std : : vector < ui32 > skills , QueryID queryID ) override ;
void heroInGarrisonChange ( const CGTownInstance * town ) override ;
void heroMoved ( const TryMoveHero & details ) override ;
void heroPrimarySkillChanged ( const CGHeroInstance * hero , int which , si64 val ) override ;
void heroSecondarySkillChanged ( const CGHeroInstance * hero , int which , int val ) override ;
void heroManaPointsChanged ( const CGHeroInstance * hero ) override ;
void heroMovePointsChanged ( const CGHeroInstance * hero ) override ;
void heroVisitsTown ( const CGHeroInstance * hero , const CGTownInstance * town ) override ;
void receivedResource ( int type , int val ) override ;
void showInfoDialog ( const std : : string & text , const std : : vector < Component * > & components , int soundID ) override ;
void showRecruitmentDialog ( const CGDwelling * dwelling , const CArmedInstance * dst , int level ) override ;
void showShipyardDialog ( const IShipyard * obj ) override ; //obj may be town or shipyard;
void showBlockingDialog ( const std : : string & text , const std : : vector < Component > & components , QueryID askID , int soundID , bool selection , bool cancel ) override ; //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.
2015-03-08 15:52:50 +02:00
void showTeleportDialog ( TeleportChannelID channel , std : : vector < ObjectInstanceID > exits , bool impassable , QueryID askID ) override ;
2013-06-26 14:18:27 +03:00
void showGarrisonDialog ( const CArmedInstance * up , const CGHeroInstance * down , bool removableUnits , QueryID queryID ) override ;
void showPuzzleMap ( ) override ;
2015-01-13 21:57:41 +02:00
void viewWorldMap ( ) override ;
2013-06-26 14:18:27 +03:00
void showMarketWindow ( const IMarket * market , const CGHeroInstance * visitor ) override ;
void showUniversityWindow ( const IMarket * market , const CGHeroInstance * visitor ) override ;
void showHillFortWindow ( const CGObjectInstance * object , const CGHeroInstance * visitor ) override ;
void showTavernWindow ( const CGObjectInstance * townOrTavern ) override ;
void showThievesGuildWindow ( const CGObjectInstance * obj ) override ;
void showQuestLog ( ) override ;
void advmapSpellCast ( const CGHeroInstance * caster , int spellID ) override ; //called when a hero casts a spell
2013-06-29 16:05:48 +03:00
void tileHidden ( const std : : unordered_set < int3 , ShashInt3 > & pos ) override ; //called when given tiles become hidden under fog of war
void tileRevealed ( const std : : unordered_set < int3 , ShashInt3 > & pos ) override ; //called when fog of war disappears from given tiles
2013-06-26 14:18:27 +03:00
void newObject ( const CGObjectInstance * obj ) override ;
void availableArtifactsChanged ( const CGBlackMarket * bm = nullptr ) override ; //bm may be nullptr, then artifacts are changed in the global pool (used by merchants in towns)
void yourTurn ( ) override ;
void availableCreaturesChanged ( const CGDwelling * town ) override ;
void heroBonusChanged ( const CGHeroInstance * hero , const Bonus & bonus , bool gain ) override ; //if gain hero received bonus, else he lost it
void playerBonusChanged ( const Bonus & bonus , bool gain ) override ;
void requestRealized ( PackageApplied * pa ) override ;
void heroExchangeStarted ( ObjectInstanceID hero1 , ObjectInstanceID hero2 , QueryID query ) override ;
void centerView ( int3 pos , int focusTime ) override ;
void objectPropertyChanged ( const SetObjectProperty * sop ) override ;
void objectRemoved ( const CGObjectInstance * obj ) override ;
2013-11-17 20:57:04 +03:00
void gameOver ( PlayerColor player , const EVictoryLossCheckResult & victoryLossCheckResult ) override ;
2013-06-26 14:18:27 +03:00
void playerStartsTurn ( PlayerColor player ) override ; //called before yourTurn on active itnerface
void showComp ( const Component & comp , std : : string message ) override ; //display component in the advmapint infobox
2014-12-21 16:27:50 +02:00
void saveGame ( COSer & h , const int version ) override ; //saving
void loadGame ( CISer & h , const int version ) override ; //loading
2015-02-26 16:15:17 +02:00
void showWorldViewEx ( const std : : vector < ObjectPosInfo > & objectPositions ) override ;
2009-03-28 20:46:20 +02:00
2009-02-20 15:06:20 +02:00
//for battles
2013-06-26 14:18:27 +03:00
void actionFinished ( const BattleAction & action ) override ; //occurs AFTER action taken by active stack or by the hero
void actionStarted ( const BattleAction & action ) override ; //occurs BEFORE action taken by active stack or by the hero
BattleAction activeStack ( const CStack * stack ) override ; //called when it's turn of that stack
void battleAttack ( const BattleAttack * ba ) override ; //stack performs attack
void battleEnd ( const BattleResult * br ) override ; //end of battle
void battleNewRoundFirst ( int round ) override ; //called at the beginning of each turn before changes are applied; used for HP regen handling
void battleNewRound ( int round ) override ; //called at the beginning of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
void battleStackMoved ( const CStack * stack , std : : vector < BattleHex > dest , int distance ) override ;
void battleSpellCast ( const BattleSpellCast * sc ) override ;
void battleStacksEffectsSet ( const SetStackEffect & sse ) override ; //called when a specific effect is set to stacks
void battleTriggerEffect ( const BattleTriggerEffect & bte ) override ; //various one-shot effect
void battleStacksAttacked ( const std : : vector < BattleStackAttacked > & bsa ) override ;
2013-09-14 22:09:35 +03:00
void battleStartBefore ( const CCreatureSet * army1 , const CCreatureSet * army2 , int3 tile , const CGHeroInstance * hero1 , const CGHeroInstance * hero2 ) override ; //called by engine just before battle starts; side=0 - left, side=1 - right
2013-06-26 14:18:27 +03:00
void battleStart ( const CCreatureSet * army1 , const CCreatureSet * army2 , int3 tile , const CGHeroInstance * hero1 , const CGHeroInstance * hero2 , bool side ) override ; //called by engine when battle starts; side=0 - left, side=1 - right
void battleStacksHealedRes ( const std : : vector < std : : pair < ui32 , ui32 > > & healedStacks , bool lifeDrain , bool tentHeal , si32 lifeDrainFrom ) override ; //called when stacks are healed / resurrected
void battleNewStackAppeared ( const CStack * stack ) override ; //not called at the beginning of a battle or by resurrection; called eg. when elemental is summoned
void battleObstaclesRemoved ( const std : : set < si32 > & removedObstacles ) override ; //called when a certain set of obstacles is removed from batlefield; IDs of them are given
void battleCatapultAttacked ( const CatapultAttack & ca ) override ; //called when catapult makes an attack
void battleStacksRemoved ( const BattleStacksRemoved & bsr ) override ; //called when certain stack is completely removed from battlefield
void battleObstaclePlaced ( const CObstacleInstance & obstacle ) override ;
void yourTacticPhase ( int distance ) override ;
2009-02-20 15:06:20 +02:00
//-------------//
2014-09-05 21:13:58 +03:00
void showArtifactAssemblyDialog ( ui32 artifactID , ui32 assembleTo , bool assemble , CFunctionList < bool ( ) > onYes , CFunctionList < bool ( ) > onNo ) ;
2012-12-11 15:12:46 +03:00
void garrisonsChanged ( std : : vector < const CGObjectInstance * > objs ) ;
2012-06-13 16:04:06 +03:00
void garrisonChanged ( const CGObjectInstance * obj ) ;
2009-08-04 02:53:18 +03:00
void heroKilled ( const CGHeroInstance * hero ) ;
2012-04-06 18:02:15 +03:00
void waitWhileDialog ( bool unlockPim = true ) ;
void waitForAllDialogs ( bool unlockPim = true ) ;
2009-05-07 20:20:41 +03:00
bool shiftPressed ( ) const ; //determines if shift key is pressed (left or right or both)
2009-11-29 04:46:30 +02:00
bool ctrlPressed ( ) const ; //determines if ctrl key is pressed (left or right or both)
2010-07-21 13:09:29 +03:00
bool altPressed ( ) const ; //determines if alt key is pressed (left or right or both)
2009-02-20 15:06:20 +02:00
void redrawHeroWin ( const CGHeroInstance * hero ) ;
void openTownWindow ( const CGTownInstance * town ) ; //shows townscreen
void openHeroWindow ( const CGHeroInstance * hero ) ; //shows hero window with given hero
2010-03-21 00:17:19 +02:00
void updateInfo ( const CGObjectInstance * specific ) ;
2013-06-22 17:47:20 +03:00
void init ( shared_ptr < CCallback > CB ) ;
2009-03-22 18:04:46 +02:00
int3 repairScreenPos ( int3 pos ) ; //returns position closest to pos we can center screen on
2013-11-30 12:43:31 +03:00
// show dialogs
2012-12-11 15:12:46 +03:00
void showInfoDialog ( const std : : string & text , CComponent * component ) ;
2011-12-22 16:05:19 +03:00
void showInfoDialog ( const std : : string & text , const std : : vector < CComponent * > & components = std : : vector < CComponent * > ( ) , int soundID = 0 , bool delComps = false ) ;
2013-11-30 12:43:31 +03:00
void showInfoDialogAndWait ( std : : vector < Component > & components , const MetaString & text ) ;
2014-08-04 21:33:59 +03:00
void showOkDialog ( std : : vector < Component > & components , const MetaString & text , const std : : function < void ( ) > & onOk ) ;
2012-04-09 05:53:50 +03:00
void showYesNoDialog ( const std : : string & text , CFunctionList < void ( ) > onYes , CFunctionList < void ( ) > onNo , bool DelComps = false , const std : : vector < CComponent * > & components = std : : vector < CComponent * > ( ) ) ; //deactivateCur - whether current main interface should be deactivated; delComps - if components will be deleted on window close
2013-11-30 12:43:31 +03:00
2010-05-14 05:18:37 +03:00
void stopMovement ( ) ;
2014-06-18 13:31:11 +03:00
void moveHero ( const CGHeroInstance * h , CGPath path ) ;
2010-01-02 03:48:44 +02:00
void initMovement ( const TryMoveHero & details , const CGHeroInstance * ho , const int3 & hp ) ; //initializing objects and performing first step of move
void movementPxStep ( const TryMoveHero & details , int i , const int3 & hp , const CGHeroInstance * ho ) ; //performing step of movement
void finishMovement ( const TryMoveHero & details , const int3 & hp , const CGHeroInstance * ho ) ; //finish movement
2010-05-16 16:42:19 +03:00
void eraseCurrentPathOf ( const CGHeroInstance * ho , bool checkForExistanceOfPath = true ) ;
2014-09-19 00:18:49 +03:00
2011-09-19 23:50:25 +03:00
void removeLastNodeFromPath ( const CGHeroInstance * ho ) ;
2010-02-20 15:24:38 +02:00
CGPath * getAndVerifyPath ( const CGHeroInstance * h ) ;
2010-02-24 15:03:36 +02:00
void acceptTurn ( ) ; //used during hot seat after your turn message is close
void tryDiggging ( const CGHeroInstance * h ) ;
2012-09-15 22:16:16 +03:00
void showShipyardDialogOrProblemPopup ( const IShipyard * obj ) ; //obj may be town or shipyard;
2010-08-18 12:50:25 +03:00
void requestReturningToMainMenu ( ) ;
2010-08-20 16:34:39 +03:00
void requestStoppingClient ( ) ;
void sendCustomEvent ( int code ) ;
2012-04-09 05:53:50 +03:00
void proposeLoadingGame ( ) ;
2009-02-20 15:06:20 +02:00
2014-06-18 13:31:11 +03:00
///returns true if all events are processed internally
bool capturedAllEvents ( ) ;
2013-03-03 20:06:03 +03:00
CPlayerInterface ( PlayerColor Player ) ; //c-tor
2009-02-20 15:06:20 +02:00
~ CPlayerInterface ( ) ; //d-tor
2009-03-28 20:46:20 +02:00
2014-06-18 13:31:11 +03:00
private :
2009-03-28 20:46:20 +02:00
template < typename Handler > void serializeTempl ( Handler & h , const int version ) ;
2014-06-18 13:31:11 +03:00
2015-01-13 21:57:41 +02:00
private :
2014-06-21 16:41:05 +03:00
struct IgnoreEvents
{
CPlayerInterface & owner ;
IgnoreEvents ( CPlayerInterface & Owner ) : owner ( Owner )
{
owner . ignoreEvents = true ;
} ;
~ IgnoreEvents ( )
{
owner . ignoreEvents = false ;
} ;
2015-01-13 21:57:41 +02:00
2014-06-21 16:41:05 +03:00
} ;
2015-01-13 21:57:41 +02:00
2014-06-21 09:49:27 +03:00
bool duringMovement ;
2014-06-21 16:41:05 +03:00
bool ignoreEvents ;
2015-01-13 21:57:41 +02:00
2014-06-18 13:31:11 +03:00
void doMoveHero ( const CGHeroInstance * h , CGPath path ) ;
2009-02-20 15:06:20 +02:00
} ;
2009-03-28 20:46:20 +02:00
2009-02-20 15:06:20 +02:00
extern CPlayerInterface * LOCPLINT ;