diff --git a/Dalamud/Interface/Windowing/Window.cs b/Dalamud/Interface/Windowing/Window.cs index 31a3d075c..a827be07b 100644 --- a/Dalamud/Interface/Windowing/Window.cs +++ b/Dalamud/Interface/Windowing/Window.cs @@ -1,6 +1,7 @@ using System.Numerics; using ImGuiNET; +using Serilog; namespace Dalamud.Interface.Windowing { @@ -11,6 +12,7 @@ namespace Dalamud.Interface.Windowing { private bool internalLastIsOpen = false; private bool internalIsOpen = false; + private bool mainIsOpen = false; /// /// Initializes a new instance of the class. @@ -28,6 +30,8 @@ namespace Dalamud.Interface.Windowing this.ForceMainWindow = forceMainWindow; } + public string Namespace { get; set; } + /// /// Gets or sets the name of the window. /// If you have multiple windows with the same name, you will need to @@ -85,13 +89,24 @@ namespace Dalamud.Interface.Windowing /// public bool ForceMainWindow { get; set; } + /// + /// Gets or sets this window's background alpha value. + /// + public float? BgAlpha { get; set; } + /// /// Gets or sets a value indicating whether or not this window will stay open. /// public bool IsOpen { - get => this.internalIsOpen; - set => this.internalIsOpen = value; + get => this.mainIsOpen; + set + { + if (!value) + this.internalIsOpen = true; + + this.mainIsOpen = value; + } } /// @@ -115,6 +130,14 @@ namespace Dalamud.Interface.Windowing /// internal void DrawInternal() { + if (!this.IsOpen) + return; + + var hasNamespace = !string.IsNullOrEmpty(this.Namespace); + + if (hasNamespace) + ImGui.PushID(this.Namespace); + this.ApplyConditionals(); if (this.ForceMainWindow) @@ -124,10 +147,13 @@ namespace Dalamud.Interface.Windowing { // Draw the actual window contents this.Draw(); - - ImGui.End(); } + ImGui.End(); + + if (hasNamespace) + ImGui.PopID(); + if (this.internalLastIsOpen != this.internalIsOpen) { if (this.internalIsOpen) @@ -141,18 +167,26 @@ namespace Dalamud.Interface.Windowing } this.internalLastIsOpen = this.internalIsOpen; + + if (this.internalIsOpen != true) + this.IsOpen = false; } private void ApplyConditionals() { if (this.Position.HasValue) { - ImGui.SetNextWindowPos(this.Position.Value, this.PositionCondition); + var pos = this.Position.Value; + + if (this.ForceMainWindow) + pos += ImGuiHelpers.MainWindowPos; + + ImGui.SetNextWindowPos(pos, this.PositionCondition); } if (this.Size.HasValue) { - ImGui.SetNextWindowPos(this.Size.Value * ImGuiHelpers.GlobalScale, this.SizeCondition); + ImGui.SetNextWindowSize(this.Size.Value * ImGuiHelpers.GlobalScale, this.SizeCondition); } if (this.Collapsed.HasValue) @@ -164,6 +198,11 @@ namespace Dalamud.Interface.Windowing { ImGui.SetNextWindowSizeConstraints(this.SizeConstraintsMin.Value * ImGuiHelpers.GlobalScale, this.SizeConstraintsMax.Value * ImGuiHelpers.GlobalScale); } + + if (this.BgAlpha.HasValue) + { + ImGui.SetNextWindowBgAlpha(this.BgAlpha.Value); + } } } }