feat: add /xlui command to disable all ImGui draw events, corresponding events to allow plugins to remove their atk mods

This commit is contained in:
goaaats 2022-05-12 14:19:49 +02:00
parent f9eb853a18
commit cadcddf7b1
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
4 changed files with 126 additions and 28 deletions

View file

@ -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<DalamudInterface>.Get().ToggleSettingsWindow();
}
private void OnUiCommand(string command, string arguments)
{
var im = Service<InterfaceManager>.Get();
im.IsDispatchingEvents = arguments switch
{
"show" => true,
"hide" => false,
_ => !im.IsDispatchingEvents,
};
var pm = Service<PluginManager>.Get();
foreach (var plugin in pm.InstalledPlugins)
{
if (im.IsDispatchingEvents)
{
plugin.DalamudInterface?.UiBuilder.NotifyShowUi();
}
else
{
plugin.DalamudInterface?.UiBuilder.NotifyHideUi();
}
}
}
}
}

View file

@ -151,7 +151,7 @@ namespace Dalamud.Interface.Internal
/// <summary>
/// Gets or sets an action that is executed right after font fallback mode has been changed.
/// </summary>
public event Action<bool> OnFallbackFontModeChange;
public event Action<bool> FallbackFontModeChange;
/// <summary>
/// Gets the default ImGui font.
@ -202,6 +202,11 @@ namespace Dalamud.Interface.Internal
/// </summary>
public bool IsReady => this.scene != null;
/// <summary>
/// Gets or sets a value indicating whether or not Draw events should be dispatched.
/// </summary>
public bool IsDispatchingEvents { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether the font has been loaded in fallback mode.
/// </summary>
@ -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<NotificationManager>.Get().Draw();

View file

@ -29,7 +29,7 @@ namespace Dalamud.Interface.Internal.Windows
var interfaceManager = Service<InterfaceManager>.Get();
var dalamud = Service<Dalamud>.Get();
Service<InterfaceManager>.Get().OnFallbackFontModeChange += this.OnFallbackFontModeChange;
Service<InterfaceManager>.Get().FallbackFontModeChange += this.OnFallbackFontModeChange;
}
private static string Title => Loc.Localize("FallbackFontNoticeWindowTitle", "Fallback Font Mode Active");
@ -80,7 +80,7 @@ namespace Dalamud.Interface.Internal.Windows
/// </summary>
public void Dispose()
{
Service<InterfaceManager>.Get().OnFallbackFontModeChange -= this.OnFallbackFontModeChange;
Service<InterfaceManager>.Get().FallbackFontModeChange -= this.OnFallbackFontModeChange;
}
private void OnFallbackFontModeChange(bool mode)

View file

@ -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;
/// <summary>
/// Initializes a new instance of the <see cref="UiBuilder"/> class and registers it.
@ -78,6 +79,18 @@ namespace Dalamud.Interface
/// </summary>
public event Action AfterBuildFonts;
/// <summary>
/// Gets or sets an action that is called when plugin UI or interface modifications are supposed to be hidden.
/// These may be fired consecutively.
/// </summary>
public event Action ShowUi;
/// <summary>
/// Gets or sets an action that is called when plugin UI or interface modifications are supposed to be shown.
/// These may be fired consecutively.
/// </summary>
public event Action HideUi;
/// <summary>
/// Gets the default Dalamud font based on Noto Sans CJK Medium in 17pt - supporting all game languages and icons.
/// </summary>
@ -137,6 +150,36 @@ namespace Dalamud.Interface
/// </summary>
public ulong FrameCount { get; private set; } = 0;
/// <summary>
/// Gets a value indicating whether or not a cutscene is playing.
/// </summary>
public bool CutsceneActive
{
get
{
var condition = Service<Condition>.Get();
return condition[ConditionFlag.OccupiedInCutSceneEvent]
|| condition[ConditionFlag.WatchingCutscene78];
}
}
/// <summary>
/// Gets a value indicating whether or not gpose is active.
/// </summary>
public bool GposeActive
{
get
{
var condition = Service<Condition>.Get();
return condition[ConditionFlag.WatchingCutscene];
}
}
/// <summary>
/// Gets a value indicating whether this plugin should modify the game's interface at this time.
/// </summary>
public bool ShouldModifyUi => Service<InterfaceManager>.GetNullable()?.IsDispatchingEvents ?? true;
/// <summary>
/// Gets or sets a value indicating whether statistics about UI draw time should be collected.
/// </summary>
@ -166,25 +209,6 @@ namespace Dalamud.Interface
/// </summary>
internal List<long> DrawTimeHistory { get; set; } = new List<long>();
private bool CutsceneActive
{
get
{
var condition = Service<Condition>.Get();
return condition[ConditionFlag.OccupiedInCutSceneEvent]
|| condition[ConditionFlag.WatchingCutscene78];
}
}
private bool GposeActive
{
get
{
var condition = Service<Condition>.Get();
return condition[ConditionFlag.WatchingCutscene];
}
}
/// <summary>
/// Loads an image from the specified file.
/// </summary>
@ -261,16 +285,49 @@ namespace Dalamud.Interface
this.OpenConfigUi?.Invoke();
}
/// <summary>
/// Notify this UiBuilder about plugin UI being hidden.
/// </summary>
internal void NotifyHideUi()
{
this.HideUi?.Invoke();
}
/// <summary>
/// Notify this UiBuilder about plugin UI being shown.
/// </summary>
internal void NotifyShowUi()
{
this.ShowUi?.Invoke();
}
private void OnDraw()
{
var configuration = Service<DalamudConfiguration>.Get();
var gameGui = Service<GameGui>.Get();
var interfaceManager = Service<InterfaceManager>.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;