From 4beac9035a96511ed30a851d5f9218c58349b233 Mon Sep 17 00:00:00 2001 From: Zackhasacat Date: Tue, 28 Nov 2023 19:58:41 -0600 Subject: [PATCH] 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