mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
feat: Add DtrInteractionEvent to allow plugins to make their own DTR events. (#2353)
This commit is contained in:
parent
579ecdc4b2
commit
3d300a7811
4 changed files with 132 additions and 3 deletions
|
|
@ -641,7 +641,7 @@ internal sealed unsafe class DtrBar : IInternalDisposableService, IDtrBar
|
|||
break;
|
||||
|
||||
case AddonEventType.MouseClick:
|
||||
dtrBarEntry.OnClick?.Invoke(new AddonMouseEventData(eventData));
|
||||
dtrBarEntry.OnClick?.Invoke(DtrInteractionEvent.FromMouseEvent(new AddonMouseEventData(eventData)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,11 @@ 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>
|
||||
/// Gets an action to be invoked when the user clicks on the dtr entry.
|
||||
/// </summary>
|
||||
public Action<DtrInteractionEvent>? OnClick { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -68,7 +73,7 @@ public interface IDtrBarEntry : IReadOnlyDtrBarEntry
|
|||
/// <summary>
|
||||
/// Gets or sets an action to be invoked when the user clicks on the dtr entry.
|
||||
/// </summary>
|
||||
public Action<AddonMouseEventData>? OnClick { get; set; }
|
||||
public new Action<DtrInteractionEvent>? OnClick { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Remove this entry from the bar.
|
||||
|
|
@ -118,7 +123,7 @@ internal sealed unsafe class DtrBarEntry : IDisposable, IDtrBarEntry
|
|||
public SeString? Tooltip { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Action<AddonMouseEventData>? OnClick { get; set; }
|
||||
public Action<DtrInteractionEvent>? OnClick { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool HasClickAction => this.OnClick != null;
|
||||
|
|
|
|||
59
Dalamud/Game/Gui/Dtr/DtrInteractionEvent.cs
Normal file
59
Dalamud/Game/Gui/Dtr/DtrInteractionEvent.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
using System.Numerics;
|
||||
|
||||
using Dalamud.Game.Addon.Events.EventDataTypes;
|
||||
|
||||
namespace Dalamud.Game.Gui.Dtr;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an interaction event from the DTR system.
|
||||
/// </summary>
|
||||
public class DtrInteractionEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of mouse click (left or right).
|
||||
/// </summary>
|
||||
public MouseClickType ClickType { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the modifier keys that were held during the click.
|
||||
/// </summary>
|
||||
public ClickModifierKeys ModifierKeys { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the scroll direction of the mouse wheel, if applicable.
|
||||
/// </summary>
|
||||
public MouseScrollDirection ScrollDirection { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets lower-level mouse data, if this event came from native UI.
|
||||
///
|
||||
/// Can only be set by Dalamud. If null, this event was manually created.
|
||||
/// </summary>
|
||||
public AddonMouseEventData? AtkEventSource { get; private init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the position of the mouse cursor when the event occurred.
|
||||
/// </summary>
|
||||
public Vector2 Position { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Helper to create a <see cref="DtrInteractionEvent"/> from an <see cref="AddonMouseEventData"/>.
|
||||
/// </summary>
|
||||
/// <param name="ev">The event.</param>
|
||||
/// <returns>A better event.</returns>
|
||||
public static DtrInteractionEvent FromMouseEvent(AddonMouseEventData ev)
|
||||
{
|
||||
return new DtrInteractionEvent
|
||||
{
|
||||
AtkEventSource = ev,
|
||||
ClickType = ev.IsLeftClick ? MouseClickType.Left : MouseClickType.Right,
|
||||
ModifierKeys = (ev.IsAltHeld ? ClickModifierKeys.Alt : 0) |
|
||||
(ev.IsControlHeld ? ClickModifierKeys.Ctrl : 0) |
|
||||
(ev.IsShiftHeld ? ClickModifierKeys.Shift : 0),
|
||||
ScrollDirection = ev.IsScrollUp ? MouseScrollDirection.Up :
|
||||
ev.IsScrollDown ? MouseScrollDirection.Down :
|
||||
MouseScrollDirection.None,
|
||||
Position = ev.Position,
|
||||
};
|
||||
}
|
||||
}
|
||||
65
Dalamud/Game/Gui/Dtr/DtrInteractionTypes.cs
Normal file
65
Dalamud/Game/Gui/Dtr/DtrInteractionTypes.cs
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
namespace Dalamud.Game.Gui.Dtr;
|
||||
|
||||
/// <summary>
|
||||
/// An enum representing the mouse click types.
|
||||
/// </summary>
|
||||
public enum MouseClickType
|
||||
{
|
||||
/// <summary>
|
||||
/// A left click.
|
||||
/// </summary>
|
||||
Left,
|
||||
|
||||
/// <summary>
|
||||
/// A right click.
|
||||
/// </summary>
|
||||
Right,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modifier keys that can be held during a mouse click event.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum ClickModifierKeys
|
||||
{
|
||||
/// <summary>
|
||||
/// No modifiers were present.
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// The CTRL key was held.
|
||||
/// </summary>
|
||||
Ctrl = 1 << 0,
|
||||
|
||||
/// <summary>
|
||||
/// The ALT key was held.
|
||||
/// </summary>
|
||||
Alt = 1 << 1,
|
||||
|
||||
/// <summary>
|
||||
/// The SHIFT key was held.
|
||||
/// </summary>
|
||||
Shift = 1 << 2,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Possible directions for scroll wheel events.
|
||||
/// </summary>
|
||||
public enum MouseScrollDirection
|
||||
{
|
||||
/// <summary>
|
||||
/// No scrolling.
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// A scroll up event.
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
|
||||
/// <summary>
|
||||
/// A scroll down event.
|
||||
/// </summary>
|
||||
Down = -1,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue