summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-03-07 22:56:05 +0300
committerAndrei Karas <akaras@inbox.ru>2012-03-09 00:29:40 +0300
commiteacf63c7a4c660b38329325c3958bbc63d10ee5c (patch)
treea06eb415526220ce0911c686dd69e9adcf848dd3 /src/gui
parentb384454131c7bd50ba171b1fdbad64cfc83d1ffb (diff)
downloadplus-eacf63c7a4c660b38329325c3958bbc63d10ee5c.tar.gz
plus-eacf63c7a4c660b38329325c3958bbc63d10ee5c.tar.bz2
plus-eacf63c7a4c660b38329325c3958bbc63d10ee5c.tar.xz
plus-eacf63c7a4c660b38329325c3958bbc63d10ee5c.zip
Add support for many update hosts (evol server only).
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/logindialog.cpp100
-rw-r--r--src/gui/logindialog.h7
-rw-r--r--src/gui/quitdialog.cpp1
-rw-r--r--src/gui/register.cpp2
-rw-r--r--src/gui/worldselectdialog.cpp2
5 files changed, 98 insertions, 14 deletions
diff --git a/src/gui/logindialog.cpp b/src/gui/logindialog.cpp
index cafc4f72c..a139e6b37 100644
--- a/src/gui/logindialog.cpp
+++ b/src/gui/logindialog.cpp
@@ -82,6 +82,36 @@ public:
}
};
+class UpdateListModel : public gcn::ListModel
+{
+ public:
+ UpdateListModel(LoginData *data) :
+ gcn::ListModel(),
+ mLoginData(data)
+ {
+ }
+
+ virtual ~UpdateListModel()
+ { }
+
+ virtual int getNumberOfElements()
+ {
+ if (!mLoginData)
+ return 0;
+ return mLoginData->updateHosts.size();
+ }
+
+ virtual std::string getElementAt(int i)
+ {
+ if (!mLoginData || i >= getNumberOfElements() || i < 0)
+ return _("???");
+
+ return mLoginData->updateHosts[i];
+ }
+ protected:
+ LoginData *mLoginData;
+};
+
LoginDialog::LoginDialog(LoginData *data, std::string serverName,
std::string *updateHost):
Window(_("Login"), false, nullptr, "login.xml"),
@@ -89,12 +119,29 @@ LoginDialog::LoginDialog(LoginData *data, std::string serverName,
mUpdateHost(updateHost),
mServerName(serverName)
{
-
gcn::Label *serverLabel1 = new Label(_("Server:"));
gcn::Label *serverLabel2 = new Label(serverName);
serverLabel2->adjustSize();
gcn::Label *userLabel = new Label(_("Name:"));
gcn::Label *passLabel = new Label(_("Password:"));
+ if (mLoginData && mLoginData->updateHosts.size() > 1)
+ {
+ mUpdateHostLabel = new Label(strprintf(_("Update host: %s"),
+ mLoginData->updateHost.c_str()));
+ mUpdateListModel = new UpdateListModel(mLoginData);
+ mUpdateHostDropDown = new DropDown(mUpdateListModel,
+ this, "updateselect");
+ const std::string str = serverConfig.getValue("updateHost2", "");
+ if (!str.empty())
+ mUpdateHostDropDown->setSelectedString(str);
+ }
+ else
+ {
+ mUpdateHostLabel = nullptr;
+ mUpdateListModel = nullptr;
+ mUpdateHostDropDown = nullptr;
+ }
+
mCustomUpdateHost = new CheckBox(_("Custom update host"),
mLoginData->updateType & LoginData::Upd_Custom, this, "customhost");
@@ -135,20 +182,30 @@ LoginDialog::LoginDialog(LoginData *data, std::string serverName,
place(0, 0, serverLabel1);
place(1, 0, serverLabel2, 8);
place(0, 1, userLabel);
- place(0, 2, passLabel);
place(1, 1, mUserField, 8);
+ place(0, 2, passLabel);
place(1, 2, mPassField, 8);
place(0, 6, mUpdateTypeLabel, 1);
place(1, 6, mUpdateTypeDropDown, 8);
- place(0, 7, mCustomUpdateHost, 9);
- place(0, 8, mUpdateHostText, 9);
- place(0, 9, mKeepCheck, 9);
- place(0, 10, mRegisterButton).setHAlign(LayoutCell::LEFT);
- place(2, 10, mServerButton);
- place(3, 10, mLoginButton);
+ int n = 7;
+ if (mUpdateHostLabel)
+ {
+ place(0, 7, mUpdateHostLabel, 9);
+ place(0, 8, mUpdateHostDropDown, 9);
+ n += 2;
+ }
+ place(0, n, mCustomUpdateHost, 9);
+ place(0, n + 1, mUpdateHostText, 9);
+ place(0, n + 2, mKeepCheck, 9);
+ place(0, n + 3, mRegisterButton).setHAlign(LayoutCell::LEFT);
+ place(2, n + 3, mServerButton);
+ place(3, n + 3, mLoginButton);
addKeyListener(this);
- setContentSize(300, 200);
+ if (mUpdateHostLabel)
+ setContentSize(300, 250);
+ else
+ setContentSize(300, 200);
center();
setVisible(true);
@@ -196,6 +253,22 @@ void LoginDialog::action(const gcn::ActionEvent &event)
*mUpdateHost = "";
}
}
+ else if (mUpdateHostDropDown)
+ {
+ const std::string str = mUpdateHostDropDown->getSelectedString();
+ serverConfig.setValue("updateHost2", str);
+ if (!str.empty() && checkPath(str))
+ {
+ mLoginData->updateHost = str;
+ *mUpdateHost = str;
+ }
+ else
+ {
+ mLoginData->updateHost = "";
+ *mUpdateHost = "";
+ }
+ }
+
mLoginData->updateType = updateType;
serverConfig.setValue("updateType", updateType);
@@ -228,6 +301,11 @@ void LoginDialog::action(const gcn::ActionEvent &event)
{
mUpdateHostText->setVisible(mCustomUpdateHost->isSelected());
}
+ else if (event.getId() == "updateselect")
+ {
+ mCustomUpdateHost->setSelected(false);
+ mUpdateHostText->setVisible(false);
+ }
}
void LoginDialog::keyPressed(gcn::KeyEvent &keyEvent)
@@ -245,6 +323,6 @@ void LoginDialog::keyPressed(gcn::KeyEvent &keyEvent)
bool LoginDialog::canSubmit() const
{
return !mUserField->getText().empty() &&
- !mPassField->getText().empty() &&
- Client::getState() == STATE_LOGIN;
+ !mPassField->getText().empty() &&
+ Client::getState() == STATE_LOGIN;
}
diff --git a/src/gui/logindialog.h b/src/gui/logindialog.h
index 08799b1c2..53149fe0d 100644
--- a/src/gui/logindialog.h
+++ b/src/gui/logindialog.h
@@ -32,7 +32,9 @@
#include <string>
#include <vector>
+class DropDown;
class LoginData;
+class UpdateListModel;
class UpdateTypeModel;
/**
@@ -78,12 +80,15 @@ class LoginDialog : public Window, public gcn::ActionListener,
gcn::TextField *mPassField;
gcn::CheckBox *mKeepCheck;
gcn::Label *mUpdateTypeLabel;
- gcn::DropDown *mUpdateTypeDropDown;
+ gcn::Label *mUpdateHostLabel;
+ DropDown *mUpdateTypeDropDown;
gcn::Button *mServerButton;
gcn::Button *mLoginButton;
gcn::Button *mRegisterButton;
gcn::CheckBox *mCustomUpdateHost;
gcn::TextField *mUpdateHostText;
+ UpdateListModel *mUpdateListModel;
+ DropDown *mUpdateHostDropDown;
LoginData *mLoginData;
std::string *mUpdateHost;
diff --git a/src/gui/quitdialog.cpp b/src/gui/quitdialog.cpp
index dff5a570c..a0f734adf 100644
--- a/src/gui/quitdialog.cpp
+++ b/src/gui/quitdialog.cpp
@@ -64,6 +64,7 @@ QuitDialog::QuitDialog(QuitDialog** pointerToMe):
if (state == STATE_CHOOSE_SERVER ||
state == STATE_CONNECT_SERVER ||
state == STATE_LOGIN ||
+ state == STATE_PRE_LOGIN ||
state == STATE_LOGIN_ATTEMPT ||
state == STATE_UPDATE ||
state == STATE_LOAD_DATA)
diff --git a/src/gui/register.cpp b/src/gui/register.cpp
index bf0cb299e..4f696dc9d 100644
--- a/src/gui/register.cpp
+++ b/src/gui/register.cpp
@@ -154,7 +154,7 @@ void RegisterDialog::action(const gcn::ActionEvent &event)
{
if (event.getId() == "cancel")
{
- Client::setState(STATE_LOGIN);
+ Client::setState(STATE_PRE_LOGIN);
}
else if (event.getId() == "register" && canSubmit())
{
diff --git a/src/gui/worldselectdialog.cpp b/src/gui/worldselectdialog.cpp
index 19e6b81f7..26fd19208 100644
--- a/src/gui/worldselectdialog.cpp
+++ b/src/gui/worldselectdialog.cpp
@@ -132,7 +132,7 @@ void WorldSelectDialog::action(const gcn::ActionEvent &event)
}
else if (event.getId() == "login")
{
- Client::setState(STATE_LOGIN);
+ Client::setState(STATE_PRE_LOGIN);
}
}