summaryrefslogtreecommitdiff
path: root/tracker/AdminServer/VarEditDialog.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 /tracker/AdminServer/VarEditDialog.cpp
downloadarchived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.tar.xz
archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.zip
Diffstat (limited to 'tracker/AdminServer/VarEditDialog.cpp')
-rw-r--r--tracker/AdminServer/VarEditDialog.cpp203
1 files changed, 203 insertions, 0 deletions
diff --git a/tracker/AdminServer/VarEditDialog.cpp b/tracker/AdminServer/VarEditDialog.cpp
new file mode 100644
index 0000000..bb118f5
--- /dev/null
+++ b/tracker/AdminServer/VarEditDialog.cpp
@@ -0,0 +1,203 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================
+
+#include "VarEditDialog.h"
+#include "RemoteServer.h"
+
+#include <stdio.h>
+
+#include <vgui/IInput.h>
+
+#include <vgui_controls/Button.h>
+#include <vgui_controls/ComboBox.h>
+#include <vgui_controls/TextEntry.h>
+#include <KeyValues.h>
+
+using namespace vgui;
+
+//-----------------------------------------------------------------------------
+// Purpose: Constructor
+//-----------------------------------------------------------------------------
+CVarEditDialog::CVarEditDialog(vgui::Panel *parent, const char *name) : Frame(parent, name)
+{
+ SetSize(280, 180);
+ SetSizeable(false);
+ m_pOKButton = new Button(this, "OKButton", "OK");
+ m_pCancelButton = new Button(this, "CancelButton", "Cancel");
+ m_pStringEdit = new TextEntry(this, "StringEdit");
+ m_pComboEdit = new ComboBox(this, "ComboEdit", 12, false);
+ m_pRules = NULL;
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Destructor
+//-----------------------------------------------------------------------------
+CVarEditDialog::~CVarEditDialog()
+{
+// input()->ReleaseAppModalSurface();
+ if (m_pRules)
+ {
+ m_pRules->deleteThis();
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Configures and shows the var edit dialog
+//-----------------------------------------------------------------------------
+void CVarEditDialog::Activate(vgui::Panel *actionSignalTarget, KeyValues *rules)
+{
+ // configure
+ AddActionSignalTarget(actionSignalTarget);
+ m_pRules = rules->MakeCopy();
+
+ const char *type = m_pRules->GetString("type");
+ if (!stricmp(type, "enumeration"))
+ {
+ LoadControlSettings("Admin/VarEditDialog_ComboBox.res", "PLATFORM");
+ m_pStringEdit->SetVisible(false);
+
+ // fill in the combo box
+ for (KeyValues *kv = m_pRules->FindKey("list", true)->GetFirstSubKey(); kv != NULL; kv = kv->GetNextKey())
+ {
+ Assert( 0 );
+ // FIXME: This Assert doesn't compile
+// Assert(index++ == atoi(kv->GetName()));
+ m_pComboEdit->AddItem(kv->GetString(), NULL);
+ }
+
+ // activate the current item
+ m_pComboEdit->ActivateItemByRow(m_pRules->GetInt("enum"));
+ }
+ else if (!stricmp(type, "customlist"))
+ {
+ LoadControlSettings("Admin/VarEditDialog_ComboBox.res", "PLATFORM");
+ m_pStringEdit->SetVisible(false);
+
+ // fill in the combo box
+ int index = 0;
+ const char *currentValue = m_pRules->GetString("value");
+ const char *parse = m_pRules->GetString("stringlist");
+ while (*parse)
+ {
+ // newline-seperated map list
+ if (*parse == '\n')
+ {
+ parse++;
+ continue;
+ }
+
+ // pull out the map name
+ const char *end = strstr(parse, "\n");
+ if (!end)
+ break;
+
+ char customString[64];
+ int nameSize = end - parse;
+ if (nameSize >= sizeof(customString))
+ {
+ nameSize = sizeof(customString) - 1;
+ }
+
+ // copy in the name
+ strncpy(customString, parse, nameSize);
+ customString[nameSize] = 0;
+ parse = end;
+
+ // add to dropdown
+ int itemID = m_pComboEdit->AddItem(customString, NULL);
+ index++;
+
+ // activate the current item
+ if (!stricmp(customString, currentValue))
+ {
+ m_pComboEdit->ActivateItem(itemID);
+ }
+ }
+ }
+ else
+ {
+ // normal string edit
+ LoadControlSettings("Admin/VarEditDialog_String.res", "PLATFORM");
+ m_pComboEdit->SetVisible(false);
+ m_pStringEdit->SelectAllOnFirstFocus(true);
+ m_pStringEdit->SetText(m_pRules->GetString("value"));
+ }
+
+ // set value
+ char title[256];
+ _snprintf(title, sizeof(title) - 1, "Change %s", m_pRules->GetString("name"));
+ SetTitle(title, false);
+
+ // bring to front
+// input()->SetAppModalSurface(GetVPanel());
+ MoveToCenterOfScreen();
+ BaseClass::Activate();
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: button command handler
+//-----------------------------------------------------------------------------
+void CVarEditDialog::OnCommand(const char *command)
+{
+ if (!stricmp(command, "OK"))
+ {
+ // change the value
+ ApplyChanges();
+ Close();
+ }
+ else if (!stricmp(command, "Cancel"))
+ {
+ Close();
+ }
+ else
+ {
+ BaseClass::OnCommand(command);
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Applies changes
+//-----------------------------------------------------------------------------
+void CVarEditDialog::ApplyChanges()
+{
+ const char *type = m_pRules->GetString("type");
+ if (!stricmp(type, "enumeration"))
+ {
+ // get the enumeration position from the combo box
+ int iVal = m_pComboEdit->GetActiveItem();
+ char value[32];
+ _snprintf(value, sizeof(value) - 1, "%d", iVal);
+ RemoteServer().SetValue(m_pRules->GetName(), value);
+
+ }
+ else if (!stricmp(type, "customlist"))
+ {
+ char value[512];
+ m_pComboEdit->GetText(value, sizeof(value));
+ RemoteServer().SetValue(m_pRules->GetName(), value);
+ }
+ else
+ {
+ // normal string
+ char value[512];
+ m_pStringEdit->GetText(value, sizeof(value));
+ RemoteServer().SetValue(m_pRules->GetName(), value);
+ }
+
+ // tell the caller the var changed
+ PostActionSignal(new KeyValues("VarChanged", "var", m_pRules->GetName()));
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Deletes on close
+//-----------------------------------------------------------------------------
+void CVarEditDialog::OnClose()
+{
+ BaseClass::OnClose();
+ MarkForDeletion();
+}
+