diff --git a/Dalamud/Interface/Internal/DalamudCommands.cs b/Dalamud/Interface/Internal/DalamudCommands.cs index eaeaaa267..56ec778d8 100644 --- a/Dalamud/Interface/Internal/DalamudCommands.cs +++ b/Dalamud/Interface/Internal/DalamudCommands.cs @@ -131,6 +131,13 @@ namespace Dalamud.Interface.Internal HelpMessage = "Dalamud version info", }); + commandManager.AddHandler("/xlui", new CommandInfo(this.OnUiCommand) + { + HelpMessage = Loc.Localize( + "DalamudUiModeHelp", + "Toggle Dalamud UI display modes. Native UI modifications may also be affected by this, but that depends on the plugin."), + }); + commandManager.AddHandler("/imdebug", new CommandInfo(this.OnDebugImInfoCommand) { HelpMessage = "ImGui DEBUG", @@ -366,5 +373,31 @@ namespace Dalamud.Interface.Internal { Service.Get().ToggleSettingsWindow(); } + + private void OnUiCommand(string command, string arguments) + { + var im = Service.Get(); + + im.IsDispatchingEvents = arguments switch + { + "show" => true, + "hide" => false, + _ => !im.IsDispatchingEvents, + }; + + var pm = Service.Get(); + + foreach (var plugin in pm.InstalledPlugins) + { + if (im.IsDispatchingEvents) + { + plugin.DalamudInterface?.UiBuilder.NotifyShowUi(); + } + else + { + plugin.DalamudInterface?.UiBuilder.NotifyHideUi(); + } + } + } } } diff --git a/Dalamud/Interface/Internal/InterfaceManager.cs b/Dalamud/Interface/Internal/InterfaceManager.cs index 6de07e0bd..5d4e1c5ef 100644 --- a/Dalamud/Interface/Internal/InterfaceManager.cs +++ b/Dalamud/Interface/Internal/InterfaceManager.cs @@ -151,7 +151,7 @@ namespace Dalamud.Interface.Internal /// /// Gets or sets an action that is executed right after font fallback mode has been changed. /// - public event Action OnFallbackFontModeChange; + public event Action FallbackFontModeChange; /// /// Gets the default ImGui font. @@ -202,6 +202,11 @@ namespace Dalamud.Interface.Internal /// public bool IsReady => this.scene != null; + /// + /// Gets or sets a value indicating whether or not Draw events should be dispatched. + /// + public bool IsDispatchingEvents { get; set; } = true; + /// /// Gets or sets a value indicating whether the font has been loaded in fallback mode. /// @@ -214,7 +219,7 @@ namespace Dalamud.Interface.Internal return; this.isFallbackFontMode = value; - this.OnFallbackFontModeChange?.Invoke(value); + this.FallbackFontModeChange?.Invoke(value); } } @@ -1109,7 +1114,10 @@ namespace Dalamud.Interface.Internal WindowSystem.FocusedWindowSystemNamespace = string.Empty; var snap = ImGuiManagedAsserts.GetSnapshot(); - this.Draw?.Invoke(); + + if (this.IsDispatchingEvents) + this.Draw?.Invoke(); + ImGuiManagedAsserts.ReportProblems("Dalamud Core", snap); Service.Get().Draw(); diff --git a/Dalamud/Interface/Internal/Windows/FallbackFontNoticeWindow.cs b/Dalamud/Interface/Internal/Windows/FallbackFontNoticeWindow.cs index c0a035d52..fc83f2138 100644 --- a/Dalamud/Interface/Internal/Windows/FallbackFontNoticeWindow.cs +++ b/Dalamud/Interface/Internal/Windows/FallbackFontNoticeWindow.cs @@ -29,7 +29,7 @@ namespace Dalamud.Interface.Internal.Windows var interfaceManager = Service.Get(); var dalamud = Service.Get(); - Service.Get().OnFallbackFontModeChange += this.OnFallbackFontModeChange; + Service.Get().FallbackFontModeChange += this.OnFallbackFontModeChange; } private static string Title => Loc.Localize("FallbackFontNoticeWindowTitle", "Fallback Font Mode Active"); @@ -80,7 +80,7 @@ namespace Dalamud.Interface.Internal.Windows /// public void Dispose() { - Service.Get().OnFallbackFontModeChange -= this.OnFallbackFontModeChange; + Service.Get().FallbackFontModeChange -= this.OnFallbackFontModeChange; } private void OnFallbackFontModeChange(bool mode) diff --git a/Dalamud/Interface/UiBuilder.cs b/Dalamud/Interface/UiBuilder.cs index e3f85426c..753e81b4e 100644 --- a/Dalamud/Interface/UiBuilder.cs +++ b/Dalamud/Interface/UiBuilder.cs @@ -25,7 +25,8 @@ namespace Dalamud.Interface private readonly Stopwatch stopwatch; private readonly string namespaceName; - private bool hasErrorWindow; + private bool hasErrorWindow = false; + private bool lastFrameUiHideState = false; /// /// Initializes a new instance of the class and registers it. @@ -78,6 +79,18 @@ namespace Dalamud.Interface /// public event Action AfterBuildFonts; + /// + /// Gets or sets an action that is called when plugin UI or interface modifications are supposed to be hidden. + /// These may be fired consecutively. + /// + public event Action ShowUi; + + /// + /// Gets or sets an action that is called when plugin UI or interface modifications are supposed to be shown. + /// These may be fired consecutively. + /// + public event Action HideUi; + /// /// Gets the default Dalamud font based on Noto Sans CJK Medium in 17pt - supporting all game languages and icons. /// @@ -137,6 +150,36 @@ namespace Dalamud.Interface /// public ulong FrameCount { get; private set; } = 0; + /// + /// Gets a value indicating whether or not a cutscene is playing. + /// + public bool CutsceneActive + { + get + { + var condition = Service.Get(); + return condition[ConditionFlag.OccupiedInCutSceneEvent] + || condition[ConditionFlag.WatchingCutscene78]; + } + } + + /// + /// Gets a value indicating whether or not gpose is active. + /// + public bool GposeActive + { + get + { + var condition = Service.Get(); + return condition[ConditionFlag.WatchingCutscene]; + } + } + + /// + /// Gets a value indicating whether this plugin should modify the game's interface at this time. + /// + public bool ShouldModifyUi => Service.GetNullable()?.IsDispatchingEvents ?? true; + /// /// Gets or sets a value indicating whether statistics about UI draw time should be collected. /// @@ -166,25 +209,6 @@ namespace Dalamud.Interface /// internal List DrawTimeHistory { get; set; } = new List(); - private bool CutsceneActive - { - get - { - var condition = Service.Get(); - return condition[ConditionFlag.OccupiedInCutSceneEvent] - || condition[ConditionFlag.WatchingCutscene78]; - } - } - - private bool GposeActive - { - get - { - var condition = Service.Get(); - return condition[ConditionFlag.WatchingCutscene]; - } - } - /// /// Loads an image from the specified file. /// @@ -261,16 +285,49 @@ namespace Dalamud.Interface this.OpenConfigUi?.Invoke(); } + /// + /// Notify this UiBuilder about plugin UI being hidden. + /// + internal void NotifyHideUi() + { + this.HideUi?.Invoke(); + } + + /// + /// Notify this UiBuilder about plugin UI being shown. + /// + internal void NotifyShowUi() + { + this.ShowUi?.Invoke(); + } + private void OnDraw() { var configuration = Service.Get(); var gameGui = Service.Get(); var interfaceManager = Service.Get(); - if ((gameGui.GameUiHidden && configuration.ToggleUiHide && !(this.DisableUserUiHide || this.DisableAutomaticUiHide)) || - (this.CutsceneActive && configuration.ToggleUiHideDuringCutscenes && !(this.DisableCutsceneUiHide || this.DisableAutomaticUiHide)) || - (this.GposeActive && configuration.ToggleUiHideDuringGpose && !(this.DisableGposeUiHide || this.DisableAutomaticUiHide))) + if ((gameGui.GameUiHidden && configuration.ToggleUiHide && + !(this.DisableUserUiHide || this.DisableAutomaticUiHide)) || + (this.CutsceneActive && configuration.ToggleUiHideDuringCutscenes && + !(this.DisableCutsceneUiHide || this.DisableAutomaticUiHide)) || + (this.GposeActive && configuration.ToggleUiHideDuringGpose && + !(this.DisableGposeUiHide || this.DisableAutomaticUiHide))) + { + if (!this.lastFrameUiHideState) + { + this.lastFrameUiHideState = true; + this.HideUi?.Invoke(); + } + return; + } + + if (this.lastFrameUiHideState) + { + this.lastFrameUiHideState = false; + this.ShowUi?.Invoke(); + } if (!interfaceManager.FontsReady) return;