File: UpdaterWindow.cpp

package info (click to toggle)
spring 0.81.2.1%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 28,496 kB
  • ctags: 37,096
  • sloc: cpp: 238,659; ansic: 13,784; java: 12,175; awk: 3,428; python: 1,159; xml: 738; perl: 405; sh: 297; makefile: 267; pascal: 228; objc: 192
file content (113 lines) | stat: -rw-r--r-- 3,331 bytes parent folder | download
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
#ifdef _MSC_VER
#include "StdAfx.h"
#endif
#include "UpdaterWindow.h"

#include <boost/bind.hpp>

#include "ConfigHandler.h"
#include "lib/liblobby/Connection.h"
#include "aGui/LineEdit.h"
#include "aGui/VerticalLayout.h"
#include "aGui/HorizontalLayout.h"
#include "aGui/TextElement.h"
#include "aGui/Button.h"
#include "aGui/Gui.h"

UpdaterWindow::UpdaterWindow(Connection* _con) : agui::Window("Lobby connection"), agreement(NULL), con(_con)
{
	agui::gui->AddElement(this);
	SetPos(0.5, 0.5);
	SetSize(0.4, 0.3);

	agui::VerticalLayout* wndLayout = new agui::VerticalLayout(this);
	label = new agui::TextElement("", wndLayout);

	agui::HorizontalLayout* usrLayout = new agui::HorizontalLayout(wndLayout);
	new agui::TextElement(std::string("Username:"), usrLayout);
	user = new agui::LineEdit(usrLayout);
	user->SetContent(configHandler->GetString("name", "UnnamedPlayer"));
	user->SetWeight(2);
	agui::HorizontalLayout* pwdLayout = new agui::HorizontalLayout(wndLayout);
	new agui::TextElement(std::string("Password:"), pwdLayout);
	passwd = new agui::LineEdit(pwdLayout);
	passwd->SetCrypt(true);
	passwd->SetFocus(true);
	passwd->SetWeight(2);
	
	agui::HorizontalLayout* bttnLayout = new agui::HorizontalLayout(wndLayout);
	
	agui::Button* login = new agui::Button("Login", bttnLayout);
	login->Clicked.connect(boost::bind(&UpdaterWindow::Login, this));
	agui::Button* registerb = new agui::Button("Register", bttnLayout);
	registerb->Clicked.connect(boost::bind(&UpdaterWindow::Register, this));
	agui::Button* close = new agui::Button("Close", bttnLayout);
	close->Clicked.connect(WantClose);

	serverLabel = new agui::TextElement(std::string("Connecting..."), wndLayout);

	GeometryChange();
}

UpdaterWindow::~UpdaterWindow()
{
	if (agreement)
	{
		agui::gui->RmElement(agreement);
		agreement = NULL;
	}
}

void UpdaterWindow::Login()
{
	con->Login(user->GetContent(), passwd->GetContent());
	configHandler->SetString("name", user->GetContent());
}

void UpdaterWindow::Register()
{
	con->Register(user->GetContent(), passwd->GetContent());
	configHandler->SetString("name", user->GetContent());
}

void UpdaterWindow::ShowAggreement(const std::string& text)
{
	agreement = new agui::Window("Agreement");
	agreement->SetSize(0.6, 0.7);
	agui::VerticalLayout* vLay = new agui::VerticalLayout(agreement);
	agui::TextElement* textEl = new agui::TextElement(text, vLay);
	
	agui::HorizontalLayout* bttnLayout = new agui::HorizontalLayout(vLay);
	bttnLayout->SetSize(0.0f, 0.04f, true);
	agui::Button* accept = new agui::Button("I Accept", bttnLayout);
	accept->Clicked.connect(boost::bind(&UpdaterWindow::AcceptAgreement, this));
	agui::Button* noAccept = new agui::Button("I don't accept", bttnLayout);
	noAccept->Clicked.connect(boost::bind(&UpdaterWindow::RejectAgreement, this));
	agreement->WantClose.connect(boost::bind(&UpdaterWindow::RejectAgreement, this));
	agreement->GeometryChange();

	agui::gui->AddElement(agreement);
}

void UpdaterWindow::AcceptAgreement()
{
	agui::gui->RmElement(agreement);
	agreement = NULL;
	con->ConfirmAggreement();
}

void UpdaterWindow::RejectAgreement()
{
	agui::gui->RmElement(agreement);
	agreement = NULL;
}

void UpdaterWindow::ServerLabel(const std::string& text)
{
	serverLabel->SetText(text);
}

void UpdaterWindow::Label(const std::string& text)
{
	label->SetText(text);
}