From 933791ef82d6a4566b15c25cf1db2762f4716a87 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 3 Apr 2012 23:09:23 +0300 Subject: Move some input handling code from game to inputmanager. --- src/inputmanager.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'src/inputmanager.cpp') 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 #include #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); } -- cgit v1.2.3-70-g09d2