summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-05-09 00:29:58 +0300
committerAndrei Karas <akaras@inbox.ru>2017-05-09 00:29:58 +0300
commiteef58035c1848a8cffbcb17373b6afbe43be1440 (patch)
treeec8ff687c1c15c6b3f8448e596f51de066a5717b
parent1f0070646425aeb23f01d769f5b1cf071d1d3d15 (diff)
downloadmv-eef58035c1848a8cffbcb17373b6afbe43be1440.tar.gz
mv-eef58035c1848a8cffbcb17373b6afbe43be1440.tar.bz2
mv-eef58035c1848a8cffbcb17373b6afbe43be1440.tar.xz
mv-eef58035c1848a8cffbcb17373b6afbe43be1440.zip
Add chat command for send any gui key.
New chat command: guikey.
-rw-r--r--src/actions/chat.cpp37
-rw-r--r--src/actions/chat.h1
-rw-r--r--src/dyetool/actions/chat.cpp1
-rw-r--r--src/enums/input/inputaction.h1
-rw-r--r--src/gui/sdlinput.cpp11
-rw-r--r--src/gui/sdlinput.h3
-rw-r--r--src/input/inputactionmap.h6
-rw-r--r--src/input/inputmanager.cpp12
-rw-r--r--src/input/inputmanager.h3
9 files changed, 75 insertions, 0 deletions
diff --git a/src/actions/chat.cpp b/src/actions/chat.cpp
index 6e6f3cae1..266f610b8 100644
--- a/src/actions/chat.cpp
+++ b/src/actions/chat.cpp
@@ -28,6 +28,8 @@
#include "being/localplayer.h"
+#include "gui/sdlinput.h"
+
#include "gui/windows/chatwindow.h"
#include "listeners/inputactionreplaylistener.h"
@@ -48,6 +50,7 @@
#include "utils/booleanoptions.h"
#include "utils/chatutils.h"
+#include "utils/parameters.h"
#include "utils/translation/podict.h"
@@ -716,4 +719,38 @@ impHandler(translate)
return true;
}
+impHandler0(sendGuiKey)
+{
+ if (!guiInput)
+ return false;
+
+ const std::string args = event.args;
+ if (args.empty())
+ return false;
+ StringVect pars;
+ if (!splitParameters(pars, args, " ,", '\"'))
+ return false;
+ const int sz = CAST_S32(pars.size());
+ if (sz < 1)
+ return false;
+
+ int keyValue = atoi(pars[0].c_str());
+ if (keyValue == 0 &&
+ pars[0].size() == 1)
+ {
+ keyValue = CAST_S32(pars[0][0]);
+ }
+ if (sz == 2)
+ {
+ const InputActionT actionId = inputManager.getActionByConfigField(
+ pars[1]);
+ guiInput->simulateKey(keyValue, actionId);
+ }
+ else
+ {
+ guiInput->simulateKey(keyValue, InputAction::NO_VALUE);
+ }
+ return true;
+}
+
} // namespace Actions
diff --git a/src/actions/chat.h b/src/actions/chat.h
index ba33806a3..3815e53e7 100644
--- a/src/actions/chat.h
+++ b/src/actions/chat.h
@@ -62,6 +62,7 @@ namespace Actions
decHandler(chatClipboard);
decHandler(guildNotice);
decHandler(translate);
+ decHandler(sendGuiKey);
} // namespace Actions
#undef decHandler
diff --git a/src/dyetool/actions/chat.cpp b/src/dyetool/actions/chat.cpp
index 940ded31c..3d5dcf5c7 100644
--- a/src/dyetool/actions/chat.cpp
+++ b/src/dyetool/actions/chat.cpp
@@ -62,5 +62,6 @@ impHandlerVoid(hat)
impHandlerVoid(chatClipboard)
impHandlerVoid(guildNotice)
impHandlerVoid(translate)
+impHandlerVoid(sendGuiKey)
} // namespace Actions
diff --git a/src/enums/input/inputaction.h b/src/enums/input/inputaction.h
index b514805b6..5fc37aa1f 100644
--- a/src/enums/input/inputaction.h
+++ b/src/enums/input/inputaction.h
@@ -687,6 +687,7 @@ enumStart(InputAction)
CREATE_ITEM,
COPY_OUTFIT_TO_CHAT,
COMMAND_TRANSLATE,
+ COMMAND_SEND_GUI_KEY,
TOTAL
}
enumEnd(InputAction);
diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp
index 7d964b030..29b6534c1 100644
--- a/src/gui/sdlinput.cpp
+++ b/src/gui/sdlinput.cpp
@@ -359,3 +359,14 @@ void SDLInput::simulateMouseMove()
mouseInput.setTimeStamp(SDL_GetTicks());
mMouseInputQueue.push(mouseInput);
}
+
+void SDLInput::simulateKey(const int guiKey,
+ const InputActionT actionId)
+{
+ KeyInput keyInput;
+ keyInput.setType(KeyEventType::PRESSED);
+ keyInput.setKey(Key(guiKey));
+ if (actionId > InputAction::NO_VALUE)
+ keyInput.setActionId(actionId);
+ mKeyInputQueue.push(keyInput);
+}
diff --git a/src/gui/sdlinput.h b/src/gui/sdlinput.h
index 7ef0034bb..142a942aa 100644
--- a/src/gui/sdlinput.h
+++ b/src/gui/sdlinput.h
@@ -128,6 +128,9 @@ class SDLInput final
void simulateMouseMove();
+ void simulateKey(const int guiKey,
+ const InputActionT actionId);
+
protected:
/**
* Converts a mouse button from SDL to a Guichan mouse button
diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h
index a717c7e5e..f4d8f5739 100644
--- a/src/input/inputactionmap.h
+++ b/src/input/inputactionmap.h
@@ -5612,6 +5612,12 @@ static const InputActionData inputActionData
"translate|trans|tran",
UseArgs_false,
Protected_true},
+ {"keyCommandSendGuiKey",
+ defaultAction(&Actions::sendGuiKey),
+ InputCondition::ENABLED,
+ "guikey|sendguikey",
+ UseArgs_false,
+ Protected_true},
};
#undef defaultAction
diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp
index eda8ba7b1..40397e91f 100644
--- a/src/input/inputmanager.cpp
+++ b/src/input/inputmanager.cpp
@@ -1019,6 +1019,18 @@ InputActionT InputManager::getActionByKey(const SDL_Event &restrict event)
return InputAction::NO_VALUE;
}
+InputActionT InputManager::getActionByConfigField(const std::string &field)
+ const restrict2
+{
+ for (int i = 0; i < CAST_S32(InputAction::TOTAL); i ++)
+ {
+ const std::string cf = inputActionData[i].configField;
+ if (field == cf)
+ return static_cast<InputActionT>(i);
+ }
+ return InputAction::NO_VALUE;
+}
+
void InputManager::addChatCommands(std::list<std::string> &restrict arr)
restrict
{
diff --git a/src/input/inputmanager.h b/src/input/inputmanager.h
index 94e85b7d2..8455ef9b0 100644
--- a/src/input/inputmanager.h
+++ b/src/input/inputmanager.h
@@ -139,6 +139,9 @@ class InputManager final
InputActionT getActionByKey(const SDL_Event &restrict event)
const restrict2 A_WARN_UNUSED;
+ InputActionT getActionByConfigField(const std::string &field)
+ const restrict2 A_WARN_UNUSED;
+
void executeAction(const InputActionT keyNum) restrict2;
bool executeChatCommand(const std::string &restrict cmd,