summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-12-06 09:35:29 -0700
committerJared Adams <jaxad0127@gmail.com>2009-12-06 09:35:29 -0700
commitc0e6ef1dd4941d689ea723542c4218179d688c7f (patch)
treedd576b75017badcf9c6740efbc1821ed811d48ef
parent7ff6ea8d742b41603a8f08c2fc16c683330cb5ec (diff)
downloadmana-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 .
-rw-r--r--src/game.cpp22
-rw-r--r--src/gui/quitdialog.cpp81
-rw-r--r--src/gui/quitdialog.h13
3 files changed, 87 insertions, 29 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 49c0b34c..83dff9d9 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -523,7 +523,7 @@ void Game::handleInput()
}
// send straight to gui for certain windows
- if (npcPostDialog->isVisible())
+ if (quitDialog || npcPostDialog->isVisible())
{
try
{
@@ -555,11 +555,8 @@ void Game::handleInput()
{
if (keyboard.isKeyActive(keyboard.KEY_OK))
{
- // Do not focus chat input when quit dialog is active
- if (quitDialog != NULL && quitDialog->isVisible())
- continue;
// Close the Browser if opened
- else if (helpWindow->isVisible() &&
+ if (helpWindow->isVisible() &&
keyboard.isKeyActive(keyboard.KEY_OK))
helpWindow->setVisible(false);
// Close the config window, cancelling changes if opened
@@ -715,16 +712,9 @@ void Game::handleInput()
break;
// Quitting confirmation dialog
case KeyboardConfig::KEY_QUIT:
- if (!quitDialog)
- {
- quitDialog = new QuitDialog(&quitDialog);
- quitDialog->requestMoveToTop();
- }
- else
- {
- quitDialog->action(gcn::ActionEvent(NULL, "cancel"));
- }
- break;
+ quitDialog = new QuitDialog(&quitDialog);
+ quitDialog->requestMoveToTop();
+ return;
default:
break;
}
@@ -916,7 +906,7 @@ void Game::handleInput()
// Moving player around
if (player_node->mAction != Being::DEAD && current_npc == 0 &&
- !chatWindow->isInputFocused())
+ !chatWindow->isInputFocused() && !quitDialog)
{
// Get the state of the keyboard keys
keyboard.refreshActiveKeys();
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);
+ }
+}
diff --git a/src/gui/quitdialog.h b/src/gui/quitdialog.h
index 04ce6d16..83c514e6 100644
--- a/src/gui/quitdialog.h
+++ b/src/gui/quitdialog.h
@@ -25,22 +25,24 @@
#include "gui/widgets/window.h"
#include "guichanfwd.h"
-#include "main.h"
#include <guichan/actionlistener.hpp>
+#include <guichan/keylistener.hpp>
+
+#include <vector>
/**
* The quit dialog.
*
* \ingroup Interface
*/
-class QuitDialog : public Window, public gcn::ActionListener
+class QuitDialog : public Window, public gcn::ActionListener,
+ public gcn::KeyListener
{
public:
/**
* Constructor
*
- * @quitGame; to be used for getting out of the while loop in Game
* @pointerToMe will be set to NULL when the QuitDialog is destroyed
*/
QuitDialog(QuitDialog **pointerToMe);
@@ -55,7 +57,12 @@ class QuitDialog : public Window, public gcn::ActionListener
*/
void action(const gcn::ActionEvent &event);
+ void keyPressed(gcn::KeyEvent &keyEvent);
+
private:
+ void placeOption(ContainerPlacer &place, gcn::RadioButton *option);
+ std::vector<gcn::RadioButton*> mOptions;
+
gcn::RadioButton *mLogoutQuit;
gcn::RadioButton *mForceQuit;
gcn::RadioButton *mSwitchAccountServer;