mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
feat: expose AddNotification API on UiBuilder
This commit is contained in:
parent
66daa03da3
commit
33cbad9f16
7 changed files with 90 additions and 78 deletions
|
|
@ -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<DalamudConfiguration>.Get();
|
||||
var pluginManager = Service<PluginManager>.Get();
|
||||
var dalamudInterface = Service<DalamudInterface>.Get();
|
||||
var notifications = Service<Notifications>.Get();
|
||||
var notifications = Service<NotificationManager>.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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
|||
/// </summary>
|
||||
public InterfaceManager()
|
||||
{
|
||||
Service<Notifications>.Set();
|
||||
Service<NotificationManager>.Set();
|
||||
|
||||
var scanner = Service<SigScanner>.Get();
|
||||
|
||||
|
|
@ -150,11 +151,6 @@ namespace Dalamud.Interface.Internal
|
|||
/// </summary>
|
||||
public static ImFontPtr MonoFont { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the manager for notifications/toasts.
|
||||
/// </summary>
|
||||
public Notifications Notifications { get; init; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an action that is exexuted when fonts are rebuilt.
|
||||
/// </summary>
|
||||
|
|
@ -644,7 +640,7 @@ namespace Dalamud.Interface.Internal
|
|||
this.lastWantCapture = this.LastImGuiIoPtr.WantCaptureMouse;
|
||||
|
||||
this.Draw?.Invoke();
|
||||
Service<Notifications>.Get().Draw();
|
||||
Service<NotificationManager>.Get().Draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ using Dalamud.Interface.Colors;
|
|||
using Dalamud.Utility;
|
||||
using ImGuiNET;
|
||||
|
||||
namespace Dalamud.Interface.Internal
|
||||
namespace Dalamud.Interface.Internal.Notifications
|
||||
{
|
||||
/// <summary>
|
||||
/// Class handling notifications/toasts in ImGui.
|
||||
/// Ported from https://github.com/patrickcjk/imgui-notify.
|
||||
/// </summary>
|
||||
internal class Notifications
|
||||
internal class NotificationManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Value indicating the bottom-left X padding.
|
||||
|
|
@ -61,7 +61,7 @@ namespace Dalamud.Interface.Internal
|
|||
/// <param name="title">The title of the notification.</param>
|
||||
/// <param name="type">The type of the notification.</param>
|
||||
/// <param name="msDelay">The time the notification should be displayed for.</param>
|
||||
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
|
|||
/// </summary>
|
||||
internal class Notification
|
||||
{
|
||||
/// <summary>
|
||||
/// Possible notification types.
|
||||
/// </summary>
|
||||
public enum Type
|
||||
{
|
||||
/// <summary>
|
||||
/// No special type.
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// Type indicating success.
|
||||
/// </summary>
|
||||
Success,
|
||||
|
||||
/// <summary>
|
||||
/// Type indicating a warning.
|
||||
/// </summary>
|
||||
Warning,
|
||||
|
||||
/// <summary>
|
||||
/// Type indicating an error.
|
||||
/// </summary>
|
||||
Error,
|
||||
|
||||
/// <summary>
|
||||
/// Type indicating generic information.
|
||||
/// </summary>
|
||||
Info,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Possible notification phases.
|
||||
/// </summary>
|
||||
|
|
@ -230,12 +199,12 @@ namespace Dalamud.Interface.Internal
|
|||
/// <summary>
|
||||
/// Gets the type of the notification.
|
||||
/// </summary>
|
||||
internal Type NotificationType { get; init; }
|
||||
internal NotificationType NotificationType { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the title of the notification.
|
||||
/// </summary>
|
||||
internal string Title { get; init; }
|
||||
internal string? Title { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content of the notification.
|
||||
|
|
@ -245,7 +214,7 @@ namespace Dalamud.Interface.Internal
|
|||
/// <summary>
|
||||
/// Gets the duration of the notification in milliseconds.
|
||||
/// </summary>
|
||||
internal int DurationMs { get; init; }
|
||||
internal uint DurationMs { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the creation time of the notification.
|
||||
|
|
@ -258,11 +227,11 @@ namespace Dalamud.Interface.Internal
|
|||
/// <exception cref="ArgumentOutOfRangeException">Thrown when <see cref="NotificationType"/> is set to an out-of-range value.</exception>
|
||||
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
|
|||
/// <exception cref="ArgumentOutOfRangeException">Thrown when <see cref="NotificationType"/> is set to an out-of-range value.</exception>
|
||||
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
|
|||
/// <exception cref="ArgumentOutOfRangeException">Thrown when <see cref="NotificationType"/> is set to an out-of-range value.</exception>
|
||||
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(),
|
||||
};
|
||||
|
||||
33
Dalamud/Interface/Internal/Notifications/NotificationType.cs
Normal file
33
Dalamud/Interface/Internal/Notifications/NotificationType.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
namespace Dalamud.Interface.Internal.Notifications
|
||||
{
|
||||
/// <summary>
|
||||
/// Possible notification types.
|
||||
/// </summary>
|
||||
public enum NotificationType
|
||||
{
|
||||
/// <summary>
|
||||
/// No special type.
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// Type indicating success.
|
||||
/// </summary>
|
||||
Success,
|
||||
|
||||
/// <summary>
|
||||
/// Type indicating a warning.
|
||||
/// </summary>
|
||||
Warning,
|
||||
|
||||
/// <summary>
|
||||
/// Type indicating an error.
|
||||
/// </summary>
|
||||
Error,
|
||||
|
||||
/// <summary>
|
||||
/// Type indicating generic information.
|
||||
/// </summary>
|
||||
Info,
|
||||
}
|
||||
}
|
||||
|
|
@ -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<InterfaceManager>.Get();
|
||||
var notifications = Service<NotificationManager>.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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<InterfaceManager>.Get();
|
||||
var pluginManager = Service<PluginManager>.Get();
|
||||
var notifications = Service<Notifications>.Get();
|
||||
var notifications = Service<NotificationManager>.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<DalamudConfiguration>.Get();
|
||||
var interfaceManager = Service<InterfaceManager>.Get();
|
||||
var notifications = Service<Notifications>.Get();
|
||||
var notifications = Service<NotificationManager>.Get();
|
||||
var pluginManager = Service<PluginManager>.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<DalamudConfiguration>.Get();
|
||||
var notifications = Service<Notifications>.Get();
|
||||
var notifications = Service<NotificationManager>.Get();
|
||||
var pluginManager = Service<PluginManager>.Get();
|
||||
var startInfo = Service<DalamudStartInfo>.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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<InterfaceManager>.Get().RebuildFonts();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a notification to the notification queue.
|
||||
/// </summary>
|
||||
/// <param name="content">The content of the notification.</param>
|
||||
/// <param name="title">The title of the notification.</param>
|
||||
/// <param name="type">The type of the notification.</param>
|
||||
/// <param name="msDelay">The time the notification should be displayed for.</param>
|
||||
public void AddNotification(
|
||||
string content, string? title = null, NotificationType type = NotificationType.None, uint msDelay = 3000) =>
|
||||
Service<NotificationManager>.Get().AddNotification(content, title, type, msDelay);
|
||||
|
||||
/// <summary>
|
||||
/// Unregister the UiBuilder. Do not call this in plugin code.
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue