From f29fb0188756c195b5c5367bafce66b59f225b7d Mon Sep 17 00:00:00 2001 From: qurious-pixel <62252937+qurious-pixel@users.noreply.github.com> Date: Thu, 16 Jun 2022 17:43:34 -0700 Subject: [PATCH] Add Controller Navigation (#429) * Add Controller Navigation - Apply Rainbow patch - Add Controller Navigation - Controller "Back" button opens F1 Menu - Controller Rumble/Gyro settings at the bottom of the controller menu * Restore changes from PR #306 Add back update from https://github.com/HarbourMasters/Shipwright/pull/306 * Add Tooltip of new functionality Tooltip: Allows controller navigation of the menu bar D-pad to move between items, A to select, and X to grab focus on the menu bar * set & save check * Fixes for switch port --- libultraship/libultraship/SohImGuiImpl.cpp | 37 ++++++++++++---------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/libultraship/libultraship/SohImGuiImpl.cpp b/libultraship/libultraship/SohImGuiImpl.cpp index 446082cbd..65fdc1b2e 100644 --- a/libultraship/libultraship/SohImGuiImpl.cpp +++ b/libultraship/libultraship/SohImGuiImpl.cpp @@ -50,6 +50,7 @@ bool oldCursorState = true; ImGui::PopStyleColor(); \ ImGui::Separator(); #define TOGGLE_BTN ImGuiKey_F1 +#define TOGGLE_PAD_BTN ImGuiKey_GamepadBack #define HOOK(b) if(b) needs_save = true; OSContPad* pads; @@ -698,7 +699,7 @@ namespace SohImGui { const std::shared_ptr wnd = GlobalCtx2::GetInstance()->GetWindow(); ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | - ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoResize; + ImGuiWindowFlags_NoResize; if (CVar_GetS32("gOpenMenuBar", 0)) window_flags |= ImGuiWindowFlags_MenuBar; const ImGuiViewport* viewport = ImGui::GetMainViewport(); @@ -726,7 +727,9 @@ namespace SohImGui { ImGui::DockSpace(dockId, ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_None); - if (ImGui::IsKeyPressed(TOGGLE_BTN)) { + ImGuiIO& io = ImGui::GetIO(); + io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; + if ((ImGui::IsKeyPressed(TOGGLE_BTN)) || (ImGui::IsKeyDown(TOGGLE_PAD_BTN))) { bool menu_bar = CVar_GetS32("gOpenMenuBar", 0); CVar_SetS32("gOpenMenuBar", !menu_bar); needs_save = true; @@ -756,7 +759,22 @@ namespace SohImGui { } if (ImGui::BeginMenu("Controller")) - { + { + EnhancementCheckbox("D-pad Support on Pause and File Select", "gDpadPauseName"); + EnhancementCheckbox("D-pad Support in Ocarina and Text Choice", "gDpadOcarinaText"); + EnhancementCheckbox("D-pad Support for Browsing Shop Items", "gDpadShop"); + + ImGui::Separator(); + + EnhancementCheckbox("Show Inputs", "gInputEnabled"); + Tooltip("Shows currently pressed inputs on the bottom right of the screen"); + EnhancementCheckbox("Rumble Enabled", "gRumbleEnabled"); + + EnhancementSliderFloat("Input Scale: %.1f", "##Input", "gInputScale", 1.0f, 3.0f, "", 1.0f, false); + Tooltip("Sets the on screen size of the displayed inputs from Show Inputs"); + + ImGui::Separator(); + for (const auto& [i, controllers] : Ship::Window::Controllers) { bool hasPad = std::find_if(controllers.begin(), controllers.end(), [](const auto& c) { @@ -786,19 +804,6 @@ namespace SohImGui { ImGui::Separator(); } - EnhancementCheckbox("Show Inputs", "gInputEnabled"); - Tooltip("Shows currently pressed inputs on the bottom right of the screen"); - EnhancementCheckbox("Rumble Enabled", "gRumbleEnabled"); - - EnhancementSliderFloat("Input Scale: %.1f", "##Input", "gInputScale", 1.0f, 3.0f, "", 1.0f, false); - Tooltip("Sets the on screen size of the displayed inputs from Show Inputs"); - - ImGui::Separator(); - - EnhancementCheckbox("D-pad Support on Pause and File Select", "gDpadPauseName"); - EnhancementCheckbox("D-pad Support in Ocarina and Text Choice", "gDpadOcarinaText"); - EnhancementCheckbox("D-pad Support for Browsing Shop Items", "gDpadShop"); - ImGui::EndMenu(); }