1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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();
}
|