From 66d42a7cfd0ded8d7571886768d353a1134947aa Mon Sep 17 00:00:00 2001 From: Chivalrik Date: Sun, 2 May 2021 11:43:31 +0200 Subject: [PATCH] feat: Draw a main-viewport-big notifier on screen whenever in gamepad mode This notifier is a light grey-ish background and some text in the upper left corner of the main viewport. --- Dalamud/Interface/DalamudInterface.cs | 12 ++++++ .../Interface/GamepadModeNotifierWindow.cs | 41 +++++++++++++++++++ Dalamud/Interface/InterfaceManager.cs | 1 + 3 files changed, 54 insertions(+) create mode 100644 Dalamud/Interface/GamepadModeNotifierWindow.cs diff --git a/Dalamud/Interface/DalamudInterface.cs b/Dalamud/Interface/DalamudInterface.cs index 9283ff79e..e7d330b55 100644 --- a/Dalamud/Interface/DalamudInterface.cs +++ b/Dalamud/Interface/DalamudInterface.cs @@ -35,6 +35,7 @@ namespace Dalamud.Interface private readonly ComponentDemoWindow componentDemoWindow; private readonly ColorDemoWindow colorDemoWindow; private readonly ScratchpadWindow scratchpadWindow; + private readonly GamepadModeNotifierWindow gamepadModeNotifierWindow; private readonly WindowSystem windowSystem = new WindowSystem("DalamudCore"); @@ -116,6 +117,9 @@ namespace Dalamud.Interface }; this.windowSystem.AddWindow(this.scratchpadWindow); + this.gamepadModeNotifierWindow = new GamepadModeNotifierWindow(); + this.windowSystem.AddWindow(this.gamepadModeNotifierWindow); + Log.Information("[DUI] Windows added"); if (dalamud.Configuration.LogOpenAtStartup) @@ -553,5 +557,13 @@ namespace Dalamud.Interface { this.scratchpadWindow.IsOpen ^= true; } + + /// + /// Toggle the gamepad notifier window window. + /// + internal void ToggleGamePadNotifierWindow() + { + this.gamepadModeNotifierWindow.IsOpen ^= true; + } } } diff --git a/Dalamud/Interface/GamepadModeNotifierWindow.cs b/Dalamud/Interface/GamepadModeNotifierWindow.cs new file mode 100644 index 000000000..b3cbef108 --- /dev/null +++ b/Dalamud/Interface/GamepadModeNotifierWindow.cs @@ -0,0 +1,41 @@ +using System.Numerics; + +using Dalamud.Interface.Windowing; +using ImGuiNET; + +namespace Dalamud.Interface +{ + /// + /// Class responsible for drawing a notifier on screen that gamepad mode is active. + /// + internal class GamepadModeNotifierWindow : Window + { + /// + /// Initializes a new instance of the class. + /// + public GamepadModeNotifierWindow() + : base( + "###DalamudGamepadModeNotifier", + ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoMouseInputs + | ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoNav + | ImGuiWindowFlags.NoInputs | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoSavedSettings, + true) + { + this.Size = Vector2.Zero; + this.SizeCondition = ImGuiCond.Always; + this.IsOpen = false; + } + + /// + /// Draws a light grey-ish, main-viewport-big filled rect in the background draw list alongside a text indicating gamepad mode. + /// + public override void Draw() + { + var drawList = ImGui.GetBackgroundDrawList(); + drawList.PushClipRectFullScreen(); + drawList.AddRectFilled(Vector2.Zero, ImGuiHelpers.MainViewport.Size, 0x661A1A1A); + drawList.AddText(Vector2.One, 0xFFFFFFFF, "Gamepad mode is ON. Press R1+L3 to deactivate, press R3 to toggle PluginInstaller."); + drawList.PopClipRect(); + } + } +} diff --git a/Dalamud/Interface/InterfaceManager.cs b/Dalamud/Interface/InterfaceManager.cs index 604c95266..4d7f8ecc4 100644 --- a/Dalamud/Interface/InterfaceManager.cs +++ b/Dalamud/Interface/InterfaceManager.cs @@ -488,6 +488,7 @@ namespace Dalamud.Interface { ImGui.GetIO().ConfigFlags ^= ImGuiConfigFlags.NavEnableGamepad; this.dalamud.ClientState.GamepadState.NavEnableGamepad ^= true; + this.dalamud.DalamudUi.ToggleGamePadNotifierWindow(); } if (gamepadEnabled