summaryrefslogtreecommitdiff
path: root/src/inputmanager.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-03-24 04:26:57 +0300
committerAndrei Karas <akaras@inbox.ru>2012-03-26 21:45:24 +0300
commit36e5d21fe06709ba4d12a8619af07b86a676cf8c (patch)
treea9209e16e6f31cd74047f86ef1e642f467e128e2 /src/inputmanager.cpp
parent0921a130f0241a17ffcedf92d602808e18f1614b (diff)
downloadmv-36e5d21fe06709ba4d12a8619af07b86a676cf8c.tar.gz
mv-36e5d21fe06709ba4d12a8619af07b86a676cf8c.tar.bz2
mv-36e5d21fe06709ba4d12a8619af07b86a676cf8c.tar.xz
mv-36e5d21fe06709ba4d12a8619af07b86a676cf8c.zip
Redesign input handling.
Diffstat (limited to 'src/inputmanager.cpp')
-rw-r--r--src/inputmanager.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp
new file mode 100644
index 000000000..46a2265c6
--- /dev/null
+++ b/src/inputmanager.cpp
@@ -0,0 +1,95 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "inputmanager.h"
+
+#include "game.h"
+#include "keyboardconfig.h"
+#include "localplayer.h"
+
+#include "gui/chatwindow.h"
+#include "gui/gui.h"
+#include "gui/inventorywindow.h"
+#include "gui/npcdialog.h"
+#include "gui/setup.h"
+
+#include <guichan/focushandler.hpp>
+
+#include "debug.h"
+
+InputManager inputManager;
+
+InputManager::InputManager()
+{
+}
+
+bool InputManager::handleKeyEvent(SDL_Event &event)
+{
+ return keyboard.triggerAction(event);
+}
+
+int InputManager::getInputConditionMask()
+{
+ int mask = 1;
+ if (keyboard.isEnabled())
+ mask += COND_ENABLED;
+ if ((!chatWindow || !chatWindow->isInputFocused()) &&
+ !NpcDialog::isAnyInputFocused() &&
+ !InventoryWindow::isAnyInputFocused())
+ {
+ mask += COND_NOINPUT;
+ }
+
+ if (!player_node || !player_node->getAway())
+ mask += COND_NOAWAY;
+
+ if (!setupWindow || !setupWindow->isVisible())
+ mask += COND_NOSETUP;
+
+ if (Game::instance()->getValidSpeed())
+ mask += COND_VALIDSPEED;
+
+ if (!gui->getFocusHandler()->getModalFocused())
+ mask += COND_NOMODAL;
+
+ NpcDialog *dialog = NpcDialog::getActive();
+ if (!dialog || !dialog->isTextInputFocused())
+ mask += COND_NONPCINPUT;
+
+ if (!player_node || !player_node->getDisableGameModifiers())
+ mask += COND_EMODS;
+
+ if (!keyboard.isActionActive(keyboard.KEY_TARGET)
+ && !keyboard.isActionActive(keyboard.KEY_UNTARGET))
+ {
+ mask += COND_NOTARGET;
+ }
+ return mask;
+}
+
+bool InputManager::checkKey(KeyFunction *key, int mask)
+{
+// logger->log("mask=%d, condition=%d", mask, key->condition);
+ if (!key || (key->condition & mask) != key->condition)
+ return false;
+
+ return (key->modKeyIndex == KeyboardConfig::KEY_NO_VALUE
+ || keyboard.isActionActive(key->modKeyIndex));
+}