Skip to content

Commit

Permalink
Allow disabling controller input
Browse files Browse the repository at this point in the history
  • Loading branch information
exelix11 committed Oct 17, 2024
1 parent 68054ad commit 72b9ba2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
14 changes: 12 additions & 2 deletions Client/ClientApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public ClientApp(CommandLineOptions args)
ShowDebugInfo = Program.Options.Debug.Log;
}


// Fonts are loaded at double the resolution to reduce blurriness when scaling on high DPI
const int FontMultiplier = 2;
const int FontTextSize = 30 * FontMultiplier;
Expand Down Expand Up @@ -219,8 +218,10 @@ internal void Initialize()
ImGui.CreateContext();

UnsafeImguiInitialization();
ImGui.GetIO().ConfigFlags |= ImGuiConfigFlags.NavEnableKeyboard | ImGuiConfigFlags.NavEnableGamepad;

ImGui.GetIO().ConfigFlags |= ImGuiConfigFlags.NavEnableKeyboard;
ImGui.GetIO().NavVisible = true;
ApplyImguiSetings();

InitializeFonts();

Expand Down Expand Up @@ -296,6 +297,15 @@ internal void PushMainview()
}
}

internal void ApplyImguiSetings()
{
sdlCtx.AcceptControllerInput = Program.Options.ControllerInput;
if (Program.Options.ControllerInput)
ImGui.GetIO().ConfigFlags |= ImGuiConfigFlags.NavEnableGamepad;
else
ImGui.GetIO().ConfigFlags &= ~ImGuiConfigFlags.NavEnableGamepad;
}

internal void EntryPoint()
{
sdlCtx.CreateWindow(CommandLine.WindowTitle);
Expand Down
2 changes: 2 additions & 0 deletions Client/Core/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public class Options

public int DefaultVolume = 60;

public bool ControllerInput = true;

public string ScaleHintForSDL => RendererScale switch
{
SDLScaleMode.Linear => "linear",
Expand Down
2 changes: 2 additions & 0 deletions Client/Core/StringTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ internal class SettingsTable

public string InvalidPathError = "The selected path does not exist, try again.";
public string PathSelectDialog = "Select path";

public string ControllerInput = "Enable joypad input for controlling the SysDVR GUI";
}

internal class PlayerTable
Expand Down
5 changes: 5 additions & 0 deletions Client/GUI/Components/SDLContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class SDLContext
public bool IsFullscreen { get; private set; } = false;
public Vector2 WindowSize { get; private set; }

internal bool AcceptControllerInput = true;

// Scaling info
Vector2 PixelSize;
Vector2 WantedDPIScale;
Expand Down Expand Up @@ -132,6 +134,9 @@ public GuiMessage PumpEvents(out SDL_Event evt)
if (SDL_PollEvent(out evt) == 0)
return GuiMessage.None;

if (evt.type == SDL_EventType.SDL_JOYBUTTONDOWN && !AcceptControllerInput)
return GuiMessage.None;

//Console.WriteLine($"Received SDL_Event {evt.type}");

#if ANDROID_LIB
Expand Down
5 changes: 4 additions & 1 deletion Client/GUI/OptionsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,10 @@ public override void Draw()
ImGui.SameLine();
ImGui.SliderInt("##SliderAudioVolume", ref Program.Options.DefaultVolume, 0, 100, "%d %%");

ImGui.Unindent();
if (ImGui.Checkbox(Strings.ControllerInput, ref Program.Options.ControllerInput))
Program.Instance.ApplyImguiSetings();

ImGui.Unindent();
ImGui.NewLine();
}

Expand Down

0 comments on commit 72b9ba2

Please sign in to comment.