diff --git a/Dalamud/Game/ChatHandlers.cs b/Dalamud/Game/ChatHandlers.cs index 12e4553d4..78dc3fc63 100644 --- a/Dalamud/Game/ChatHandlers.cs +++ b/Dalamud/Game/ChatHandlers.cs @@ -13,6 +13,7 @@ using Dalamud.Game.Text; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Interface.Internal; +using Dalamud.Interface.Internal.Notifications; using Dalamud.IoC; using Dalamud.IoC.Internal; using Dalamud.Plugin.Internal; @@ -252,7 +253,7 @@ namespace Dalamud.Game var configuration = Service.Get(); var pluginManager = Service.Get(); var dalamudInterface = Service.Get(); - var notifications = Service.Get(); + var notifications = Service.Get(); var assemblyVersion = Assembly.GetAssembly(typeof(ChatHandlers)).GetName().Version.ToString(); @@ -298,7 +299,7 @@ namespace Dalamud.Game if (configuration.AutoUpdatePlugins) { pluginManager.PrintUpdatedPlugins(updatedPlugins, Loc.Localize("DalamudPluginAutoUpdate", "Auto-update:")); - notifications.AddNotification(Loc.Localize("NotificationUpdatedPlugins", "{0} of your plugins were updated.").Format(updatedPlugins.Count), Loc.Localize("NotificationAutoUpdate", "Auto-Update"), Notifications.Notification.Type.Info); + notifications.AddNotification(Loc.Localize("NotificationUpdatedPlugins", "{0} of your plugins were updated.").Format(updatedPlugins.Count), Loc.Localize("NotificationAutoUpdate", "Auto-Update"), NotificationType.Info); } else { diff --git a/Dalamud/Interface/Internal/InterfaceManager.cs b/Dalamud/Interface/Internal/InterfaceManager.cs index 146a89a50..b5493605e 100644 --- a/Dalamud/Interface/Internal/InterfaceManager.cs +++ b/Dalamud/Interface/Internal/InterfaceManager.cs @@ -15,6 +15,7 @@ using Dalamud.Game.Gui.Internal; using Dalamud.Game.Internal.DXGI; using Dalamud.Hooking; using Dalamud.Hooking.Internal; +using Dalamud.Interface.Internal.Notifications; using Dalamud.Utility; using ImGuiNET; using ImGuiScene; @@ -58,7 +59,7 @@ namespace Dalamud.Interface.Internal /// public InterfaceManager() { - Service.Set(); + Service.Set(); var scanner = Service.Get(); @@ -150,11 +151,6 @@ namespace Dalamud.Interface.Internal /// public static ImFontPtr MonoFont { get; private set; } - /// - /// Gets the manager for notifications/toasts. - /// - public Notifications Notifications { get; init; } = new(); - /// /// Gets or sets an action that is exexuted when fonts are rebuilt. /// @@ -644,7 +640,7 @@ namespace Dalamud.Interface.Internal this.lastWantCapture = this.LastImGuiIoPtr.WantCaptureMouse; this.Draw?.Invoke(); - Service.Get().Draw(); + Service.Get().Draw(); } } } diff --git a/Dalamud/Interface/Internal/Notifications.cs b/Dalamud/Interface/Internal/Notifications/NotificationManager.cs similarity index 83% rename from Dalamud/Interface/Internal/Notifications.cs rename to Dalamud/Interface/Internal/Notifications/NotificationManager.cs index f685e1ab9..aeef3c934 100644 --- a/Dalamud/Interface/Internal/Notifications.cs +++ b/Dalamud/Interface/Internal/Notifications/NotificationManager.cs @@ -7,13 +7,13 @@ using Dalamud.Interface.Colors; using Dalamud.Utility; using ImGuiNET; -namespace Dalamud.Interface.Internal +namespace Dalamud.Interface.Internal.Notifications { /// /// Class handling notifications/toasts in ImGui. /// Ported from https://github.com/patrickcjk/imgui-notify. /// - internal class Notifications + internal class NotificationManager { /// /// Value indicating the bottom-left X padding. @@ -61,7 +61,7 @@ namespace Dalamud.Interface.Internal /// The title of the notification. /// The type of the notification. /// The time the notification should be displayed for. - public void AddNotification(string content, string title = null, Notification.Type type = Notification.Type.None, int msDelay = NotifyDefaultDismiss) + public void AddNotification(string content, string? title = null, NotificationType type = NotificationType.None, uint msDelay = NotifyDefaultDismiss) { this.notifications.Add(new Notification { @@ -170,37 +170,6 @@ namespace Dalamud.Interface.Internal /// internal class Notification { - /// - /// Possible notification types. - /// - public enum Type - { - /// - /// No special type. - /// - None, - - /// - /// Type indicating success. - /// - Success, - - /// - /// Type indicating a warning. - /// - Warning, - - /// - /// Type indicating an error. - /// - Error, - - /// - /// Type indicating generic information. - /// - Info, - } - /// /// Possible notification phases. /// @@ -230,12 +199,12 @@ namespace Dalamud.Interface.Internal /// /// Gets the type of the notification. /// - internal Type NotificationType { get; init; } + internal NotificationType NotificationType { get; init; } /// /// Gets the title of the notification. /// - internal string Title { get; init; } + internal string? Title { get; init; } /// /// Gets the content of the notification. @@ -245,7 +214,7 @@ namespace Dalamud.Interface.Internal /// /// Gets the duration of the notification in milliseconds. /// - internal int DurationMs { get; init; } + internal uint DurationMs { get; init; } /// /// Gets the creation time of the notification. @@ -258,11 +227,11 @@ namespace Dalamud.Interface.Internal /// Thrown when is set to an out-of-range value. internal Vector4 Color => this.NotificationType switch { - Type.None => ImGuiColors.DalamudWhite, - Type.Success => ImGuiColors.HealerGreen, - Type.Warning => ImGuiColors.DalamudOrange, - Type.Error => ImGuiColors.DalamudRed, - Type.Info => ImGuiColors.TankBlue, + NotificationType.None => ImGuiColors.DalamudWhite, + NotificationType.Success => ImGuiColors.HealerGreen, + NotificationType.Warning => ImGuiColors.DalamudOrange, + NotificationType.Error => ImGuiColors.DalamudRed, + NotificationType.Info => ImGuiColors.TankBlue, _ => throw new ArgumentOutOfRangeException(), }; @@ -272,11 +241,11 @@ namespace Dalamud.Interface.Internal /// Thrown when is set to an out-of-range value. internal string? Icon => this.NotificationType switch { - Type.None => null, - Type.Success => FontAwesomeIcon.CheckCircle.ToIconString(), - Type.Warning => FontAwesomeIcon.ExclamationCircle.ToIconString(), - Type.Error => FontAwesomeIcon.TimesCircle.ToIconString(), - Type.Info => FontAwesomeIcon.InfoCircle.ToIconString(), + NotificationType.None => null, + NotificationType.Success => FontAwesomeIcon.CheckCircle.ToIconString(), + NotificationType.Warning => FontAwesomeIcon.ExclamationCircle.ToIconString(), + NotificationType.Error => FontAwesomeIcon.TimesCircle.ToIconString(), + NotificationType.Info => FontAwesomeIcon.InfoCircle.ToIconString(), _ => throw new ArgumentOutOfRangeException(), }; @@ -286,11 +255,11 @@ namespace Dalamud.Interface.Internal /// Thrown when is set to an out-of-range value. internal string? DefaultTitle => this.NotificationType switch { - Type.None => null, - Type.Success => Type.Success.ToString(), - Type.Warning => Type.Warning.ToString(), - Type.Error => Type.Error.ToString(), - Type.Info => Type.Info.ToString(), + NotificationType.None => null, + NotificationType.Success => NotificationType.Success.ToString(), + NotificationType.Warning => NotificationType.Warning.ToString(), + NotificationType.Error => NotificationType.Error.ToString(), + NotificationType.Info => NotificationType.Info.ToString(), _ => throw new ArgumentOutOfRangeException(), }; diff --git a/Dalamud/Interface/Internal/Notifications/NotificationType.cs b/Dalamud/Interface/Internal/Notifications/NotificationType.cs new file mode 100644 index 000000000..d2cb56686 --- /dev/null +++ b/Dalamud/Interface/Internal/Notifications/NotificationType.cs @@ -0,0 +1,33 @@ +namespace Dalamud.Interface.Internal.Notifications +{ + /// + /// Possible notification types. + /// + public enum NotificationType + { + /// + /// No special type. + /// + None, + + /// + /// Type indicating success. + /// + Success, + + /// + /// Type indicating a warning. + /// + Warning, + + /// + /// Type indicating an error. + /// + Error, + + /// + /// Type indicating generic information. + /// + Info, + } +} diff --git a/Dalamud/Interface/Internal/Windows/DataWindow.cs b/Dalamud/Interface/Internal/Windows/DataWindow.cs index 253f9a4ac..676c2e9c1 100644 --- a/Dalamud/Interface/Internal/Windows/DataWindow.cs +++ b/Dalamud/Interface/Internal/Windows/DataWindow.cs @@ -22,6 +22,7 @@ using Dalamud.Game.Gui; using Dalamud.Game.Gui.FlyText; using Dalamud.Game.Gui.Toast; using Dalamud.Game.Text; +using Dalamud.Interface.Internal.Notifications; using Dalamud.Interface.Windowing; using Dalamud.Memory; using Dalamud.Plugin; @@ -1056,6 +1057,7 @@ namespace Dalamud.Interface.Internal.Windows private void DrawImGui() { var interfaceManager = Service.Get(); + var notifications = Service.Get(); ImGui.Text("Monitor count: " + ImGui.GetPlatformIO().Monitors.Size); ImGui.Text("OverrideGameCursor: " + interfaceManager.OverrideGameCursor); @@ -1082,17 +1084,17 @@ namespace Dalamud.Interface.Internal.Windows var type = rand.Next(0, 4) switch { - 0 => Notifications.Notification.Type.Error, - 1 => Notifications.Notification.Type.Warning, - 2 => Notifications.Notification.Type.Info, - 3 => Notifications.Notification.Type.Success, - 4 => Notifications.Notification.Type.None, - _ => Notifications.Notification.Type.None, + 0 => Notifications.NotificationType.Error, + 1 => Notifications.NotificationType.Warning, + 2 => Notifications.NotificationType.Info, + 3 => Notifications.NotificationType.Success, + 4 => Notifications.NotificationType.None, + _ => Notifications.NotificationType.None, }; var text = "Bla bla bla bla bla bla bla bla bla bla bla.\nBla bla bla bla bla bla bla bla bla bla bla bla bla bla."; - interfaceManager.Notifications.AddNotification(text, title, type); + notifications.AddNotification(text, title, type); } } diff --git a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs index 45b7071a2..4ca59b8e9 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs @@ -15,6 +15,7 @@ using Dalamud.Configuration.Internal; using Dalamud.Game.Command; using Dalamud.Interface.Colors; using Dalamud.Interface.Components; +using Dalamud.Interface.Internal.Notifications; using Dalamud.Interface.Windowing; using Dalamud.Logging.Internal; using Dalamud.Plugin; @@ -321,9 +322,8 @@ namespace Dalamud.Interface.Internal.Windows private void DrawUpdatePluginsButton() { - var interfaceManager = Service.Get(); var pluginManager = Service.Get(); - var notifications = Service.Get(); + var notifications = Service.Get(); var ready = pluginManager.PluginsReady && pluginManager.ReposReady; @@ -379,11 +379,11 @@ namespace Dalamud.Interface.Internal.Windows if (this.updatePluginCount > 0) { pluginManager.PrintUpdatedPlugins(this.updatedPlugins, Locs.PluginUpdateHeader_Chatbox); - notifications.AddNotification(Locs.Notifications_UpdatesInstalled(this.updatePluginCount), Locs.Notifications_UpdatesInstalledTitle, Notifications.Notification.Type.Success); + notifications.AddNotification(Locs.Notifications_UpdatesInstalled(this.updatePluginCount), Locs.Notifications_UpdatesInstalledTitle, NotificationType.Success); } else if (this.updatePluginCount == 0) { - notifications.AddNotification(Locs.Notifications_NoUpdatesFound, Locs.Notifications_NoUpdatesFoundTitle, Notifications.Notification.Type.Info); + notifications.AddNotification(Locs.Notifications_NoUpdatesFound, Locs.Notifications_NoUpdatesFoundTitle, NotificationType.Info); } } }); @@ -898,8 +898,7 @@ namespace Dalamud.Interface.Internal.Windows private void DrawAvailablePlugin(RemotePluginManifest manifest, int index) { var configuration = Service.Get(); - var interfaceManager = Service.Get(); - var notifications = Service.Get(); + var notifications = Service.Get(); var pluginManager = Service.Get(); var useTesting = pluginManager.UseTesting(manifest); @@ -976,11 +975,11 @@ namespace Dalamud.Interface.Internal.Windows { if (task.Result.State == PluginState.Loaded) { - notifications.AddNotification(Locs.Notifications_PluginInstalled(manifest.Name), Locs.Notifications_PluginInstalledTitle, Notifications.Notification.Type.Success); + notifications.AddNotification(Locs.Notifications_PluginInstalled(manifest.Name), Locs.Notifications_PluginInstalledTitle, NotificationType.Success); } else { - notifications.AddNotification(Locs.Notifications_PluginNotInstalled(manifest.Name), Locs.Notifications_PluginNotInstalledTitle, Notifications.Notification.Type.Error); + notifications.AddNotification(Locs.Notifications_PluginNotInstalled(manifest.Name), Locs.Notifications_PluginNotInstalledTitle, NotificationType.Error); this.ShowErrorModal(Locs.ErrorModal_InstallFail(manifest.Name)); } } @@ -1248,7 +1247,7 @@ namespace Dalamud.Interface.Internal.Windows private void DrawPluginControlButton(LocalPlugin plugin) { var configuration = Service.Get(); - var notifications = Service.Get(); + var notifications = Service.Get(); var pluginManager = Service.Get(); var startInfo = Service.Get(); @@ -1293,7 +1292,7 @@ namespace Dalamud.Interface.Internal.Windows pluginManager.RemovePlugin(plugin); } - notifications.AddNotification(Locs.Notifications_PluginDisabled(plugin.Manifest.Name), Locs.Notifications_PluginDisabledTitle, Notifications.Notification.Type.Success); + notifications.AddNotification(Locs.Notifications_PluginDisabled(plugin.Manifest.Name), Locs.Notifications_PluginDisabledTitle, NotificationType.Success); }); } } diff --git a/Dalamud/Interface/UiBuilder.cs b/Dalamud/Interface/UiBuilder.cs index f888442c2..7de2dbae9 100644 --- a/Dalamud/Interface/UiBuilder.cs +++ b/Dalamud/Interface/UiBuilder.cs @@ -6,6 +6,7 @@ using Dalamud.Configuration.Internal; using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.Gui; using Dalamud.Interface.Internal; +using Dalamud.Interface.Internal.Notifications; using ImGuiNET; using ImGuiScene; using Serilog; @@ -201,6 +202,17 @@ namespace Dalamud.Interface Service.Get().RebuildFonts(); } + /// + /// Add a notification to the notification queue. + /// + /// The content of the notification. + /// The title of the notification. + /// The type of the notification. + /// The time the notification should be displayed for. + public void AddNotification( + string content, string? title = null, NotificationType type = NotificationType.None, uint msDelay = 3000) => + Service.Get().AddNotification(content, title, type, msDelay); + /// /// Unregister the UiBuilder. Do not call this in plugin code. ///