Let's just break things and make them really nice

This commit is contained in:
MidoriKami 2025-07-26 11:12:03 -07:00
parent 5f534be9d9
commit 57f7de6772
6 changed files with 119 additions and 73 deletions

View file

@ -1,10 +1,32 @@
namespace Dalamud.Game.Addon.Events; namespace Dalamud.Game.Addon.Events.EventDataTypes;
/// <summary> /// <summary>
/// Object representing data that is relevant in handling native events. /// Object representing data that is relevant in handling native events.
/// </summary> /// </summary>
public class AddonEventData public class AddonEventData
{ {
/// <summary>
/// Initializes a new instance of the <see cref="AddonEventData"/> class.
/// </summary>
internal AddonEventData()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="AddonEventData"/> class.
/// </summary>
/// <param name="eventData">Other event data to copy.</param>
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;
}
/// <summary> /// <summary>
/// Gets the AtkEventType for this event. /// Gets the AtkEventType for this event.
/// </summary> /// </summary>
@ -18,8 +40,8 @@ public class AddonEventData
/// <summary> /// <summary>
/// Gets the pointer to the AtkEvent object for this event. /// Gets the pointer to the AtkEvent object for this event.
/// </summary> /// </summary>
/// <remarks>Note: This is not a pointer to the AtkEventData object.<br/><br/></remarks> /// <remarks>Note: This is not a pointer to the AtkEventData object.<br/><br/>
/// <remarks>Warning: AtkEvent->Node has been modified to be the AtkUnitBase*, and AtkEvent->Target has been modified to be the AtkResNode* that triggered this event.</remarks> /// Warning: AtkEvent->Node has been modified to be the AtkUnitBase*, and AtkEvent->Target has been modified to be the AtkResNode* that triggered this event.</remarks>
public nint AtkEventPointer { get; internal set; } public nint AtkEventPointer { get; internal set; }
/// <summary> /// <summary>

View file

@ -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;
/// <inheritdoc />
public unsafe class AddonMouseEventData : AddonEventData
{
/// <summary>
/// Initializes a new instance of the <see cref="AddonMouseEventData"/> class.
/// </summary>
internal AddonMouseEventData()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="AddonMouseEventData"/> class.
/// </summary>
/// <param name="eventData">Other event data to copy.</param>
internal AddonMouseEventData(AddonEventData eventData)
: base(eventData)
{
}
/// <summary>
/// Gets a value indicating whether the event was a Left Mouse Click
/// </summary>
public bool IsLeftClick => this.MouseData.ButtonId is 0;
/// <summary>
/// Gets a value indicating whether the event was a Right Mouse Click
/// </summary>
public bool IsRightClick => this.MouseData.ButtonId is 1;
/// <summary>
/// Gets a value indicating whether there are any modifiers set such as alt, control, shift, or dragging
/// </summary>
public bool IsNoModifier => this.MouseData.Modifier is 0;
/// <summary>
/// Gets a value indicating whether alt was being held when this event triggered
/// </summary>
public bool IsAltHeld => this.MouseData.Modifier.HasFlag(ModifierFlag.Alt);
/// <summary>
/// Gets a value indicating whether control was being held when this event triggered
/// </summary>
public bool IsControlHeld => this.MouseData.Modifier.HasFlag(ModifierFlag.Ctrl);
/// <summary>
/// Gets a value indicating whether shift was being held when this event triggered
/// </summary>
public bool IsShiftHeld => this.MouseData.Modifier.HasFlag(ModifierFlag.Shift);
/// <summary>
/// Gets a value indicating whether this event is a mouse drag or not
/// </summary>
public bool IsDragging => this.MouseData.Modifier.HasFlag(ModifierFlag.Dragging);
/// <summary>
/// Gets a value indicating whether the event was a scroll up
/// </summary>
public bool IsScrollUp => this.MouseData.WheelDirection is 1;
/// <summary>
/// Gets a value indicating whether the event was a scroll down
/// </summary>
public bool IsScrollDown => this.MouseData.WheelDirection is -1;
/// <summary>
/// Gets the position of the mouse when this event was triggered
/// </summary>
public Vector2 Position => new(this.MouseData.PosX, this.MouseData.PosY);
private AtkEventData* AtkEventData => (AtkEventData*)this.AtkEventDataPointer;
private AtkMouseData MouseData => this.AtkEventData->MouseData;
}

View file

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Dalamud.Game.Addon.Events.EventDataTypes;
using Dalamud.Game.Gui; using Dalamud.Game.Gui;
using Dalamud.Logging.Internal; using Dalamud.Logging.Internal;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;

View file

@ -5,6 +5,7 @@ using System.Threading;
using Dalamud.Configuration.Internal; using Dalamud.Configuration.Internal;
using Dalamud.Game.Addon.Events; using Dalamud.Game.Addon.Events;
using Dalamud.Game.Addon.Events.EventDataTypes;
using Dalamud.Game.Addon.Lifecycle; using Dalamud.Game.Addon.Lifecycle;
using Dalamud.Game.Addon.Lifecycle.AddonArgTypes; using Dalamud.Game.Addon.Lifecycle.AddonArgTypes;
using Dalamud.Game.Text.SeStringHandling; 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) switch (atkEventType)
{ {
@ -641,22 +642,7 @@ internal sealed unsafe class DtrBar : IInternalDisposableService, IDtrBar
break; break;
case AddonEventType.MouseClick: case AddonEventType.MouseClick:
dtrBarEntry.OnClick?.Invoke(); dtrBarEntry.OnClick?.Invoke(new AddonMouseEventData(eventData));
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();
}
break; break;
} }
} }

View file

@ -1,5 +1,5 @@
using Dalamud.Configuration.Internal; using Dalamud.Configuration.Internal;
using Dalamud.Game.Addon.Events; using Dalamud.Game.Addon.Events.EventDataTypes;
using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Plugin.Internal.Types; using Dalamud.Plugin.Internal.Types;
using Dalamud.Utility; 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. /// Gets a value indicating whether the user has hidden this entry from view through the Dalamud settings.
/// </summary> /// </summary>
public bool UserHidden { get; } public bool UserHidden { get; }
/// <summary>
/// Triggers the click action of this entry.
/// </summary>
/// <returns>True, if a click action was registered and executed.</returns>
[Api13ToDo("Remove, doesn't mesh well with new click actions")]
public bool TriggerClickAction();
} }
/// <summary> /// <summary>
@ -73,25 +66,9 @@ public interface IDtrBarEntry : IReadOnlyDtrBarEntry
public new bool Shown { get; set; } public new bool Shown { get; set; }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
[Api13ToDo("Remove this, and rename OnClicked to OnClick")] public Action<AddonMouseEventData>? OnClick { get; set; }
public Action? OnClick { get; set; }
/// <summary>
/// Gets or sets a action to be invoked when the user left-clicks on the dtr entry.
/// </summary>
public Action? OnLeftClick { get; set; }
/// <summary>
/// Gets or sets a action to be invoked when the user right-clicks on the dtr entry.
/// </summary>
public Action? OnRightClick { get; set; }
/// <summary>
/// Gets or sets a action to be invoked when the user clicks on the dtr entry.
/// </summary>
public Action<AddonEventData>? OnClicked { get; set; }
/// <summary> /// <summary>
/// Remove this entry from the bar. /// Remove this entry from the bar.
@ -140,23 +117,11 @@ internal sealed unsafe class DtrBarEntry : IDisposable, IDtrBarEntry
/// <inheritdoc cref="IDtrBarEntry.Tooltip" /> /// <inheritdoc cref="IDtrBarEntry.Tooltip" />
public SeString? Tooltip { get; set; } public SeString? Tooltip { get; set; }
/// <summary> /// <inheritdoc/>
/// Gets or sets a action to be invoked when the user clicks on the dtr entry. public Action<AddonMouseEventData>? OnClick { get; set; }
/// </summary>
[Api13ToDo("Remove this and rename OnClicked to OnClick")]
public Action? OnClick { get; set; }
/// <inheritdoc/> /// <inheritdoc/>
public Action? OnLeftClick { get; set; } public bool HasClickAction => this.OnClick != null;
/// <inheritdoc/>
public Action? OnRightClick { get; set; }
/// <inheritdoc/>
public Action<AddonEventData>? OnClicked { get; set; }
/// <inheritdoc/>
public bool HasClickAction => this.OnClick != null || this.OnLeftClick != null || this.OnRightClick != null || this.OnClicked != null;
/// <inheritdoc cref="IDtrBarEntry.Shown" /> /// <inheritdoc cref="IDtrBarEntry.Shown" />
public bool Shown public bool Shown
@ -173,7 +138,7 @@ internal sealed unsafe class DtrBarEntry : IDisposable, IDtrBarEntry
} }
/// <inheritdoc/> /// <inheritdoc/>
[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; public bool UserHidden => this.configuration.DtrIgnore?.Contains(this.Title) ?? false;
/// <summary> /// <summary>
@ -206,17 +171,6 @@ internal sealed unsafe class DtrBarEntry : IDisposable, IDtrBarEntry
/// </summary> /// </summary>
internal LocalPlugin? OwnerPlugin { get; set; } internal LocalPlugin? OwnerPlugin { get; set; }
/// <inheritdoc/>
[Api13ToDo("Remove, doesn't mesh well with new click actions")]
public bool TriggerClickAction()
{
if (this.OnClick == null)
return false;
this.OnClick.Invoke();
return true;
}
/// <summary> /// <summary>
/// Remove this entry from the bar. /// Remove this entry from the bar.
/// You will need to re-acquire it from DtrBar to reuse it. /// You will need to re-acquire it from DtrBar to reuse it.

View file

@ -1,4 +1,5 @@
using Dalamud.Game.Addon.Events; using Dalamud.Game.Addon.Events;
using Dalamud.Game.Addon.Events.EventDataTypes;
namespace Dalamud.Plugin.Services; namespace Dalamud.Plugin.Services;