Update vscript_vgui

enabled parenting to clientmode hud viewport
added script func `vgui.GetHudViewport()`
fixed case sensitivity of panel classname and panel callback inputs
fixed script fonts not being reloaded when no panel parented to the root was created
This commit is contained in:
samisalreadytaken 2022-11-24 13:39:59 +03:00
parent 1ca7558421
commit 5e891f85a6
2 changed files with 265 additions and 100 deletions

View File

@ -51,7 +51,7 @@
#include "view.h" #include "view.h"
#include "hudelement.h" #include "hudelement.h"
//#include "iclientmode.h" // g_pClientMode->GetViewport() #include "iclientmode.h" // g_pClientMode->GetViewport()
#include "vscript_vgui.h" #include "vscript_vgui.h"
#include "vscript_vgui.nut" #include "vscript_vgui.nut"
@ -92,10 +92,18 @@
// Changing this is not backwards compatible, as existing top level script panel depth would then change relative to non-script panels. // Changing this is not backwards compatible, as existing top level script panel depth would then change relative to non-script panels.
#define SCRIPT_ENGINE_ROOT_PANELS 1 #define SCRIPT_ENGINE_ROOT_PANELS 1
// NOTE: causes rendering issues //
#define ALLOW_SCRIPT_HUD_VIEWPORT_ROOT_PANEL 0 // Options to restrict where script panels can be parented to.
// The safest options any game can have are HUD viewport and clientdll.
//
#define ALLOW_SCRIPT_GAMEUI_ROOT_PANEL 0 #define ALLOW_ROOT_PANEL_PARENT 1
#define ALLOW_HUD_VIEWPORT_ROOT_PARENT 1
#define ALLOW_CLIENTDLL_ROOT_PARENT 1
#define ALLOW_GAMEUI_ROOT_PARENT 0
// On level transitions Restore is called up to 4 times in a row (due to .hl? client state files), each time // On level transitions Restore is called up to 4 times in a row (due to .hl? client state files), each time
// trying to restore script panels from pre and post transitions, failing every time because script panels are // trying to restore script panels from pre and post transitions, failing every time because script panels are
@ -353,8 +361,10 @@ public:
} }
}; };
#if ALLOW_CLIENTDLL_ROOT_PARENT
CScriptRootDLLPanel *g_pScriptClientDLLPanel = NULL; CScriptRootDLLPanel *g_pScriptClientDLLPanel = NULL;
#if ALLOW_SCRIPT_GAMEUI_ROOT_PANEL #endif
#if ALLOW_GAMEUI_ROOT_PARENT
CScriptRootDLLPanel *g_pScriptGameUIDLLPanel = NULL; CScriptRootDLLPanel *g_pScriptGameUIDLLPanel = NULL;
#endif #endif
#endif #endif
@ -367,12 +377,14 @@ void VGUI_DestroyScriptRootPanels()
g_pScriptRootPanel = NULL; g_pScriptRootPanel = NULL;
} }
#if SCRIPT_ENGINE_ROOT_PANELS #if SCRIPT_ENGINE_ROOT_PANELS
#if ALLOW_CLIENTDLL_ROOT_PARENT
if ( g_pScriptClientDLLPanel ) if ( g_pScriptClientDLLPanel )
{ {
delete g_pScriptClientDLLPanel; delete g_pScriptClientDLLPanel;
g_pScriptClientDLLPanel = NULL; g_pScriptClientDLLPanel = NULL;
} }
#if ALLOW_SCRIPT_GAMEUI_ROOT_PANEL #endif
#if ALLOW_GAMEUI_ROOT_PARENT
if ( g_pScriptGameUIDLLPanel ) if ( g_pScriptGameUIDLLPanel )
{ {
delete g_pScriptGameUIDLLPanel; delete g_pScriptGameUIDLLPanel;
@ -384,30 +396,29 @@ void VGUI_DestroyScriptRootPanels()
VPANEL VGUI_GetScriptRootPanel( VGuiPanel_t type ) VPANEL VGUI_GetScriptRootPanel( VGuiPanel_t type )
{ {
#if !SCRIPT_ENGINE_ROOT_PANELS #if SCRIPT_ENGINE_ROOT_PANELS
if ( !g_pScriptRootPanel )
g_pScriptRootPanel = new CScriptRootPanel();
return enginevgui->GetPanel( type );
#else
switch ( type ) switch ( type )
{ {
case PANEL_ROOT: case PANEL_ROOT:
#if ALLOW_ROOT_PANEL_PARENT
{ {
if ( !g_pScriptRootPanel ) if ( !g_pScriptRootPanel )
g_pScriptRootPanel = new CScriptRootPanel(); g_pScriptRootPanel = new CScriptRootPanel();
return g_pScriptRootPanel->GetVPanel(); return g_pScriptRootPanel->GetVPanel();
} }
#endif
case PANEL_CLIENTDLL: case PANEL_CLIENTDLL:
#if ALLOW_CLIENTDLL_ROOT_PARENT
{ {
if ( !g_pScriptClientDLLPanel ) if ( !g_pScriptClientDLLPanel )
g_pScriptClientDLLPanel = new CScriptRootDLLPanel( PANEL_CLIENTDLL, "VScriptClient" ); g_pScriptClientDLLPanel = new CScriptRootDLLPanel( PANEL_CLIENTDLL, "VScriptClient" );
return g_pScriptClientDLLPanel->GetVPanel(); return g_pScriptClientDLLPanel->GetVPanel();
} }
#if ALLOW_SCRIPT_GAMEUI_ROOT_PANEL #endif
case PANEL_GAMEUIDLL: case PANEL_GAMEUIDLL:
#if ALLOW_GAMEUI_ROOT_PARENT
{ {
if ( !g_pScriptGameUIDLLPanel ) if ( !g_pScriptGameUIDLLPanel )
g_pScriptGameUIDLLPanel = new CScriptRootDLLPanel( PANEL_GAMEUIDLL, "VScriptGameUI" ); g_pScriptGameUIDLLPanel = new CScriptRootDLLPanel( PANEL_GAMEUIDLL, "VScriptGameUI" );
@ -415,8 +426,10 @@ VPANEL VGUI_GetScriptRootPanel( VGuiPanel_t type )
return g_pScriptGameUIDLLPanel->GetVPanel(); return g_pScriptGameUIDLLPanel->GetVPanel();
} }
#endif #endif
default: return NULL;
} }
return NULL; #else
return enginevgui->GetPanel(type);
#endif #endif
} }
@ -663,6 +676,11 @@ int CScriptSurface::GetCharacterWidth( int font, int ch )
void CScriptSurface::CreateFont( const char *customName, const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags, int yresMin, int yresMax, bool proportional ) void CScriptSurface::CreateFont( const char *customName, const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags, int yresMin, int yresMax, bool proportional )
{ {
// Make sure font invalidation callback is established.
// Not necessary if script fonts are reloaded in engine.
if ( !g_pScriptRootPanel )
g_pScriptRootPanel = new CScriptRootPanel();
if ( flags & ISurface::FONTFLAG_BITMAP ) if ( flags & ISurface::FONTFLAG_BITMAP )
{ {
AssertMsg( 0, "Bitmap fonts are not supported!" ); AssertMsg( 0, "Bitmap fonts are not supported!" );
@ -681,16 +699,41 @@ void CScriptSurface::CreateFont( const char *customName, const char *windowsFont
return; return;
} }
#if 0
bool bProportionalFallbackFont = false;
if ( proportional )
{
// Find if this is a resolution filtered font alias
const char *fontAlias = GetFixedFontName( customName, false );
int idx = g_ScriptFonts.Find( fontAlias );
if ( idx != g_ScriptFonts.InvalidIndex() )
{
fontalias_t &alias = g_ScriptFonts[idx];
for ( int i = 0; i < alias.Count(); ++i )
{
FontData_t &data = alias.Element(i);
if ( data.yres_min && data.yres_max )
{
bProportionalFallbackFont = true;
// Save this proportional font in non-proportional alias
proportional = false;
break;
}
}
}
}
#endif
const char *fontAlias = GetFixedFontName( customName, proportional ); const char *fontAlias = GetFixedFontName( customName, proportional );
int idx = g_ScriptFonts.Find( fontAlias ); int idx = g_ScriptFonts.Find( fontAlias );
if ( idx != g_ScriptFonts.InvalidIndex() ) if ( idx != g_ScriptFonts.InvalidIndex() )
{ {
fontalias_t &alias = g_ScriptFonts[idx]; fontalias_t &alias = g_ScriptFonts[idx];
// TODO: One proportional font to fall back to amongst resolution filtered fonts.
#ifdef _DEBUG #ifdef _DEBUG
if ( !yresMin && !yresMax ) if ( !yresMin && !yresMax /*&& !bProportionalFallbackFont*/ )
{ {
// There must be only one font registered. // There must be only one font registered.
Assert( alias.Count() == 1 ); Assert( alias.Count() == 1 );
@ -703,7 +746,7 @@ void CScriptSurface::CreateFont( const char *customName, const char *windowsFont
// Font changes will not be applied. // Font changes will not be applied.
Assert( oldTall == newTall ); Assert( oldTall == newTall );
if ( oldName ) // can be null if ( oldName ) // can be null
Assert( !V_stricmp( oldName, windowsFontName ) ); AssertMsg( !V_stricmp( oldName, windowsFontName ), "'%s' != '%s'", oldName, windowsFontName );
} }
#endif #endif
@ -716,7 +759,10 @@ void CScriptSurface::CreateFont( const char *customName, const char *windowsFont
if ( yresMin == data.yres_min && yresMax == data.yres_max ) if ( yresMin == data.yres_min && yresMax == data.yres_max )
return; return;
} }
#if 0
if ( bProportionalFallbackFont )
proportional = true;
#endif
DebugMsg( "Create font add '%s' [%d %d]\n", fontAlias, yresMin, yresMax ); DebugMsg( "Create font add '%s' [%d %d]\n", fontAlias, yresMin, yresMax );
FontData_t &newFont = alias.Element( alias.AddToTail() ); FontData_t &newFont = alias.Element( alias.AddToTail() );
@ -731,6 +777,22 @@ void CScriptSurface::CreateFont( const char *customName, const char *windowsFont
newFont.yres_max = yresMax; newFont.yres_max = yresMax;
newFont.proportional = proportional; newFont.proportional = proportional;
#if 0
// Put the proportional font in the very end so that it is loaded only when no resolution is matched
struct L
{
static int __cdecl F( const FontData_t* a, const FontData_t* b )
{
if ( !a->proportional && b->proportional )
return -1;
if ( a->proportional && !b->proportional )
return 1;
return 0;
}
};
alias.Sort( L::F );
#endif
LoadFont( newFont DBG_PARAM(, fontAlias) ); LoadFont( newFont DBG_PARAM(, fontAlias) );
} }
else else
@ -1067,7 +1129,7 @@ public:\
class CScript_##panelClass : public panelClass\ class CScript_##panelClass : public panelClass\
{\ {\
DECLARE_SCRIPTVGUI_CLASS( panelClass )\ DECLARE_SCRIPTVGUI_CLASS( panelClass )\
void Shutdown() {}\ void ScriptShutdown() {}\
\ \
public:\ public:\
CScript_##panelClass( Panel *parent, const char *name )\ CScript_##panelClass( Panel *parent, const char *name )\
@ -1085,7 +1147,7 @@ public:\
class CScript_##panelClass : public panelClass\ class CScript_##panelClass : public panelClass\
{\ {\
DECLARE_SCRIPTVGUI_CLASS( panelClass )\ DECLARE_SCRIPTVGUI_CLASS( panelClass )\
void Shutdown() {}\ void ScriptShutdown() {}\
\ \
public:\ public:\
CScript_##panelClass( Panel *parent, const char *name, const char *text )\ CScript_##panelClass( Panel *parent, const char *name, const char *text )\
@ -1292,7 +1354,7 @@ public:
if ( GetVPanel() ) if ( GetVPanel() )
{ {
DebugMsg( " Destroy panel '%s' %s\n", _base->GetName(), GetDebugName() ); DebugMsg( " Destroy panel '%s' %s\n", _base->GetName(), GetDebugName() );
_base->Shutdown(); _base->ScriptShutdown();
ResolveChildren_r( _vpanel ); ResolveChildren_r( _vpanel );
_base->MarkForDeletion(); _base->MarkForDeletion();
} }
@ -1339,6 +1401,11 @@ public:
} }
AssertMsg( 0, "invalid parent" ); AssertMsg( 0, "invalid parent" );
g_ScriptPanels.AddToTail( this );
// leave me parentless
return;
} }
g_ScriptPanels.AddToTail( this ); g_ScriptPanels.AddToTail( this );
@ -1348,27 +1415,37 @@ public:
// //
// This parameter is hidden in script, and is defined by the return value of dummy functions. // This parameter is hidden in script, and is defined by the return value of dummy functions.
VPANEL vparent = 0; VPANEL vparent = 0;
switch ( root ) switch ( root )
{ {
#if ALLOW_ROOT_PANEL_PARENT
case 0: case 0:
vparent = VGUI_GetScriptRootPanel( PANEL_ROOT ); vparent = VGUI_GetScriptRootPanel( PANEL_ROOT );
break; break;
#if ALLOW_SCRIPT_GAMEUI_ROOT_PANEL #endif
#if ALLOW_GAMEUI_ROOT_PARENT
case 1: case 1:
vparent = VGUI_GetScriptRootPanel( PANEL_GAMEUIDLL ); vparent = VGUI_GetScriptRootPanel( PANEL_GAMEUIDLL );
break; break;
#endif #endif
#if ALLOW_CLIENTDLL_ROOT_PARENT
case 2: case 2:
vparent = VGUI_GetScriptRootPanel( PANEL_CLIENTDLL ); vparent = VGUI_GetScriptRootPanel( PANEL_CLIENTDLL );
break; break;
#if ALLOW_SCRIPT_HUD_VIEWPORT_ROOT_PANEL #endif
// Hud viewport #if ALLOW_HUD_VIEWPORT_ROOT_PARENT
case 10: case 10: // Hud viewport
Assert( g_pClientMode && g_pClientMode->GetViewport() ); Assert( g_pClientMode && g_pClientMode->GetViewport() );
vparent = g_pClientMode->GetViewport()->GetVPanel(); vparent = g_pClientMode->GetViewport()->GetVPanel();
break; break;
#endif #endif
default: UNREACHABLE(); // Invalid parent panel default:
#if SCRIPT_ENGINE_ROOT_PANELS
UNREACHABLE(); // Invalid parent panel
#else
// Allow everything defined in vscript_vgui.nut
vparent = VGUI_GetScriptRootPanel( (VGuiPanel_t)root );
#endif
} }
_base->SetParent( vparent ); _base->SetParent( vparent );
@ -1434,10 +1511,12 @@ public:
bool bRootParent = false; bool bRootParent = false;
#if SCRIPT_ENGINE_ROOT_PANELS #if SCRIPT_ENGINE_ROOT_PANELS
if ( ( parent == g_pScriptRootPanel->GetVPanel() ) if ( ( parent == g_pScriptRootPanel->GetVPanel() )
#if ALLOW_SCRIPT_GAMEUI_ROOT_PANEL #if ALLOW_GAMEUI_ROOT_PARENT
|| ( g_pScriptGameUIDLLPanel && parent == g_pScriptGameUIDLLPanel->GetVPanel() ) || ( g_pScriptGameUIDLLPanel && parent == g_pScriptGameUIDLLPanel->GetVPanel() )
#endif #endif
#if ALLOW_CLIENTDLL_ROOT_PARENT
|| ( g_pScriptClientDLLPanel && parent == g_pScriptClientDLLPanel->GetVPanel() ) || ( g_pScriptClientDLLPanel && parent == g_pScriptClientDLLPanel->GetVPanel() )
#endif
) )
{ {
bRootParent = true; bRootParent = true;
@ -1452,7 +1531,7 @@ public:
break; break;
} }
} }
#if ALLOW_SCRIPT_HUD_VIEWPORT_ROOT_PANEL #if ALLOW_HUD_VIEWPORT_ROOT_PARENT
if ( g_pClientMode && g_pClientMode->GetViewport() && ( parent == g_pClientMode->GetViewport()->GetVPanel() ) ) if ( g_pClientMode && g_pClientMode->GetViewport() && ( parent == g_pClientMode->GetViewport()->GetVPanel() ) )
bRootParent = true; bRootParent = true;
#endif #endif
@ -1829,10 +1908,12 @@ public:
\ \
DEFINE_SCRIPTFUNC( SetCursor, "" )\ DEFINE_SCRIPTFUNC( SetCursor, "" )\
DEFINE_SCRIPTFUNC( IsCursorOver, "" )\ DEFINE_SCRIPTFUNC( IsCursorOver, "" )\
\
DEFINE_SCRIPTFUNC( HasFocus, "" )\ DEFINE_SCRIPTFUNC( HasFocus, "" )\
DEFINE_SCRIPTFUNC( RequestFocus, "" )\ DEFINE_SCRIPTFUNC( RequestFocus, "" )\
DEFINE_SCRIPTFUNC( MakePopup, "" )\ DEFINE_SCRIPTFUNC( MakePopup, "" )\
DEFINE_SCRIPTFUNC( MoveToFront, "" )\ DEFINE_SCRIPTFUNC( MoveToFront, "" )\
\
DEFINE_SCRIPTFUNC( SetMouseInputEnabled, "" )\ DEFINE_SCRIPTFUNC( SetMouseInputEnabled, "" )\
DEFINE_SCRIPTFUNC( SetKeyBoardInputEnabled, "" )\ DEFINE_SCRIPTFUNC( SetKeyBoardInputEnabled, "" )\
\ \
@ -1842,10 +1923,7 @@ public:
//-------------------------------------------------------------- //--------------------------------------------------------------
//-------------------------------------------------------------- //--------------------------------------------------------------
// These need more testing. // These need more testing.
// TODO: IScript_Panel::FindChildByName()
// TODO: DECLARE_BUILD_FACTORY_SCRIPT() to create overridable script panels from controls file // TODO: DECLARE_BUILD_FACTORY_SCRIPT() to create overridable script panels from controls file
// TODO: CScript_EditablePanel::ApplySchemeSettings() callback
// (IScheme parameter can be passed as null until schemes are also tested)
#if BUILD_GROUPS_ENABLED #if BUILD_GROUPS_ENABLED
CLASS_HELPER_INTERFACE( EditablePanel, Panel ) CLASS_HELPER_INTERFACE( EditablePanel, Panel )
{ {
@ -1855,11 +1933,27 @@ public:
{ {
__base()->LoadControlSettings( resName ); __base()->LoadControlSettings( resName );
} }
HSCRIPT FindChildByName( const char *childName )
{
Panel *pPanel = __base()->FindChildByName( childName, false );
if ( pPanel )
{
int i;
IScriptVGUIObject* obj = FindInScriptPanels( child, i );
if ( obj )
{
return obj->GetScriptInstance();
}
}
return NULL;
}
}; };
#define DEFINE_VGUI_SCRIPTFUNC_EditablePanel()\ #define DEFINE_VGUI_SCRIPTFUNC_EditablePanel()\
DEFINE_VGUI_SCRIPTFUNC_Panel()\ DEFINE_VGUI_SCRIPTFUNC_Panel()\
DEFINE_SCRIPTFUNC( LoadControlSettings, "" ) DEFINE_SCRIPTFUNC( LoadControlSettings, "" )\
DEFINE_SCRIPTFUNC( FindChildByName, "" )
#endif #endif
//-------------------------------------------------------------- //--------------------------------------------------------------
//-------------------------------------------------------------- //--------------------------------------------------------------
@ -2106,6 +2200,16 @@ public:
{ {
__base()->SetShouldScaleImage( state ); __base()->SetShouldScaleImage( state );
} }
void SetRotation( int rotation )
{
Assert( rotation == ROTATED_UNROTATED ||
rotation == ROTATED_CLOCKWISE_90 ||
rotation == ROTATED_ANTICLOCKWISE_90 ||
rotation == ROTATED_FLIPPED );
__base()->SetRotation( rotation );
}
#if 0 #if 0
void SetFrame( int nFrame ) void SetFrame( int nFrame )
{ {
@ -2120,6 +2224,7 @@ public:
DEFINE_SCRIPTFUNC( SetDrawColor, "" )\ DEFINE_SCRIPTFUNC( SetDrawColor, "" )\
DEFINE_SCRIPTFUNC( SetTileImage, "" )\ DEFINE_SCRIPTFUNC( SetTileImage, "" )\
DEFINE_SCRIPTFUNC( SetShouldScaleImage, "" )\ DEFINE_SCRIPTFUNC( SetShouldScaleImage, "" )\
DEFINE_SCRIPTFUNC( SetRotation, "" )\
//-------------------------------------------------------------- //--------------------------------------------------------------
//-------------------------------------------------------------- //--------------------------------------------------------------
@ -2435,10 +2540,10 @@ public:
//-------------------------------------------------------------- //--------------------------------------------------------------
//-------------------------------------------------------------- //--------------------------------------------------------------
#if VGUI_TGA_IMAGE_PANEL #if VGUI_TGA_IMAGE_PANEL
CLASS_HELPER_INTERFACE( TGAImagePanel, Panel ) CLASS_HELPER_INTERFACE( TGAImage, Panel )
{ {
public: public:
void SetTGAImage( const char *p ) void SetImage( const char *p )
{ {
__base()->SetTGAImage( p ); __base()->SetTGAImage( p );
} }
@ -2454,9 +2559,37 @@ public:
} }
}; };
#define DEFINE_VGUI_SCRIPTFUNC_TGAImagePanel()\ #define DEFINE_VGUI_SCRIPTFUNC_TGAImage()\
DEFINE_VGUI_SCRIPTFUNC_Panel()\ DEFINE_VGUI_SCRIPTFUNC_Panel()\
DEFINE_SCRIPTFUNC( SetTGAImage, "" )\ DEFINE_SCRIPTFUNC( SetImage, "" )\
DEFINE_SCRIPTFUNC( SetDrawColor, "" )\
DEFINE_SCRIPTFUNC( SetShouldScaleImage, "" )
#endif
//--------------------------------------------------------------
//--------------------------------------------------------------
#if 0
CLASS_HELPER_INTERFACE( PNGImage, Panel )
{
public:
void SetImage( const char *p )
{
__base()->SetPNGImage( p );
}
void SetDrawColor( int r, int g, int b, int a )
{
__base()->SetDrawColor( r, g, b, a );
}
void SetShouldScaleImage( bool i )
{
__base()->SetShouldScaleImage( i );
}
};
#define DEFINE_VGUI_SCRIPTFUNC_PNGImage()\
DEFINE_VGUI_SCRIPTFUNC_Panel()\
DEFINE_SCRIPTFUNC( SetImage, "" )\
DEFINE_SCRIPTFUNC( SetDrawColor, "" )\ DEFINE_SCRIPTFUNC( SetDrawColor, "" )\
DEFINE_SCRIPTFUNC( SetShouldScaleImage, "" ) DEFINE_SCRIPTFUNC( SetShouldScaleImage, "" )
#endif #endif
@ -2479,7 +2612,7 @@ static inline void SetHScript( HSCRIPT &var, HSCRIPT val )
} }
#define CheckCallback(s)\ #define CheckCallback(s)\
if ( FStrEq( cb, #s ) )\ if ( !V_strcmp( cb, #s ) )\
{\ {\
SetHScript( m_hfn##s, fn );\ SetHScript( m_hfn##s, fn );\
return;\ return;\
@ -2515,6 +2648,7 @@ private:
HSCRIPT m_hfnOnKeyCodePressed; HSCRIPT m_hfnOnKeyCodePressed;
HSCRIPT m_hfnOnKeyCodeReleased; HSCRIPT m_hfnOnKeyCodeReleased;
HSCRIPT m_hfnOnKeyCodeTyped; HSCRIPT m_hfnOnKeyCodeTyped;
#if SCRIPT_VGUI_SIGNAL_INTERFACE #if SCRIPT_VGUI_SIGNAL_INTERFACE
HSCRIPT m_hfnOnCommand; HSCRIPT m_hfnOnCommand;
#endif #endif
@ -2530,7 +2664,9 @@ public:
m_hfnPerformLayout(NULL), m_hfnPerformLayout(NULL),
m_hfnOnTick(NULL), m_hfnOnTick(NULL),
m_hfnOnScreenSizeChanged(NULL), m_hfnOnScreenSizeChanged(NULL),
#if SCRIPT_VGUI_SIGNAL_INTERFACE
m_hfnOnCommand(NULL),
#endif
m_hfnOnCursorEntered(NULL), m_hfnOnCursorEntered(NULL),
m_hfnOnCursorExited(NULL), m_hfnOnCursorExited(NULL),
m_hfnOnCursorMoved(NULL), m_hfnOnCursorMoved(NULL),
@ -2543,13 +2679,9 @@ public:
m_hfnOnKeyCodePressed(NULL), m_hfnOnKeyCodePressed(NULL),
m_hfnOnKeyCodeReleased(NULL), m_hfnOnKeyCodeReleased(NULL),
m_hfnOnKeyCodeTyped(NULL) m_hfnOnKeyCodeTyped(NULL)
#if SCRIPT_VGUI_SIGNAL_INTERFACE
,
m_hfnOnCommand(NULL)
#endif
{} {}
void Shutdown() void ScriptShutdown()
{ {
ivgui()->RemoveTickSignal( GetVPanel() ); ivgui()->RemoveTickSignal( GetVPanel() );
@ -2573,6 +2705,7 @@ public:
SetHScript( m_hfnOnKeyCodePressed, NULL ); SetHScript( m_hfnOnKeyCodePressed, NULL );
SetHScript( m_hfnOnKeyCodeReleased, NULL ); SetHScript( m_hfnOnKeyCodeReleased, NULL );
SetHScript( m_hfnOnKeyCodeTyped, NULL ); SetHScript( m_hfnOnKeyCodeTyped, NULL );
#if SCRIPT_VGUI_SIGNAL_INTERFACE #if SCRIPT_VGUI_SIGNAL_INTERFACE
SetHScript( m_hfnOnCommand, NULL ); SetHScript( m_hfnOnCommand, NULL );
#endif #endif
@ -2775,6 +2908,7 @@ public:
CheckCallback( OnKeyCodePressed ); CheckCallback( OnKeyCodePressed );
CheckCallback( OnKeyCodeReleased ); CheckCallback( OnKeyCodeReleased );
CheckCallback( OnKeyCodeTyped ); CheckCallback( OnKeyCodeTyped );
#if SCRIPT_VGUI_SIGNAL_INTERFACE #if SCRIPT_VGUI_SIGNAL_INTERFACE
CheckCallback( OnCommand ); CheckCallback( OnCommand );
#endif #endif
@ -2810,6 +2944,7 @@ private:
HSCRIPT m_hfnOnKeyCodePressed; HSCRIPT m_hfnOnKeyCodePressed;
HSCRIPT m_hfnOnKeyCodeReleased; HSCRIPT m_hfnOnKeyCodeReleased;
HSCRIPT m_hfnOnKeyCodeTyped; HSCRIPT m_hfnOnKeyCodeTyped;
#if SCRIPT_VGUI_SIGNAL_INTERFACE #if SCRIPT_VGUI_SIGNAL_INTERFACE
HSCRIPT m_hfnOnCommand; HSCRIPT m_hfnOnCommand;
#endif #endif
@ -2826,6 +2961,9 @@ public:
m_hfnPerformLayout(NULL), m_hfnPerformLayout(NULL),
m_hfnOnTick(NULL), m_hfnOnTick(NULL),
m_hfnOnScreenSizeChanged(NULL), m_hfnOnScreenSizeChanged(NULL),
#if SCRIPT_VGUI_SIGNAL_INTERFACE
m_hfnOnCommand(NULL),
#endif
m_hfnOnCursorEntered(NULL), m_hfnOnCursorEntered(NULL),
m_hfnOnCursorExited(NULL), m_hfnOnCursorExited(NULL),
@ -2839,15 +2977,11 @@ public:
m_hfnOnKeyCodePressed(NULL), m_hfnOnKeyCodePressed(NULL),
m_hfnOnKeyCodeReleased(NULL), m_hfnOnKeyCodeReleased(NULL),
m_hfnOnKeyCodeTyped(NULL) m_hfnOnKeyCodeTyped(NULL)
#if SCRIPT_VGUI_SIGNAL_INTERFACE
,
m_hfnOnCommand(NULL)
#endif
{ {
SetFadeEffectDisableOverride( true ); SetFadeEffectDisableOverride( true );
} }
void Shutdown() void ScriptShutdown()
{ {
ivgui()->RemoveTickSignal( GetVPanel() ); ivgui()->RemoveTickSignal( GetVPanel() );
@ -2866,6 +3000,7 @@ public:
SetHScript( m_hfnOnKeyCodePressed, NULL ); SetHScript( m_hfnOnKeyCodePressed, NULL );
SetHScript( m_hfnOnKeyCodeReleased, NULL ); SetHScript( m_hfnOnKeyCodeReleased, NULL );
SetHScript( m_hfnOnKeyCodeTyped, NULL ); SetHScript( m_hfnOnKeyCodeTyped, NULL );
#if SCRIPT_VGUI_SIGNAL_INTERFACE #if SCRIPT_VGUI_SIGNAL_INTERFACE
SetHScript( m_hfnOnCommand, NULL ); SetHScript( m_hfnOnCommand, NULL );
#endif #endif
@ -2898,7 +3033,18 @@ public:
g_pScriptVM->ExecuteFunction( m_hfnPerformLayout, NULL, 0, NULL, NULL, true ); g_pScriptVM->ExecuteFunction( m_hfnPerformLayout, NULL, 0, NULL, NULL, true );
} }
} }
#if 0
void ApplySchemeSettings( IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
if ( m_hfnApplySchemeSettings )
{
ScriptVariant_t arg;
g_pScriptVM->ExecuteFunction( m_hfnApplySchemeSettings, &arg, 1, NULL, NULL, true );
}
}
#endif
void OnTick() void OnTick()
{ {
g_pScriptVM->ExecuteFunction( m_hfnOnTick, NULL, 0, NULL, NULL, true ); g_pScriptVM->ExecuteFunction( m_hfnOnTick, NULL, 0, NULL, NULL, true );
@ -3072,6 +3218,7 @@ public:
CheckCallback( OnKeyCodePressed ); CheckCallback( OnKeyCodePressed );
CheckCallback( OnKeyCodeReleased ); CheckCallback( OnKeyCodeReleased );
CheckCallback( OnKeyCodeTyped ); CheckCallback( OnKeyCodeTyped );
#if SCRIPT_VGUI_SIGNAL_INTERFACE #if SCRIPT_VGUI_SIGNAL_INTERFACE
CheckCallback( OnCommand ); CheckCallback( OnCommand );
#endif #endif
@ -3102,7 +3249,7 @@ public:
m_hfnDoClick(NULL) m_hfnDoClick(NULL)
{} {}
void Shutdown() void ScriptShutdown()
{ {
SetHScript( m_hfnPaint, NULL ); SetHScript( m_hfnPaint, NULL );
SetHScript( m_hfnPaintBackground, NULL ); SetHScript( m_hfnPaintBackground, NULL );
@ -3173,7 +3320,7 @@ public:
m_hfnTextChanged(NULL) m_hfnTextChanged(NULL)
{} {}
void Shutdown() void ScriptShutdown()
{ {
SetHScript( m_hfnTextChanged, NULL ); SetHScript( m_hfnTextChanged, NULL );
} }
@ -3216,9 +3363,12 @@ public:
SetShouldDrawFriendIcon( false ); SetShouldDrawFriendIcon( false );
} }
DEBUG_DESTRUCTOR( ~CScript_AvatarImage, CAvatarImagePanel ) ~CScript_AvatarImage()
{
DebugDestructor( CAvatarImagePanel );
}
void Shutdown() {} void ScriptShutdown() {}
}; };
#endif #endif
//-------------------------------------------------------------- //--------------------------------------------------------------
@ -3229,7 +3379,7 @@ class CTGAImagePanel : public Panel
DECLARE_SCRIPTVGUI_CLASS_EX( CTGAImagePanel, Panel ); DECLARE_SCRIPTVGUI_CLASS_EX( CTGAImagePanel, Panel );
private: private:
int m_iTextureID; int m_iTexture;
int m_nWidth; int m_nWidth;
int m_nHeight; int m_nHeight;
Color m_ImageColor; Color m_ImageColor;
@ -3238,7 +3388,7 @@ private:
public: public:
CTGAImagePanel( Panel *parent, const char *name ) : CTGAImagePanel( Panel *parent, const char *name ) :
BaseClass( parent, name ), BaseClass( parent, name ),
m_iTextureID(-1), m_iTexture(-1),
m_bScaleImage(0), m_bScaleImage(0),
m_ImageColor( 255, 255, 255, 255 ) m_ImageColor( 255, 255, 255, 255 )
{ {
@ -3249,21 +3399,21 @@ public:
{ {
DebugDestructor( CTGAImagePanel ); DebugDestructor( CTGAImagePanel );
if ( m_iTextureID != -1 ) if ( m_iTexture != -1 )
{ {
surface()->DestroyTextureID( m_iTextureID ); surface()->DestroyTextureID( m_iTexture );
} }
} }
void Shutdown() {} void ScriptShutdown() {}
public: public:
void Paint() void Paint()
{ {
if ( m_iTextureID != -1 ) if ( m_iTexture != -1 )
{ {
surface()->DrawSetColor( m_ImageColor ); surface()->DrawSetColor( m_ImageColor );
surface()->DrawSetTexture( m_iTextureID ); surface()->DrawSetTexture( m_iTexture );
if ( m_bScaleImage ) if ( m_bScaleImage )
{ {
@ -3288,19 +3438,21 @@ public:
public: public:
void SetTGAImage( const char *fileName ) void SetTGAImage( const char *fileName )
{ {
if ( V_stricmp( V_GetFileExtension( fileName ), "tga" ) != 0 ) const char *ext = V_GetFileExtension( fileName );
if ( ext && V_stricmp( ext, "tga" ) != 0 )
return; return;
CUtlMemory< unsigned char > tga; CUtlMemory< unsigned char > tga;
if ( TGALoader::LoadRGBA8888( fileName, tga, m_nWidth, m_nHeight ) ) if ( TGALoader::LoadRGBA8888( fileName, tga, m_nWidth, m_nHeight ) )
{ {
if ( m_iTextureID == -1 ) if ( m_iTexture == -1 )
{ {
m_iTextureID = surface()->CreateNewTextureID( true ); m_iTexture = surface()->CreateNewTextureID( true );
} }
surface()->DrawSetTextureRGBA( m_iTextureID, tga.Base(), m_nWidth, m_nHeight, false, false ); surface()->DrawSetTextureRGBA( m_iTexture, tga.Base(), m_nWidth, m_nHeight, false, false );
} }
else else
{ {
@ -3393,10 +3545,19 @@ END_SCRIPTDESC()
//-------------------------------------------------------------- //--------------------------------------------------------------
//-------------------------------------------------------------- //--------------------------------------------------------------
#if VGUI_TGA_IMAGE_PANEL #if VGUI_TGA_IMAGE_PANEL
BEGIN_VGUI_HELPER_EX( TGAImagePanel, CTGAImagePanel ) BEGIN_VGUI_HELPER_EX( TGAImage, CTGAImagePanel )
END_VGUI_HELPER() END_VGUI_HELPER()
BEGIN_SCRIPTDESC_VGUI( TGAImagePanel ) BEGIN_SCRIPTDESC_VGUI( TGAImage )
END_SCRIPTDESC()
#endif
//--------------------------------------------------------------
//--------------------------------------------------------------
#if 0
BEGIN_VGUI_HELPER_EX( PNGImage, CPNGImagePanel )
END_VGUI_HELPER()
BEGIN_SCRIPTDESC_VGUI( PNGImage )
END_SCRIPTDESC() END_SCRIPTDESC()
#endif #endif
//-------------------------------------------------------------- //--------------------------------------------------------------
@ -3448,7 +3609,7 @@ HSCRIPT CScriptVGUI::CreatePanel( const char* panelClass, HSCRIPT parent, const
} }
#define Check( _name )\ #define Check( _name )\
if ( FStrEq( panelClass, #_name ) )\ if ( !V_strcmp( panelClass, #_name ) )\
{\ {\
CScript_##_name##_Helper *helper = AllocScriptPanel< CScript_##_name##_Helper >();\ CScript_##_name##_Helper *helper = AllocScriptPanel< CScript_##_name##_Helper >();\
helper->CreateFromScript< CScript_##_name##_Helper >( (HSCRIPT)parent, panelName, root );\ helper->CreateFromScript< CScript_##_name##_Helper >( (HSCRIPT)parent, panelName, root );\
@ -3467,7 +3628,7 @@ HSCRIPT CScriptVGUI::CreatePanel( const char* panelClass, HSCRIPT parent, const
Check( AvatarImage ); Check( AvatarImage );
#endif #endif
#if VGUI_TGA_IMAGE_PANEL #if VGUI_TGA_IMAGE_PANEL
Check( TGAImagePanel ); Check( TGAImage );
#endif #endif
g_pScriptVM->RaiseException("invalid vgui class"); g_pScriptVM->RaiseException("invalid vgui class");
@ -3480,6 +3641,8 @@ void CScriptVGUI::LevelShutdownPostEntity()
{ {
DebugMsg( "LevelShutdownPostEntity()\n" ); DebugMsg( "LevelShutdownPostEntity()\n" );
if ( g_ScriptPanels.Count() )
{
while ( g_ScriptPanels.Count() ) while ( g_ScriptPanels.Count() )
{ {
Assert( g_ScriptPanels.Head() != g_ScriptPanels.InvalidIndex() ); Assert( g_ScriptPanels.Head() != g_ScriptPanels.InvalidIndex() );
@ -3487,9 +3650,13 @@ void CScriptVGUI::LevelShutdownPostEntity()
int head = g_ScriptPanels.Head(); int head = g_ScriptPanels.Head();
g_ScriptPanels[ head ]->Destroy( head ); g_ScriptPanels[ head ]->Destroy( head );
} }
g_ScriptPanels.Purge();
FOR_EACH_VEC( g_ScriptTextureIDs, i ) g_ScriptPanels.Purge();
}
if ( int i = g_ScriptTextureIDs.Count() )
{
while ( i-- )
{ {
#ifdef _DEBUG #ifdef _DEBUG
char tex[MAX_PATH]; char tex[MAX_PATH];
@ -3498,7 +3665,9 @@ void CScriptVGUI::LevelShutdownPostEntity()
#endif #endif
surface()->DestroyTextureID( g_ScriptTextureIDs[i] ); surface()->DestroyTextureID( g_ScriptTextureIDs[i] );
} }
g_ScriptTextureIDs.Purge(); g_ScriptTextureIDs.Purge();
}
// //
// Reset hud element visibility // Reset hud element visibility

View File

@ -1,6 +1,6 @@
static const char* g_Script_vgui_init = R"script( static const char* g_Script_vgui_init = R"script(
local DoCreateFont = ISurface.CreateFont; local DoCreateFont = ISurface.CreateFont;
ISurface.CreateFont <- function( name, props ) function ISurface::CreateFont( name, props )
{ {
if ( !("name" in props) || typeof props.name != "string" ) if ( !("name" in props) || typeof props.name != "string" )
throw "invalid parameter 'name'"; throw "invalid parameter 'name'";
@ -86,12 +86,12 @@ ISurface.CreateFont <- function( name, props )
return DoCreateFont( name, props.name, props.tall, props.weight, blur, scanlines, flags, yres_min, yres_max, proportional ); return DoCreateFont( name, props.name, props.tall, props.weight, blur, scanlines, flags, yres_min, yres_max, proportional );
} }
local _Schemes = {}
local _FontTall = {} local _FontTall = {}
local _Schemes = {}
local DoGetFont = ISurface.DoGetFont <- ISurface.GetFont; local DoGetFont = ISurface.DoGetFont <- ISurface.GetFont;
local DoGetFontTall = ISurface.GetFontTall; local DoGetFontTall = ISurface.GetFontTall;
ISurface.GetFont <- function( name, proportional, sch = "" ) function ISurface::GetFont( name, proportional, sch = "" )
{ {
if ( sch in _Schemes ) if ( sch in _Schemes )
{ {
@ -151,33 +151,28 @@ ISurface.GetTextureID <- function( name )
} }
// Forward compatibility // Forward compatibility
IVGui.GetRootPanel <- function() { return 1000 } IVGui.GetRootPanel <- function() { return 0x8888 }
//IVGui.GetGameUIRootPanel <- function() { return 1001 } //IVGui.GetGameUIRootPanel <- function() { return 0x8888+1 }
IVGui.GetClientDLLRootPanel <- function() { return 1002 } IVGui.GetClientDLLRootPanel <- function() { return 0x8888+2 }
//IVGui.GetHudViewportPanel <- function() { return 1010 } IVGui.GetHudViewport <- function() { return 0x8888+10 }
local CreatePanel = IVGui.CreatePanel; local CreatePanel = IVGui.CreatePanel;
IVGui.CreatePanel <- function( type, parent, name ) function IVGui::CreatePanel( type, parent, name )
{ {
if ( !parent ) if ( !parent )
throw "invalid parent"; throw "invalid parent";
local root = 0; local root = -1;
if ( typeof parent == "integer" ) if ( typeof parent == "integer" )
{ {
switch ( parent ) root = parent-0x8888;
switch ( root )
{ {
case 1000: case 0:
root = 0; case 2:
case 10:
break; break;
default: throw "invalid parent";
case 1002:
root = 2;
break;
default:
throw "invalid parent";
} }
parent = null; parent = null;
} }
@ -390,5 +385,6 @@ if ( __Documentation.RegisterHelp != dummy )
__Documentation.RegisterHelp( "IVGui::CreatePanel", "handle IVGui::CreatePanel(string, handle, string)", "" ); __Documentation.RegisterHelp( "IVGui::CreatePanel", "handle IVGui::CreatePanel(string, handle, string)", "" );
__Documentation.RegisterHelp( "IVGui::GetRootPanel", "handle IVGui::GetRootPanel()", "" ); __Documentation.RegisterHelp( "IVGui::GetRootPanel", "handle IVGui::GetRootPanel()", "" );
__Documentation.RegisterHelp( "IVGui::GetClientDLLRootPanel", "handle IVGui::GetClientDLLRootPanel()", "" ); __Documentation.RegisterHelp( "IVGui::GetClientDLLRootPanel", "handle IVGui::GetClientDLLRootPanel()", "" );
__Documentation.RegisterHelp( "IVGui::GetHudViewport", "handle IVGui::GetHudViewport()", "" );
} }
)script"; )script";