From 3bf9df6b2785fa6d951086978a3e66f49427166a Mon Sep 17 00:00:00 2001 From: FluorescentCIAAfricanAmerican <0934gj3049fk@protonmail.com> Date: Wed, 22 Apr 2020 12:56:21 -0400 Subject: 1 --- tracker/AdminServer/VarEditDialog.cpp | 203 ++++++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 tracker/AdminServer/VarEditDialog.cpp (limited to 'tracker/AdminServer/VarEditDialog.cpp') 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 + +#include + +#include +#include +#include +#include + +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(); +} + -- cgit v1.2.3