From 555862b34ccbbdbcd44241a00ec168a6a2716411 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Thu, 16 Dec 2010 16:36:03 +0100 Subject: Made the client handle the number of slots given by the server. I turned the CharacterEntries into a vector. As for now, it's basically working but I discovered bugs about slots handling mainly for Manaserv that were already present before that patch. Hence, there are three remaining issues: - Under ManaServ, the character's slots numbers aren't handled when loading the characters but used when sending selection or deletion attempts. For instance, if you delete the character at slot 1, you won't be able to select or delete characters at slots 2 and 3, since the server believes that the characters are now in slots 1 and 2, even thought the client still displays them at the former slots. - Also under manaserv, you won't be able to create a character at slot 1 and 3, the server will automatically add the new one to the next slot, which is not corresponding to where you clicked to the 'Create' button. I propose to make Manaserv send again the character slots numbers and store them in database since we used them in creation, selection, and deletion attempts. It would make more sense IMHO. - The last remaining issue found is that when switching between different servers, the loginData don't get cleaned up, make the characterSelect dialog look crazy when the number of slots is different between two servers. If this one is accepted, my next patch will make the logindata be cleaned up between each login attempts (as for the slot number, and maybe other sensible data) and the next ones will readd character slot handling server and client side. Reviewed-by: Jaxad0127. --- src/gui/charselectdialog.cpp | 29 ++++++++++++++++++++--------- src/gui/charselectdialog.h | 4 ++-- 2 files changed, 22 insertions(+), 11 deletions(-) (limited to 'src/gui') 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 #include +// 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::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 mCharacterEntries; LoginData *mLoginData; -- cgit v1.2.3-70-g09d2