mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-02 13:53:40 +01:00
Scope DTRBar
This commit is contained in:
parent
166669597d
commit
692113958b
2 changed files with 62 additions and 3 deletions
|
|
@ -26,9 +26,6 @@ namespace Dalamud.Game.Gui.Dtr;
|
||||||
[PluginInterface]
|
[PluginInterface]
|
||||||
[InterfaceVersion("1.0")]
|
[InterfaceVersion("1.0")]
|
||||||
[ServiceManager.BlockingEarlyLoadedService]
|
[ServiceManager.BlockingEarlyLoadedService]
|
||||||
#pragma warning disable SA1015
|
|
||||||
[ResolveVia<IDtrBar>]
|
|
||||||
#pragma warning restore SA1015
|
|
||||||
public sealed unsafe class DtrBar : IDisposable, IServiceType, IDtrBar
|
public sealed unsafe class DtrBar : IDisposable, IServiceType, IDtrBar
|
||||||
{
|
{
|
||||||
private const uint BaseNodeId = 1000;
|
private const uint BaseNodeId = 1000;
|
||||||
|
|
@ -95,6 +92,15 @@ public sealed unsafe class DtrBar : IDisposable, IServiceType, IDtrBar
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public void Remove(string title)
|
||||||
|
{
|
||||||
|
if (this.entries.FirstOrDefault(entry => entry.Title == title) is { } dtrBarEntry)
|
||||||
|
{
|
||||||
|
dtrBarEntry.Remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
void IDisposable.Dispose()
|
void IDisposable.Dispose()
|
||||||
{
|
{
|
||||||
|
|
@ -497,3 +503,50 @@ public sealed unsafe class DtrBar : IDisposable, IServiceType, IDtrBar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Plugin-scoped version of a AddonEventManager service.
|
||||||
|
/// </summary>
|
||||||
|
[PluginInterface]
|
||||||
|
[InterfaceVersion("1.0")]
|
||||||
|
[ServiceManager.ScopedService]
|
||||||
|
#pragma warning disable SA1015
|
||||||
|
[ResolveVia<IDtrBar>]
|
||||||
|
#pragma warning restore SA1015
|
||||||
|
internal class DtrBarPluginScoped : IDisposable, IServiceType, IDtrBar
|
||||||
|
{
|
||||||
|
[ServiceManager.ServiceDependency]
|
||||||
|
private readonly DtrBar dtrBarService = Service<DtrBar>.Get();
|
||||||
|
|
||||||
|
private readonly Dictionary<string, DtrBarEntry> pluginEntries = new();
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
foreach (var entry in this.pluginEntries)
|
||||||
|
{
|
||||||
|
entry.Value.Remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.pluginEntries.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public DtrBarEntry Get(string title, SeString? text = null)
|
||||||
|
{
|
||||||
|
// If we already have a known entry for this plugin, return it.
|
||||||
|
if (this.pluginEntries.TryGetValue(title, out var existingEntry)) return existingEntry;
|
||||||
|
|
||||||
|
return this.pluginEntries[title] = this.dtrBarService.Get(title, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public void Remove(string title)
|
||||||
|
{
|
||||||
|
if (this.pluginEntries.TryGetValue(title, out var existingEntry))
|
||||||
|
{
|
||||||
|
existingEntry.Remove();
|
||||||
|
this.pluginEntries.Remove(title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,4 +19,10 @@ public interface IDtrBar
|
||||||
/// <returns>The entry object used to update, hide and remove the entry.</returns>
|
/// <returns>The entry object used to update, hide and remove the entry.</returns>
|
||||||
/// <exception cref="ArgumentException">Thrown when an entry with the specified title exists.</exception>
|
/// <exception cref="ArgumentException">Thrown when an entry with the specified title exists.</exception>
|
||||||
public DtrBarEntry Get(string title, SeString? text = null);
|
public DtrBarEntry Get(string title, SeString? text = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a DTR bar entry from the system.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="title">Title of the entry to remove.</param>
|
||||||
|
public void Remove(string title);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue