From 6ceb808f93694328d053c8dc03e82bb1fe7c408a Mon Sep 17 00:00:00 2001 From: Blixibon Date: Sun, 30 Oct 2022 13:30:02 -0500 Subject: [PATCH] Added more convenient way to hide HUD elements from clientside VScript --- sp/src/game/client/hud.cpp | 13 +++++++ sp/src/game/client/mapbase/vscript_vgui.cpp | 35 +++++++++++++++++++ .../shared/mapbase/vscript_consts_shared.cpp | 19 ++++++++++ 3 files changed, 67 insertions(+) diff --git a/sp/src/game/client/hud.cpp b/sp/src/game/client/hud.cpp index a7d77a32ed..11aab40c91 100644 --- a/sp/src/game/client/hud.cpp +++ b/sp/src/game/client/hud.cpp @@ -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 //----------------------------------------------------------------------------- @@ -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; diff --git a/sp/src/game/client/mapbase/vscript_vgui.cpp b/sp/src/game/client/mapbase/vscript_vgui.cpp index 61354093b9..27e9eb5324 100644 --- a/sp/src/game/client/mapbase/vscript_vgui.cpp +++ b/sp/src/game/client/mapbase/vscript_vgui.cpp @@ -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; @@ -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() @@ -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() { @@ -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" ); diff --git a/sp/src/game/shared/mapbase/vscript_consts_shared.cpp b/sp/src/game/shared/mapbase/vscript_consts_shared.cpp index 2ced70863e..f9b9d2339e 100644 --- a/sp/src/game/shared/mapbase/vscript_consts_shared.cpp +++ b/sp/src/game/shared/mapbase/vscript_consts_shared.cpp @@ -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 //