From b388aa7b712a89d49bf36bf6f144c26e5d560a4d Mon Sep 17 00:00:00 2001 From: water111 <48171810+water111@users.noreply.github.com> Date: Sun, 21 Aug 2022 19:00:13 -0400 Subject: [PATCH] add option to disable mouse hiding (#1782) * add option to disable mouse hiding * write setting --- game/graphics/gfx.cpp | 3 +++ game/graphics/pipelines/opengl.cpp | 8 +++++--- game/system/newpad.h | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/game/graphics/gfx.cpp b/game/graphics/gfx.cpp index 896d6b1bd1..ea1b6c640c 100644 --- a/game/graphics/gfx.cpp +++ b/game/graphics/gfx.cpp @@ -94,6 +94,7 @@ void DumpToJson(ghc::filesystem::path& filename) { nlohmann::json json; json["Debug Menu Visibility"] = false; // Assume start up debug display is disabled auto& peripherals_json = json["Peripherals"]; + json["Use Mouse"] = g_settings.pad_mapping_info.use_mouse; for (uint32_t i = 0; i < Pad::CONTROLLER_COUNT; ++i) { nlohmann::json peripheral_json; @@ -154,6 +155,8 @@ void LoadPeripheralSettings(const ghc::filesystem::path& filepath) { g_is_debug_menu_visible_on_startup = configuration["Debug Menu Visibility"].get(); } + g_settings.pad_mapping_info.use_mouse = configuration.value("Use Mouse", false); + int controller_index = 0; for (const auto& peripheral : configuration["Peripherals"]) { auto& controller_buttons_json = peripheral["Controller"]["Buttons"]; diff --git a/game/graphics/pipelines/opengl.cpp b/game/graphics/pipelines/opengl.cpp index e2877b2ee1..3f026299cd 100644 --- a/game/graphics/pipelines/opengl.cpp +++ b/game/graphics/pipelines/opengl.cpp @@ -306,8 +306,10 @@ GLDisplay::~GLDisplay() { } void GLDisplay::update_cursor_visibility(GLFWwindow* window, bool is_visible) { - auto cursor_mode = (is_visible) ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_DISABLED; - glfwSetInputMode(window, GLFW_CURSOR, cursor_mode); + if (Gfx::get_button_mapping().use_mouse) { + auto cursor_mode = is_visible ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_DISABLED; + glfwSetInputMode(window, GLFW_CURSOR, cursor_mode); + } } void GLDisplay::on_key(GLFWwindow* window, int key, int /*scancode*/, int action, int /*mods*/) { @@ -344,7 +346,7 @@ void GLDisplay::on_mouse_key(GLFWwindow* window, int button, int action, int mod void GLDisplay::on_cursor_position(GLFWwindow* window, double xposition, double yposition) { Pad::MappingInfo mapping_info = Gfx::get_button_mapping(); - if (is_imgui_visible()) { + if (is_imgui_visible() || !mapping_info.use_mouse) { if (is_cursor_position_valid == true) { Pad::ClearAnalogAxisValue(mapping_info, GlfwKeyCustomAxis::CURSOR_X_AXIS); Pad::ClearAnalogAxisValue(mapping_info, GlfwKeyCustomAxis::CURSOR_Y_AXIS); diff --git a/game/system/newpad.h b/game/system/newpad.h index 0eb2e3ed30..2b74e4ba2d 100644 --- a/game/system/newpad.h +++ b/game/system/newpad.h @@ -75,7 +75,8 @@ struct AnalogMappingInfo { }; struct MappingInfo { - bool debug = true; // debug mode + bool debug = true; // debug mode + bool use_mouse = false; bool buffer_mode = true; // use buffered inputs int controller_button_mapping[CONTROLLER_COUNT][(int)Pad::Button::Max];