summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/login.cpp23
-rw-r--r--src/gui/login.h4
-rw-r--r--src/gui/serverdialog.cpp32
-rw-r--r--src/gui/serverdialog.h8
-rw-r--r--src/gui/worldselectdialog.cpp74
-rw-r--r--src/gui/worldselectdialog.h9
-rw-r--r--src/main.cpp6
-rw-r--r--src/net/ea/loginhandler.cpp3
8 files changed, 83 insertions, 76 deletions
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index 84a6a22c..ad2eb966 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -55,12 +55,12 @@ LoginDialog::LoginDialog(LoginData *loginData):
mPassField = new PasswordField(mLoginData->password);
mKeepCheck = new CheckBox(_("Remember username"), mLoginData->remember);
- mOkButton = new Button(_("OK"), "ok", this);
- mCancelButton = new Button(_("Cancel"), "cancel", this);
mRegisterButton = new Button(_("Register"), "register", this);
+ mServerButton = new Button(_("Select Server"), "server", this);
+ mLoginButton = new Button(_("Login"), "login", this);
- mUserField->setActionEventId("ok");
- mPassField->setActionEventId("ok");
+ mUserField->setActionEventId("login");
+ mPassField->setActionEventId("login");
mUserField->addKeyListener(this);
mPassField->addKeyListener(this);
@@ -73,8 +73,8 @@ LoginDialog::LoginDialog(LoginData *loginData):
place(1, 1, mPassField, 3).setPadding(1);
place(0, 5, mKeepCheck, 4);
place(0, 6, mRegisterButton).setHAlign(LayoutCell::LEFT);
- place(2, 6, mCancelButton);
- place(3, 6, mOkButton);
+ place(2, 6, mServerButton);
+ place(3, 6, mLoginButton);
reflowLayout(250, 0);
center();
@@ -85,7 +85,7 @@ LoginDialog::LoginDialog(LoginData *loginData):
else
mPassField->requestFocus();
- mOkButton->setEnabled(canSubmit());
+ mLoginButton->setEnabled(canSubmit());
}
LoginDialog::~LoginDialog()
@@ -94,18 +94,19 @@ LoginDialog::~LoginDialog()
void LoginDialog::action(const gcn::ActionEvent &event)
{
- if (event.getId() == "ok" && canSubmit())
+ if (event.getId() == "login" && canSubmit())
{
mLoginData->username = mUserField->getText();
mLoginData->password = mPassField->getText();
mLoginData->remember = mKeepCheck->isSelected();
mLoginData->registerLogin = false;
- mOkButton->setEnabled(false);
mRegisterButton->setEnabled(false);
+ mServerButton->setEnabled(false);
+ mLoginButton->setEnabled(false);
state = STATE_LOGIN_ATTEMPT;
}
- else if (event.getId() == "cancel")
+ else if (event.getId() == "server")
{
state = STATE_SWITCH_SERVER;
}
@@ -120,7 +121,7 @@ void LoginDialog::action(const gcn::ActionEvent &event)
void LoginDialog::keyPressed(gcn::KeyEvent &keyEvent)
{
- mOkButton->setEnabled(canSubmit());
+ mLoginButton->setEnabled(canSubmit());
}
bool LoginDialog::canSubmit()
diff --git a/src/gui/login.h b/src/gui/login.h
index 74a998ba..d3ec7b39 100644
--- a/src/gui/login.h
+++ b/src/gui/login.h
@@ -71,8 +71,8 @@ class LoginDialog : public Window, public gcn::ActionListener,
gcn::TextField *mUserField;
gcn::TextField *mPassField;
gcn::CheckBox *mKeepCheck;
- gcn::Button *mOkButton;
- gcn::Button *mCancelButton;
+ gcn::Button *mServerButton;
+ gcn::Button *mLoginButton;
gcn::Button *mRegisterButton;
LoginData *mLoginData;
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
index 6cca0f3d..bbc2d3f9 100644
--- a/src/gui/serverdialog.cpp
+++ b/src/gui/serverdialog.cpp
@@ -24,9 +24,10 @@
#include "gui/okdialog.h"
#include "gui/widgets/button.h"
-#include "gui/widgets/dropdown.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layout.h"
+#include "gui/widgets/listbox.h"
+#include "gui/widgets/scrollarea.h"
#include "gui/widgets/textfield.h"
#include "configuration.h"
@@ -96,10 +97,12 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo):
}
}
- mMostUsedServersDropDown = new DropDown(mMostUsedServersListModel);
+ mMostUsedServersDropDown = new ListBox(mMostUsedServersListModel);
+ ScrollArea *usedScroll = new ScrollArea(mMostUsedServersDropDown);
+ usedScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
- mOkButton = new Button(_("OK"), "connect", this);
- mCancelButton = new Button(_("Cancel"), "cancel", this);
+ mQuitButton = new Button(_("Quit"), "quit", this);
+ mConnectButton = new Button(_("Connect"), "connect", this);
mServerNameField->setActionEventId("connect");
mPortField->setActionEventId("connect");
@@ -115,13 +118,16 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo):
place(0, 1, portLabel);
place(1, 0, mServerNameField, 3).setPadding(2);
place(1, 1, mPortField, 3).setPadding(2);
- place(0, 2, mMostUsedServersDropDown, 4).setPadding(2);
- // TODO: Find a better way to give the dropdown window more room
- place(2, 12, mOkButton);
- place(3, 12, mCancelButton);
+ place(0, 2, usedScroll, 4, 5).setPadding(2);
+ place(2, 7, mQuitButton);
+ place(3, 7, mConnectButton);
+
+ // Make sure the list has enough height
+ getLayout().setRowHeight(2, 60);
+
reflowLayout(250, 0);
- setLocationRelativeTo(getParent());
+ center();
setVisible(true);
if (mServerNameField->getText().empty()) {
@@ -130,7 +136,7 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo):
if (mPortField->getText().empty()) {
mPortField->requestFocus();
} else {
- mOkButton->requestFocus();
+ mConnectButton->requestFocus();
}
}
}
@@ -167,8 +173,8 @@ ServerDialog::action(const gcn::ActionEvent &event)
}
else
{
- mOkButton->setEnabled(false);
- mCancelButton->setEnabled(false);
+ mQuitButton->setEnabled(false);
+ mConnectButton->setEnabled(false);
// First, look if the entry is a new one.
ServerInfo currentServer;
@@ -202,7 +208,7 @@ ServerDialog::action(const gcn::ActionEvent &event)
state = STATE_CONNECT_SERVER;
}
}
- else if (event.getId() == "cancel")
+ else if (event.getId() == "quit")
{
state = STATE_FORCE_QUIT;
}
diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h
index f1cd26d4..6922f7a9 100644
--- a/src/gui/serverdialog.h
+++ b/src/gui/serverdialog.h
@@ -34,7 +34,7 @@
#include <string>
#include <vector>
-class DropDown;
+class ListBox;
/**
* Server and Port List Model
@@ -100,10 +100,10 @@ class ServerDialog : public Window, public gcn::ActionListener
private:
gcn::TextField *mServerNameField;
gcn::TextField *mPortField;
- gcn::Button *mOkButton;
- gcn::Button *mCancelButton;
+ gcn::Button *mQuitButton;
+ gcn::Button *mConnectButton;
- DropDown *mMostUsedServersDropDown;
+ ListBox *mMostUsedServersDropDown;
ServersListModel *mMostUsedServersListModel;
ServerInfo *mServerInfo;
diff --git a/src/gui/worldselectdialog.cpp b/src/gui/worldselectdialog.cpp
index cdc6bb75..aef98078 100644
--- a/src/gui/worldselectdialog.cpp
+++ b/src/gui/worldselectdialog.cpp
@@ -22,6 +22,7 @@
#include "gui/worldselectdialog.h"
#include "gui/widgets/button.h"
+#include "gui/widgets/layout.h"
#include "gui/widgets/listbox.h"
#include "gui/widgets/scrollarea.h"
@@ -40,15 +41,15 @@ extern WorldInfo **server_info;
/**
* The list model for the server list.
*/
-class ServerListModel : public gcn::ListModel
+class WorldListModel : public gcn::ListModel
{
public:
- ServerListModel(Worlds worlds):
+ WorldListModel(Worlds worlds):
mWorlds(worlds)
{
}
- virtual ~ServerListModel() {}
+ virtual ~WorldListModel() {}
int getNumberOfElements()
{
@@ -67,59 +68,54 @@ class ServerListModel : public gcn::ListModel
WorldSelectDialog::WorldSelectDialog(Worlds worlds):
Window(_("Select World"))
{
- mServerListModel = new ServerListModel(worlds);
- mServerList = new ListBox(mServerListModel);
- ScrollArea *mScrollArea = new ScrollArea(mServerList);
- mOkButton = new Button(_("OK"), "ok", this);
- Button *mCancelButton = new Button(_("Cancel"), "cancel", this);
-
- setContentSize(200, 100);
-
- mCancelButton->setPosition(
- 200 - mCancelButton->getWidth() - 5,
- 100 - mCancelButton->getHeight() - 5);
- mOkButton->setPosition(
- mCancelButton->getX() - mOkButton->getWidth() - 5,
- 100 - mOkButton->getHeight() - 5);
- mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
- mScrollArea->setDimension(gcn::Rectangle(
- 5, 5, 200 - 2 * 5,
- 100 - 3 * 5 - mCancelButton->getHeight() -
- mScrollArea->getFrameSize()));
-
- mServerList->setActionEventId("ok");
-
- //mServerList->addActionListener(this);
-
- add(mScrollArea);
- add(mOkButton);
- add(mCancelButton);
+ mWorldListModel = new WorldListModel(worlds);
+ mWorldList = new ListBox(mWorldListModel);
+ ScrollArea *worldsScroll = new ScrollArea(mWorldList);
+ mChangeLoginButton = new Button(_("Change Login"), "login", this);
+ mChooseWorld = new Button(_("Choose World"), "world", this);
+
+ worldsScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
+
+ place(0, 0, worldsScroll, 3, 5).setPadding(2);
+ place(1, 5, mChangeLoginButton);
+ place(2, 5, mChooseWorld);
+
+ // Make sure the list has enough height
+ getLayout().setRowHeight(0, 60);
+
+ reflowLayout(0, 0);
if (worlds.size() == 0)
// Disable Ok button
- mOkButton->setEnabled(false);
+ mChooseWorld->setEnabled(false);
else
// Select first server
- mServerList->setSelected(0);
+ mWorldList->setSelected(0);
center();
setVisible(true);
- mOkButton->requestFocus();
+ mChooseWorld->requestFocus();
}
WorldSelectDialog::~WorldSelectDialog()
{
- delete mServerListModel;
+ delete mWorldListModel;
}
void WorldSelectDialog::action(const gcn::ActionEvent &event)
{
- if (event.getId() == "ok")
+ if (event.getId() == "world")
{
- mOkButton->setEnabled(false);
- Net::getLoginHandler()->chooseServer(mServerList->getSelected());
- state = STATE_UPDATE;
+ mChangeLoginButton->setEnabled(false);
+ mChooseWorld->setEnabled(false);
+ Net::getLoginHandler()->chooseServer(mWorldList->getSelected());
+
+ // Check in case netcode moves us forward
+ if (state == STATE_WORLD_SELECT)
+ state = STATE_WORLD_SELECT_ATTEMPT;
}
- else if (event.getId() == "cancel")
+ else if (event.getId() == "login")
+ {
state = STATE_LOGIN;
+ }
}
diff --git a/src/gui/worldselectdialog.h b/src/gui/worldselectdialog.h
index be18705c..0b93e62e 100644
--- a/src/gui/worldselectdialog.h
+++ b/src/gui/worldselectdialog.h
@@ -31,7 +31,7 @@
#include <vector>
class LoginData;
-class ServerListModel;
+class WorldListModel;
/**
* The server select dialog.
@@ -58,9 +58,10 @@ class WorldSelectDialog : public Window, public gcn::ActionListener {
void action(const gcn::ActionEvent &event);
private:
- ServerListModel *mServerListModel;
- gcn::ListBox *mServerList;
- gcn::Button *mOkButton;
+ WorldListModel *mWorldListModel;
+ gcn::ListBox *mWorldList;
+ gcn::Button *mChangeLoginButton;
+ gcn::Button *mChooseWorld;
};
#endif // WORLD_SELECT_DIALOG_H
diff --git a/src/main.cpp b/src/main.cpp
index e587e28e..b1d00ce4 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1043,6 +1043,7 @@ int main(int argc, char *argv[])
if (worlds.size() == 0)
{
+ // Trust that the netcode knows what it's doing
state = STATE_UPDATE;
}
else if (worlds.size() == 1)
@@ -1058,14 +1059,13 @@ int main(int argc, char *argv[])
((WorldSelectDialog*) currentDialog)->action(
gcn::ActionEvent(NULL, "ok"));
}
-
- state = STATE_WORLD_SELECT_ATTEMPT;
}
}
break;
case STATE_WORLD_SELECT_ATTEMPT:
- // TODO
+ logger->log("State: Attempting world selection");
+ currentDialog = new ConnectionDialog(STATE_WORLD_SELECT);
break;
case STATE_LOGIN_ERROR:
diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp
index de52bfa3..be547afa 100644
--- a/src/net/ea/loginhandler.cpp
+++ b/src/net/ea/loginhandler.cpp
@@ -116,6 +116,7 @@ void LoginHandler::handleMessage(MessageIn &msg)
msg.skip(30); // unknown
netToken.sex = msg.readInt8() ? GENDER_MALE : GENDER_FEMALE;
+ worlds.clear();
for (int i = 0; i < worldCount; i++)
{
WorldInfo *world = new WorldInfo;
@@ -241,6 +242,8 @@ void LoginHandler::chooseServer(unsigned int server)
charServer.clear();
charServer.hostname = ipToString(worlds[server]->address);
charServer.port = worlds[server]->port;
+
+ state = STATE_UPDATE;
}
void LoginHandler::registerAccount(LoginData *loginData)