From 3fa8968027fca50f0cda20ba72b63db0df93a3b8 Mon Sep 17 00:00:00 2001 From: MidoriKami <9083275+MidoriKami@users.noreply.github.com> Date: Sat, 24 Jun 2023 21:07:17 -0700 Subject: [PATCH] Add IDtrBar (#1276) --- Dalamud/Game/Gui/Dtr/DtrBar.cs | 19 ++++++++----------- Dalamud/Plugin/Services/IDtrBar.cs | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 Dalamud/Plugin/Services/IDtrBar.cs diff --git a/Dalamud/Game/Gui/Dtr/DtrBar.cs b/Dalamud/Game/Gui/Dtr/DtrBar.cs index d77b406f0..dd1e7aa30 100644 --- a/Dalamud/Game/Gui/Dtr/DtrBar.cs +++ b/Dalamud/Game/Gui/Dtr/DtrBar.cs @@ -6,6 +6,7 @@ using Dalamud.Configuration.Internal; using Dalamud.Game.Text.SeStringHandling; using Dalamud.IoC; using Dalamud.IoC.Internal; +using Dalamud.Plugin.Services; using FFXIVClientStructs.FFXIV.Client.System.Memory; using FFXIVClientStructs.FFXIV.Component.GUI; using Serilog; @@ -18,7 +19,10 @@ namespace Dalamud.Game.Gui.Dtr; [PluginInterface] [InterfaceVersion("1.0")] [ServiceManager.BlockingEarlyLoadedService] -public sealed unsafe class DtrBar : IDisposable, IServiceType +#pragma warning disable SA1015 +[ResolveVia] +#pragma warning restore SA1015 +public sealed unsafe class DtrBar : IDisposable, IServiceType, IDtrBar { private const uint BaseNodeId = 1000; @@ -44,14 +48,7 @@ public sealed unsafe class DtrBar : IDisposable, IServiceType this.configuration.QueueSave(); } - /// - /// Get a DTR bar entry. - /// This allows you to add your own text, and users to sort it. - /// - /// A user-friendly name for sorting. - /// The text the entry shows. - /// The entry object used to update, hide and remove the entry. - /// Thrown when an entry with the specified title exists. + /// public DtrBarEntry Get(string title, SeString? text = null) { if (this.entries.Any(x => x.Title == title)) @@ -134,7 +131,7 @@ public sealed unsafe class DtrBar : IDisposable, IServiceType }); } - private AtkUnitBase* GetDtr() => (AtkUnitBase*)this.gameGui.GetAddonByName("_DTR", 1).ToPointer(); + private AtkUnitBase* GetDtr() => (AtkUnitBase*)this.gameGui.GetAddonByName("_DTR").ToPointer(); private void Update(Framework unused) { @@ -293,7 +290,7 @@ public sealed unsafe class DtrBar : IDisposable, IServiceType newTextNode->AtkResNode.NodeID = nodeId; newTextNode->AtkResNode.Type = NodeType.Text; - newTextNode->AtkResNode.Flags = (short)(NodeFlags.AnchorLeft | NodeFlags.AnchorTop); + newTextNode->AtkResNode.NodeFlags = NodeFlags.AnchorLeft | NodeFlags.AnchorTop; newTextNode->AtkResNode.DrawFlags = 12; newTextNode->AtkResNode.SetWidth(22); newTextNode->AtkResNode.SetHeight(22); diff --git a/Dalamud/Plugin/Services/IDtrBar.cs b/Dalamud/Plugin/Services/IDtrBar.cs new file mode 100644 index 000000000..6c2b8ad1e --- /dev/null +++ b/Dalamud/Plugin/Services/IDtrBar.cs @@ -0,0 +1,22 @@ +using System; + +using Dalamud.Game.Gui.Dtr; +using Dalamud.Game.Text.SeStringHandling; + +namespace Dalamud.Plugin.Services; + +/// +/// Class used to interface with the server info bar. +/// +public interface IDtrBar +{ + /// + /// Get a DTR bar entry. + /// This allows you to add your own text, and users to sort it. + /// + /// A user-friendly name for sorting. + /// The text the entry shows. + /// The entry object used to update, hide and remove the entry. + /// Thrown when an entry with the specified title exists. + public DtrBarEntry Get(string title, SeString? text = null); +}