mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-25 22:21:49 +01:00
Add focused changed lifecycle event
This commit is contained in:
parent
0e3126f160
commit
6e311b04e7
4 changed files with 71 additions and 0 deletions
|
|
@ -0,0 +1,22 @@
|
||||||
|
namespace Dalamud.Game.Addon.Lifecycle.AddonArgTypes;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Addon argument data for OnFocusChanged events.
|
||||||
|
/// </summary>
|
||||||
|
public class AddonFocusChangedArgs : AddonArgs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="AddonFocusChangedArgs"/> class.
|
||||||
|
/// </summary>
|
||||||
|
internal AddonFocusChangedArgs()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override AddonArgsType Type => AddonArgsType.FocusChanged;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether the window is being focused or unfocused.
|
||||||
|
/// </summary>
|
||||||
|
public bool ShouldFocus { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -44,4 +44,9 @@ public enum AddonArgsType
|
||||||
/// Contains argument data for Close.
|
/// Contains argument data for Close.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Close,
|
Close,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Contains argument data for OnFocusChanged.
|
||||||
|
/// </summary>
|
||||||
|
FocusChanged,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -203,4 +203,14 @@ public enum AddonEvent
|
||||||
/// Be aware this is only called for certain popup windows, it is not triggered when clicking on windows.
|
/// Be aware this is only called for certain popup windows, it is not triggered when clicking on windows.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
PostFocus,
|
PostFocus,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An event that is fired before an addon processes its FocusChanged method.
|
||||||
|
/// </summary>
|
||||||
|
PreFocusChanged,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An event that is fired after a addon processes its FocusChanged method.
|
||||||
|
/// </summary>
|
||||||
|
PostFocusChanged,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ internal unsafe class AddonVirtualTable : IDisposable
|
||||||
private readonly AddonArgs onMouseOverArgs = new();
|
private readonly AddonArgs onMouseOverArgs = new();
|
||||||
private readonly AddonArgs onMouseOutArgs = new();
|
private readonly AddonArgs onMouseOutArgs = new();
|
||||||
private readonly AddonArgs focusArgs = new();
|
private readonly AddonArgs focusArgs = new();
|
||||||
|
private readonly AddonFocusChangedArgs focusChangedArgs = new();
|
||||||
|
|
||||||
private readonly AtkUnitBase* atkUnitBase;
|
private readonly AtkUnitBase* atkUnitBase;
|
||||||
|
|
||||||
|
|
@ -63,6 +64,7 @@ internal unsafe class AddonVirtualTable : IDisposable
|
||||||
private readonly AtkUnitBase.Delegates.OnMouseOver onMouseOverFunction;
|
private readonly AtkUnitBase.Delegates.OnMouseOver onMouseOverFunction;
|
||||||
private readonly AtkUnitBase.Delegates.OnMouseOut onMouseOutFunction;
|
private readonly AtkUnitBase.Delegates.OnMouseOut onMouseOutFunction;
|
||||||
private readonly AtkUnitBase.Delegates.Focus focusFunction;
|
private readonly AtkUnitBase.Delegates.Focus focusFunction;
|
||||||
|
private readonly AtkUnitBase.Delegates.OnFocusChange onFocusChangeFunction;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="AddonVirtualTable"/> class.
|
/// Initializes a new instance of the <see cref="AddonVirtualTable"/> class.
|
||||||
|
|
@ -103,6 +105,7 @@ internal unsafe class AddonVirtualTable : IDisposable
|
||||||
this.onMouseOverFunction = this.OnAddonMouseOver;
|
this.onMouseOverFunction = this.OnAddonMouseOver;
|
||||||
this.onMouseOutFunction = this.OnAddonMouseOut;
|
this.onMouseOutFunction = this.OnAddonMouseOut;
|
||||||
this.focusFunction = this.OnAddonFocus;
|
this.focusFunction = this.OnAddonFocus;
|
||||||
|
this.onFocusChangeFunction = this.OnAddonFocusChange;
|
||||||
|
|
||||||
// Overwrite specific virtual table entries
|
// Overwrite specific virtual table entries
|
||||||
this.ModifiedVirtualTable->Dtor = (delegate* unmanaged<AtkUnitBase*, byte, AtkEventListener*>)Marshal.GetFunctionPointerForDelegate(this.destructorFunction);
|
this.ModifiedVirtualTable->Dtor = (delegate* unmanaged<AtkUnitBase*, byte, AtkEventListener*>)Marshal.GetFunctionPointerForDelegate(this.destructorFunction);
|
||||||
|
|
@ -121,6 +124,7 @@ internal unsafe class AddonVirtualTable : IDisposable
|
||||||
this.ModifiedVirtualTable->OnMouseOver = (delegate* unmanaged<AtkUnitBase*, void>)Marshal.GetFunctionPointerForDelegate(this.onMouseOverFunction);
|
this.ModifiedVirtualTable->OnMouseOver = (delegate* unmanaged<AtkUnitBase*, void>)Marshal.GetFunctionPointerForDelegate(this.onMouseOverFunction);
|
||||||
this.ModifiedVirtualTable->OnMouseOut = (delegate* unmanaged<AtkUnitBase*, void>)Marshal.GetFunctionPointerForDelegate(this.onMouseOutFunction);
|
this.ModifiedVirtualTable->OnMouseOut = (delegate* unmanaged<AtkUnitBase*, void>)Marshal.GetFunctionPointerForDelegate(this.onMouseOutFunction);
|
||||||
this.ModifiedVirtualTable->Focus = (delegate* unmanaged<AtkUnitBase*, void>)Marshal.GetFunctionPointerForDelegate(this.focusFunction);
|
this.ModifiedVirtualTable->Focus = (delegate* unmanaged<AtkUnitBase*, void>)Marshal.GetFunctionPointerForDelegate(this.focusFunction);
|
||||||
|
this.ModifiedVirtualTable->OnFocusChange = (delegate* unmanaged<AtkUnitBase*, bool, void>)Marshal.GetFunctionPointerForDelegate(this.onFocusChangeFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -630,6 +634,36 @@ internal unsafe class AddonVirtualTable : IDisposable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnAddonFocusChange(AtkUnitBase* thisPtr, bool isFocused)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.LogEvent(EnableLogging);
|
||||||
|
|
||||||
|
this.focusChangedArgs.Addon = thisPtr;
|
||||||
|
this.focusChangedArgs.ShouldFocus = isFocused;
|
||||||
|
|
||||||
|
this.lifecycleService.InvokeListenersSafely(AddonEvent.PreFocusChanged, this.focusChangedArgs);
|
||||||
|
|
||||||
|
isFocused = this.focusChangedArgs.ShouldFocus;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.OriginalVirtualTable->OnFocusChange(thisPtr, isFocused);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Error(e, "Caught exception when calling original Addon OnFocusChanged. This may be a bug in the game or another plugin hooking this method.");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.lifecycleService.InvokeListenersSafely(AddonEvent.PostFocusChanged, this.focusChangedArgs);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Error(e, "Caught exception from Dalamud when attempting to process OnAddonFocusChange.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Conditional("DEBUG")]
|
[Conditional("DEBUG")]
|
||||||
private void LogEvent(bool loggingEnabled, [CallerMemberName] string caller = "")
|
private void LogEvent(bool loggingEnabled, [CallerMemberName] string caller = "")
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue