diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-04-03 23:09:23 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-04-03 23:09:23 +0300 |
commit | 933791ef82d6a4566b15c25cf1db2762f4716a87 (patch) | |
tree | f603318581518a2a49d868c75282988d52e6058d | |
parent | e848a47b6ceb86cb2a40d094d608b791aff674e6 (diff) | |
download | mv-933791ef82d6a4566b15c25cf1db2762f4716a87.tar.gz mv-933791ef82d6a4566b15c25cf1db2762f4716a87.tar.bz2 mv-933791ef82d6a4566b15c25cf1db2762f4716a87.tar.xz mv-933791ef82d6a4566b15c25cf1db2762f4716a87.zip |
Move some input handling code from game to inputmanager.
-rw-r--r-- | src/game.cpp | 55 | ||||
-rw-r--r-- | src/inputmanager.cpp | 66 | ||||
-rw-r--r-- | src/inputmanager.h | 4 |
3 files changed, 70 insertions, 55 deletions
diff --git a/src/game.cpp b/src/game.cpp index 5c4785ef0..670188038 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -958,65 +958,14 @@ void Game::handleInput() updateHistory(event); checkKeys(); - if (event.type == SDL_KEYDOWN) - { - if (setupWindow && setupWindow->isVisible() && - keyboard.getNewKeyIndex() > keyboard.KEY_NO_VALUE) - { - keyboard.setNewKey(event); - keyboard.callbackNewKey(); - keyboard.setNewKeyIndex(keyboard.KEY_NO_VALUE); - return; - } - - // send straight to gui for certain windows - if (quitDialog || TextDialog::isActive() || - NpcPostDialog::isActive()) - { - try - { - if (guiInput) - guiInput->pushInput(event); - if (gui) - gui->handleInput(); - } - catch (const gcn::Exception &e) - { - const char* err = e.getMessage().c_str(); - logger->log("Warning: guichan input exception: %s", err); - } - return; - } - } - - try - { - if (guiInput) - guiInput->pushInput(event); - } - catch (const gcn::Exception &e) - { - const char *err = e.getMessage().c_str(); - logger->log("Warning: guichan input exception: %s", err); - } - if (gui) - { - bool res = gui->handleInput(); - if (res && event.type == SDL_KEYDOWN) - return; - } + if (inputManager.handleEvent(event)) + return; if (event.type == SDL_VIDEORESIZE) { // Let the client deal with this one (it'll pass down from there) Client::resize(event.resize.w, event.resize.h); } - // Keyboard events (for discontinuous keys) - else if (event.type == SDL_KEYDOWN) - { - if (inputManager.handleKeyEvent(event)) - return; - } // Active event else if (event.type == SDL_ACTIVEEVENT) { diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp index f57a48b30..5e30f3894 100644 --- a/src/inputmanager.cpp +++ b/src/inputmanager.cpp @@ -28,20 +28,84 @@ #include "gui/gui.h" #include "gui/inventorywindow.h" #include "gui/npcdialog.h" +#include "gui/npcpostdialog.h" #include "gui/setup.h" +#include "gui/textdialog.h" #include "gui/tradewindow.h" +#include <guichan/exception.hpp> #include <guichan/focushandler.hpp> #include "debug.h" InputManager inputManager; +extern QuitDialog *quitDialog; + InputManager::InputManager() { } -bool InputManager::handleKeyEvent(SDL_Event &event) +bool InputManager::handleEvent(const SDL_Event &event) +{ + if (event.type == SDL_KEYDOWN) + { + if (setupWindow && setupWindow->isVisible() && + keyboard.getNewKeyIndex() > keyboard.KEY_NO_VALUE) + { + keyboard.setNewKey(event); + keyboard.callbackNewKey(); + keyboard.setNewKeyIndex(keyboard.KEY_NO_VALUE); + return true; + } + + // send straight to gui for certain windows + if (quitDialog || TextDialog::isActive() || + NpcPostDialog::isActive()) + { + try + { + if (guiInput) + guiInput->pushInput(event); + if (gui) + gui->handleInput(); + } + catch (const gcn::Exception &e) + { + const char* err = e.getMessage().c_str(); + logger->log("Warning: guichan input exception: %s", err); + } + return true; + } + } + + try + { + if (guiInput) + guiInput->pushInput(event); + } + catch (const gcn::Exception &e) + { + const char *err = e.getMessage().c_str(); + logger->log("Warning: guichan input exception: %s", err); + } + if (gui) + { + bool res = gui->handleInput(); + if (res && event.type == SDL_KEYDOWN) + return true; + } + + if (event.type == SDL_KEYDOWN) + { + if (handleKeyEvent(event)) + return true; + } + + return false; +} + +bool InputManager::handleKeyEvent(const SDL_Event &event) { return keyboard.triggerAction(event); } diff --git a/src/inputmanager.h b/src/inputmanager.h index 3276e979b..7a6ac6d05 100644 --- a/src/inputmanager.h +++ b/src/inputmanager.h @@ -50,7 +50,9 @@ class InputManager public: InputManager(); - bool handleKeyEvent(SDL_Event &event); + bool handleEvent(const SDL_Event &event); + + bool handleKeyEvent(const SDL_Event &event); int getInputConditionMask(); |