using Dalamud.Game.Addon.Lifecycle.AddonArgTypes;
using Dalamud.Game.ClientState.Objects;
using FFXIVClientStructs.FFXIV.Client.UI;
using FFXIVClientStructs.FFXIV.Component.GUI;
namespace Dalamud.Game.Gui.NamePlate;
///
/// Contains information related to the pending nameplate data update. This is only valid for a single frame and should
/// not be kept across frames.
///
public interface INamePlateUpdateContext
{
///
/// Gets the number of active nameplates. The actual number visible may be lower than this in cases where some
/// nameplates are hidden by default (based on in-game "Display Name Settings" and so on).
///
int ActiveNamePlateCount { get; }
///
/// Gets a value indicating whether the game is currently performing a full update of all active nameplates.
///
bool IsFullUpdate { get; }
///
/// Gets the address of the NamePlate addon.
///
nint AddonAddress { get; }
///
/// Gets the address of the NamePlate addon's number array data container.
///
nint NumberArrayDataAddress { get; }
///
/// Gets the address of the NamePlate addon's string array data container.
///
nint StringArrayDataAddress { get; }
///
/// Gets the address of the first entry in the NamePlate addon's int array.
///
nint NumberArrayDataEntryAddress { get; }
}
///
/// Contains information related to the pending nameplate data update. This is only valid for a single frame and should
/// not be kept across frames.
///
internal unsafe class NamePlateUpdateContext : INamePlateUpdateContext
{
///
/// Initializes a new instance of the class.
///
/// An object table.
/// The addon lifecycle arguments for the update request.
internal NamePlateUpdateContext(ObjectTable objectTable, AddonRequestedUpdateArgs args)
{
this.ObjectTable = objectTable;
this.RaptureAtkModule = FFXIVClientStructs.FFXIV.Client.UI.RaptureAtkModule.Instance();
this.Ui3DModule = UIModule.Instance()->GetUI3DModule();
this.ResetState(args);
}
///
/// Gets the number of active nameplates. The actual number visible may be lower than this in cases where some
/// nameplates are hidden by default (based on in-game "Display Name Settings" and so on).
///
public int ActiveNamePlateCount { get; private set; }
///
/// Gets a value indicating whether the game is currently performing a full update of all active nameplates.
///
public bool IsFullUpdate { get; private set; }
///
/// Gets the address of the NamePlate addon.
///
public nint AddonAddress => (nint)this.Addon;
///
/// Gets the address of the NamePlate addon's number array data container.
///
public nint NumberArrayDataAddress => (nint)this.NumberData;
///
/// Gets the address of the NamePlate addon's string array data container.
///
public nint StringArrayDataAddress => (nint)this.StringData;
///
/// Gets the address of the first entry in the NamePlate addon's int array.
///
public nint NumberArrayDataEntryAddress => (nint)this.NumberStruct;
///
/// Gets the RaptureAtkModule.
///
internal RaptureAtkModule* RaptureAtkModule { get; }
///
/// Gets the Ui3DModule.
///
internal UI3DModule* Ui3DModule { get; }
///
/// Gets the ObjectTable.
///
internal ObjectTable ObjectTable { get; }
///
/// Gets a pointer to the NamePlate addon.
///
internal AddonNamePlate* Addon { get; private set; }
///
/// Gets a pointer to the NamePlate addon's number array data container.
///
internal NumberArrayData* NumberData { get; private set; }
///
/// Gets a pointer to the NamePlate addon's string array data container.
///
internal StringArrayData* StringData { get; private set; }
///
/// Gets a pointer to the NamePlate addon's number array entries as a struct.
///
internal AddonNamePlate.NamePlateIntArrayData* NumberStruct { get; private set; }
///
/// Gets or sets a value indicating whether any handler in the current context has instantiated a part builder.
///
internal bool HasParts { get; set; }
///
/// Resets the state of the context based on the provided addon lifecycle arguments.
///
/// The addon lifecycle arguments for the update request.
internal void ResetState(AddonRequestedUpdateArgs args)
{
this.Addon = (AddonNamePlate*)args.Addon;
this.NumberData = ((NumberArrayData**)args.NumberArrayData)![NamePlateGui.NumberArrayIndex];
this.NumberStruct = (AddonNamePlate.NamePlateIntArrayData*)this.NumberData->IntArray;
this.StringData = ((StringArrayData**)args.StringArrayData)![NamePlateGui.StringArrayIndex];
this.HasParts = false;
this.ActiveNamePlateCount = this.NumberStruct->ActiveNamePlateCount;
this.IsFullUpdate = this.Addon->DoFullUpdate != 0;
}
}