Add AddonLifecycle Service (#1361)

Adds new service to manage addon lifecycle events, such as setup/teardown.
This commit is contained in:
MidoriKami 2023-08-28 21:56:31 -07:00 committed by GitHub
parent 49bffccf82
commit efefcd70cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 246 additions and 0 deletions

View file

@ -0,0 +1,50 @@
using System;
using Dalamud.Memory;
using FFXIVClientStructs.FFXIV.Component.GUI;
namespace Dalamud.Plugin.Services;
/// <summary>
/// This class provides events for in-game addon lifecycles.
/// </summary>
public interface IAddonLifecycle
{
/// <summary>
/// Event that fires before an addon is being setup.
/// </summary>
public event Action<AddonArgs> AddonPreSetup;
/// <summary>
/// Event that fires after an addon is done being setup.
/// </summary>
public event Action<AddonArgs> AddonPostSetup;
/// <summary>
/// Event that fires before an addon is being finalized.
/// </summary>
public event Action<AddonArgs> AddonPreFinalize;
/// <summary>
/// Event that fires after an addon is done being finalized.
/// </summary>
public event Action<AddonArgs> AddonPostFinalize;
/// <summary>
/// Addon argument data for use in event subscribers.
/// </summary>
public unsafe class AddonArgs
{
private string? addonName;
/// <summary>
/// Gets the name of the addon this args referrers to.
/// </summary>
public string AddonName => this.addonName ??= MemoryHelper.ReadString((nint)((AtkUnitBase*)this.Addon)->Name, 0x20);
/// <summary>
/// Gets the pointer to the addons AtkUnitBase.
/// </summary>
required public nint Addon { get; init; }
}
}