From dfd0f1949031b5e7b252bb6b702431395d18575a Mon Sep 17 00:00:00 2001 From: MidoriKami Date: Sat, 26 Jul 2025 11:12:03 -0700 Subject: [PATCH] Let's just break things and make them really nice --- .../{ => EventDataTypes}/AddonEventData.cs | 28 ++++++- .../EventDataTypes/AddonMouseEventData.cs | 82 +++++++++++++++++++ .../Addon/Events/PluginEventController.cs | 1 + Dalamud/Game/Gui/Dtr/DtrBar.cs | 20 +---- Dalamud/Game/Gui/Dtr/DtrBarEntry.cs | 60 ++------------ Dalamud/Plugin/Services/IAddonEventManager.cs | 23 +++++- 6 files changed, 140 insertions(+), 74 deletions(-) rename Dalamud/Game/Addon/Events/{ => EventDataTypes}/AddonEventData.cs (59%) create mode 100644 Dalamud/Game/Addon/Events/EventDataTypes/AddonMouseEventData.cs diff --git a/Dalamud/Game/Addon/Events/AddonEventData.cs b/Dalamud/Game/Addon/Events/EventDataTypes/AddonEventData.cs similarity index 59% rename from Dalamud/Game/Addon/Events/AddonEventData.cs rename to Dalamud/Game/Addon/Events/EventDataTypes/AddonEventData.cs index 3a5c05660..423bf5eb9 100644 --- a/Dalamud/Game/Addon/Events/AddonEventData.cs +++ b/Dalamud/Game/Addon/Events/EventDataTypes/AddonEventData.cs @@ -1,10 +1,32 @@ -namespace Dalamud.Game.Addon.Events; +namespace Dalamud.Game.Addon.Events.EventDataTypes; /// /// Object representing data that is relevant in handling native events. /// public class AddonEventData { + /// + /// Initializes a new instance of the class. + /// + internal AddonEventData() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Other event data to copy. + internal AddonEventData(AddonEventData eventData) + { + this.AtkEventType = eventData.AtkEventType; + this.Param = eventData.Param; + this.AtkEventPointer = eventData.AtkEventPointer; + this.AtkEventDataPointer = eventData.AtkEventDataPointer; + this.AddonPointer = eventData.AddonPointer; + this.NodeTargetPointer = eventData.NodeTargetPointer; + this.AtkEventListener = eventData.AtkEventListener; + } + /// /// Gets the AtkEventType for this event. /// @@ -18,8 +40,8 @@ public class AddonEventData /// /// Gets the pointer to the AtkEvent object for this event. /// - /// Note: This is not a pointer to the AtkEventData object.

- /// Warning: AtkEvent->Node has been modified to be the AtkUnitBase*, and AtkEvent->Target has been modified to be the AtkResNode* that triggered this event. + /// Note: This is not a pointer to the AtkEventData object.

+ /// Warning: AtkEvent->Node has been modified to be the AtkUnitBase*, and AtkEvent->Target has been modified to be the AtkResNode* that triggered this event.
public nint AtkEventPointer { get; internal set; } /// diff --git a/Dalamud/Game/Addon/Events/EventDataTypes/AddonMouseEventData.cs b/Dalamud/Game/Addon/Events/EventDataTypes/AddonMouseEventData.cs new file mode 100644 index 000000000..7dff37e95 --- /dev/null +++ b/Dalamud/Game/Addon/Events/EventDataTypes/AddonMouseEventData.cs @@ -0,0 +1,82 @@ +using System.Numerics; + +using FFXIVClientStructs.FFXIV.Component.GUI; + +using AtkMouseData = FFXIVClientStructs.FFXIV.Component.GUI.AtkEventData.AtkMouseData; +using ModifierFlag = FFXIVClientStructs.FFXIV.Component.GUI.AtkEventData.AtkMouseData.ModifierFlag; + +namespace Dalamud.Game.Addon.Events.EventDataTypes; + +/// +public unsafe class AddonMouseEventData : AddonEventData +{ + /// + /// Initializes a new instance of the class. + /// + internal AddonMouseEventData() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Other event data to copy. + internal AddonMouseEventData(AddonEventData eventData) + : base(eventData) + { + } + + /// + /// Gets a value indicating whether the event was a Left Mouse Click + /// + public bool IsLeftClick => this.MouseData.ButtonId is 0; + + /// + /// Gets a value indicating whether the event was a Right Mouse Click + /// + public bool IsRightClick => this.MouseData.ButtonId is 1; + + /// + /// Gets a value indicating whether there are any modifiers set such as alt, control, shift, or dragging + /// + public bool IsNoModifier => this.MouseData.Modifier is 0; + + /// + /// Gets a value indicating whether alt was being held when this event triggered + /// + public bool IsAltHeld => this.MouseData.Modifier.HasFlag(ModifierFlag.Alt); + + /// + /// Gets a value indicating whether control was being held when this event triggered + /// + public bool IsControlHeld => this.MouseData.Modifier.HasFlag(ModifierFlag.Ctrl); + + /// + /// Gets a value indicating whether shift was being held when this event triggered + /// + public bool IsShiftHeld => this.MouseData.Modifier.HasFlag(ModifierFlag.Shift); + + /// + /// Gets a value indicating whether this event is a mouse drag or not + /// + public bool IsDragging => this.MouseData.Modifier.HasFlag(ModifierFlag.Dragging); + + /// + /// Gets a value indicating whether the event was a scroll up + /// + public bool IsScrollUp => this.MouseData.WheelDirection is 1; + + /// + /// Gets a value indicating whether the event was a scroll down + /// + public bool IsScrollDown => this.MouseData.WheelDirection is -1; + + /// + /// Gets the position of the mouse when this event was triggered + /// + public Vector2 Position => new(this.MouseData.PosX, this.MouseData.PosY); + + private AtkEventData* AtkEventData => (AtkEventData*)this.AtkEventDataPointer; + + private AtkMouseData MouseData => this.AtkEventData->MouseData; +} diff --git a/Dalamud/Game/Addon/Events/PluginEventController.cs b/Dalamud/Game/Addon/Events/PluginEventController.cs index b1251855b..181169de0 100644 --- a/Dalamud/Game/Addon/Events/PluginEventController.cs +++ b/Dalamud/Game/Addon/Events/PluginEventController.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; +using Dalamud.Game.Addon.Events.EventDataTypes; using Dalamud.Game.Gui; using Dalamud.Logging.Internal; using Dalamud.Plugin.Services; diff --git a/Dalamud/Game/Gui/Dtr/DtrBar.cs b/Dalamud/Game/Gui/Dtr/DtrBar.cs index 54c3b2f95..b637791f0 100644 --- a/Dalamud/Game/Gui/Dtr/DtrBar.cs +++ b/Dalamud/Game/Gui/Dtr/DtrBar.cs @@ -5,6 +5,7 @@ using System.Threading; using Dalamud.Configuration.Internal; using Dalamud.Game.Addon.Events; +using Dalamud.Game.Addon.Events.EventDataTypes; using Dalamud.Game.Addon.Lifecycle; using Dalamud.Game.Addon.Lifecycle.AddonArgTypes; using Dalamud.Game.Text.SeStringHandling; @@ -628,7 +629,7 @@ internal sealed unsafe class DtrBar : IInternalDisposableService, IDtrBar } } - if (dtrBarEntry is not null) + if (dtrBarEntry is { OnClick: not null }) { switch (atkEventType) { @@ -641,22 +642,7 @@ internal sealed unsafe class DtrBar : IInternalDisposableService, IDtrBar break; case AddonEventType.MouseClick: - dtrBarEntry.OnClick?.Invoke(); - dtrBarEntry.OnClicked?.Invoke(eventData); - - var dataPointer = (AtkEventData*)eventData.AtkEventDataPointer; - var mouseData = dataPointer->MouseData; - - if (mouseData.ButtonId is 0) - { - dtrBarEntry.OnLeftClick?.Invoke(); - } - - if (mouseData.ButtonId is 1) - { - dtrBarEntry.OnRightClick?.Invoke(); - } - + dtrBarEntry.OnClick?.Invoke(new AddonMouseEventData(eventData)); break; } } diff --git a/Dalamud/Game/Gui/Dtr/DtrBarEntry.cs b/Dalamud/Game/Gui/Dtr/DtrBarEntry.cs index 2b9634588..54847705d 100644 --- a/Dalamud/Game/Gui/Dtr/DtrBarEntry.cs +++ b/Dalamud/Game/Gui/Dtr/DtrBarEntry.cs @@ -1,5 +1,5 @@ using Dalamud.Configuration.Internal; -using Dalamud.Game.Addon.Events; +using Dalamud.Game.Addon.Events.EventDataTypes; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Plugin.Internal.Types; using Dalamud.Utility; @@ -43,13 +43,6 @@ public interface IReadOnlyDtrBarEntry /// Gets a value indicating whether the user has hidden this entry from view through the Dalamud settings. /// public bool UserHidden { get; } - - /// - /// Triggers the click action of this entry. - /// - /// True, if a click action was registered and executed. - [Api13ToDo("Remove, doesn't mesh well with new click actions")] - public bool TriggerClickAction(); } /// @@ -73,25 +66,9 @@ public interface IDtrBarEntry : IReadOnlyDtrBarEntry public new bool Shown { get; set; } /// - /// Gets or sets a action to be invoked when the user clicks on the dtr entry. + /// Gets or sets an action to be invoked when the user clicks on the dtr entry. /// - [Api13ToDo("Remove this, and rename OnClicked to OnClick")] - public Action? OnClick { get; set; } - - /// - /// Gets or sets a action to be invoked when the user left-clicks on the dtr entry. - /// - public Action? OnLeftClick { get; set; } - - /// - /// Gets or sets a action to be invoked when the user right-clicks on the dtr entry. - /// - public Action? OnRightClick { get; set; } - - /// - /// Gets or sets a action to be invoked when the user clicks on the dtr entry. - /// - public Action? OnClicked { get; set; } + public Action? OnClick { get; set; } /// /// Remove this entry from the bar. @@ -140,23 +117,11 @@ internal sealed unsafe class DtrBarEntry : IDisposable, IDtrBarEntry /// public SeString? Tooltip { get; set; } - /// - /// Gets or sets a action to be invoked when the user clicks on the dtr entry. - /// - [Api13ToDo("Remove this and rename OnClicked to OnClick")] - public Action? OnClick { get; set; } + /// + public Action? OnClick { get; set; } /// - public Action? OnLeftClick { get; set; } - - /// - public Action? OnRightClick { get; set; } - - /// - public Action? OnClicked { get; set; } - - /// - public bool HasClickAction => this.OnClick != null || this.OnLeftClick != null || this.OnRightClick != null || this.OnClicked != null; + public bool HasClickAction => this.OnClick != null; /// public bool Shown @@ -173,7 +138,7 @@ internal sealed unsafe class DtrBarEntry : IDisposable, IDtrBarEntry } /// - [Api13ToDo("Maybe make this config scoped to internalname?")] + [Api13ToDo("Maybe make this config scoped to internal name?")] public bool UserHidden => this.configuration.DtrIgnore?.Contains(this.Title) ?? false; /// @@ -206,17 +171,6 @@ internal sealed unsafe class DtrBarEntry : IDisposable, IDtrBarEntry /// internal LocalPlugin? OwnerPlugin { get; set; } - /// - [Api13ToDo("Remove, doesn't mesh well with new click actions")] - public bool TriggerClickAction() - { - if (this.OnClick == null) - return false; - - this.OnClick.Invoke(); - return true; - } - /// /// Remove this entry from the bar. /// You will need to re-acquire it from DtrBar to reuse it. diff --git a/Dalamud/Plugin/Services/IAddonEventManager.cs b/Dalamud/Plugin/Services/IAddonEventManager.cs index e50548c58..ba8ec59e5 100644 --- a/Dalamud/Plugin/Services/IAddonEventManager.cs +++ b/Dalamud/Plugin/Services/IAddonEventManager.cs @@ -1,4 +1,5 @@ -using Dalamud.Game.Addon.Events; +using Dalamud.Game.Addon.Events; +using Dalamud.Game.Addon.Events.EventDataTypes; namespace Dalamud.Plugin.Services; @@ -7,6 +8,15 @@ namespace Dalamud.Plugin.Services; /// public interface IAddonEventManager { + /// + /// Delegate to be called when an event is received. + /// + /// Event type for this event handler. + /// The parent addon for this event handler. + /// The specific node that will trigger this event handler. + [Obsolete("Use AddonEventDelegate instead")] + public delegate void AddonEventHandler(AddonEventType atkEventType, nint atkUnitBase, nint atkResNode); + /// /// Delegate to be called when an event is received. /// @@ -14,6 +24,17 @@ public interface IAddonEventManager /// The event data object for use in handling this event. public delegate void AddonEventDelegate(AddonEventType atkEventType, AddonEventData data); + /// + /// Registers an event handler for the specified addon, node, and type. + /// + /// The parent addon for this event. + /// The node that will trigger this event. + /// The event type for this event. + /// The handler to call when event is triggered. + /// IAddonEventHandle used to remove the event. Null if no event was added. + [Obsolete("Use AddEvent with AddonEventDelegate instead of AddonEventHandler")] + IAddonEventHandle? AddEvent(nint atkUnitBase, nint atkResNode, AddonEventType eventType, AddonEventHandler eventHandler); + /// /// Registers an event handler for the specified addon, node, and type. ///