Skip to content

Commit

Permalink
Add Controller Navigation (HarbourMasters#429)
Browse files Browse the repository at this point in the history
* 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 HarbourMasters#306

Add back update from HarbourMasters#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
  • Loading branch information
qurious-pixel authored and th-2021 committed Jun 19, 2022
1 parent 39d00f4 commit b0b640b
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions libultraship/libultraship/SohImGuiImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -698,7 +699,7 @@ namespace SohImGui {
const std::shared_ptr<Window> 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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit b0b640b

Please sign in to comment.