summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-09-30 19:54:06 -0600
committerJared Adams <jaxad0127@gmail.com>2009-09-30 19:54:06 -0600
commitd4f32a38fd498c180d562ced38a9129e0abf2252 (patch)
treee655b59ff686ad5fe2bdd11d6e072f5c3a4493b7 /src/gui
parent6707d108790ab1fe1d4a3ef52d717966990fdf0a (diff)
downloadmana-d4f32a38fd498c180d562ced38a9129e0abf2252.tar.gz
mana-d4f32a38fd498c180d562ced38a9129e0abf2252.tar.bz2
mana-d4f32a38fd498c180d562ced38a9129e0abf2252.tar.xz
mana-d4f32a38fd498c180d562ced38a9129e0abf2252.zip
Merge login state machines for both clients
Also do some cleanup and refactoring of related code.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/charselectdialog.cpp11
-rw-r--r--src/gui/charselectdialog.h2
-rw-r--r--src/gui/login.cpp213
-rw-r--r--src/gui/login.h51
-rw-r--r--src/gui/quitdialog.cpp10
-rw-r--r--src/gui/register.cpp102
-rw-r--r--src/gui/register.h38
-rw-r--r--src/gui/serverdialog.cpp62
-rw-r--r--src/gui/serverdialog.h28
-rw-r--r--src/gui/updatewindow.cpp2
-rw-r--r--src/gui/worldselectdialog.cpp (renamed from src/gui/serverselectdialog.cpp)40
-rw-r--r--src/gui/worldselectdialog.h (renamed from src/gui/serverselectdialog.h)17
12 files changed, 112 insertions, 464 deletions
diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp
index 69a627e1..be1cd3de 100644
--- a/src/gui/charselectdialog.cpp
+++ b/src/gui/charselectdialog.cpp
@@ -98,9 +98,6 @@ CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo,
mCharInfo(charInfo),
mLoginData(loginData),
mCharSelected(false)
-#ifdef EATHENA_SUPPORT
- , mGender(loginData->sex)
-#endif
{
mSelectButton = new Button(_("OK"), "ok", this);
mCancelButton = new Button(_("Cancel"), "cancel", this);
@@ -214,12 +211,8 @@ void CharSelectDialog::action(const gcn::ActionEvent &event)
}
else if (event.getId() == "cancel")
{
-#ifdef TMWSERV_SUPPORT
mCharInfo->clear();
- state = STATE_SWITCH_ACCOUNTSERVER_ATTEMPT;
-#else
- state = STATE_EXIT;
-#endif
+ state = STATE_SWITCH_SERVER_ATTEMPT;
}
#ifdef TMWSERV_SUPPORT
else if (event.getId() == "new")
@@ -250,7 +243,7 @@ void CharSelectDialog::action(const gcn::ActionEvent &event)
{
new CharDeleteConfirm(this);
}
- else if (n_character <= maxSlot)
+ else if (n_character < MAX_CHARACTER_COUNT)
{
// Start new character dialog
CharCreateDialog *charCreateDialog =
diff --git a/src/gui/charselectdialog.h b/src/gui/charselectdialog.h
index 4427017e..5f067404 100644
--- a/src/gui/charselectdialog.h
+++ b/src/gui/charselectdialog.h
@@ -83,11 +83,9 @@ class CharSelectDialog : public Window, public gcn::ActionListener
gcn::Button *mDelCharButton;
gcn::Button *mUnRegisterButton;
gcn::Button *mChangeEmailButton;
-
#else
gcn::Button *mNewDelCharButton;
gcn::Label *mJobLevelLabel;
- Gender mGender;
#endif
/**
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index f6272936..84a6a22c 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -50,73 +50,27 @@ LoginDialog::LoginDialog(LoginData *loginData):
{
gcn::Label *userLabel = new Label(_("Name:"));
gcn::Label *passLabel = new Label(_("Password:"));
-#ifdef EATHENA_SUPPORT
- gcn::Label *serverLabel = new Label(_("Server:"));
- gcn::Label *portLabel = new Label(_("Port:"));
- gcn::Label *dropdownLabel = new Label(_("Recent:"));
- std::vector<std::string> dfltServer;
- dfltServer.push_back("server.themanaworld.org");
- std::vector<std::string> dfltPort;
- dfltPort.push_back("6901");
- mServerList = new DropDownList("MostRecent00", dfltServer, dfltPort,
- MAX_SERVER_LIST_SIZE);
-#endif
mUserField = new TextField(mLoginData->username);
mPassField = new PasswordField(mLoginData->password);
-#ifdef EATHENA_SUPPORT
- mServerField = new TextField(mServerList->getServerAt(0));
- mPortField = new TextField(mServerList->getPortAt(0));
- mServerDropDown = new DropDown(mServerList);
-#endif
mKeepCheck = new CheckBox(_("Remember username"), mLoginData->remember);
mOkButton = new Button(_("OK"), "ok", this);
-#ifdef TMWSERV_SUPPORT
mCancelButton = new Button(_("Cancel"), "cancel", this);
-#else
- mCancelButton = new Button(_("Quit"), "cancel", this);
-#endif
mRegisterButton = new Button(_("Register"), "register", this);
mUserField->setActionEventId("ok");
mPassField->setActionEventId("ok");
-#ifdef EATHENA_SUPPORT
- mServerField->setActionEventId("ok");
- mPortField->setActionEventId("ok");
- mServerDropDown->setActionEventId("changeSelection");
-#endif
mUserField->addKeyListener(this);
mPassField->addKeyListener(this);
-#ifdef EATHENA_SUPPORT
- mServerField->addKeyListener(this);
- mPortField->addKeyListener(this);
- mServerDropDown->addKeyListener(this);
-#endif
mUserField->addActionListener(this);
mPassField->addActionListener(this);
-#ifdef EATHENA_SUPPORT
- mServerField->addActionListener(this);
- mPortField->addActionListener(this);
- mServerDropDown->addActionListener(this);
- mKeepCheck->addActionListener(this);
-#endif
place(0, 0, userLabel);
place(0, 1, passLabel);
-#ifdef EATHENA_SUPPORT
- place(0, 2, serverLabel);
- place(0, 3, portLabel);
- place(0, 4, dropdownLabel);
-#endif
place(1, 0, mUserField, 3).setPadding(1);
place(1, 1, mPassField, 3).setPadding(1);
-#ifdef EATHENA_SUPPORT
- place(1, 2, mServerField, 3).setPadding(1);
- place(1, 3, mPortField, 3).setPadding(1);
- place(1, 4, mServerDropDown, 3).setPadding(1);
-#endif
place(0, 5, mKeepCheck, 4);
place(0, 6, mRegisterButton).setHAlign(LayoutCell::LEFT);
place(2, 6, mCancelButton);
@@ -136,19 +90,12 @@ LoginDialog::LoginDialog(LoginData *loginData):
LoginDialog::~LoginDialog()
{
-#ifdef EATHENA_SUPPORT
- delete mServerList;
-#endif
}
void LoginDialog::action(const gcn::ActionEvent &event)
{
if (event.getId() == "ok" && canSubmit())
{
-#ifdef EATHENA_SUPPORT
- mLoginData->hostname = mServerField->getText();
- mLoginData->port = getUShort(mPortField->getText());
-#endif
mLoginData->username = mUserField->getText();
mLoginData->password = mPassField->getText();
mLoginData->remember = mKeepCheck->isSelected();
@@ -156,41 +103,14 @@ void LoginDialog::action(const gcn::ActionEvent &event)
mOkButton->setEnabled(false);
mRegisterButton->setEnabled(false);
-#ifdef EATHENA_SUPPORT
- mServerList->save(mServerField->getText(), mPortField->getText());
- state = STATE_ACCOUNT;
-#else
state = STATE_LOGIN_ATTEMPT;
-#endif
}
-#ifdef EATHENA_SUPPORT
- else if (event.getId() == "changeSelection")
- {
- int selected = mServerDropDown->getSelected();
- mServerField->setText(mServerList->getServerAt(selected));
- mPortField->setText(mServerList->getPortAt(selected));
- }
-#endif
else if (event.getId() == "cancel")
{
-#ifdef TMWSERV_SUPPORT
- state = STATE_SWITCH_ACCOUNTSERVER;
-#else
- state = STATE_EXIT;
-#endif
+ state = STATE_SWITCH_SERVER;
}
else if (event.getId() == "register")
{
-#ifdef EATHENA_SUPPORT
- // Transfer these fields on to the register dialog
- mLoginData->hostname = mServerField->getText();
-
- if (isUShort(mPortField->getText()))
- mLoginData->port = getUShort(mPortField->getText());
- else
- mLoginData->port = 6901;
-#endif
-
mLoginData->username = mUserField->getText();
mLoginData->password = mPassField->getText();
@@ -207,136 +127,5 @@ bool LoginDialog::canSubmit()
{
return !mUserField->getText().empty() &&
!mPassField->getText().empty() &&
-#ifdef EATHENA_SUPPORT
- !mServerField->getText().empty() &&
- isUShort(mPortField->getText()) &&
-#endif
state == STATE_LOGIN;
}
-
-#ifdef EATHENA_SUPPORT
-bool LoginDialog::isUShort(const std::string &str)
-{
- if (str.empty())
- {
- return false;
- }
- unsigned long l = 0;
- for (std::string::const_iterator strPtr = str.begin(), strEnd = str.end();
- strPtr != strEnd; ++strPtr)
- {
- if (*strPtr < '0' || *strPtr > '9')
- return false;
-
- l = l * 10 + (*strPtr - '0'); // *strPtr - '0' will never be negative
-
- if (l > 65535)
- return false;
- }
- return true;
-}
-
-unsigned short LoginDialog::getUShort(const std::string &str)
-{
- unsigned long l = 0;
- for (std::string::const_iterator strPtr = str.begin(), strEnd = str.end();
- strPtr != strEnd; ++strPtr)
- {
- l = l * 10 + (*strPtr - '0');
- }
- return static_cast<unsigned short>(l);
-}
-
-/**
- * LoginDialog::DropDownList
- */
-
-void LoginDialog::DropDownList::saveEntry(const std::string &server,
- const std::string &port, int &saved)
-{
- if (saved < MAX_SERVER_LIST_SIZE && !server.empty())
- {
- config.setValue(mConfigPrefix + "Server" + toString(saved), server);
- config.setValue(mConfigPrefix + "Port" + toString(saved), port);
- ++saved;
- }
-}
-
-LoginDialog::DropDownList::DropDownList(std::string prefix,
- std::vector<std::string> dflt,
- std::vector<std::string> dfltPort,
- int maxEntries) :
- mConfigPrefix(prefix),
- mMaxEntries(maxEntries)
-{
- for (int i = 0; i < maxEntries; ++i)
- {
- std::string server = config.getValue(mConfigPrefix + "Server" +
- toString(i), "");
- if (server.empty()) // Just in case had original config entries
- {
- server = config.getValue(mConfigPrefix + "ServerList" +
- toString(i), "");
- }
- std::string port = config.getValue(mConfigPrefix + "Port" +
- toString(i), dfltPort.front());
-
- if (!server.empty())
- {
- mServers.push_back(server);
- mPorts.push_back(port);
- }
- }
- if (mServers.empty())
- {
- mServers.assign(dflt.begin(), dflt.end());
- mPorts.assign(dfltPort.begin(), dfltPort.end());
- }
-}
-
-void LoginDialog::DropDownList::save(const std::string &server,
- const std::string &port)
-{
- int position = 0;
- saveEntry(server, port, position);
- for (std::vector<std::string>::const_iterator sPtr = mServers.begin(),
- sEnd = mServers.end(),
- pPtr = mPorts.begin(),
- pEnd = mPorts.end();
- sPtr != sEnd && pPtr != pEnd;
- ++sPtr, ++pPtr)
- {
- if (*sPtr != server || *pPtr != port)
- saveEntry(*sPtr, *pPtr, position);
- }
-}
-
-int LoginDialog::DropDownList::getNumberOfElements()
-{
- return mServers.size();
-}
-
-std::string LoginDialog::DropDownList::getElementAt(int i)
-{
- if (i < 0 || i >= getNumberOfElements())
- return "";
-
- return getServerAt(i) + ":" + getPortAt(i);
-}
-
-std::string LoginDialog::DropDownList::getServerAt(int i)
-{
- if (i < 0 || i >= getNumberOfElements())
- return "";
-
- return mServers.at(i);
-}
-
-std::string LoginDialog::DropDownList::getPortAt(int i)
-{
- if (i < 0 || i >= getNumberOfElements())
- return "";
-
- return mPorts.at(i);
-}
-#endif
diff --git a/src/gui/login.h b/src/gui/login.h
index 97e76dfc..74a998ba 100644
--- a/src/gui/login.h
+++ b/src/gui/login.h
@@ -68,65 +68,14 @@ class LoginDialog : public Window, public gcn::ActionListener,
*/
bool canSubmit();
-#ifdef EATHENA_SUPPORT
- /**
- * Function to decide whether string is an unsigned short or not
- *
- * @param str the string to parse
- *
- * @return true is str is an unsigned short, false otherwise
- */
- static bool isUShort(const std::string &str);
-
- /**
- * Converts string to an unsigned short (undefined if invalid)
- *
- * @param str the string to parse
- *
- * @return the value str represents
- */
- static unsigned short getUShort(const std::string &str);
-
-#endif
gcn::TextField *mUserField;
gcn::TextField *mPassField;
-#ifdef EATHENA_SUPPORT
- gcn::TextField *mServerField;
- gcn::TextField *mPortField;
- gcn::DropDown *mServerDropDown;
-#endif
gcn::CheckBox *mKeepCheck;
gcn::Button *mOkButton;
gcn::Button *mCancelButton;
gcn::Button *mRegisterButton;
LoginData *mLoginData;
-
- /**
- * Helper class to keep a list of all the recent entries for the
- * dropdown
- */
- class DropDownList : public gcn::ListModel
- {
- private:
- std::vector<std::string> mServers;
- std::vector<std::string> mPorts;
- std::string mConfigPrefix;
- int mMaxEntries;
- void saveEntry(const std::string &server,
- const std::string &port, int &saved);
- public:
- DropDownList(std::string prefix,
- std::vector<std::string> dfltServer,
- std::vector<std::string> dfltPort,
- int maxEntries);
- void save(const std::string &server, const std::string &port);
- int getNumberOfElements();
- std::string getElementAt(int i);
- std::string getServerAt(int i);
- std::string getPortAt(int i);
- };
- DropDownList *mServerList;
};
#endif
diff --git a/src/gui/quitdialog.cpp b/src/gui/quitdialog.cpp
index 98657001..b2faa618 100644
--- a/src/gui/quitdialog.cpp
+++ b/src/gui/quitdialog.cpp
@@ -55,10 +55,11 @@ QuitDialog::QuitDialog(bool* quitGame, QuitDialog** pointerToMe):
//All states, when we're not logged in to someone.
if (state == STATE_CHOOSE_SERVER ||
- state == STATE_CONNECT_ACCOUNT ||
+ state == STATE_CONNECT_SERVER ||
state == STATE_LOGIN ||
state == STATE_LOGIN_ATTEMPT ||
- state == STATE_UPDATE)
+ state == STATE_UPDATE ||
+ state == STATE_LOAD_DATA)
{
mForceQuit->setSelected(true);
add(mForceQuit);
@@ -107,6 +108,7 @@ void QuitDialog::action(const gcn::ActionEvent &event)
{
*mQuitGame = true;
}
+
state = STATE_EXIT;
}
else if (mSwitchAccountServer->isSelected())
@@ -115,7 +117,8 @@ void QuitDialog::action(const gcn::ActionEvent &event)
{
*mQuitGame = true;
}
- state = STATE_SWITCH_ACCOUNTSERVER_ATTEMPT;
+
+ state = STATE_SWITCH_SERVER_ATTEMPT;
}
else if (mSwitchCharacter->isSelected())
{
@@ -123,7 +126,6 @@ void QuitDialog::action(const gcn::ActionEvent &event)
state = STATE_SWITCH_CHARACTER;
}
-
}
scheduleDelete();
}
diff --git a/src/gui/register.cpp b/src/gui/register.cpp
index f1313a5e..ec91c098 100644
--- a/src/gui/register.cpp
+++ b/src/gui/register.cpp
@@ -52,6 +52,8 @@ void WrongDataNoticeListener::action(const gcn::ActionEvent &event)
mTarget->requestFocus();
}
+Gender *RegisterDialog::useGender = NULL;
+
RegisterDialog::RegisterDialog(LoginData *loginData):
Window(_("Register")),
mWrongDataNoticeListener(new WrongDataNoticeListener),
@@ -60,21 +62,15 @@ RegisterDialog::RegisterDialog(LoginData *loginData):
gcn::Label *userLabel = new Label(_("Name:"));
gcn::Label *passwordLabel = new Label(_("Password:"));
gcn::Label *confirmLabel = new Label(_("Confirm:"));
-#ifdef EATHENA_SUPPORT
- gcn::Label *serverLabel = new Label(_("Server:"));
- gcn::Label *portLabel = new Label(_("Port:"));
-#else
+#ifdef TMWSERV_SUPPORT
gcn::Label *emailLabel = new Label(_("Email:"));
#endif
mUserField = new TextField(loginData->username);
mPasswordField = new PasswordField(loginData->password);
mConfirmField = new PasswordField;
-#ifdef EATHENA_SUPPORT
- mServerField = new TextField(loginData->hostname);
- mPortField = new TextField(toString(loginData->port));
mMaleButton = new RadioButton(_("Male"), "sex", true);
mFemaleButton = new RadioButton(_("Female"), "sex", false);
-#else
+#ifdef TMWSERV_SUPPORT
mEmailField = new TextField;
#endif
mRegisterButton = new Button(_("Register"), "register", this);
@@ -85,21 +81,20 @@ RegisterDialog::RegisterDialog(LoginData *loginData):
place(0, 0, userLabel);
place(0, 1, passwordLabel);
place(0, 2, confirmLabel);
-#ifdef EATHENA_SUPPORT
- place(1, 3, mMaleButton);
- place(2, 3, mFemaleButton);
- place(0, 4, serverLabel);
- place(0, 5, portLabel);
-#else
+
+ if (useGender)
+ {
+ place(1, 3, mMaleButton);
+ place(2, 3, mFemaleButton);
+ }
+
+#ifdef TMWSERV_SUPPORT
place(0, 3, emailLabel);
#endif
place(1, 0, mUserField, 3).setPadding(2);
place(1, 1, mPasswordField, 3).setPadding(2);
place(1, 2, mConfirmField, 3).setPadding(2);
-#ifdef EATHENA_SUPPORT
- place(1, 4, mServerField, 3).setPadding(2);
- place(1, 5, mPortField, 3).setPadding(2);
-#else
+#ifdef TMWSERV_SUPPORT
place(1, 3, mEmailField, 3).setPadding(2);
#endif
place = getPlacer(0, 2);
@@ -110,10 +105,6 @@ RegisterDialog::RegisterDialog(LoginData *loginData):
mUserField->addKeyListener(this);
mPasswordField->addKeyListener(this);
mConfirmField->addKeyListener(this);
-#ifdef EATHENA_SUPPORT
- mServerField->addKeyListener(this);
- mPortField->addKeyListener(this);
-#endif
/* TODO:
* This is a quick and dirty way to respond to the ENTER key, regardless of
@@ -128,14 +119,6 @@ RegisterDialog::RegisterDialog(LoginData *loginData):
mPasswordField->addActionListener(this);
mConfirmField->addActionListener(this);
-#ifdef EATHENA_SUPPORT
- mServerField->setActionEventId("register");
- mPortField->setActionEventId("register");
-
- mServerField->addActionListener(this);
- mPortField->addActionListener(this);
-#endif
-
center();
setVisible(true);
mUserField->requestFocus();
@@ -229,21 +212,15 @@ void RegisterDialog::action(const gcn::ActionEvent &event)
mLoginData->username = mUserField->getText();
mLoginData->password = mPasswordField->getText();
-#ifdef EATHENA_SUPPORT
- mLoginData->hostname = mServerField->getText();
- mLoginData->port = getUShort(mPortField->getText());
- mLoginData->sex =
- mFemaleButton->isSelected() ? GENDER_FEMALE : GENDER_MALE;
-#else
+ if (useGender)
+ *useGender = mFemaleButton->isSelected() ? GENDER_FEMALE :
+ GENDER_MALE;
+#ifdef TMWSERV_SUPPORT
mLoginData->email = mEmailField->getText();
#endif
mLoginData->registerLogin = true;
-#ifdef TMWSERV_SUPPORT
state = STATE_REGISTER_ATTEMPT;
-#else
- state = STATE_ACCOUNT;
-#endif
}
}
}
@@ -253,50 +230,15 @@ void RegisterDialog::keyPressed(gcn::KeyEvent &keyEvent)
mRegisterButton->setEnabled(canSubmit());
}
+void RegisterDialog::setGender(Gender *gender)
+{
+ useGender = gender;
+}
+
bool RegisterDialog::canSubmit() const
{
return !mUserField->getText().empty() &&
!mPasswordField->getText().empty() &&
!mConfirmField->getText().empty() &&
-#ifdef EATHENA_SUPPORT
- !mServerField->getText().empty() &&
- isUShort(mPortField->getText()) &&
-#endif
state == STATE_REGISTER;
}
-
-#ifdef EATHENA_SUPPORT
-bool RegisterDialog::isUShort(const std::string &str)
-{
- if (str.empty())
- {
- return false;
- }
- unsigned long l = 0;
- for (std::string::const_iterator strPtr = str.begin(), strEnd = str.end();
- strPtr != strEnd; ++strPtr)
- {
- if (*strPtr < '0' || *strPtr > '9')
- {
- return false;
- }
- l = l * 10 + (*strPtr - '0'); // *strPtr - '0' will never be negative
- if (l > 65535)
- {
- return false;
- }
- }
- return true;
-}
-
-unsigned short RegisterDialog::getUShort(const std::string &str)
-{
- unsigned long l = 0;
- for (std::string::const_iterator strPtr = str.begin(), strEnd = str.end();
- strPtr != strEnd; ++strPtr)
- {
- l = l * 10 + (*strPtr - '0');
- }
- return static_cast<unsigned short>(l);
-}
-#endif
diff --git a/src/gui/register.h b/src/gui/register.h
index 6839c805..729b21c3 100644
--- a/src/gui/register.h
+++ b/src/gui/register.h
@@ -24,6 +24,8 @@
#include "gui/widgets/window.h"
+#include "player.h"
+
#include <guichan/actionlistener.hpp>
#include <guichan/keylistener.hpp>
@@ -78,6 +80,13 @@ class RegisterDialog : public Window, public gcn::ActionListener,
*/
void keyPressed(gcn::KeyEvent &keyEvent);
+ /**
+ * Tell the dialog to show a gender selection. Value stored in the
+ * passed Gender pointer. Default Gender from pointer. Passing NULL
+ * disables the feature.
+ */
+ static void setGender(Gender *gender);
+
private:
/**
* Returns whether submit can be enabled. This is true in the register
@@ -85,46 +94,23 @@ class RegisterDialog : public Window, public gcn::ActionListener,
*/
bool canSubmit() const;
-#ifdef EATHENA_SUPPORT
- /**
- * Function to decide whether string is an unsigned short or not
- *
- * @param str the string to parse
- *
- * @return true if str is an unsigned short, false otherwise
- */
- static bool isUShort(const std::string &str);
-
- /**
- * Converts string to an unsigned short (undefined if invalid)
- *
- * @param str the string to parse
- *
- * @return the value str represents
- */
- static unsigned short getUShort(const std::string &str);
-#endif
-
gcn::TextField *mUserField;
gcn::TextField *mPasswordField;
gcn::TextField *mConfirmField;
-#ifdef EATHENA_SUPPORT
- gcn::TextField *mServerField;
- gcn::TextField *mPortField;
-#else
+#ifdef TMWSERV_SUPPORT
gcn::TextField *mEmailField;
#endif
gcn::Button *mRegisterButton;
gcn::Button *mCancelButton;
-#ifdef EATHENA_SUPPORT
gcn::RadioButton *mMaleButton;
gcn::RadioButton *mFemaleButton;
-#endif
WrongDataNoticeListener *mWrongDataNoticeListener;
LoginData *mLoginData;
+
+ static Gender *useGender;
};
#endif
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
index bd6b7d4b..91d2dbc7 100644
--- a/src/gui/serverdialog.cpp
+++ b/src/gui/serverdialog.cpp
@@ -29,12 +29,12 @@
#include "gui/widgets/layout.h"
#include "gui/widgets/textfield.h"
-#include "net/logindata.h"
-
#include "configuration.h"
#include "log.h"
#include "main.h"
+#include "net/net.h"
+
#include "utils/gettext.h"
#include "utils/stringutils.h"
@@ -51,48 +51,46 @@ int ServersListModel::getNumberOfElements()
std::string ServersListModel::getElementAt(int elementIndex)
{
- std::string myServer = "";
- myServer = servers.at(elementIndex).serverName;
+ std::string myServer = std::string(servers.at(elementIndex).hostname);
myServer += ":";
myServer += toString(servers.at(elementIndex).port);
return myServer;
}
-void ServersListModel::addFirstElement(Server server)
+void ServersListModel::addFirstElement(ServerInfo server)
{
// Equivalent to push_front
- std::vector<Server>::iterator MyIterator = servers.begin();
+ std::vector<ServerInfo>::iterator MyIterator = servers.begin();
servers.insert(MyIterator, 1, server);
}
-void ServersListModel::addElement(Server server)
+void ServersListModel::addElement(ServerInfo server)
{
servers.push_back(server);
}
-ServerDialog::ServerDialog(LoginData *loginData):
- Window(_("Choose Your Server")), mLoginData(loginData)
+ServerDialog::ServerDialog(ServerInfo *serverInfo):
+ Window(_("Choose Your Server")), mServerInfo(serverInfo)
{
gcn::Label *serverLabel = new Label(_("Server:"));
gcn::Label *portLabel = new Label(_("Port:"));
- mServerNameField = new TextField(mLoginData->hostname);
- mPortField = new TextField(toString(mLoginData->port));
+ mServerNameField = new TextField(mServerInfo->hostname);
+ mPortField = new TextField(toString(mServerInfo->port));
// Add the most used servers from config
mMostUsedServersListModel = new ServersListModel;
- Server currentServer;
+ ServerInfo currentServer;
std::string currentConfig = "";
for (int i=0; i<=MAX_SERVERLIST; i++)
{
- currentServer.serverName = "";
- currentServer.port = 0;
+ currentServer.clear();
currentConfig = "MostUsedServerName" + toString(i);
- currentServer.serverName = config.getValue(currentConfig, "");
+ currentServer.hostname = config.getValue(currentConfig, "");
currentConfig = "MostUsedServerPort" + toString(i);
currentServer.port = (short)atoi(config.getValue(currentConfig, "").c_str());
- if (!currentServer.serverName.empty() || currentServer.port != 0)
+ if (!currentServer.hostname.empty() || currentServer.port != 0)
{
mMostUsedServersListModel->addElement(currentServer);
}
@@ -111,6 +109,8 @@ ServerDialog::ServerDialog(LoginData *loginData):
mPortField->addActionListener(this);
mMostUsedServersDropDown->addActionListener(this);
+ mMostUsedServersDropDown->setSelected(0);
+
place(0, 0, serverLabel);
place(0, 1, portLabel);
place(1, 0, mServerNameField, 3).setPadding(2);
@@ -150,9 +150,9 @@ ServerDialog::action(const gcn::ActionEvent &event)
else if (event.getId() == "changeSelection")
{
// Change the textField Values according to new selection
- Server myServer = mMostUsedServersListModel->getServer
+ ServerInfo myServer = mMostUsedServersListModel->getServer
(mMostUsedServersDropDown->getSelected());
- mServerNameField->setText(myServer.serverName);
+ mServerNameField->setText(myServer.hostname);
mPortField->setText(toString(myServer.port));
}
else if (event.getId() == "connect")
@@ -166,39 +166,39 @@ ServerDialog::action(const gcn::ActionEvent &event)
}
else
{
- mLoginData->hostname = mServerNameField->getText();
- mLoginData->port = (short) atoi(mPortField->getText().c_str());
mOkButton->setEnabled(false);
mCancelButton->setEnabled(false);
// First, look if the entry is a new one.
- Server currentServer;
+ ServerInfo currentServer;
+ ServerInfo tempServer;
+ currentServer.hostname = mServerNameField->getText();
+ currentServer.port = (short) atoi(mPortField->getText().c_str());
bool newEntry = true;
for (int i = 0; i < mMostUsedServersListModel->getNumberOfElements(); i++)
{
- currentServer = mMostUsedServersListModel->getServer(i);
- if (currentServer.serverName == mLoginData->hostname &&
- currentServer.port == mLoginData->port)
+ tempServer = mMostUsedServersListModel->getServer(i);
+ if (tempServer.hostname == mServerInfo->hostname &&
+ tempServer.port == mServerInfo->port)
newEntry = false;
}
- // Then, add it to config if it's really new
- currentServer.serverName = mLoginData->hostname;
- currentServer.port = mLoginData->port;
if (newEntry)
mMostUsedServersListModel->addFirstElement(currentServer);
// Write the entry in config
std::string currentConfig = "";
for (int i = 0; i < mMostUsedServersListModel->getNumberOfElements(); i++)
{
- currentServer = mMostUsedServersListModel->getServer(i);
+ tempServer = mMostUsedServersListModel->getServer(i);
currentConfig = "MostUsedServerName" + toString(i);
- config.setValue(currentConfig, currentServer.serverName);
+ config.setValue(currentConfig, tempServer.hostname);
currentConfig = "MostUsedServerPort" + toString(i);
- config.setValue(currentConfig, toString(currentServer.port));
+ config.setValue(currentConfig, toString(tempServer.port));
}
- state = STATE_CONNECT_ACCOUNT;
+ mServerInfo->hostname = currentServer.hostname;
+ mServerInfo->port = currentServer.port;
+ state = STATE_CONNECT_SERVER;
}
}
else if (event.getId() == "cancel")
diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h
index 93903c08..f1cd26d4 100644
--- a/src/gui/serverdialog.h
+++ b/src/gui/serverdialog.h
@@ -26,7 +26,7 @@
#include "guichanfwd.h"
-#include "net/tmwserv/network.h"
+#include "net/serverinfo.h"
#include <guichan/actionlistener.hpp>
#include <guichan/listmodel.hpp>
@@ -35,20 +35,6 @@
#include <vector>
class DropDown;
-class LoginData;
-
-/**
- * A server structure to keep pairs of servers and ports.
- */
-struct Server
-{
- Server():
- port(0)
- {}
-
- std::string serverName;
- short port;
-};
/**
* Server and Port List Model
@@ -69,21 +55,21 @@ class ServersListModel : public gcn::ListModel
/**
* Used to get the corresponding Server struct
*/
- Server getServer(int elementIndex) const
+ ServerInfo getServer(int elementIndex) const
{ return servers[elementIndex]; }
/**
* Add an Element at the end of the server list
*/
- void addElement(Server server);
+ void addElement(ServerInfo server);
/**
* Add an Element at the beginning of the server list
*/
- void addFirstElement(Server server);
+ void addFirstElement(ServerInfo server);
private:
- std::vector<Server> servers;
+ std::vector<ServerInfo> servers;
};
/**
@@ -99,7 +85,7 @@ class ServerDialog : public Window, public gcn::ActionListener
*
* @see Window::Window
*/
- ServerDialog(LoginData *loginData);
+ ServerDialog(ServerInfo *serverInfo);
/**
* Destructor
@@ -120,7 +106,7 @@ class ServerDialog : public Window, public gcn::ActionListener
DropDown *mMostUsedServersDropDown;
ServersListModel *mMostUsedServersListModel;
- LoginData *mLoginData;
+ ServerInfo *mServerInfo;
};
#endif
diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp
index bb2128b4..b39ee8c2 100644
--- a/src/gui/updatewindow.cpp
+++ b/src/gui/updatewindow.cpp
@@ -183,7 +183,7 @@ void UpdaterWindow::action(const gcn::ActionEvent &event)
}
else if (event.getId() == "play")
{
- state = STATE_LOADDATA;
+ state = STATE_LOAD_DATA;
}
}
diff --git a/src/gui/serverselectdialog.cpp b/src/gui/worldselectdialog.cpp
index f492ebc7..cdc6bb75 100644
--- a/src/gui/serverselectdialog.cpp
+++ b/src/gui/worldselectdialog.cpp
@@ -19,21 +19,23 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "gui/serverselectdialog.h"
+#include "gui/worldselectdialog.h"
#include "gui/widgets/button.h"
#include "gui/widgets/listbox.h"
#include "gui/widgets/scrollarea.h"
#include "net/logindata.h"
-#include "net/serverinfo.h"
+#include "net/loginhandler.h"
+#include "net/net.h"
+#include "net/worldinfo.h"
#include "main.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
-extern SERVER_INFO **server_info;
+extern WorldInfo **server_info;
/**
* The list model for the server list.
@@ -41,26 +43,31 @@ extern SERVER_INFO **server_info;
class ServerListModel : public gcn::ListModel
{
public:
+ ServerListModel(Worlds worlds):
+ mWorlds(worlds)
+ {
+ }
+
virtual ~ServerListModel() {}
int getNumberOfElements()
{
- return n_server;
+ return mWorlds.size();
}
std::string getElementAt(int i)
{
- const SERVER_INFO *si = server_info[i];
+ const WorldInfo *si = mWorlds[i];
return si->name + " (" + toString(si->online_users) + ")";
}
+ private:
+ Worlds mWorlds;
};
-ServerSelectDialog::ServerSelectDialog(LoginData *loginData, State nextState):
- Window(_("Select Server")),
- mLoginData(loginData),
- mNextState(nextState)
+WorldSelectDialog::WorldSelectDialog(Worlds worlds):
+ Window(_("Select World"))
{
- mServerListModel = new ServerListModel;
+ mServerListModel = new ServerListModel(worlds);
mServerList = new ListBox(mServerListModel);
ScrollArea *mScrollArea = new ScrollArea(mServerList);
mOkButton = new Button(_("OK"), "ok", this);
@@ -88,7 +95,7 @@ ServerSelectDialog::ServerSelectDialog(LoginData *loginData, State nextState):
add(mOkButton);
add(mCancelButton);
- if (n_server == 0)
+ if (worlds.size() == 0)
// Disable Ok button
mOkButton->setEnabled(false);
else
@@ -100,21 +107,18 @@ ServerSelectDialog::ServerSelectDialog(LoginData *loginData, State nextState):
mOkButton->requestFocus();
}
-ServerSelectDialog::~ServerSelectDialog()
+WorldSelectDialog::~WorldSelectDialog()
{
delete mServerListModel;
}
-void ServerSelectDialog::action(const gcn::ActionEvent &event)
+void WorldSelectDialog::action(const gcn::ActionEvent &event)
{
if (event.getId() == "ok")
{
mOkButton->setEnabled(false);
- const SERVER_INFO *si = server_info[mServerList->getSelected()];
- mLoginData->hostname = ipToString(si->address);
- mLoginData->port = si->port;
- mLoginData->updateHost = si->updateHost;
- state = mNextState;
+ Net::getLoginHandler()->chooseServer(mServerList->getSelected());
+ state = STATE_UPDATE;
}
else if (event.getId() == "cancel")
state = STATE_LOGIN;
diff --git a/src/gui/serverselectdialog.h b/src/gui/worldselectdialog.h
index fd1484af..be18705c 100644
--- a/src/gui/serverselectdialog.h
+++ b/src/gui/worldselectdialog.h
@@ -19,15 +19,16 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef _CHAR_SEL_SERVER_H
-#define _CHAR_SEL_SERVER_H
+#ifndef WORLD_SELECT_DIALOG_H
+#define WORLD_SELECT_DIALOG_H
#include "gui/widgets/window.h"
-#include "main.h"
+#include "net/worldinfo.h"
#include <guichan/actionlistener.hpp>
#include <guichan/listmodel.hpp>
+#include <vector>
class LoginData;
class ServerListModel;
@@ -37,19 +38,19 @@ class ServerListModel;
*
* \ingroup Interface
*/
-class ServerSelectDialog : public Window, public gcn::ActionListener {
+class WorldSelectDialog : public Window, public gcn::ActionListener {
public:
/**
* Constructor
*
* @see Window::Window
*/
- ServerSelectDialog(LoginData *loginData, State nextState);
+ WorldSelectDialog(Worlds worlds);
/**
* Destructor.
*/
- ~ServerSelectDialog();
+ ~WorldSelectDialog();
/**
* Called when receiving actions from the widgets.
@@ -57,11 +58,9 @@ class ServerSelectDialog : public Window, public gcn::ActionListener {
void action(const gcn::ActionEvent &event);
private:
- LoginData *mLoginData;
ServerListModel *mServerListModel;
gcn::ListBox *mServerList;
gcn::Button *mOkButton;
- State mNextState;
};
-#endif
+#endif // WORLD_SELECT_DIALOG_H