-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1369 from MidoriKami/DTRBarEnhancements
- Loading branch information
Showing
10 changed files
with
952 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ | ||
} | ||
} |
Oops, something went wrong.