show focus target on visibility hover
This commit is contained in:
@@ -14,6 +14,7 @@ using LightlessSync.Interop;
|
||||
using LightlessSync.LightlessConfiguration;
|
||||
using LightlessSync.PlayerData.Factories;
|
||||
using LightlessSync.PlayerData.Handlers;
|
||||
using LightlessSync.PlayerData.Pairs;
|
||||
using LightlessSync.Services.ActorTracking;
|
||||
using LightlessSync.Services.Mediator;
|
||||
using LightlessSync.Utils;
|
||||
@@ -41,10 +42,13 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
private readonly ILogger<DalamudUtilService> _logger;
|
||||
private readonly IObjectTable _objectTable;
|
||||
private readonly ActorObjectService _actorObjectService;
|
||||
private readonly ITargetManager _targetManager;
|
||||
private readonly PerformanceCollectorService _performanceCollector;
|
||||
private readonly LightlessConfigService _configService;
|
||||
private readonly PlayerPerformanceConfigService _playerPerformanceConfigService;
|
||||
private readonly Lazy<PairFactory> _pairFactory;
|
||||
private PairUniqueIdentifier? _FocusPairIdent;
|
||||
private IGameObject? _FocusOriginalTarget;
|
||||
private uint? _classJobId = 0;
|
||||
private DateTime _delayedFrameworkUpdateCheck = DateTime.UtcNow;
|
||||
private string _lastGlobalBlockPlayer = string.Empty;
|
||||
@@ -68,6 +72,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
_gameData = gameData;
|
||||
_gameConfig = gameConfig;
|
||||
_actorObjectService = actorObjectService;
|
||||
_targetManager = targetManager;
|
||||
_blockedCharacterHandler = blockedCharacterHandler;
|
||||
Mediator = mediator;
|
||||
_performanceCollector = performanceCollector;
|
||||
@@ -125,20 +130,24 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
mediator.Subscribe<TargetPairMessage>(this, (msg) =>
|
||||
{
|
||||
if (clientState.IsPvP) return;
|
||||
var pair = _pairFactory.Value.Create(msg.Pair.UniqueIdent) ?? msg.Pair;
|
||||
var name = pair.PlayerName;
|
||||
if (string.IsNullOrEmpty(name)) return;
|
||||
if (!_actorObjectService.TryGetPlayerByName(name, out var descriptor))
|
||||
return;
|
||||
var addr = descriptor.Address;
|
||||
if (addr == nint.Zero) return;
|
||||
if (!ResolvePairAddress(msg.Pair, out var pair, out var addr)) return;
|
||||
var useFocusTarget = _configService.Current.UseFocusTarget;
|
||||
_ = RunOnFrameworkThread(() =>
|
||||
{
|
||||
var gameObject = CreateGameObject(addr);
|
||||
if (gameObject is null) return;
|
||||
if (useFocusTarget)
|
||||
targetManager.FocusTarget = CreateGameObject(addr);
|
||||
{
|
||||
_targetManager.FocusTarget = gameObject;
|
||||
if (_FocusPairIdent.HasValue && _FocusPairIdent.Value.Equals(pair.UniqueIdent))
|
||||
{
|
||||
_FocusOriginalTarget = _targetManager.FocusTarget;
|
||||
}
|
||||
}
|
||||
else
|
||||
targetManager.Target = CreateGameObject(addr);
|
||||
{
|
||||
_targetManager.Target = gameObject;
|
||||
}
|
||||
}).ConfigureAwait(false);
|
||||
});
|
||||
IsWine = Util.IsWine();
|
||||
@@ -148,6 +157,61 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
private Lazy<ulong> RebuildCID() => new(GetCID);
|
||||
|
||||
public bool IsWine { get; init; }
|
||||
private bool ResolvePairAddress(Pair pair, out Pair resolvedPair, out nint address)
|
||||
{
|
||||
resolvedPair = _pairFactory.Value.Create(pair.UniqueIdent) ?? pair;
|
||||
address = nint.Zero;
|
||||
var name = resolvedPair.PlayerName;
|
||||
if (string.IsNullOrEmpty(name)) return false;
|
||||
if (!_actorObjectService.TryGetPlayerByName(name, out var descriptor))
|
||||
return false;
|
||||
address = descriptor.Address;
|
||||
return address != nint.Zero;
|
||||
}
|
||||
|
||||
public void FocusVisiblePair(Pair pair)
|
||||
{
|
||||
if (_clientState.IsPvP) return;
|
||||
if (!ResolvePairAddress(pair, out var resolvedPair, out var address)) return;
|
||||
_ = RunOnFrameworkThread(() => FocusPairUnsafe(address, resolvedPair.UniqueIdent));
|
||||
}
|
||||
|
||||
public void ReleaseVisiblePairFocus()
|
||||
{
|
||||
_ = RunOnFrameworkThread(ReleaseFocusUnsafe);
|
||||
}
|
||||
|
||||
private void FocusPairUnsafe(nint address, PairUniqueIdentifier pairIdent)
|
||||
{
|
||||
var target = CreateGameObject(address);
|
||||
if (target is null) return;
|
||||
|
||||
if (!_FocusPairIdent.HasValue)
|
||||
{
|
||||
_FocusOriginalTarget = _targetManager.FocusTarget;
|
||||
}
|
||||
|
||||
_targetManager.FocusTarget = target;
|
||||
_FocusPairIdent = pairIdent;
|
||||
}
|
||||
|
||||
private void ReleaseFocusUnsafe()
|
||||
{
|
||||
if (!_FocusPairIdent.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var previous = _FocusOriginalTarget;
|
||||
if (previous != null && !IsObjectPresent(previous))
|
||||
{
|
||||
previous = null;
|
||||
}
|
||||
|
||||
_targetManager.FocusTarget = previous;
|
||||
_FocusPairIdent = null;
|
||||
_FocusOriginalTarget = null;
|
||||
}
|
||||
|
||||
public unsafe GameObject* GposeTarget
|
||||
{
|
||||
@@ -505,6 +569,17 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
||||
|
||||
Mediator.UnsubscribeAll(this);
|
||||
_framework.Update -= FrameworkOnUpdate;
|
||||
if (_FocusPairIdent.HasValue)
|
||||
{
|
||||
if (_framework.IsInFrameworkUpdateThread)
|
||||
{
|
||||
ReleaseFocusUnsafe();
|
||||
}
|
||||
else
|
||||
{
|
||||
_ = RunOnFrameworkThread(ReleaseFocusUnsafe);
|
||||
}
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user