summaryrefslogtreecommitdiff
path: root/gameui/CvarTextEntry.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /gameui/CvarTextEntry.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'gameui/CvarTextEntry.cpp')
-rw-r--r--gameui/CvarTextEntry.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/gameui/CvarTextEntry.cpp b/gameui/CvarTextEntry.cpp
new file mode 100644
index 0000000..8f8e926
--- /dev/null
+++ b/gameui/CvarTextEntry.cpp
@@ -0,0 +1,112 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#include "CvarTextEntry.h"
+#include "EngineInterface.h"
+#include <vgui/IVGui.h>
+#include "IGameUIFuncs.h"
+#include "tier1/KeyValues.h"
+#include "tier1/convar.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+using namespace vgui;
+
+static const int MAX_CVAR_TEXT = 64;
+
+CCvarTextEntry::CCvarTextEntry( Panel *parent, const char *panelName, char const *cvarname )
+ : TextEntry( parent, panelName)
+{
+ m_pszCvarName = cvarname ? strdup( cvarname ) : NULL;
+ m_pszStartValue[0] = 0;
+
+ if ( m_pszCvarName )
+ {
+ Reset();
+ }
+
+ AddActionSignalTarget( this );
+}
+
+CCvarTextEntry::~CCvarTextEntry()
+{
+ if ( m_pszCvarName )
+ {
+ free( m_pszCvarName );
+ }
+}
+
+void CCvarTextEntry::ApplySchemeSettings(IScheme *pScheme)
+{
+ BaseClass::ApplySchemeSettings(pScheme);
+ if (GetMaximumCharCount() < 0 || GetMaximumCharCount() > MAX_CVAR_TEXT)
+ {
+ SetMaximumCharCount(MAX_CVAR_TEXT - 1);
+ }
+}
+
+void CCvarTextEntry::ApplyChanges( bool immediate )
+{
+ if ( !m_pszCvarName )
+ return;
+
+ char szText[ MAX_CVAR_TEXT ];
+ GetText( szText, MAX_CVAR_TEXT );
+
+ if ( !szText[ 0 ] )
+ return;
+
+ if ( immediate )
+ {
+ // set immediately - don't wait for the next frame
+ ConVarRef newCvar( m_pszCvarName );
+ newCvar.SetValue( szText );
+ }
+ else
+ {
+ char szCommand[ 256 ];
+ sprintf( szCommand, "%s \"%s\"\n", m_pszCvarName, szText );
+ engine->ClientCmd_Unrestricted( szCommand );
+ }
+
+ Q_strncpy( m_pszStartValue, szText, sizeof( m_pszStartValue ) );
+}
+
+void CCvarTextEntry::Reset()
+{
+// char *value = engine->pfnGetCvarString( m_pszCvarName );
+ ConVarRef var( m_pszCvarName );
+ if ( !var.IsValid() )
+ return;
+ const char *value = var.GetString();
+ if ( value && value[ 0 ] )
+ {
+ SetText( value );
+ Q_strncpy( m_pszStartValue, value, sizeof( m_pszStartValue ) );
+ }
+}
+
+bool CCvarTextEntry::HasBeenModified()
+{
+ char szText[ MAX_CVAR_TEXT ];
+ GetText( szText, MAX_CVAR_TEXT );
+
+ return stricmp( szText, m_pszStartValue );
+}
+
+
+void CCvarTextEntry::OnTextChanged()
+{
+ if ( !m_pszCvarName )
+ return;
+
+ if (HasBeenModified())
+ {
+ PostActionSignal(new KeyValues("ControlModified"));
+ }
+}