Add additional dtr click events

This commit is contained in:
MidoriKami 2025-07-26 10:07:39 -07:00
parent dfd0f19490
commit 124c024c4d
2 changed files with 70 additions and 10 deletions

View file

@ -5,7 +5,6 @@ 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;
@ -629,7 +628,7 @@ internal sealed unsafe class DtrBar : IInternalDisposableService, IDtrBar
}
}
if (dtrBarEntry is { OnClick: not null })
if (dtrBarEntry is not null)
{
switch (atkEventType)
{
@ -642,7 +641,22 @@ internal sealed unsafe class DtrBar : IInternalDisposableService, IDtrBar
break;
case AddonEventType.MouseClick:
dtrBarEntry.OnClick?.Invoke(new AddonMouseEventData(eventData));
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();
}
break;
}
}

View file

@ -1,5 +1,5 @@
using Dalamud.Configuration.Internal;
using Dalamud.Game.Addon.Events.EventDataTypes;
using Dalamud.Game.Addon.Events;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Plugin.Internal.Types;
using Dalamud.Utility;
@ -43,6 +43,13 @@ public interface IReadOnlyDtrBarEntry
/// Gets a value indicating whether the user has hidden this entry from view through the Dalamud settings.
/// </summary>
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>
@ -66,9 +73,25 @@ public interface IDtrBarEntry : IReadOnlyDtrBarEntry
public new bool Shown { get; set; }
/// <summary>
/// Gets or sets an action to be invoked when the user clicks on the dtr entry.
/// Gets or sets a action to be invoked when the user clicks on the dtr entry.
/// </summary>
public Action<AddonMouseEventData>? OnClick { get; set; }
[Api13ToDo("Remove this, and rename OnClicked to OnClick")]
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>
/// Remove this entry from the bar.
@ -117,11 +140,23 @@ internal sealed unsafe class DtrBarEntry : IDisposable, IDtrBarEntry
/// <inheritdoc cref="IDtrBarEntry.Tooltip" />
public SeString? Tooltip { get; set; }
/// <inheritdoc/>
public Action<AddonMouseEventData>? OnClick { get; set; }
/// <summary>
/// Gets or sets a action to be invoked when the user clicks on the dtr entry.
/// </summary>
[Api13ToDo("Remove this and rename OnClicked to OnClick")]
public Action? OnClick { get; set; }
/// <inheritdoc/>
public bool HasClickAction => this.OnClick != null;
public Action? OnLeftClick { get; set; }
/// <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" />
public bool Shown
@ -138,7 +173,7 @@ internal sealed unsafe class DtrBarEntry : IDisposable, IDtrBarEntry
}
/// <inheritdoc/>
[Api13ToDo("Maybe make this config scoped to internal name?")]
[Api13ToDo("Maybe make this config scoped to internalname?")]
public bool UserHidden => this.configuration.DtrIgnore?.Contains(this.Title) ?? false;
/// <summary>
@ -171,6 +206,17 @@ internal sealed unsafe class DtrBarEntry : IDisposable, IDtrBarEntry
/// </summary>
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>
/// Remove this entry from the bar.
/// You will need to re-acquire it from DtrBar to reuse it.