diff options
-rw-r--r-- | src/commandhandler.cpp | 9 | ||||
-rw-r--r-- | src/input/inputmanager.cpp | 23 | ||||
-rw-r--r-- | src/input/inputmanager.h | 4 |
3 files changed, 31 insertions, 5 deletions
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 0cf4f803c..daf65b6a8 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -95,10 +95,13 @@ void CommandHandler::invokeCommand(const std::string &type, } else if (!tab->handleCommand(type, args)) { - if (warn) + if (!inputManager.executeChatCommand(type, args, tab)) { - // TRANSLATORS: chat commands handling message - tab->chatLog(_("Unknown command.")); + if (warn) + { + // TRANSLATORS: chat commands handling message + tab->chatLog(_("Unknown command.")); + } } } } diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp index 2cbd100e2..c74544432 100644 --- a/src/input/inputmanager.cpp +++ b/src/input/inputmanager.cpp @@ -157,8 +157,9 @@ void InputManager::retrieve() } } } - if (!inputActionData[i].chatCommand.empty()) - mChatMap[i] = i; + const std::string &cmd = inputActionData[i].chatCommand; + if (!cmd.empty()) + mChatMap[cmd] = i; } } @@ -728,6 +729,24 @@ void InputManager::executeAction(const int keyNum) func(evt); } +bool InputManager::executeChatCommand(const std::string &cmd, + const std::string &args, + ChatTab *const tab) +{ + const std::map<std::string, int>::const_iterator it = mChatMap.find(cmd); + if (it != mChatMap.end()) + { + ActionFuncPtr func = *(inputActionData[(*it).second].action); + if (func) + { + InputEvent evt(args, tab); + func(evt); + return true; + } + } + return false; +} + void InputManager::updateKeyActionMap(KeyToActionMap &actionMap, KeyToIdMap &idMap, KeyTimeMap &keyTimeMap, diff --git a/src/input/inputmanager.h b/src/input/inputmanager.h index 1635bf03c..ab8f3d2f0 100644 --- a/src/input/inputmanager.h +++ b/src/input/inputmanager.h @@ -118,6 +118,10 @@ class InputManager final void executeAction(const int keyNum); + bool executeChatCommand(const std::string &cmd, + const std::string &args, + ChatTab *const tab); + protected: void resetKey(const int i); |