summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/charselectdialog.cpp29
-rw-r--r--src/gui/charselectdialog.h4
-rw-r--r--src/net/logindata.h12
-rw-r--r--src/net/manaserv/loginhandler.cpp13
-rw-r--r--src/net/manaserv/loginhandler.h2
5 files changed, 45 insertions, 15 deletions
diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp
index d8794afd..1fe7d3ba 100644
--- a/src/gui/charselectdialog.cpp
+++ b/src/gui/charselectdialog.cpp
@@ -59,6 +59,9 @@
#include <string>
#include <cassert>
+// Character slots per row in the dialog
+static const int SLOTS_PER_ROW = 5;
+
/**
* Listener for confirming character deletion.
*/
@@ -118,6 +121,7 @@ CharSelectDialog::CharSelectDialog(LoginData *loginData):
mLocked(false),
mUnregisterButton(0),
mChangeEmailButton(0),
+ mCharacterEntries(0),
mLoginData(loginData),
mCharHandler(Net::getCharHandler())
{
@@ -154,10 +158,10 @@ CharSelectDialog::CharSelectDialog(LoginData *loginData):
place = getPlacer(0, 1);
- for (int i = 0; i < MAX_CHARACTER_COUNT; i++)
+ for (int i = 0; i < (int)mLoginData->characterSlots; i++)
{
- mCharacterEntries[i] = new CharacterDisplay(this);
- place(i, 0, mCharacterEntries[i]);
+ mCharacterEntries.push_back(new CharacterDisplay(this));
+ place(i % SLOTS_PER_ROW, (int)i / SLOTS_PER_ROW, mCharacterEntries[i]);
}
reflowLayout();
@@ -180,9 +184,14 @@ void CharSelectDialog::action(const gcn::ActionEvent &event)
// Check if a button of a character was pressed
const gcn::Widget *sourceParent = event.getSource()->getParent();
int selected = -1;
- for (int i = 0; i < MAX_CHARACTER_COUNT; ++i)
+ for (int i = 0; i < (int)mCharacterEntries.size(); ++i)
+ {
if (mCharacterEntries[i] == sourceParent)
+ {
selected = i;
+ break;
+ }
+ }
const std::string &eventId = event.getId();
@@ -263,14 +272,16 @@ void CharSelectDialog::attemptCharacterSelect(int index)
void CharSelectDialog::setCharacters(const Net::Characters &characters)
{
// Reset previous characters
- for (int i = 0; i < MAX_CHARACTER_COUNT; ++i)
- mCharacterEntries[i]->setCharacter(0);
+ std::vector<CharacterDisplay*>::iterator iter, iter_end;
+ for (iter = mCharacterEntries.begin(), iter_end = mCharacterEntries.end();
+ iter != iter_end; ++iter)
+ (*iter)->setCharacter(0);
Net::Characters::const_iterator i, i_end = characters.end();
for (i = characters.begin(); i != i_end; ++i)
{
Net::Character *character = *i;
- if (character->slot >= MAX_CHARACTER_COUNT)
+ if (character->slot >= (int)mCharacterEntries.size())
{
logger->log("Warning: slot out of range: %d", character->slot);
continue;
@@ -302,7 +313,7 @@ void CharSelectDialog::setLocked(bool locked)
if (mChangeEmailButton)
mChangeEmailButton->setEnabled(!locked);
- for (int i = 0; i < MAX_CHARACTER_COUNT; ++i)
+ for (int i = 0; i < (int)mCharacterEntries.size(); ++i)
mCharacterEntries[i]->setActive(!mLocked);
}
@@ -312,7 +323,7 @@ bool CharSelectDialog::selectByName(const std::string &name,
if (mLocked)
return false;
- for (int i = 0; i < MAX_CHARACTER_COUNT; ++i)
+ for (int i = 0; i < (int)mCharacterEntries.size(); ++i)
{
if (Net::Character *character = mCharacterEntries[i]->getCharacter())
{
diff --git a/src/gui/charselectdialog.h b/src/gui/charselectdialog.h
index 2c0444bf..455ec2df 100644
--- a/src/gui/charselectdialog.h
+++ b/src/gui/charselectdialog.h
@@ -96,8 +96,8 @@ class CharSelectDialog : public Window, public gcn::ActionListener,
gcn::Button *mUnregisterButton;
gcn::Button *mChangeEmailButton;
- enum { MAX_CHARACTER_COUNT = 3 };
- CharacterDisplay *mCharacterEntries[MAX_CHARACTER_COUNT];
+ /** The player boxes */
+ std::vector<CharacterDisplay*> mCharacterEntries;
LoginData *mLoginData;
diff --git a/src/net/logindata.h b/src/net/logindata.h
index 22675d5a..7f729559 100644
--- a/src/net/logindata.h
+++ b/src/net/logindata.h
@@ -29,6 +29,15 @@
class LoginData
{
public:
+ /**
+ * Constructor
+ *
+ * Initialize character slots to 3 for TmwAthena compatibility
+ */
+ LoginData():
+ characterSlots(3)
+ {}
+
std::string username;
std::string password;
std::string newPassword;
@@ -42,6 +51,8 @@ public:
bool remember; /**< Whether to store the username. */
bool registerLogin; /**< Whether an account is being registered. */
+ unsigned short characterSlots; /**< The number of character slots */
+
void clear()
{
username.clear();
@@ -51,6 +62,7 @@ public:
email.clear();
captchaResponse.clear();
gender = GENDER_UNSPECIFIED;
+ characterSlots = 3; // Default value, used for TmwAthena.
}
};
diff --git a/src/net/manaserv/loginhandler.cpp b/src/net/manaserv/loginhandler.cpp
index 29418124..05a51efe 100644
--- a/src/net/manaserv/loginhandler.cpp
+++ b/src/net/manaserv/loginhandler.cpp
@@ -251,7 +251,7 @@ void LoginHandler::handleLoginResponse(Net::MessageIn &msg)
if (errMsg == ERRMSG_OK)
{
- readUpdateHost(msg);
+ readServerInfo(msg);
// No worlds atm, but future use :-D
Client::setState(STATE_WORLD_SELECT);
}
@@ -289,7 +289,7 @@ void LoginHandler::handleRegisterResponse(Net::MessageIn &msg)
if (errMsg == ERRMSG_OK)
{
- readUpdateHost(msg);
+ readServerInfo(msg);
Client::setState(STATE_WORLD_SELECT);
}
else
@@ -320,7 +320,7 @@ void LoginHandler::handleRegisterResponse(Net::MessageIn &msg)
}
}
-void LoginHandler::readUpdateHost(Net::MessageIn &msg)
+void LoginHandler::readServerInfo(Net::MessageIn &msg)
{
// Safety check for outdated manaserv versions (remove me later)
if (msg.getUnreadLength() == 0)
@@ -332,6 +332,13 @@ void LoginHandler::readUpdateHost(Net::MessageIn &msg)
mLoginData->updateHost = updateHost;
else
logger->log("Warning: server does not have an update host set!");
+
+ // Read the client data folder for dynamic data loading.
+ // This is only used by the QT client.
+ msg.readString();
+
+ // Read the number of character slots
+ mLoginData->characterSlots = msg.readInt8();
}
void LoginHandler::connect()
diff --git a/src/net/manaserv/loginhandler.h b/src/net/manaserv/loginhandler.h
index d2ffbc3d..2062dcb5 100644
--- a/src/net/manaserv/loginhandler.h
+++ b/src/net/manaserv/loginhandler.h
@@ -80,7 +80,7 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler
void handleLoginResponse(Net::MessageIn &msg);
void handleRegisterResponse(Net::MessageIn &msg);
- void readUpdateHost(Net::MessageIn &msg);
+ void readServerInfo(Net::MessageIn &msg);
LoginData *mLoginData;
unsigned int mMinUserNameLength;