summaryrefslogtreecommitdiff
path: root/tracker/AdminServer/DialogCvarChange.cpp
blob: 3c94d3abc2f32820d079ce801281ef32a210d400 (plain) (blame)
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================

#include <stdio.h>
#include "DialogCvarChange.h"

#include <vgui/IInput.h>
#include <vgui/ISurface.h>
#include <KeyValues.h>

#include <vgui_controls/Button.h>
#include <vgui_controls/Panel.h>
#include <vgui_controls/Label.h>
#include <vgui_controls/TextEntry.h>

using namespace vgui;

//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CDialogCvarChange::CDialogCvarChange(vgui::Panel *parent) : Frame(parent, "DialogCvarChange")
{
	SetSize(320, 200);

	m_bAddCvarText = true;

	m_pInfoLabel = new Label(this, "InfoLabel", "");
	m_pCvarLabel = new Label(this, "CvarLabel", "");
	m_pCvarEntry = new TextEntry(this, "CvarEntry");
	m_pOkayButton = new Button(this, "OkayButton", "#Okay_Button");

	LoadControlSettings("Admin/DialogCvarChange.res", "PLATFORM");

	SetTitle("#Cvar_Title", true);

	SetSizeable(false);
	// set our initial position in the middle of the workspace
	MoveToCenterOfScreen();
}

//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
CDialogCvarChange::~CDialogCvarChange()
{
}

//-----------------------------------------------------------------------------
// Purpose: Hides value text
//-----------------------------------------------------------------------------
void CDialogCvarChange::MakePassword()
{
	m_pCvarEntry->SetTextHidden(true);
	m_bAddCvarText = false; // this isn't asking about a cvar
}

//-----------------------------------------------------------------------------
// Purpose: initializes the dialog and brings it to the foreground
//-----------------------------------------------------------------------------
void CDialogCvarChange::Activate(const char *cvarName, const char *curValue, const char *type, const char *question)
{
	m_pCvarLabel->SetText(cvarName);
	if (!m_bAddCvarText)
	{
		m_pCvarLabel->SetVisible(false); // hide this
	}

	m_pInfoLabel->SetText(question);

	m_cType=type;

	m_pOkayButton->SetAsDefaultButton(true);
	MakePopup();
	MoveToFront();

	m_pCvarEntry->SetText(curValue);
	m_pCvarEntry->RequestFocus();
	RequestFocus();

	// make it modal
	input()->SetAppModalSurface(GetVPanel());
	SetVisible(true);

	BaseClass::Activate();
}

//-----------------------------------------------------------------------------
// Purpose: Sets the text of a labell by name
//-----------------------------------------------------------------------------
void CDialogCvarChange::SetLabelText(const char *textEntryName, const char *text)
{
	Label *entry = dynamic_cast<Label *>(FindChildByName(textEntryName));
	if (entry)
	{
		entry->SetText(text);
	}
}

//-----------------------------------------------------------------------------
// Purpose: Handles button presses
//-----------------------------------------------------------------------------
void CDialogCvarChange::OnCommand(const char *command)
{
	bool bClose = false;

	if (!stricmp(command, "Okay"))
	{
		KeyValues *msg = new KeyValues("CvarChangeValue");
		char buf[64];
		m_pCvarLabel->GetText(buf,64);

		msg->SetString("player", buf );
		m_pCvarEntry->GetText(buf, sizeof(buf)-1);
		msg->SetString("value", buf);
		msg->SetString("type",m_cType);

		PostActionSignal(msg);

		bClose = true;
	}
	else if (!stricmp(command, "Close"))
	{
		bClose = true;
	}
	else
	{
		BaseClass::OnCommand(command);
	}

	if (bClose)
	{
		Close();
	}
}

//-----------------------------------------------------------------------------
// Purpose: deletes the dialog on close
//-----------------------------------------------------------------------------
void CDialogCvarChange::OnClose()
{
	BaseClass::OnClose();
	MarkForDeletion();
}