mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
fix: allow Window to be instantiated without Dalamud services
This commit is contained in:
parent
4dc43b7ed3
commit
a82096c671
2 changed files with 21 additions and 15 deletions
|
|
@ -17,7 +17,6 @@ public abstract class Window
|
|||
private bool internalLastIsOpen = false;
|
||||
private bool internalIsOpen = false;
|
||||
private bool nextFrameBringToFront = false;
|
||||
private DalamudConfiguration Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Window"/> class.
|
||||
|
|
@ -33,7 +32,6 @@ public abstract class Window
|
|||
this.WindowName = name;
|
||||
this.Flags = flags;
|
||||
this.ForceMainWindow = forceMainWindow;
|
||||
this.Configuration = Service<DalamudConfiguration>.Get();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -225,10 +223,12 @@ public abstract class Window
|
|||
/// <summary>
|
||||
/// Draw the window via ImGui.
|
||||
/// </summary>
|
||||
internal void DrawInternal()
|
||||
internal void DrawInternal(DalamudConfiguration? configuration)
|
||||
{
|
||||
this.PreOpenCheck();
|
||||
|
||||
var doSoundEffects = configuration?.EnablePluginUISoundEffects ?? false;
|
||||
|
||||
if (!this.IsOpen)
|
||||
{
|
||||
if (this.internalIsOpen != this.internalLastIsOpen)
|
||||
|
|
@ -238,7 +238,7 @@ public abstract class Window
|
|||
|
||||
this.IsFocused = false;
|
||||
|
||||
if (this.Configuration.EnablePluginUISoundEffects && !this.DisableWindowSounds) UIModule.PlaySound(this.OnCloseSfxId, 0, 0, 0);
|
||||
if (doSoundEffects && !this.DisableWindowSounds) UIModule.PlaySound(this.OnCloseSfxId, 0, 0, 0);
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
@ -264,7 +264,7 @@ public abstract class Window
|
|||
this.internalLastIsOpen = this.internalIsOpen;
|
||||
this.OnOpen();
|
||||
|
||||
if (this.Configuration.EnablePluginUISoundEffects && !this.DisableWindowSounds) UIModule.PlaySound(this.OnOpenSfxId, 0, 0, 0);
|
||||
if (doSoundEffects && !this.DisableWindowSounds) UIModule.PlaySound(this.OnOpenSfxId, 0, 0, 0);
|
||||
}
|
||||
|
||||
var wasFocused = this.IsFocused;
|
||||
|
|
@ -294,16 +294,19 @@ public abstract class Window
|
|||
|
||||
this.IsFocused = ImGui.IsWindowFocused(ImGuiFocusedFlags.RootAndChildWindows);
|
||||
|
||||
var escapeDown = Service<KeyState>.Get()[VirtualKey.ESCAPE];
|
||||
var isAllowed = Service<DalamudConfiguration>.Get().IsFocusManagementEnabled;
|
||||
if (escapeDown && this.IsFocused && isAllowed && !wasEscPressedLastFrame && this.RespectCloseHotkey)
|
||||
var isAllowed = configuration?.IsFocusManagementEnabled ?? false;
|
||||
if (isAllowed)
|
||||
{
|
||||
this.IsOpen = false;
|
||||
wasEscPressedLastFrame = true;
|
||||
}
|
||||
else if (!escapeDown && wasEscPressedLastFrame)
|
||||
{
|
||||
wasEscPressedLastFrame = false;
|
||||
var escapeDown = Service<KeyState>.Get()[VirtualKey.ESCAPE];
|
||||
if (escapeDown && this.IsFocused && !wasEscPressedLastFrame && this.RespectCloseHotkey)
|
||||
{
|
||||
this.IsOpen = false;
|
||||
wasEscPressedLastFrame = true;
|
||||
}
|
||||
else if (!escapeDown && wasEscPressedLastFrame)
|
||||
{
|
||||
wasEscPressedLastFrame = false;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.End();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Dalamud.Configuration.Internal;
|
||||
using Dalamud.Interface.Internal.ManagedAsserts;
|
||||
using ImGuiNET;
|
||||
using Serilog;
|
||||
|
|
@ -111,6 +112,8 @@ public class WindowSystem
|
|||
if (hasNamespace)
|
||||
ImGui.PushID(this.Namespace);
|
||||
|
||||
var config = Service<DalamudConfiguration>.GetNullable();
|
||||
|
||||
// Shallow clone the list of windows so that we can edit it without modifying it while the loop is iterating
|
||||
foreach (var window in this.windows.ToArray())
|
||||
{
|
||||
|
|
@ -119,7 +122,7 @@ public class WindowSystem
|
|||
#endif
|
||||
var snapshot = ImGuiManagedAsserts.GetSnapshot();
|
||||
|
||||
window.DrawInternal();
|
||||
window.DrawInternal(config);
|
||||
|
||||
var source = ($"{this.Namespace}::" ?? string.Empty) + window.WindowName;
|
||||
ImGuiManagedAsserts.ReportProblems(source, snapshot);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue