diff --git a/Dalamud/Interface/ImGuiNotification/IActiveNotification.cs b/Dalamud/Interface/ImGuiNotification/IActiveNotification.cs index fecccf092..cbe5d9e25 100644 --- a/Dalamud/Interface/ImGuiNotification/IActiveNotification.cs +++ b/Dalamud/Interface/ImGuiNotification/IActiveNotification.cs @@ -67,6 +67,9 @@ public interface IActiveNotification : INotification /// new bool Interactible { get; set; } + /// + new bool UserDismissable { get; set; } + /// new TimeSpan HoverExtendDuration { get; set; } diff --git a/Dalamud/Interface/ImGuiNotification/INotification.cs b/Dalamud/Interface/ImGuiNotification/INotification.cs index c4a7b46ac..92b28fb15 100644 --- a/Dalamud/Interface/ImGuiNotification/INotification.cs +++ b/Dalamud/Interface/ImGuiNotification/INotification.cs @@ -38,9 +38,13 @@ public interface INotification /// . /// Note that the close buttons for notifications are always provided and interactible. /// If set to true, then clicking on the notification itself will be interpreted as user-initiated dismissal, - /// unless is set. + /// unless is set or is unset. /// bool Interactible { get; } + + /// Gets a value indicating whether the user can dismiss the notification by themselves. + /// Consider adding a cancel button to . + bool UserDismissable { get; } /// Gets the new duration for this notification if mouse cursor is on the notification window. /// diff --git a/Dalamud/Interface/ImGuiNotification/Internal/ActiveNotification.cs b/Dalamud/Interface/ImGuiNotification/Internal/ActiveNotification.cs index 64b812197..246c6cce5 100644 --- a/Dalamud/Interface/ImGuiNotification/Internal/ActiveNotification.cs +++ b/Dalamud/Interface/ImGuiNotification/Internal/ActiveNotification.cs @@ -148,6 +148,18 @@ internal sealed class ActiveNotification : IActiveNotification, IDisposable } } + /// + public bool UserDismissable + { + get => this.underlyingNotification.UserDismissable; + set + { + if (this.IsDismissed) + return; + this.underlyingNotification.UserDismissable = value; + } + } + /// public TimeSpan HoverExtendDuration { @@ -317,7 +329,6 @@ internal sealed class ActiveNotification : IActiveNotification, IDisposable if (opacity <= 0) return 0; - var notificationManager = Service.Get(); var interfaceManager = Service.Get(); var unboundedWidth = ImGui.CalcTextSize(this.Content).X; float closeButtonHorizontalSpaceReservation; @@ -386,7 +397,7 @@ internal sealed class ActiveNotification : IActiveNotification, IDisposable ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.NoDocking); - this.DrawNotificationMainWindowContent(notificationManager, width); + this.DrawNotificationMainWindowContent(width); var windowPos = ImGui.GetWindowPos(); var windowSize = ImGui.GetWindowSize(); var hovered = ImGui.IsWindowHovered(); @@ -433,7 +444,7 @@ internal sealed class ActiveNotification : IActiveNotification, IDisposable { if (this.Click is null) { - if (ImGui.IsMouseClicked(ImGuiMouseButton.Left)) + if (this.UserDismissable && ImGui.IsMouseClicked(ImGuiMouseButton.Left)) this.DismissNow(NotificationDismissReason.Manual); } else @@ -546,7 +557,7 @@ internal sealed class ActiveNotification : IActiveNotification, IDisposable this.MaterializedIcon = null; } - private void DrawNotificationMainWindowContent(NotificationManager notificationManager, float width) + private void DrawNotificationMainWindowContent(float width) { var basePos = ImGui.GetCursorPos(); this.DrawIcon( @@ -706,6 +717,9 @@ internal sealed class ActiveNotification : IActiveNotification, IDisposable private void DrawCloseButton(InterfaceManager interfaceManager, Vector2 rt, float pad) { + if (!this.UserDismissable) + return; + using (interfaceManager.IconFontHandle?.Push()) { var str = FontAwesomeIcon.Times.ToIconString(); @@ -719,7 +733,7 @@ internal sealed class ActiveNotification : IActiveNotification, IDisposable ImGui.SetCursorPos(rt - new Vector2(size, 0) - new Vector2(pad)); if (ImGui.Button(str, new(size + (pad * 2)))) - this.DismissNow(); + this.DismissNow(NotificationDismissReason.Manual); ImGui.PopStyleColor(2); if (!this.IsMouseHovered) diff --git a/Dalamud/Interface/ImGuiNotification/Notification.cs b/Dalamud/Interface/ImGuiNotification/Notification.cs index be2b9237d..e082aaaed 100644 --- a/Dalamud/Interface/ImGuiNotification/Notification.cs +++ b/Dalamud/Interface/ImGuiNotification/Notification.cs @@ -24,6 +24,9 @@ public sealed record Notification : INotification /// public bool Interactible { get; set; } + /// + public bool UserDismissable { get; set; } + /// public TimeSpan HoverExtendDuration { get; set; } = NotificationConstants.DefaultHoverExtendDuration; diff --git a/Dalamud/Interface/Internal/Windows/Data/Widgets/ImGuiWidget.cs b/Dalamud/Interface/Internal/Windows/Data/Widgets/ImGuiWidget.cs index 71cba3297..6239c9749 100644 --- a/Dalamud/Interface/Internal/Windows/Data/Widgets/ImGuiWidget.cs +++ b/Dalamud/Interface/Internal/Windows/Data/Widgets/ImGuiWidget.cs @@ -120,7 +120,11 @@ internal class ImGuiWidget : IDataWindowWidget ImGui.Checkbox("Interactible", ref this.notificationTemplate.Interactible); - ImGui.Checkbox("Action Bar", ref this.notificationTemplate.ActionBar); + ImGui.Checkbox("User Dismissable", ref this.notificationTemplate.UserDismissable); + + ImGui.Checkbox( + "Action Bar (always on if not user dismissable for the example)", + ref this.notificationTemplate.ActionBar); if (ImGui.Button("Add notification")) { @@ -144,6 +148,7 @@ internal class ImGuiWidget : IDataWindowWidget Title = title, Type = type, Interactible = this.notificationTemplate.Interactible, + UserDismissable = this.notificationTemplate.UserDismissable, Expiry = duration == TimeSpan.MaxValue ? DateTime.MaxValue : DateTime.Now + duration, Progress = this.notificationTemplate.ProgressMode switch { @@ -203,7 +208,7 @@ internal class ImGuiWidget : IDataWindowWidget break; } - if (this.notificationTemplate.ActionBar) + if (this.notificationTemplate.ActionBar || !this.notificationTemplate.UserDismissable) { var nclick = 0; n.Click += _ => nclick++; @@ -326,6 +331,7 @@ internal class ImGuiWidget : IDataWindowWidget public int TypeInt; public int DurationInt; public bool Interactible; + public bool UserDismissable; public bool ActionBar; public int ProgressMode; @@ -342,6 +348,7 @@ internal class ImGuiWidget : IDataWindowWidget this.TypeInt = (int)NotificationType.None; this.DurationInt = 2; this.Interactible = true; + this.UserDismissable = true; this.ActionBar = true; this.ProgressMode = 0; }