From 076bcc1f8361c705d7dbe9088b18cca7d7fe21de Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sat, 3 Oct 2009 23:28:45 +0200 Subject: Made passing character name on the command line work again It was only selecting it when found, instead of also logging in with the character. --- src/gui/charselectdialog.cpp | 43 ++++++++++++++++++++++++++----------------- src/gui/charselectdialog.h | 3 +++ 2 files changed, 29 insertions(+), 17 deletions(-) (limited to 'src/gui') diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index ec9c4818..6407e05e 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -91,11 +91,11 @@ class CharEntry : public Container public: CharEntry(CharSelectDialog *m, char slot, LocalPlayer *chr); - char getSlot() + char getSlot() const { return mSlot; } - LocalPlayer *getChar() - { return mChr; } + LocalPlayer *getChar() const + { return mCharacter; } void requestFocus(); @@ -104,7 +104,7 @@ class CharEntry : public Container protected: friend class CharSelectDialog; char mSlot; - LocalPlayer *mChr; + LocalPlayer *mCharacter; PlayerBox *mPlayerBox; Label *mName; @@ -173,16 +173,15 @@ CharSelectDialog::CharSelectDialog(LockedArray *charInfo, void CharSelectDialog::action(const gcn::ActionEvent &event) { - CharEntry *entry = dynamic_cast(event.getSource()->getParent()); + const gcn::Widget *sourceParent = event.getSource()->getParent(); - // Update the locked array - if (entry) + // Update which character is selected when applicable + if (const CharEntry *entry = dynamic_cast(sourceParent)) mCharInfo->select(entry->getSlot()); if (event.getId() == "use") { - setVisible(false); - attemptCharSelect(); + chooseSelected(); } else if (event.getId() == "switch") { @@ -245,9 +244,10 @@ bool CharSelectDialog::selectByName(const std::string &name) LocalPlayer *player = mCharInfo->getEntry(); if (player && player->getName() == name) - { + { mCharEntries[mCharInfo->getPos()]->requestFocus(); - } + return true; + } mCharInfo->next(); } while (mCharInfo->getPos()); @@ -257,8 +257,17 @@ bool CharSelectDialog::selectByName(const std::string &name) return false; } +void CharSelectDialog::chooseSelected() +{ + if (!mCharInfo->getSize()) + return; + + setVisible(false); + attemptCharSelect(); +} + void CharSelectDialog::setNetworkOptions(bool allowUnregister, - bool allowChangeEmail) + bool allowChangeEmail) { doAllowUnregister = allowUnregister; doAllowChangeEmail = allowChangeEmail; @@ -266,7 +275,7 @@ void CharSelectDialog::setNetworkOptions(bool allowUnregister, CharEntry::CharEntry(CharSelectDialog *m, char slot, LocalPlayer *chr): mSlot(slot), - mChr(chr), + mCharacter(chr), mPlayerBox(new PlayerBox(chr)) { mButton = new Button("wwwwwwwww", "go", m); @@ -294,13 +303,13 @@ void CharEntry::requestFocus() void CharEntry::update() { - if (mChr) + if (mCharacter) { mButton->setCaption(_("Choose")); mButton->setActionEventId("use"); - mName->setCaption(strprintf("%s (%d)", mChr->getName().c_str(), - mChr->getLevel())); - mMoney->setCaption(Units::formatCurrency(mChr->getMoney())); + mName->setCaption(strprintf("%s (%d)", mCharacter->getName().c_str(), + mCharacter->getLevel())); + mMoney->setCaption(Units::formatCurrency(mCharacter->getMoney())); } else { diff --git a/src/gui/charselectdialog.h b/src/gui/charselectdialog.h index 965b4abf..e1c8071e 100644 --- a/src/gui/charselectdialog.h +++ b/src/gui/charselectdialog.h @@ -45,6 +45,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener { public: friend class CharDeleteConfirm; + /** * Constructor. */ @@ -55,6 +56,8 @@ class CharSelectDialog : public Window, public gcn::ActionListener bool selectByName(const std::string &name); + void chooseSelected(); + static void setNetworkOptions(bool allowUnregister, bool allowChangeEmail); -- cgit v1.2.3-70-g09d2