Skip to content

Commit

Permalink
Merge pull request #1369 from MidoriKami/DTRBarEnhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
goaaats authored Sep 17, 2023
2 parents 452cf78 + f1c8201 commit 0f74c8e
Show file tree
Hide file tree
Showing 10 changed files with 952 additions and 38 deletions.
97 changes: 97 additions & 0 deletions Dalamud/Game/AddonEventManager/AddonCursorType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
namespace Dalamud.Game.AddonEventManager;

/// <summary>
/// Reimplementation of CursorType.
/// </summary>
public enum AddonCursorType
{
/// <summary>
/// Arrow.
/// </summary>
Arrow,

/// <summary>
/// Boot.
/// </summary>
Boot,

/// <summary>
/// Search.
/// </summary>
Search,

/// <summary>
/// Chat Pointer.
/// </summary>
ChatPointer,

/// <summary>
/// Interact.
/// </summary>
Interact,

/// <summary>
/// Attack.
/// </summary>
Attack,

/// <summary>
/// Hand.
/// </summary>
Hand,

/// <summary>
/// Resizeable Left-Right.
/// </summary>
ResizeWE,

/// <summary>
/// Resizeable Up-Down.
/// </summary>
ResizeNS,

/// <summary>
/// Resizeable.
/// </summary>
ResizeNWSR,

/// <summary>
/// Resizeable 4-way.
/// </summary>
ResizeNESW,

/// <summary>
/// Clickable.
/// </summary>
Clickable,

/// <summary>
/// Text Input.
/// </summary>
TextInput,

/// <summary>
/// Text Click.
/// </summary>
TextClick,

/// <summary>
/// Grab.
/// </summary>
Grab,

/// <summary>
/// Chat Bubble.
/// </summary>
ChatBubble,

/// <summary>
/// No Access.
/// </summary>
NoAccess,

/// <summary>
/// Hidden.
/// </summary>
Hidden,
}
87 changes: 87 additions & 0 deletions Dalamud/Game/AddonEventManager/AddonEventListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System;
using System.Runtime.InteropServices;

using FFXIVClientStructs.FFXIV.Component.GUI;

namespace Dalamud.Game.AddonEventManager;

/// <summary>
/// Event listener class for managing custom events.
/// </summary>
// Custom event handler tech provided by Pohky, implemented by MidoriKami
internal unsafe class AddonEventListener : IDisposable
{
private ReceiveEventDelegate? receiveEventDelegate;

private AtkEventListener* eventListener;

/// <summary>
/// Initializes a new instance of the <see cref="AddonEventListener"/> class.
/// </summary>
/// <param name="eventHandler">The managed handler to send events to.</param>
public AddonEventListener(ReceiveEventDelegate eventHandler)
{
this.receiveEventDelegate = eventHandler;

this.eventListener = (AtkEventListener*)Marshal.AllocHGlobal(sizeof(AtkEventListener));
this.eventListener->vtbl = (void*)Marshal.AllocHGlobal(sizeof(void*) * 3);
this.eventListener->vfunc[0] = (delegate* unmanaged<void>)&NullSub;
this.eventListener->vfunc[1] = (delegate* unmanaged<void>)&NullSub;
this.eventListener->vfunc[2] = (void*)Marshal.GetFunctionPointerForDelegate(this.receiveEventDelegate);
}

/// <summary>
/// Delegate for receiving custom events.
/// </summary>
/// <param name="self">Pointer to the event listener.</param>
/// <param name="eventType">Event type.</param>
/// <param name="eventParam">Unique Id for this event.</param>
/// <param name="eventData">Event Data.</param>
/// <param name="unknown">Unknown Parameter.</param>
public delegate void ReceiveEventDelegate(AtkEventListener* self, AtkEventType eventType, uint eventParam, AtkEvent* eventData, nint unknown);

/// <inheritdoc />
public void Dispose()
{
if (this.eventListener is null) return;

Marshal.FreeHGlobal((nint)this.eventListener->vtbl);
Marshal.FreeHGlobal((nint)this.eventListener);

this.eventListener = null;
this.receiveEventDelegate = null;
}

/// <summary>
/// Register an event to this event handler.
/// </summary>
/// <param name="addon">Addon that triggers this event.</param>
/// <param name="node">Node to attach event to.</param>
/// <param name="eventType">Event type to trigger this event.</param>
/// <param name="param">Unique id for this event.</param>
public void RegisterEvent(AtkUnitBase* addon, AtkResNode* node, AtkEventType eventType, uint param)
{
if (node is null) return;

node->AddEvent(eventType, param, this.eventListener, (AtkResNode*)addon, false);
}

/// <summary>
/// Unregister an event from this event handler.
/// </summary>
/// <param name="node">Node to remove the event from.</param>
/// <param name="eventType">Event type that this event is for.</param>
/// <param name="param">Unique id for this event.</param>
public void UnregisterEvent(AtkResNode* node, AtkEventType eventType, uint param)
{
if (node is null) return;

node->RemoveEvent(eventType, param, this.eventListener, false);
}

[UnmanagedCallersOnly]
private static void NullSub()
{
/* do nothing */
}
}
Loading

0 comments on commit 0f74c8e

Please sign in to comment.