From 873877795ac6a3da1f7bf0073420c06eae20492e Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Tue, 20 Feb 2024 12:06:19 -0600 Subject: [PATCH] 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