From 4beac9035a96511ed30a851d5f9218c58349b233 Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Tue, 28 Nov 2023 19:58:41 -0600 Subject: [PATCH 1/7] Add bindings for controller cursor mode --- apps/openmw/mwbase/inputmanager.hpp | 1 + apps/openmw/mwinput/inputmanagerimp.cpp | 5 +++++ apps/openmw/mwinput/inputmanagerimp.hpp | 1 + apps/openmw/mwlua/inputbindings.cpp | 6 ++++++ files/lua_api/openmw/input.lua | 10 ++++++++++ 5 files changed, 23 insertions(+) diff --git a/apps/openmw/mwbase/inputmanager.hpp b/apps/openmw/mwbase/inputmanager.hpp index f52f9ea454..5ee20476b3 100644 --- a/apps/openmw/mwbase/inputmanager.hpp +++ b/apps/openmw/mwbase/inputmanager.hpp @@ -45,6 +45,7 @@ namespace MWBase virtual void processChangedSettings(const std::set>& changed) = 0; virtual void setDragDrop(bool dragDrop) = 0; + virtual bool isGamepadGuiCursorEnabled() = 0; virtual void setGamepadGuiCursorEnabled(bool enabled) = 0; virtual void toggleControlSwitch(std::string_view sw, bool value) = 0; diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index f9ca0a3432..d0d6e7023d 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -102,6 +102,11 @@ namespace MWInput mControllerManager->setGamepadGuiCursorEnabled(enabled); } + bool InputManager::isGamepadGuiCursorEnabled() + { + return mControllerManager->gamepadGuiCursorEnabled(); + } + void InputManager::changeInputMode(bool guiMode) { mControllerManager->setGuiCursorEnabled(guiMode); diff --git a/apps/openmw/mwinput/inputmanagerimp.hpp b/apps/openmw/mwinput/inputmanagerimp.hpp index c5de579961..f8f1411ebf 100644 --- a/apps/openmw/mwinput/inputmanagerimp.hpp +++ b/apps/openmw/mwinput/inputmanagerimp.hpp @@ -68,6 +68,7 @@ namespace MWInput void setDragDrop(bool dragDrop) override; void setGamepadGuiCursorEnabled(bool enabled) override; + bool isGamepadGuiCursorEnabled() override; void toggleControlSwitch(std::string_view sw, bool value) override; bool getControlSwitch(std::string_view sw) override; diff --git a/apps/openmw/mwlua/inputbindings.cpp b/apps/openmw/mwlua/inputbindings.cpp index 02babf0399..414bb575b7 100644 --- a/apps/openmw/mwlua/inputbindings.cpp +++ b/apps/openmw/mwlua/inputbindings.cpp @@ -9,6 +9,7 @@ #include "../mwbase/environment.hpp" #include "../mwbase/inputmanager.hpp" +#include "../mwbase/windowmanager.hpp" #include "../mwinput/actions.hpp" namespace sol @@ -68,6 +69,11 @@ namespace MWLua }; api["isMouseButtonPressed"] = [](int button) -> bool { return SDL_GetMouseState(nullptr, nullptr) & SDL_BUTTON(button); }; + api["isGamepadCursorActive"] = [input]() -> bool { return input->isGamepadGuiCursorEnabled(); }; + api["setGamepadCursorActive"] = [input](bool v) { + input->setGamepadGuiCursorEnabled(v); + MWBase::Environment::get().getWindowManager()->setCursorActive(v); + }; api["getMouseMoveX"] = [input]() { return input->getMouseMoveX(); }; api["getMouseMoveY"] = [input]() { return input->getMouseMoveY(); }; api["getAxisValue"] = [input](int axis) { diff --git a/files/lua_api/openmw/input.lua b/files/lua_api/openmw/input.lua index 4ca4e5af4e..fbb790ce49 100644 --- a/files/lua_api/openmw/input.lua +++ b/files/lua_api/openmw/input.lua @@ -29,6 +29,16 @@ -- @param #number buttonId Button index (see @{openmw.input#CONTROLLER_BUTTON}) -- @return #boolean +--- +-- Checks if the gamepad cursor is active. If it is active, the left stick can move the cursor, and A will be interpreted as a mouse click. +-- @function [parent=#input] isGamepadCursorActive +-- @return #boolean + +--- +-- Set if the gamepad cursor is active. If it is active, the left stick can move the cursor, and A will be interpreted as a mouse click. +-- @function [parent=#input] setGamepadCursorActive +-- @param #boolean value + --- -- Is `Shift` key pressed. -- @function [parent=#input] isShiftPressed From 873877795ac6a3da1f7bf0073420c06eae20492e Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Tue, 20 Feb 2024 12:06:19 -0600 Subject: [PATCH 2/7] Move gamepad controls to lua interface --- apps/openmw/mwlua/inputbindings.cpp | 4 +-- docs/source/luadoc_data_paths.sh | 1 + docs/source/reference/lua-scripting/api.rst | 1 + .../interface_gamepadcontrols.rst | 8 +++++ .../lua-scripting/tables/interfaces.rst | 4 +++ files/data/CMakeLists.txt | 3 +- files/data/builtin.omwscripts | 1 + .../scripts/omw/input/gamepadcontrols.lua | 29 +++++++++++++++++++ files/lua_api/openmw/input.lua | 10 ------- 9 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 docs/source/reference/lua-scripting/interface_gamepadcontrols.rst create mode 100644 files/data/scripts/omw/input/gamepadcontrols.lua diff --git a/apps/openmw/mwlua/inputbindings.cpp b/apps/openmw/mwlua/inputbindings.cpp index 315b0db7bc..a5a6399c96 100644 --- a/apps/openmw/mwlua/inputbindings.cpp +++ b/apps/openmw/mwlua/inputbindings.cpp @@ -202,8 +202,8 @@ namespace MWLua }; api["isMouseButtonPressed"] = [](int button) -> bool { return SDL_GetMouseState(nullptr, nullptr) & SDL_BUTTON(button); }; - api["isGamepadCursorActive"] = [input]() -> bool { return input->isGamepadGuiCursorEnabled(); }; - api["setGamepadCursorActive"] = [input](bool v) { + api["_isGamepadCursorActive"] = [input]() -> bool { return input->isGamepadGuiCursorEnabled(); }; + api["_setGamepadCursorActive"] = [input](bool v) { input->setGamepadGuiCursorEnabled(v); MWBase::Environment::get().getWindowManager()->setCursorActive(v); }; diff --git a/docs/source/luadoc_data_paths.sh b/docs/source/luadoc_data_paths.sh index 02b03cbd69..9af80d6444 100755 --- a/docs/source/luadoc_data_paths.sh +++ b/docs/source/luadoc_data_paths.sh @@ -4,6 +4,7 @@ paths=( scripts/omw/ai.lua scripts/omw/mechanics/animationcontroller.lua scripts/omw/playercontrols.lua + scripts/omw/input/gamepadcontrols.lua scripts/omw/camera/camera.lua scripts/omw/mwui/init.lua scripts/omw/settings/player.lua diff --git a/docs/source/reference/lua-scripting/api.rst b/docs/source/reference/lua-scripting/api.rst index 1bb7e0b6e9..8fef9c475e 100644 --- a/docs/source/reference/lua-scripting/api.rst +++ b/docs/source/reference/lua-scripting/api.rst @@ -37,6 +37,7 @@ Lua API reference interface_animation interface_camera interface_controls + interface_gamepadcontrols interface_item_usage interface_mwui interface_settings diff --git a/docs/source/reference/lua-scripting/interface_gamepadcontrols.rst b/docs/source/reference/lua-scripting/interface_gamepadcontrols.rst new file mode 100644 index 0000000000..f89738b25b --- /dev/null +++ b/docs/source/reference/lua-scripting/interface_gamepadcontrols.rst @@ -0,0 +1,8 @@ +Interface GamepadControls +========================= + +.. include:: version.rst + +.. raw:: html + :file: generated_html/scripts_omw_input_gamepadcontrols.html + diff --git a/docs/source/reference/lua-scripting/tables/interfaces.rst b/docs/source/reference/lua-scripting/tables/interfaces.rst index 5029baf0a3..606b68b8e0 100644 --- a/docs/source/reference/lua-scripting/tables/interfaces.rst +++ b/docs/source/reference/lua-scripting/tables/interfaces.rst @@ -21,6 +21,10 @@ - by player scripts - | Allows to alter behavior of the built-in script | that handles player controls. + * - :ref:`Controls ` + - by player scripts + - | Allows to alter behavior of the built-in script + | that handles player gamepad controls. * - :ref:`ItemUsage ` - by global scripts - | Allows to extend or override built-in item usage diff --git a/files/data/CMakeLists.txt b/files/data/CMakeLists.txt index 3ab30c87ff..817a64c014 100644 --- a/files/data/CMakeLists.txt +++ b/files/data/CMakeLists.txt @@ -95,7 +95,8 @@ set(BUILTIN_DATA_FILES scripts/omw/worldeventhandlers.lua scripts/omw/input/actionbindings.lua scripts/omw/input/smoothmovement.lua - + scripts/omw/input/gamepadcontrols.lua + shaders/adjustments.omwfx shaders/bloomlinear.omwfx shaders/debug.omwfx diff --git a/files/data/builtin.omwscripts b/files/data/builtin.omwscripts index a6f4ca5f33..1549920dab 100644 --- a/files/data/builtin.omwscripts +++ b/files/data/builtin.omwscripts @@ -16,6 +16,7 @@ PLAYER: scripts/omw/playercontrols.lua PLAYER: scripts/omw/camera/camera.lua PLAYER: scripts/omw/input/actionbindings.lua PLAYER: scripts/omw/input/smoothmovement.lua +PLAYER: scripts/omw/input/gamepadcontrols.lua NPC,CREATURE: scripts/omw/ai.lua # User interface diff --git a/files/data/scripts/omw/input/gamepadcontrols.lua b/files/data/scripts/omw/input/gamepadcontrols.lua new file mode 100644 index 0000000000..0af17efa39 --- /dev/null +++ b/files/data/scripts/omw/input/gamepadcontrols.lua @@ -0,0 +1,29 @@ +local input = require('openmw.input') + +return { + + interfaceName = 'GamepadControls', + --- + -- Gamepad control interface + -- @module GamepadControls + + interface = { + --- Interface version + -- @field [parent=#GamepadControls] #number version + version = 0, + + --- Checks if the gamepad cursor is active. If it is active, the left stick can move the cursor, and A will be interpreted as a mouse click. + -- @function [parent=#GamepadControls] isGamepadCursorActive + -- @return #boolean + isGamepadCursorActive = function() + return input._isGamepadCursorActive() + end, + + --- Set if the gamepad cursor is active. If it is active, the left stick can move the cursor, and A will be interpreted as a mouse click. + -- @function [parent=#GamepadControls] setGamepadCursorActive + -- @param #boolean value + setGamepadCursorActive = function(state) + input._setGamepadCursorActive(state) + end, + } +} diff --git a/files/lua_api/openmw/input.lua b/files/lua_api/openmw/input.lua index 12bd51b47a..0a85602bcc 100644 --- a/files/lua_api/openmw/input.lua +++ b/files/lua_api/openmw/input.lua @@ -28,16 +28,6 @@ -- @param #number buttonId Button index (see @{openmw.input#CONTROLLER_BUTTON}) -- @return #boolean ---- --- Checks if the gamepad cursor is active. If it is active, the left stick can move the cursor, and A will be interpreted as a mouse click. --- @function [parent=#input] isGamepadCursorActive --- @return #boolean - ---- --- Set if the gamepad cursor is active. If it is active, the left stick can move the cursor, and A will be interpreted as a mouse click. --- @function [parent=#input] setGamepadCursorActive --- @param #boolean value - --- -- Is `Shift` key pressed. -- @function [parent=#input] isShiftPressed From a29be8909d33e0e83f510cf71ab76f36a7ec6236 Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Sun, 7 Apr 2024 10:35:13 -0500 Subject: [PATCH 3/7] Add bindings to select the next menu element --- apps/openmw/mwlua/inputbindings.cpp | 6 ++++++ files/data/scripts/omw/input/gamepadcontrols.lua | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/apps/openmw/mwlua/inputbindings.cpp b/apps/openmw/mwlua/inputbindings.cpp index dbe79ca377..cc1e4b99f8 100644 --- a/apps/openmw/mwlua/inputbindings.cpp +++ b/apps/openmw/mwlua/inputbindings.cpp @@ -214,6 +214,12 @@ namespace MWLua input->setGamepadGuiCursorEnabled(v); MWBase::Environment::get().getWindowManager()->setCursorActive(v); }; + api["_selectNextMenuElement"] = []() { + MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::Period, 0, false); + }; + api["_selectPrevMenuElement"] = []() { + MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::Slash, 0, false); + }; api["getMouseMoveX"] = [input]() { return input->getMouseMoveX(); }; api["getMouseMoveY"] = [input]() { return input->getMouseMoveY(); }; api["getAxisValue"] = [input](int axis) { diff --git a/files/data/scripts/omw/input/gamepadcontrols.lua b/files/data/scripts/omw/input/gamepadcontrols.lua index 0af17efa39..9c8810b98f 100644 --- a/files/data/scripts/omw/input/gamepadcontrols.lua +++ b/files/data/scripts/omw/input/gamepadcontrols.lua @@ -25,5 +25,17 @@ return { setGamepadCursorActive = function(state) input._setGamepadCursorActive(state) end, + + --- Sends an event to the interface to select the next menu element + -- @function [parent=#GamepadControls] selectNextMenuElement + selectNextMenuElement = function(state) + input._selectNextMenuElement() + end, + + --- Sends an event to the interface to select the next menu element + -- @function [parent=#GamepadControls] selectPrevMenuElement + selectPrevMenuElement = function(state) + input._selectPrevMenuElement() + end, } } From da4e6b38a8b74be0528d0cddbbd97c43715486f2 Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Sun, 7 Apr 2024 10:37:15 -0500 Subject: [PATCH 4/7] Clang format --- apps/openmw/mwlua/inputbindings.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwlua/inputbindings.cpp b/apps/openmw/mwlua/inputbindings.cpp index cc1e4b99f8..1b9ed3bf11 100644 --- a/apps/openmw/mwlua/inputbindings.cpp +++ b/apps/openmw/mwlua/inputbindings.cpp @@ -214,12 +214,10 @@ namespace MWLua input->setGamepadGuiCursorEnabled(v); MWBase::Environment::get().getWindowManager()->setCursorActive(v); }; - api["_selectNextMenuElement"] = []() { - MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::Period, 0, false); - }; - api["_selectPrevMenuElement"] = []() { - MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::Slash, 0, false); - }; + api["_selectNextMenuElement"] + = []() { MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::Period, 0, false); }; + api["_selectPrevMenuElement"] + = []() { MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::Slash, 0, false); }; api["getMouseMoveX"] = [input]() { return input->getMouseMoveX(); }; api["getMouseMoveY"] = [input]() { return input->getMouseMoveY(); }; api["getAxisValue"] = [input](int axis) { From a51b6c7392a7f216923e9254400c7b0821b6adb8 Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Sun, 7 Apr 2024 15:23:27 -0500 Subject: [PATCH 5/7] Remove menu select --- files/data/scripts/omw/input/gamepadcontrols.lua | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/files/data/scripts/omw/input/gamepadcontrols.lua b/files/data/scripts/omw/input/gamepadcontrols.lua index 9c8810b98f..0af17efa39 100644 --- a/files/data/scripts/omw/input/gamepadcontrols.lua +++ b/files/data/scripts/omw/input/gamepadcontrols.lua @@ -25,17 +25,5 @@ return { setGamepadCursorActive = function(state) input._setGamepadCursorActive(state) end, - - --- Sends an event to the interface to select the next menu element - -- @function [parent=#GamepadControls] selectNextMenuElement - selectNextMenuElement = function(state) - input._selectNextMenuElement() - end, - - --- Sends an event to the interface to select the next menu element - -- @function [parent=#GamepadControls] selectPrevMenuElement - selectPrevMenuElement = function(state) - input._selectPrevMenuElement() - end, } } From 4018b1ae598e585cd168c0bd9f6f69222e3a5c49 Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Tue, 9 Apr 2024 21:24:53 -0500 Subject: [PATCH 6/7] Remove hidden functions --- apps/openmw/mwlua/inputbindings.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apps/openmw/mwlua/inputbindings.cpp b/apps/openmw/mwlua/inputbindings.cpp index 1b9ed3bf11..dbe79ca377 100644 --- a/apps/openmw/mwlua/inputbindings.cpp +++ b/apps/openmw/mwlua/inputbindings.cpp @@ -214,10 +214,6 @@ namespace MWLua input->setGamepadGuiCursorEnabled(v); MWBase::Environment::get().getWindowManager()->setCursorActive(v); }; - api["_selectNextMenuElement"] - = []() { MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::Period, 0, false); }; - api["_selectPrevMenuElement"] - = []() { MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::Slash, 0, false); }; api["getMouseMoveX"] = [input]() { return input->getMouseMoveX(); }; api["getMouseMoveY"] = [input]() { return input->getMouseMoveY(); }; api["getAxisValue"] = [input](int axis) { From 55f4f6a5bfcbc89888ac9a6def574b2f32d9ba1f Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Wed, 24 Apr 2024 18:06:24 -0500 Subject: [PATCH 7/7] Update API_REVISION --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 93da5feec4..e61fdd7844 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,7 @@ message(STATUS "Configuring OpenMW...") set(OPENMW_VERSION_MAJOR 0) set(OPENMW_VERSION_MINOR 49) set(OPENMW_VERSION_RELEASE 0) -set(OPENMW_LUA_API_REVISION 59) +set(OPENMW_LUA_API_REVISION 60) set(OPENMW_POSTPROCESSING_API_REVISION 1) set(OPENMW_VERSION_COMMITHASH "")