Skip to content

Commit

Permalink
Added more convenient way to hide HUD elements from clientside VScript
Browse files Browse the repository at this point in the history
  • Loading branch information
Blixibon committed Oct 30, 2022
1 parent 2214301 commit 6ceb808
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
13 changes: 13 additions & 0 deletions sp/src/game/client/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,11 @@ float CHud::GetFOVSensitivityAdjust()
{
return m_flFOVSensitivityAdjust;
}

#ifdef MAPBASE_VSCRIPT
extern int g_iVScriptHideHUD;
#endif

//-----------------------------------------------------------------------------
// Purpose: Return true if the passed in sections of the HUD shouldn't be drawn
//-----------------------------------------------------------------------------
Expand All @@ -968,6 +973,14 @@ bool CHud::IsHidden( int iHudFlags )
iHideHud = hidehud.GetInt();
}

#ifdef MAPBASE_VSCRIPT
// Hide elements hidden by scripts
if ( g_iVScriptHideHUD )
{
iHideHud |= g_iVScriptHideHUD;
}
#endif

// Everything hidden?
if ( iHideHud & HIDEHUD_ALL )
return true;
Expand Down
35 changes: 35 additions & 0 deletions sp/src/game/client/mapbase/vscript_vgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ CUtlVector< int > g_ScriptTextureIDs;
CUtlLinkedList< IScriptVGUIObject*, unsigned short > g_ScriptPanels;


// Used in hud.cpp to help scripts hide HUD elements
int g_iVScriptHideHUD = 0;


// Boundary is not checked in Surface, keep count manually to sanitise user input.
static int g_nFontCount = 0;

Expand Down Expand Up @@ -3403,6 +3407,9 @@ void CScriptVGUI::LevelShutdownPostEntity()
surface()->DestroyTextureID( g_ScriptTextureIDs[i] );
}
g_ScriptTextureIDs.Purge();

// Reset HUD hidden bits
g_iVScriptHideHUD = 0;
}

void CScriptVGUI::Shutdown()
Expand Down Expand Up @@ -3690,6 +3697,29 @@ vgui::HFont GetScriptFont( const char *name, bool proportional )
return script_surface.GetFont( name, proportional, NULL );
}

//-----------------------------------------------------------------------------
// Control which HUD elements on the screen are hidden.
//-----------------------------------------------------------------------------
static int ScriptGetHUDHiddenBits()
{
return g_iVScriptHideHUD;
}

static void ScriptSetHUDHiddenBits( int iBits )
{
g_iVScriptHideHUD = iBits;
}

static void ScriptAddHUDHiddenBits( int iBits )
{
g_iVScriptHideHUD |= iBits;
}

static void ScriptClearHUDHiddenBits( int iBits )
{
g_iVScriptHideHUD &= ~(iBits);
}


void RegisterScriptVGUI()
{
Expand All @@ -3702,6 +3732,11 @@ void RegisterScriptVGUI()
ScriptRegisterFunction( g_pScriptVM, ScreenToRay, "Get a ray from screen pixel position to world space." );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptScreenTransform, "ScreenTransform", "Get world position normalised in screen space. Return true if on screen." );

ScriptRegisterFunctionNamed( g_pScriptVM, ScriptGetHUDHiddenBits, "GetHUDHiddenBits", "Use with 'HIDEHUD_' constants." );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptSetHUDHiddenBits, "SetHUDHiddenBits", "Use with 'HIDEHUD_' constants." );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptAddHUDHiddenBits, "AddHUDHiddenBits", "Use with 'HIDEHUD_' constants." );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptClearHUDHiddenBits, "ClearHUDHiddenBits", "Use with 'HIDEHUD_' constants." );

g_pScriptVM->Run( g_Script_vgui_init );

g_pScriptVM->RegisterInstance( &script_surface, "surface" );
Expand Down
19 changes: 19 additions & 0 deletions sp/src/game/shared/mapbase/vscript_consts_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,25 @@ void RegisterSharedScriptConstants()
ScriptRegisterConstant( g_pScriptVM, D_NU, "Denotes a 'Neutral' relationship. Used by NPCs and players for relationship disposition." );
#endif

#ifdef CLIENT_DLL
//
// HUD
//
ScriptRegisterConstant( g_pScriptVM, HIDEHUD_WEAPONSELECTION, "Hide ammo count & weapon selection" );
ScriptRegisterConstant( g_pScriptVM, HIDEHUD_FLASHLIGHT, "" );
ScriptRegisterConstant( g_pScriptVM, HIDEHUD_ALL, "" );
ScriptRegisterConstant( g_pScriptVM, HIDEHUD_HEALTH, "Hide health & armor / suit battery" );
ScriptRegisterConstant( g_pScriptVM, HIDEHUD_PLAYERDEAD, "Hide when local player's dead" );
ScriptRegisterConstant( g_pScriptVM, HIDEHUD_NEEDSUIT, "Hide when the local player doesn't have the HEV suit" );
ScriptRegisterConstant( g_pScriptVM, HIDEHUD_MISCSTATUS, "Hide miscellaneous status elements (trains, pickup history, death notices, etc)" );
ScriptRegisterConstant( g_pScriptVM, HIDEHUD_CHAT, "Hide all communication elements (saytext, voice icon, etc)" );
ScriptRegisterConstant( g_pScriptVM, HIDEHUD_CROSSHAIR, "Hide crosshairs" );
ScriptRegisterConstant( g_pScriptVM, HIDEHUD_VEHICLE_CROSSHAIR, "Hide vehicle crosshair" );
ScriptRegisterConstant( g_pScriptVM, HIDEHUD_INVEHICLE, "" );
ScriptRegisterConstant( g_pScriptVM, HIDEHUD_BONUS_PROGRESS, "Hide bonus progress display (for bonus map challenges)" );
ScriptRegisterConstant( g_pScriptVM, HIDEHUD_BITCOUNT, "" );
#endif

//
// Misc. General
//
Expand Down

0 comments on commit 6ceb808

Please sign in to comment.