diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-12-06 09:35:29 -0700 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-12-06 09:35:29 -0700 |
commit | c0e6ef1dd4941d689ea723542c4218179d688c7f (patch) | |
tree | dd576b75017badcf9c6740efbc1821ed811d48ef /src/gui/quitdialog.cpp | |
parent | 7ff6ea8d742b41603a8f08c2fc16c683330cb5ec (diff) | |
download | mana-client-c0e6ef1dd4941d689ea723542c4218179d688c7f.tar.gz mana-client-c0e6ef1dd4941d689ea723542c4218179d688c7f.tar.bz2 mana-client-c0e6ef1dd4941d689ea723542c4218179d688c7f.tar.xz mana-client-c0e6ef1dd4941d689ea723542c4218179d688c7f.zip |
Improve keyboard control of the QuitDialog
Fixes http://mantis.themanaworld.org/view.php?id=562 .
Diffstat (limited to 'src/gui/quitdialog.cpp')
-rw-r--r-- | src/gui/quitdialog.cpp | 81 |
1 files changed, 71 insertions, 10 deletions
diff --git a/src/gui/quitdialog.cpp b/src/gui/quitdialog.cpp index c7448f7c..d34af7ca 100644 --- a/src/gui/quitdialog.cpp +++ b/src/gui/quitdialog.cpp @@ -27,6 +27,8 @@ #include "gui/widgets/button.h" #include "gui/widgets/radiobutton.h" +#include "gui/sdlinput.h" + #include "net/charhandler.h" #include "net/net.h" @@ -37,8 +39,6 @@ QuitDialog::QuitDialog(QuitDialog** pointerToMe): Window(_("Quit"), true, NULL), mMyPointer(pointerToMe) { - ContainerPlacer place = getPlacer(0, 0); - mForceQuit = new RadioButton(_("Quit"), "quitdialog"); mLogoutQuit = new RadioButton(_("Quit"), "quitdialog"); mSwitchAccountServer = new RadioButton(_("Switch server"), "quitdialog"); @@ -46,6 +46,10 @@ QuitDialog::QuitDialog(QuitDialog** pointerToMe): mOkButton = new Button(_("OK"), "ok", this); mCancelButton = new Button(_("Cancel"), "cancel", this); + addKeyListener(this); + + ContainerPlacer place = getPlacer(0, 0); + //All states, when we're not logged in to someone. if (state == STATE_CHOOSE_SERVER || state == STATE_CONNECT_SERVER || @@ -54,26 +58,29 @@ QuitDialog::QuitDialog(QuitDialog** pointerToMe): state == STATE_UPDATE || state == STATE_LOAD_DATA) { - place(0, 0, mForceQuit, 3); - mForceQuit->setSelected(true); + placeOption(place, mForceQuit); } else { // Only added if we are connected to an accountserver or gameserver - place(0, 0, mLogoutQuit, 3); - place(0, 1, mSwitchAccountServer, 3); - mLogoutQuit->setSelected(true); + placeOption(place, mLogoutQuit); + placeOption(place, mSwitchAccountServer); // Only added if we are connected to a gameserver - if (state == STATE_GAME) place(0, 2, mSwitchCharacter, 3); + if (state == STATE_GAME) placeOption(place, mSwitchCharacter); } - place(1, 3, mOkButton); - place(2, 3, mCancelButton); + mOptions[0]->setSelected(true); + + place = getPlacer(0, 1); + + place(1, 0, mOkButton); + place(2, 0, mCancelButton); reflowLayout(150, 0); setLocationRelativeTo(getParent()); setVisible(true); + requestModalFocus(); mOkButton->requestFocus(); } @@ -87,6 +94,12 @@ QuitDialog::~QuitDialog() delete mSwitchCharacter; } +void QuitDialog::placeOption(ContainerPlacer &place, gcn::RadioButton *option) +{ + place(0, mOptions.size(), option, 3); + mOptions.push_back(option); +} + void QuitDialog::action(const gcn::ActionEvent &event) { if (event.getId() == "ok") @@ -112,3 +125,51 @@ void QuitDialog::action(const gcn::ActionEvent &event) } scheduleDelete(); } + +void QuitDialog::keyPressed(gcn::KeyEvent &keyEvent) +{ + const gcn::Key &key = keyEvent.getKey(); + int dir = 0; + + switch (key.getValue()) + { + case Key::ENTER: + action(gcn::ActionEvent(NULL, mOkButton->getActionEventId())); + break; + case Key::ESCAPE: + action(gcn::ActionEvent(NULL, mCancelButton->getActionEventId())); + break; + case Key::UP: + dir = -1; + break; + case Key::DOWN: + dir = 1; + break; + } + + if (dir != 0) + { + std::vector<gcn::RadioButton*>::iterator it = mOptions.begin(); + + for (; it < mOptions.end(); it++) + { + if ((*it)->isSelected()) + break; + } + + if (it == mOptions.end()) + { + mOptions[0]->setSelected(true); + return; + } + else if (it == mOptions.begin() && dir < 0) + it = mOptions.end(); + + it += dir; + + if (it == mOptions.end()) + it = mOptions.begin(); + + (*it)->setSelected(true); + } +} |