git-svn-id: https://scorched3d.svn.sourceforge.net/svnroot/scorched3d/trunk/scorched...
[scorched3d/parasti.git] / src / client / dialogs / AdminAuthDialog.cpp
bloba5aecbf4a0b5b678541500d9a0795edfd3eb1ad3
1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
3 //
4 // This file is part of Scorched3D.
5 //
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <dialogs/AdminAuthDialog.h>
22 #include <dialogs/AdminDialog.h>
23 #include <GLW/GLWTextButton.h>
24 #include <GLW/GLWWindowManager.h>
25 #include <client/ClientAdminResultHandler.h>
26 #include <coms/ComsAdminMessage.h>
27 #include <coms/ComsMessageSender.h>
29 AdminAuthDialog *AdminAuthDialog::instance_ = 0;
31 AdminAuthDialog *AdminAuthDialog::instance()
33 if (!instance_)
35 instance_ = new AdminAuthDialog;
37 return instance_;
40 AdminAuthDialog::AdminAuthDialog() :
41 GLWWindow("", 10.0f, 10.0f, 300.0f, 70.0f, eSmallTitle, "")
43 needCentered_ = true;
46 AdminAuthDialog::~AdminAuthDialog()
50 void AdminAuthDialog::display()
52 GLWWindow::display();
54 clear();
56 addWidget(
57 new GLWLabel(0.0f, 0.0f, LANG_RESOURCE("ADMINAUTH_LINE", "Admin authentication.")),
58 0, SpaceAll, 10.0f);
60 GLWPanel *inputPanel = new GLWPanel(0.0f, 0.0f, 0.0f, 0.0f, false, false);
62 username_ = 0;
64 username_ = new GLWTextBox(0.0f, 0.0f, 200.0f);
65 inputPanel->addWidget(new GLWLabel(0.0f, 0.0f, LANG_RESOURCE("USER_NAME_LABEL", "User Name :")));
66 inputPanel->addWidget(username_, 0, SpaceLeft | SpaceTop, 10.0f);
68 password_ = 0;
70 password_ = new GLWTextBox(0.0f, 0.0f, 200.0f, LangString(), GLWTextBox::eFlagPassword);
71 inputPanel->addWidget(new GLWLabel(0.0f, 0.0f, LANG_RESOURCE("PASSWORD_LABEL", "Password :")));
72 inputPanel->addWidget(password_, 0, SpaceLeft | SpaceTop, 10.0f);
74 inputPanel->setGridWidth(2);
75 inputPanel->setLayout(GLWPanel::LayoutGrid);
76 addWidget(inputPanel, 0, SpaceAll, 10.0f);
78 username_->setCurrent();
80 GLWPanel *buttonPanel = new GLWPanel(0.0f, 0.0f, 0.0f, 0.0f, false, false);
81 GLWButton *cancelButton = new GLWTextButton(LANG_RESOURCE("CANCEL", "Cancel"), 95, 10, 105, this,
82 GLWButton::ButtonFlagCancel | GLWButton::ButtonFlagCenterX);
83 cancelId_ = cancelButton->getId();
84 buttonPanel->addWidget(cancelButton, 0, SpaceRight, 10.0f);
85 GLWButton *okButton = new GLWTextButton(LANG_RESOURCE("OK", "Ok"), 235, 10, 55, this,
86 GLWButton::ButtonFlagOk | GLWButton::ButtonFlagCenterX);
87 okId_ = okButton->getId();
88 buttonPanel->addWidget(okButton);
89 buttonPanel->setLayout(GLWPanel::LayoutHorizontal);
90 addWidget(buttonPanel, 0, SpaceAll, 10.0f);
92 setLayout(GLWPanel::LayoutVerticle);
93 layout();
96 void AdminAuthDialog::buttonDown(unsigned int id)
98 GLWWindowManager::instance()->hideWindow(getId());
99 if (id == okId_)
101 unsigned int sid = ClientAdminResultHandler::instance()->getSid();
102 ComsAdminMessage message(sid, ComsAdminMessage::AdminLogin,
103 username_->getText().c_str(),
104 password_->getText().c_str());
105 ComsMessageSender::sendToServer(message);