From 617c2bdb9c752ee067eacbabf5827dc2731b06e5 Mon Sep 17 00:00:00 2001
From: MidoriKami <9083275+MidoriKami@users.noreply.github.com>
Date: Sun, 10 Sep 2023 16:18:10 -0700
Subject: [PATCH] Add IFlyTextGui (v9) (#1278)
---
Dalamud/Game/Gui/FlyText/FlyTextGui.cs | 92 +++++++++++++-------------
Dalamud/Plugin/Services/IFlyTextGui.cs | 55 +++++++++++++++
2 files changed, 101 insertions(+), 46 deletions(-)
create mode 100644 Dalamud/Plugin/Services/IFlyTextGui.cs
diff --git a/Dalamud/Game/Gui/FlyText/FlyTextGui.cs b/Dalamud/Game/Gui/FlyText/FlyTextGui.cs
index f2222a7cd..3c04c744a 100644
--- a/Dalamud/Game/Gui/FlyText/FlyTextGui.cs
+++ b/Dalamud/Game/Gui/FlyText/FlyTextGui.cs
@@ -7,6 +7,7 @@ using Dalamud.Hooking;
using Dalamud.IoC;
using Dalamud.IoC.Internal;
using Dalamud.Memory;
+using Dalamud.Plugin.Services;
using Serilog;
namespace Dalamud.Game.Gui.FlyText;
@@ -14,10 +15,9 @@ namespace Dalamud.Game.Gui.FlyText;
///
/// This class facilitates interacting with and creating native in-game "fly text".
///
-[PluginInterface]
[InterfaceVersion("1.0")]
[ServiceManager.BlockingEarlyLoadedService]
-public sealed class FlyTextGui : IDisposable, IServiceType
+internal sealed class FlyTextGui : IDisposable, IServiceType, IFlyTextGui
{
///
/// The native function responsible for adding fly text to the UI. See .
@@ -39,32 +39,6 @@ public sealed class FlyTextGui : IDisposable, IServiceType
this.createFlyTextHook = Hook.FromAddress(this.Address.CreateFlyText, this.CreateFlyTextDetour);
}
- ///
- /// The delegate defining the type for the FlyText event.
- ///
- /// The FlyTextKind. See .
- /// Value1 passed to the native flytext function.
- /// Value2 passed to the native flytext function. Seems unused.
- /// Text1 passed to the native flytext function.
- /// Text2 passed to the native flytext function.
- /// Color passed to the native flytext function. Changes flytext color.
- /// Icon ID passed to the native flytext function. Only displays with select FlyTextKind.
- /// Damage Type Icon ID passed to the native flytext function. Displayed next to damage values to denote damage type.
- /// The vertical offset to place the flytext at. 0 is default. Negative values result
- /// in text appearing higher on the screen. This does not change where the element begins to fade.
- /// Whether this flytext has been handled. If a subscriber sets this to true, the FlyText will not appear.
- public delegate void OnFlyTextCreatedDelegate(
- ref FlyTextKind kind,
- ref int val1,
- ref int val2,
- ref SeString text1,
- ref SeString text2,
- ref uint color,
- ref uint icon,
- ref uint damageTypeIcon,
- ref float yOffset,
- ref bool handled);
-
///
/// Private delegate for the native CreateFlyText function's hook.
///
@@ -95,12 +69,8 @@ public sealed class FlyTextGui : IDisposable, IServiceType
uint offsetStrMax,
int unknown);
- ///
- /// The FlyText event that can be subscribed to.
- ///
- public event OnFlyTextCreatedDelegate? FlyTextCreated;
-
- private Dalamud Dalamud { get; }
+ ///
+ public event IFlyTextGui.OnFlyTextCreatedDelegate? FlyTextCreated;
private FlyTextGuiAddressResolver Address { get; }
@@ -112,18 +82,7 @@ public sealed class FlyTextGui : IDisposable, IServiceType
this.createFlyTextHook.Dispose();
}
- ///
- /// Displays a fly text in-game on the local player.
- ///
- /// The FlyTextKind. See .
- /// The index of the actor to place flytext on. Indexing unknown. 1 places flytext on local player.
- /// Value1 passed to the native flytext function.
- /// Value2 passed to the native flytext function. Seems unused.
- /// Text1 passed to the native flytext function.
- /// Text2 passed to the native flytext function.
- /// Color passed to the native flytext function. Changes flytext color.
- /// Icon ID passed to the native flytext function. Only displays with select FlyTextKind.
- /// Damage Type Icon ID passed to the native flytext function. Displayed next to damage values to denote damage type.
+ ///
public unsafe void AddFlyText(FlyTextKind kind, uint actorIndex, uint val1, uint val2, SeString text1, SeString text2, uint color, uint icon, uint damageTypeIcon)
{
// Known valid flytext region within the atk arrays
@@ -318,3 +277,44 @@ public sealed class FlyTextGui : IDisposable, IServiceType
return retVal;
}
}
+
+///
+/// Plugin scoped version of FlyTextGui.
+///
+[PluginInterface]
+[InterfaceVersion("1.0")]
+[ServiceManager.ScopedService]
+#pragma warning disable SA1015
+[ResolveVia]
+#pragma warning restore SA1015
+internal class FlyTextGuiPluginScoped : IDisposable, IServiceType, IFlyTextGui
+{
+ [ServiceManager.ServiceDependency]
+ private readonly FlyTextGui flyTextGuiService = Service.Get();
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ internal FlyTextGuiPluginScoped()
+ {
+ this.flyTextGuiService.FlyTextCreated += this.FlyTextCreatedForward;
+ }
+
+ ///
+ public event IFlyTextGui.OnFlyTextCreatedDelegate? FlyTextCreated;
+
+ ///
+ public void Dispose()
+ {
+ this.flyTextGuiService.FlyTextCreated -= this.FlyTextCreatedForward;
+ }
+
+ ///
+ public void AddFlyText(FlyTextKind kind, uint actorIndex, uint val1, uint val2, SeString text1, SeString text2, uint color, uint icon, uint damageTypeIcon)
+ {
+ this.flyTextGuiService.AddFlyText(kind, actorIndex, val1, val2, text1, text2, color, icon, damageTypeIcon);
+ }
+
+ private void FlyTextCreatedForward(ref FlyTextKind kind, ref int val1, ref int val2, ref SeString text1, ref SeString text2, ref uint color, ref uint icon, ref uint damageTypeIcon, ref float yOffset, ref bool handled)
+ => this.FlyTextCreated?.Invoke(ref kind, ref val1, ref val2, ref text1, ref text2, ref color, ref icon, ref damageTypeIcon, ref yOffset, ref handled);
+}
diff --git a/Dalamud/Plugin/Services/IFlyTextGui.cs b/Dalamud/Plugin/Services/IFlyTextGui.cs
new file mode 100644
index 000000000..04fae351d
--- /dev/null
+++ b/Dalamud/Plugin/Services/IFlyTextGui.cs
@@ -0,0 +1,55 @@
+using Dalamud.Game.Gui.FlyText;
+using Dalamud.Game.Text.SeStringHandling;
+
+namespace Dalamud.Plugin.Services;
+
+///
+/// This class facilitates interacting with and creating native in-game "fly text".
+///
+public interface IFlyTextGui
+{
+ ///
+ /// The delegate defining the type for the FlyText event.
+ ///
+ /// The FlyTextKind. See .
+ /// Value1 passed to the native flytext function.
+ /// Value2 passed to the native flytext function. Seems unused.
+ /// Text1 passed to the native flytext function.
+ /// Text2 passed to the native flytext function.
+ /// Color passed to the native flytext function. Changes flytext color.
+ /// Icon ID passed to the native flytext function. Only displays with select FlyTextKind.
+ /// Damage Type Icon ID passed to the native flytext function. Displayed next to damage values to denote damage type.
+ /// The vertical offset to place the flytext at. 0 is default. Negative values result
+ /// in text appearing higher on the screen. This does not change where the element begins to fade.
+ /// Whether this flytext has been handled. If a subscriber sets this to true, the FlyText will not appear.
+ public delegate void OnFlyTextCreatedDelegate(
+ ref FlyTextKind kind,
+ ref int val1,
+ ref int val2,
+ ref SeString text1,
+ ref SeString text2,
+ ref uint color,
+ ref uint icon,
+ ref uint damageTypeIcon,
+ ref float yOffset,
+ ref bool handled);
+
+ ///
+ /// The FlyText event that can be subscribed to.
+ ///
+ public event OnFlyTextCreatedDelegate? FlyTextCreated;
+
+ ///
+ /// Displays a fly text in-game on the local player.
+ ///
+ /// The FlyTextKind. See .
+ /// The index of the actor to place flytext on. Indexing unknown. 1 places flytext on local player.
+ /// Value1 passed to the native flytext function.
+ /// Value2 passed to the native flytext function. Seems unused.
+ /// Text1 passed to the native flytext function.
+ /// Text2 passed to the native flytext function.
+ /// Color passed to the native flytext function. Changes flytext color.
+ /// Icon ID passed to the native flytext function. Only displays with select FlyTextKind.
+ /// Damage Type Icon ID passed to the native flytext function. Displayed next to damage values to denote damage type.
+ public void AddFlyText(FlyTextKind kind, uint actorIndex, uint val1, uint val2, SeString text1, SeString text2, uint color, uint icon, uint damageTypeIcon);
+}