summaryrefslogtreecommitdiff
path: root/tracker/AdminServer/ConfigPanel.cpp
blob: fb1c6f50a87c277412e9ecdbdf56eacfaf4a7ead (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
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================

#include "ConfigPanel.h"
//#include "Info.h"

#include <vgui/ISystem.h>
#include <vgui/ISurface.h>
#include <vgui/IVGui.h>
#include <KeyValues.h>

#include <vgui_controls/Label.h>
#include <vgui_controls/TextEntry.h>
#include <vgui_controls/Button.h>
#include <vgui_controls/ToggleButton.h>
#include <vgui_controls/CheckButton.h>
#include <vgui_controls/MessageBox.h>
#include <vgui_controls/RadioButton.h>

#include <stdio.h>

using namespace vgui;

static const long RETRY_TIME = 10000;		// refresh server every 10 seconds

//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CConfigPanel::CConfigPanel(vgui::Panel *parent, bool autorefresh,bool savercon,int refreshtime,
							bool graphs, int graphsrefreshtime,bool getlogs) : Frame(parent, "ConfigPanel")
{
	196, 181, 80,

	SetMinimumSize(400,240);
	SetSizeable(false);
	MakePopup();

	m_pOkayButton = new Button(this, "Okay", "#Okay_Button");
	m_pCloseButton = new Button(this, "Close", "#Close_Button");

	m_pRefreshCheckButton = new CheckButton(this, "RefreshCheckButton", "");

	m_pRconCheckButton = new CheckButton(this, "RconCheckButton", "");

	m_pRefreshTextEntry= new TextEntry(this,"RefreshTextEntry");

	m_pGraphsButton = new CheckButton(this, "GraphsButton", "");
	m_pGraphsRefreshTimeTextEntry= new TextEntry(this,"GraphsRefreshTimeTextEntry");

	m_pLogsButton = new CheckButton(this, "LogsButton", "");

	SetTitle("My servers - Options",true);

	LoadControlSettings("Admin\\ConfigPanel.res", "PLATFORM");

	m_pRefreshCheckButton->SetSelected(autorefresh);
	m_pRconCheckButton->SetSelected(savercon);
	m_pGraphsButton->SetSelected(graphs);
	m_pLogsButton->SetSelected(getlogs);

	m_pRefreshTextEntry->SetEnabled(m_pRefreshCheckButton->IsSelected());
	m_pRefreshTextEntry->SetEditable(m_pRefreshCheckButton->IsSelected());
	m_pGraphsRefreshTimeTextEntry->SetEnabled(m_pGraphsButton->IsSelected());
	m_pGraphsRefreshTimeTextEntry->SetEditable(m_pGraphsButton->IsSelected());

	char refreshText[20];
	_snprintf(refreshText,20,"%i",refreshtime);

	m_pRefreshTextEntry->SetText(refreshText);
	
	_snprintf(refreshText,20,"%i",graphsrefreshtime);

	m_pGraphsRefreshTimeTextEntry->SetText(refreshText);

	SetVisible(true);

}

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

//-----------------------------------------------------------------------------
// Purpose: Activates the dialog
//-----------------------------------------------------------------------------
void CConfigPanel::Run()
{
	RequestFocus();
}


//-----------------------------------------------------------------------------
// Purpose: Deletes the dialog when it's closed
//-----------------------------------------------------------------------------
void CConfigPanel::OnClose()
{
	BaseClass::OnClose();
	MarkForDeletion();
}

//-----------------------------------------------------------------------------
// Purpose: turn on and off components when check boxes are checked
//-----------------------------------------------------------------------------
void CConfigPanel::OnButtonToggled(Panel *panel)
{
	if (panel == m_pRefreshCheckButton) 
		// you can only edit the refresh time if you allow auto refresh
	{
		m_pRefreshTextEntry->SetEnabled(m_pRefreshCheckButton->IsSelected());
		m_pRefreshTextEntry->SetEditable(m_pRefreshCheckButton->IsSelected());
	}
	else if (panel == m_pGraphsButton) 
		// you can only edit the refresh time if you allow auto refresh
	{
		m_pGraphsRefreshTimeTextEntry->SetEnabled(m_pGraphsButton->IsSelected());
		m_pGraphsRefreshTimeTextEntry->SetEditable(m_pGraphsButton->IsSelected());
	}


	InvalidateLayout();
}


//-----------------------------------------------------------------------------
// Purpose: Sets the text of a control by name
//-----------------------------------------------------------------------------
void CConfigPanel::SetControlText(const char *textEntryName, const char *text)
{
	TextEntry *entry = dynamic_cast<TextEntry *>(FindChildByName(textEntryName));
	if (entry)
	{
		entry->SetText(text);
	}
}



//-----------------------------------------------------------------------------
// Purpose: Parse posted messages
//			 
//-----------------------------------------------------------------------------
void CConfigPanel::OnCommand(const char *command)
{

	if(!stricmp(command,"okay"))
	{ // save away the new settings
		char timeText[20];
		int time,timeGraphs;

		m_pRefreshTextEntry->GetText(timeText,20);
		sscanf(timeText,"%i",&time);
	
		memset(timeText, 0x0, sizeof(timeText));
		m_pGraphsRefreshTimeTextEntry->GetText(timeText, 20);
		sscanf(timeText,"%i",&timeGraphs);


		if(time>0 && time < 9999 && timeGraphs>0 && timeGraphs< 9999) 
		{

			OnClose();

		}
		else
		{
			MessageBox *dlg = new MessageBox ("#Config_Panel", "#Config_Time_Error");
			dlg->DoModal();
		}
	}
	else if(!stricmp(command,"close") )
	{
		Close();
	}
}