Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions sp/src/game/client/clientmode_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,38 @@ void ClientModeShared::ReloadScheme( void )
{
m_pViewport->ReloadScheme( "resource/ClientScheme.res" );
ClearKeyValuesCache();
#ifdef MAPBASE
m_bResetSchemeOnReload = false;
#endif
}

#ifdef MAPBASE
void ClientModeShared::SetCustomClientScheme( const char *pszFile )
{
m_pViewport->ReloadScheme( pszFile );
ClearKeyValuesCache();
m_bResetSchemeOnReload = true;
}

void ClientModeShared::SetCustomHudLayout( const char *pszFile )
{
m_pViewport->SetCustomHUDLayout( pszFile );
if ( pszFile != NULL )
m_bResetSchemeOnReload = true;
}

bool ClientModeShared::LoadCustomHudAnimations( const char *pszFile )
{
m_bResetSchemeOnReload = true;
return m_pViewport->LoadCustomHudAnimations( pszFile );
}

bool ClientModeShared::LoadCustomHudAnimationsManifest( const char *pszFile )
{
m_bResetSchemeOnReload = true;
return m_pViewport->LoadCustomHudAnimationsManifest( pszFile );
}
#endif


//----------------------------------------------------------------------------
Expand Down Expand Up @@ -898,6 +929,16 @@ void ClientModeShared::LevelInit( const char *newmap )
#ifdef DEMO_AUTORECORD
AutoRecord(newmap);
#endif

#ifdef MAPBASE
if ( m_bResetSchemeOnReload )
{
// Restore default HUD
// (note that there is currently no way to destruct the old scheme)
m_pViewport->SetCustomHUDLayout( NULL );
ReloadScheme();
}
#endif
}

#ifdef DEMO_AUTORECORD
Expand Down
9 changes: 9 additions & 0 deletions sp/src/game/client/clientmode_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ class ClientModeShared : public IClientMode, public CGameEventListener
virtual void Layout();

virtual void ReloadScheme( void );
#ifdef MAPBASE
virtual void SetCustomClientScheme( const char *pszFile );
virtual void SetCustomHudLayout( const char *pszFile );
virtual bool LoadCustomHudAnimations( const char *pszFile );
virtual bool LoadCustomHudAnimationsManifest( const char *pszFile );
#endif
virtual void OverrideView( CViewSetup *pSetup );
virtual bool ShouldDrawDetailObjects( );
virtual bool ShouldDrawEntity(C_BaseEntity *pEnt);
Expand Down Expand Up @@ -179,6 +185,9 @@ class ClientModeShared : public IClientMode, public CGameEventListener
CountdownTimer m_PostProcessLerpTimer;

CHandle<C_ColorCorrection> m_pCurrentColorCorrection;

// When using a custom client scheme
bool m_bResetSchemeOnReload;
#endif
};

Expand Down
102 changes: 102 additions & 0 deletions sp/src/game/client/game_controls/baseviewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,68 @@ bool CBaseViewport::LoadCustomHudAnimations( const char *pszFile )
{
return m_pAnimController->SetScriptFile( GetVPanel(), pszFile, true );
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CBaseViewport::LoadCustomHudAnimationsManifest( const char *pszFile )
{
// First load the custom manifest
KeyValues *manifest = new KeyValues( pszFile );
if ( manifest->LoadFromFile( g_pFullFileSystem, pszFile, "GAME" ) == false )
{
manifest->deleteThis();
return false;
}

// Then load the default manifest
const char *HUDANIMATION_MANIFEST_FILE = "scripts/hudanimations_manifest.txt";
KeyValues *defaultManifest = new KeyValues( HUDANIMATION_MANIFEST_FILE );
if ( defaultManifest->LoadFromFile( g_pFullFileSystem, HUDANIMATION_MANIFEST_FILE, "GAME" ) == false )
{
defaultManifest->deleteThis();
manifest->deleteThis();
return false;
}

bool bClearScript = true;

// Load each file defined in the text
for ( KeyValues *sub = defaultManifest->GetFirstSubKey(); sub != NULL; sub = sub->GetNextKey() )
{
if ( !Q_stricmp( sub->GetName(), "file" ) )
{
const char *pszLoadFile = sub->GetString();

// Check if this is remapped by the custom manifest
for ( KeyValues *csub = manifest->GetFirstSubKey(); csub != NULL; csub = csub->GetNextKey() )
{
if ( Q_strstr( pszLoadFile, csub->GetName() ) )
{
// Use the custom manifest's file instead
pszLoadFile = csub->GetString();
break;
}
}

if ( !pszLoadFile || !*pszLoadFile )
continue;

// Add it
if ( m_pAnimController->SetScriptFile( GetVPanel(), pszLoadFile, bClearScript ) == false )
{
Assert( 0 );
}

bClearScript = false;
continue;
}
}

defaultManifest->deleteThis();
manifest->deleteThis();
return true;
}
#endif

//================================================================
Expand Down Expand Up @@ -692,12 +754,23 @@ void CBaseViewport::ReloadScheme(const char *fromFile)
CETWScope timer( "CBaseViewport::ReloadScheme" );

// See if scheme should change

bool bSchemeChange = false;

if ( fromFile != NULL )
{
// "resource/ClientScheme.res"
vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFileEx( enginevgui->GetPanel( PANEL_CLIENTDLL ), fromFile, "HudScheme" );

#ifdef MAPBASE
if ( scheme != GetScheme() )
{
// If this is a different scheme from what we had before, then we need to re-apply default settings for stuff like fonts
SetApplyDefaultSettings( true );
bSchemeChange = true;
}
#endif

SetScheme(scheme);
SetProportional( true );
m_pAnimController->SetScheme(scheme);
Expand All @@ -719,16 +792,45 @@ void CBaseViewport::ReloadScheme(const char *fromFile)
g_pClientMode->ComputeVguiResConditions( pConditions );

// reload the .res file from disk
#ifdef MAPBASE
if ( m_szCustomHUDLayout[0] )
LoadControlSettings( m_szCustomHUDLayout, NULL, NULL, pConditions );
else
#endif
LoadControlSettings( "scripts/HudLayout.res", NULL, NULL, pConditions );

gHUD.RefreshHudTextures();

InvalidateLayout( true, true );

// reset the hud
#ifdef MAPBASE
if ( bSchemeChange )
{
// Need to initialize values
gHUD.VidInit();
}
else
#endif
gHUD.ResetHUD();
}

#ifdef MAPBASE
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseViewport::SetCustomHUDLayout( const char *pszHUDLayout )
{
if ( !pszHUDLayout )
{
m_szCustomHUDLayout[0] = NULL;
return;
}

V_strncpy( m_szCustomHUDLayout, pszHUDLayout, sizeof( m_szCustomHUDLayout ) );
}
#endif

int CBaseViewport::GetDeathMessageStartHeight( void )
{
return YRES(2);
Expand Down
8 changes: 8 additions & 0 deletions sp/src/game/client/game_controls/baseviewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class CBaseViewport : public vgui::EditablePanel, public IViewPort, public IGame
virtual void SetParent(vgui::VPANEL parent);

virtual void ReloadScheme(const char *fromFile);
#ifdef MAPBASE
virtual void SetCustomHUDLayout( const char *pszHUDLayout );
#endif
virtual void ActivateClientUI();
virtual void HideClientUI();
virtual bool AllowedToPrintText( void );
Expand All @@ -75,6 +78,7 @@ class CBaseViewport : public vgui::EditablePanel, public IViewPort, public IGame

#ifdef MAPBASE
bool LoadCustomHudAnimations( const char *pszFile );
bool LoadCustomHudAnimationsManifest( const char *pszFile );
void ReloadHudAnimations( void );
#endif

Expand Down Expand Up @@ -146,6 +150,10 @@ class CBaseViewport : public vgui::EditablePanel, public IViewPort, public IGame
vgui::HCursor m_hCursorNone;
vgui::AnimationController *m_pAnimController;
int m_OldSize[2];

#ifdef MAPBASE
char m_szCustomHUDLayout[MAX_PATH];
#endif
};


Expand Down
77 changes: 76 additions & 1 deletion sp/src/game/client/hl2/c_basehlplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include "c_ai_basenpc.h"
#include "in_buttons.h"
#include "collisionutils.h"
#ifdef MAPBASE
#include "mapbase/protagonist_system.h"
#include "clientmode_shared.h"
#endif

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
Expand Down Expand Up @@ -83,7 +87,7 @@ C_BaseHLPlayer::C_BaseHLPlayer()
ConVarRef scissor("r_flashlightscissor");
scissor.SetValue("0");

m_nProtagonistIndex = -1;
m_nProtagonistIndex = m_nOldProtagonistIndex = -1;
#endif
}

Expand All @@ -99,6 +103,14 @@ void C_BaseHLPlayer::OnDataChanged( DataUpdateType_t updateType )
SetNextClientThink( CLIENT_THINK_ALWAYS );
}

#ifdef MAPBASE
if ( m_nProtagonistIndex != m_nOldProtagonistIndex )
{
OnChangeProtagonist();
m_nOldProtagonistIndex = m_nProtagonistIndex;
}
#endif

#ifdef SP_ANIM_STATE
if (m_flAnimRenderYaw != FLT_MAX)
{
Expand Down Expand Up @@ -694,6 +706,69 @@ void C_BaseHLPlayer::BuildTransformations( CStudioHdr *hdr, Vector *pos, Quatern
}


#ifdef MAPBASE
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_BaseHLPlayer::ModifyEmitSoundParams( EmitSound_t &params )
{
BaseClass::ModifyEmitSoundParams( params );

if ( m_nProtagonistIndex != -1 )
{
const char *pszSoundOverride = g_ProtagonistSystem.GetProtagonist_SoundOverride( this, params.m_pSoundName );
if ( pszSoundOverride )
params.m_pSoundName = pszSoundOverride;
}
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_BaseHLPlayer::OnChangeProtagonist()
{
g_ProtagonistSystem.PrecacheProtagonist( this, m_nProtagonistIndex );

// Check if this protagonist has a custom HUD
const char *pszClientScheme = g_ProtagonistSystem.GetProtagonist_ClientScheme( this );
if ( pszClientScheme )
{
ClientModeShared *mode = ( ClientModeShared * )GetClientModeNormal();
if ( !mode )
return;

CBaseViewport *pViewport = ( CBaseViewport * )mode->GetViewport();
if ( pViewport )
{
mode->SetCustomHudLayout( g_ProtagonistSystem.GetProtagonist_HUDLayout( this ) );
mode->SetCustomClientScheme( pszClientScheme );

const char *pszHUDAnims = g_ProtagonistSystem.GetProtagonist_HUDAnims( this );
if ( pszHUDAnims )
pViewport->LoadCustomHudAnimationsManifest( pszHUDAnims );
}
}
else if ( m_nOldProtagonistIndex != -1 )
{
// Check if the previous protagonist had a custom HUD. If it did, then load the default scheme
pszClientScheme = g_ProtagonistSystem.GetProtagonist_ClientScheme( m_nOldProtagonistIndex );
if ( pszClientScheme )
{
ClientModeShared *mode = ( ClientModeShared * )GetClientModeNormal();
if ( !mode )
return;

CBaseViewport *pViewport = ( CBaseViewport * )mode->GetViewport();
if ( pViewport )
{
mode->SetCustomHudLayout( NULL );
mode->ReloadScheme();
}
}
}
}
#endif

#ifdef SP_ANIM_STATE
//-----------------------------------------------------------------------------
// Purpose:
Expand Down
4 changes: 4 additions & 0 deletions sp/src/game/client/hl2/c_basehlplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ class C_BaseHLPlayer : public C_BasePlayer
bool IsWeaponLowered( void ) { return m_HL2Local.m_bWeaponLowered; }

#ifdef MAPBASE
virtual void ModifyEmitSoundParams( EmitSound_t &params );

int GetProtagonistIndex() const { return m_nProtagonistIndex; }
virtual void OnChangeProtagonist();
#endif

#ifdef SP_ANIM_STATE
Expand Down Expand Up @@ -96,6 +99,7 @@ class C_BaseHLPlayer : public C_BasePlayer

#ifdef MAPBASE
int m_nProtagonistIndex;
int m_nOldProtagonistIndex;
#endif

#ifdef MAPBASE_MP
Expand Down
Loading
Loading