summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/charselectdialog.cpp13
-rw-r--r--src/gui/charselectdialog.h6
-rw-r--r--src/gui/login.cpp18
-rw-r--r--src/gui/serverdialog.cpp18
-rw-r--r--src/gui/serverdialog.h4
-rw-r--r--src/gui/updatewindow.cpp27
-rw-r--r--src/gui/updatewindow.h6
-rw-r--r--src/gui/worldselectdialog.cpp18
-rw-r--r--src/gui/worldselectdialog.h6
-rw-r--r--src/main.cpp14
10 files changed, 118 insertions, 12 deletions
diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp
index 43537ca3..4f3619ae 100644
--- a/src/gui/charselectdialog.cpp
+++ b/src/gui/charselectdialog.cpp
@@ -34,6 +34,7 @@
#include "gui/confirmdialog.h"
#include "gui/okdialog.h"
#include "gui/playerbox.h"
+#include "gui/sdlinput.h"
#include "gui/unregisterdialog.h"
#include "game.h"
@@ -162,6 +163,8 @@ CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo,
reflowLayout();
+ addKeyListener(this);
+
center();
mCharEntries[0]->requestFocus();
setVisible(true);
@@ -217,6 +220,16 @@ void CharSelectDialog::action(const gcn::ActionEvent &event)
}
}
+void CharSelectDialog::keyPressed(gcn::KeyEvent &keyEvent)
+{
+ gcn::Key key = keyEvent.getKey();
+
+ if (key.getValue() == Key::ESCAPE)
+ {
+ action(gcn::ActionEvent(NULL, mSwitchLoginButton->getActionEventId()));
+ }
+}
+
void CharSelectDialog::attemptCharDelete()
{
mCharHandler->deleteCharacter(mCharInfo->getPos(), mCharInfo->getEntry());
diff --git a/src/gui/charselectdialog.h b/src/gui/charselectdialog.h
index 44917d6c..507b0d9f 100644
--- a/src/gui/charselectdialog.h
+++ b/src/gui/charselectdialog.h
@@ -30,6 +30,7 @@
#include "player.h"
#include <guichan/actionlistener.hpp>
+#include <guichan/keylistener.hpp>
class CharEntry;
class LocalPlayer;
@@ -45,7 +46,8 @@ class CharHandler;
*
* \ingroup Interface
*/
-class CharSelectDialog : public Window, public gcn::ActionListener
+class CharSelectDialog : public Window, public gcn::ActionListener,
+ public gcn::KeyListener
{
public:
friend class CharDeleteConfirm;
@@ -58,6 +60,8 @@ class CharSelectDialog : public Window, public gcn::ActionListener
void action(const gcn::ActionEvent &event);
+ void keyPressed(gcn::KeyEvent &keyEvent);
+
bool selectByName(const std::string &name);
void chooseSelected();
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index aa14b00e..396c5d1a 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -22,6 +22,7 @@
#include "gui/login.h"
#include "gui/okdialog.h"
+#include "gui/sdlinput.h"
#include "gui/widgets/button.h"
#include "gui/widgets/checkbox.h"
@@ -77,6 +78,8 @@ LoginDialog::LoginDialog(LoginData *loginData):
place(3, 6, mLoginButton);
reflowLayout(250, 0);
+ addKeyListener(this);
+
center();
setVisible(true);
@@ -121,7 +124,20 @@ void LoginDialog::action(const gcn::ActionEvent &event)
void LoginDialog::keyPressed(gcn::KeyEvent &keyEvent)
{
- mLoginButton->setEnabled(canSubmit());
+ gcn::Key key = keyEvent.getKey();
+
+ if (key.getValue() == Key::ESCAPE)
+ {
+ action(gcn::ActionEvent(NULL, mServerButton->getActionEventId()));
+ }
+ else if (key.getValue() == Key::ENTER)
+ {
+ action(gcn::ActionEvent(NULL, mLoginButton->getActionEventId()));
+ }
+ else
+ {
+ mLoginButton->setEnabled(canSubmit());
+ }
}
bool LoginDialog::canSubmit()
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
index 39c2792f..32e714c6 100644
--- a/src/gui/serverdialog.cpp
+++ b/src/gui/serverdialog.cpp
@@ -22,6 +22,7 @@
#include "gui/serverdialog.h"
#include "gui/okdialog.h"
+#include "gui/sdlinput.h"
#include "gui/widgets/button.h"
#include "gui/widgets/label.h"
@@ -149,9 +150,10 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir):
// Make sure the list has enough height
getLayout().setRowHeight(3, 80);
-
reflowLayout(300, 0);
+ addKeyListener(this);
+
center();
setFieldsReadOnly(true);
setVisible(true);
@@ -248,6 +250,20 @@ void ServerDialog::action(const gcn::ActionEvent &event)
}
}
+void ServerDialog::keyPressed(gcn::KeyEvent &keyEvent)
+{
+ gcn::Key key = keyEvent.getKey();
+
+ if (key.getValue() == Key::ESCAPE)
+ {
+ state = STATE_EXIT;
+ }
+ else if (key.getValue() == Key::ENTER)
+ {
+ action(gcn::ActionEvent(NULL, mConnectButton->getActionEventId()));
+ }
+}
+
void ServerDialog::valueChanged(const gcn::SelectionEvent &event)
{
const int index = mServersList->getSelected();
diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h
index 943d69c9..d82e2613 100644
--- a/src/gui/serverdialog.h
+++ b/src/gui/serverdialog.h
@@ -30,6 +30,7 @@
#include "utils/mutex.h"
#include <guichan/actionlistener.hpp>
+#include <guichan/keylistener.hpp>
#include <guichan/listmodel.hpp>
#include <guichan/selectionlistener.hpp>
@@ -78,6 +79,7 @@ class ServersListModel : public gcn::ListModel
*/
class ServerDialog : public Window,
public gcn::ActionListener,
+ public gcn::KeyListener,
public gcn::SelectionListener
{
public:
@@ -98,6 +100,8 @@ class ServerDialog : public Window,
*/
void action(const gcn::ActionEvent &event);
+ void keyPressed(gcn::KeyEvent &keyEvent);
+
/**
* Called when the selected value changed in the servers list box.
*/
diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp
index 801bd161..afb87430 100644
--- a/src/gui/updatewindow.cpp
+++ b/src/gui/updatewindow.cpp
@@ -28,6 +28,8 @@
#include "gui/widgets/progressbar.h"
#include "gui/widgets/scrollarea.h"
+#include "gui/sdlinput.h"
+
#include "configuration.h"
#include "log.h"
#include "main.h"
@@ -105,6 +107,8 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost,
Layout &layout = getLayout();
layout.setRowHeight(0, Layout::AUTO_SET);
+ addKeyListener(this);
+
center();
setVisible(true);
mCancelButton->requestFocus();
@@ -162,6 +166,29 @@ void UpdaterWindow::action(const gcn::ActionEvent &event)
}
}
+void UpdaterWindow::keyPressed(gcn::KeyEvent &keyEvent)
+{
+ gcn::Key key = keyEvent.getKey();
+
+ if (key.getValue() == Key::ESCAPE)
+ {
+ action(gcn::ActionEvent(NULL, mCancelButton->getActionEventId()));
+ state = STATE_WORLD_SELECT;
+ }
+ else if (key.getValue() == Key::ENTER)
+ {
+ if (mDownloadStatus == UPDATE_COMPLETE ||
+ mDownloadStatus == UPDATE_ERROR)
+ {
+ action(gcn::ActionEvent(NULL, mPlayButton->getActionEventId()));
+ }
+ else
+ {
+ action(gcn::ActionEvent(NULL, mCancelButton->getActionEventId()));
+ }
+ }
+}
+
void UpdaterWindow::loadNews()
{
if (!mMemoryBuffer)
diff --git a/src/gui/updatewindow.h b/src/gui/updatewindow.h
index 6e738fca..8388b722 100644
--- a/src/gui/updatewindow.h
+++ b/src/gui/updatewindow.h
@@ -29,6 +29,7 @@
#include "utils/mutex.h"
#include <guichan/actionlistener.hpp>
+#include <guichan/keylistener.hpp>
#include <string>
#include <vector>
@@ -43,7 +44,8 @@ class ScrollArea;
*
* \ingroup GUI
*/
-class UpdaterWindow : public Window, public gcn::ActionListener
+class UpdaterWindow : public Window, public gcn::ActionListener,
+ public gcn::KeyListener
{
public:
/**
@@ -84,6 +86,8 @@ class UpdaterWindow : public Window, public gcn::ActionListener
void action(const gcn::ActionEvent &event);
+ void keyPressed(gcn::KeyEvent &keyEvent);
+
void logic();
int updateState;
diff --git a/src/gui/worldselectdialog.cpp b/src/gui/worldselectdialog.cpp
index aef98078..0a616f25 100644
--- a/src/gui/worldselectdialog.cpp
+++ b/src/gui/worldselectdialog.cpp
@@ -26,6 +26,8 @@
#include "gui/widgets/listbox.h"
#include "gui/widgets/scrollarea.h"
+#include "gui/sdlinput.h"
+
#include "net/logindata.h"
#include "net/loginhandler.h"
#include "net/net.h"
@@ -92,6 +94,8 @@ WorldSelectDialog::WorldSelectDialog(Worlds worlds):
// Select first server
mWorldList->setSelected(0);
+ addKeyListener(this);
+
center();
setVisible(true);
mChooseWorld->requestFocus();
@@ -119,3 +123,17 @@ void WorldSelectDialog::action(const gcn::ActionEvent &event)
state = STATE_LOGIN;
}
}
+
+void WorldSelectDialog::keyPressed(gcn::KeyEvent &keyEvent)
+{
+ gcn::Key key = keyEvent.getKey();
+
+ if (key.getValue() == Key::ESCAPE)
+ {
+ action(gcn::ActionEvent(NULL, mChangeLoginButton->getActionEventId()));
+ }
+ else if (key.getValue() == Key::ENTER)
+ {
+ action(gcn::ActionEvent(NULL, mChooseWorld->getActionEventId()));
+ }
+}
diff --git a/src/gui/worldselectdialog.h b/src/gui/worldselectdialog.h
index 0b93e62e..acd00898 100644
--- a/src/gui/worldselectdialog.h
+++ b/src/gui/worldselectdialog.h
@@ -27,6 +27,7 @@
#include "net/worldinfo.h"
#include <guichan/actionlistener.hpp>
+#include <guichan/keylistener.hpp>
#include <guichan/listmodel.hpp>
#include <vector>
@@ -38,7 +39,8 @@ class WorldListModel;
*
* \ingroup Interface
*/
-class WorldSelectDialog : public Window, public gcn::ActionListener {
+class WorldSelectDialog : public Window, public gcn::ActionListener,
+ public gcn::KeyListener {
public:
/**
* Constructor
@@ -57,6 +59,8 @@ class WorldSelectDialog : public Window, public gcn::ActionListener {
*/
void action(const gcn::ActionEvent &event);
+ void keyPressed(gcn::KeyEvent &keyEvent);
+
private:
WorldListModel *mWorldListModel;
gcn::ListBox *mWorldList;
diff --git a/src/main.cpp b/src/main.cpp
index 5308304f..73752c9e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -835,13 +835,6 @@ int main(int argc, char *argv[])
break;
case SDL_KEYDOWN:
- if (event.key.keysym.sym == SDLK_ESCAPE)
- {
- if (!quitDialog)
- quitDialog = new QuitDialog(&quitDialog);
- else
- quitDialog->requestMoveToTop();
- }
break;
}
@@ -881,6 +874,13 @@ int main(int argc, char *argv[])
Net::getCharHandler()->setCharInfo(&charInfo);
state = STATE_LOGIN;
}
+ else if (state == STATE_WORLD_SELECT && oldstate == STATE_UPDATE)
+ {
+ if (Net::getLoginHandler()->getWorlds().size() < 2)
+ {
+ state = STATE_LOGIN;
+ }
+ }
else if (oldstate == STATE_START || oldstate == STATE_GAME)
{
desktop = new Desktop;