This commit is contained in:
Stanley Dimant
2023-04-21 16:09:29 +02:00
6 changed files with 60 additions and 42 deletions

View File

@@ -34,6 +34,11 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
private readonly ICallGateSubscriber<float, object?> _heelsOffsetUpdate; private readonly ICallGateSubscriber<float, object?> _heelsOffsetUpdate;
private readonly ICallGateSubscriber<GameObject, float, object?> _heelsRegisterPlayer; private readonly ICallGateSubscriber<GameObject, float, object?> _heelsRegisterPlayer;
private readonly ICallGateSubscriber<GameObject, object?> _heelsUnregisterPlayer; private readonly ICallGateSubscriber<GameObject, object?> _heelsUnregisterPlayer;
private readonly ICallGateSubscriber<(uint major, uint minor)> _honorificApiVersion;
private readonly ICallGateSubscriber<Character, object> _honorificClearCharacterTitle;
private readonly ICallGateSubscriber<(string Title, bool IsPrefix)> _honorificGetLocalCharacterTitle;
private readonly ICallGateSubscriber<string, bool, object> _honorificLocalCharacterTitleChanged;
private readonly ICallGateSubscriber<Character, string, bool, object> _honorificSetCharacterTitle;
private readonly ConcurrentQueue<Action> _normalQueue = new(); private readonly ConcurrentQueue<Action> _normalQueue = new();
private readonly ICallGateSubscriber<string> _palettePlusApiVersion; private readonly ICallGateSubscriber<string> _palettePlusApiVersion;
private readonly ICallGateSubscriber<Character, string> _palettePlusBuildCharaPalette; private readonly ICallGateSubscriber<Character, string> _palettePlusBuildCharaPalette;
@@ -58,18 +63,13 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
private readonly FuncSubscriber<string, string, int, PenumbraApiEc> _penumbraRemoveTemporaryMod; private readonly FuncSubscriber<string, string, int, PenumbraApiEc> _penumbraRemoveTemporaryMod;
private readonly FuncSubscriber<string> _penumbraResolveModDir; private readonly FuncSubscriber<string> _penumbraResolveModDir;
private readonly FuncSubscriber<string[], string[], (string[], string[][])> _penumbraResolvePaths; private readonly FuncSubscriber<string[], string[], (string[], string[][])> _penumbraResolvePaths;
private readonly ICallGateSubscriber<(uint major, uint minor)> _honorificApiVersion;
private readonly ICallGateSubscriber<(string Title, bool IsPrefix)> _honorificGetLocalCharacterTitle;
private readonly ICallGateSubscriber<Character, object> _honorificClearCharacterTitle;
private readonly ICallGateSubscriber<Character, string, bool, object> _honorificSetCharacterTitle;
private readonly ICallGateSubscriber<string, bool, object> _honorificLocalCharacterTitleChanged;
private bool _customizePlusAvailable = false; private bool _customizePlusAvailable = false;
private CancellationTokenSource _disposalCts = new(); private CancellationTokenSource _disposalCts = new();
private bool _glamourerAvailable = false; private bool _glamourerAvailable = false;
private bool _heelsAvailable = false; private bool _heelsAvailable = false;
private bool _honorificAvailable = false;
private bool _inGposeQueueMode = false; private bool _inGposeQueueMode = false;
private bool _palettePlusAvailable = false; private bool _palettePlusAvailable = false;
private bool _honorificAvailable = false;
private bool _penumbraAvailable = false; private bool _penumbraAvailable = false;
private bool _shownGlamourerUnavailable = false; private bool _shownGlamourerUnavailable = false;
private bool _shownPenumbraUnavailable = false; private bool _shownPenumbraUnavailable = false;
@@ -160,10 +160,10 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
public bool CheckHeelsApi() => _heelsAvailable; public bool CheckHeelsApi() => _heelsAvailable;
public bool CheckPalettePlusApi() => _palettePlusAvailable;
public bool CheckHonorificApi() => _honorificAvailable; public bool CheckHonorificApi() => _honorificAvailable;
public bool CheckPalettePlusApi() => _palettePlusAvailable;
public bool CheckPenumbraApi() => _penumbraAvailable; public bool CheckPenumbraApi() => _penumbraAvailable;
public async Task CustomizePlusRevert(IntPtr character) public async Task CustomizePlusRevert(IntPtr character)
@@ -289,7 +289,21 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
} }
}).ConfigureAwait(false); }).ConfigureAwait(false);
} }
public async Task HonorificClearTitle(nint character)
{
if (!CheckHonorificApi()) return;
await _dalamudUtil.RunOnFrameworkThread(() =>
{
var gameObj = _dalamudUtil.CreateGameObject(character);
if (gameObj is PlayerCharacter c)
{
Logger.LogTrace("Honorific removing for {addr}", c.Address.ToString("X"));
_honorificClearCharacterTitle!.InvokeAction(c);
}
}).ConfigureAwait(false);
}
public string HonorificGetTitle() public string HonorificGetTitle()
{ {
if (!CheckHonorificApi()) return string.Empty; if (!CheckHonorificApi()) return string.Empty;
@@ -312,26 +326,12 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
} }
else else
{ {
_honorificSetCharacterTitle!.InvokeAction(pc, honorificData[1..], honorificData[0] == '1'); _honorificSetCharacterTitle!.InvokeAction(pc, honorificData[1..], honorificData[0] == '1');
} }
} }
}).ConfigureAwait(false); }).ConfigureAwait(false);
} }
public async Task HonorificClearTitle(nint character)
{
if (!CheckHonorificApi()) return;
await _dalamudUtil.RunOnFrameworkThread(() =>
{
var gameObj = _dalamudUtil.CreateGameObject(character);
if (gameObj is PlayerCharacter c)
{
Logger.LogTrace("Honorific removing for {addr}", c.Address.ToString("X"));
_honorificClearCharacterTitle!.InvokeAction(c);
}
}).ConfigureAwait(false);
}
public async Task<string> PalettePlusBuildPalette() public async Task<string> PalettePlusBuildPalette()
{ {
if (!CheckPalettePlusApi()) return string.Empty; if (!CheckPalettePlusApi()) return string.Empty;
@@ -523,11 +523,11 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
} }
} }
private bool CheckPalettePlusApiInternal() private bool CheckHonorificApiInternal()
{ {
try try
{ {
return string.Equals(_palettePlusApiVersion.InvokeFunc(), "1.1.0", StringComparison.Ordinal); return _honorificApiVersion.InvokeFunc() is { Item1: 1, Item2: >= 0 };
} }
catch catch
{ {
@@ -535,11 +535,11 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
} }
} }
private bool CheckHonorificApiInternal() private bool CheckPalettePlusApiInternal()
{ {
try try
{ {
return _honorificApiVersion.InvokeFunc() is { Item1: 1, Item2: >= 0 }; return string.Equals(_palettePlusApiVersion.InvokeFunc(), "1.1.0", StringComparison.Ordinal);
} }
catch catch
{ {
@@ -612,16 +612,16 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
Mediator.Publish(new CustomizePlusMessage()); Mediator.Publish(new CustomizePlusMessage());
} }
private void OnHonorificLocalCharacterTitleChanged(string title, bool isPrefix)
{
Mediator.Publish(new HonorificMessage((isPrefix ? 0 : 1) + title));
}
private void OnPalettePlusPaletteChange(Character character, string palette) private void OnPalettePlusPaletteChange(Character character, string palette)
{ {
Mediator.Publish(new PalettePlusMessage(character)); Mediator.Publish(new PalettePlusMessage(character));
} }
private void OnHonorificLocalCharacterTitleChanged(string title, bool isPrefix)
{
Mediator.Publish(new HonorificMessage());
}
private void PenumbraDispose() private void PenumbraDispose()
{ {
_disposalCts.Cancel(); _disposalCts.Cancel();

View File

@@ -141,7 +141,7 @@ public class Pair
ShownHonorificWarning = _configService.Current.DisableOptionalPluginWarnings, ShownHonorificWarning = _configService.Current.DisableOptionalPluginWarnings,
}; };
CachedPlayer.Initialize(name); CachedPlayer.Initialize(name).Wait();
ApplyLastReceivedData(); ApplyLastReceivedData();
@@ -222,7 +222,7 @@ public class Pair
data.FileReplacements[objectKind] = data.FileReplacements[objectKind] data.FileReplacements[objectKind] = data.FileReplacements[objectKind]
.Where(f => !f.GamePaths.Any(p => p.EndsWith("tmb", StringComparison.OrdinalIgnoreCase) || p.EndsWith("pap", StringComparison.OrdinalIgnoreCase))) .Where(f => !f.GamePaths.Any(p => p.EndsWith("tmb", StringComparison.OrdinalIgnoreCase) || p.EndsWith("pap", StringComparison.OrdinalIgnoreCase)))
.ToList(); .ToList();
if(disableVFX) if (disableVFX)
data.FileReplacements[objectKind] = data.FileReplacements[objectKind] data.FileReplacements[objectKind] = data.FileReplacements[objectKind]
.Where(f => !f.GamePaths.Any(p => p.EndsWith("atex", StringComparison.OrdinalIgnoreCase) || p.EndsWith("avfx", StringComparison.OrdinalIgnoreCase))) .Where(f => !f.GamePaths.Any(p => p.EndsWith("atex", StringComparison.OrdinalIgnoreCase) || p.EndsWith("avfx", StringComparison.OrdinalIgnoreCase)))
.ToList(); .ToList();

View File

@@ -17,6 +17,7 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
private readonly CharacterData _playerData = new(); private readonly CharacterData _playerData = new();
private readonly Dictionary<ObjectKind, GameObjectHandler> _playerRelatedObjects = new(); private readonly Dictionary<ObjectKind, GameObjectHandler> _playerRelatedObjects = new();
private Task? _cacheCreationTask; private Task? _cacheCreationTask;
private CancellationTokenSource _honorificCts = new();
private CancellationTokenSource _palettePlusCts = new(); private CancellationTokenSource _palettePlusCts = new();
public CacheCreationService(ILogger<CacheCreationService> logger, MareMediator mediator, Func<ObjectKind, Func<IntPtr>, bool, GameObjectHandler> gameObjectHandlerFactory, public CacheCreationService(ILogger<CacheCreationService> logger, MareMediator mediator, Func<ObjectKind, Func<IntPtr>, bool, GameObjectHandler> gameObjectHandlerFactory,
@@ -61,10 +62,13 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
PalettePlusChanged(); PalettePlusChanged();
} }
}); });
Mediator.Subscribe<HonorificMessage>(this, async (_) => Mediator.Subscribe<HonorificMessage>(this, (msg) =>
{ {
Logger.LogDebug("Received Honorific change, updating player"); if (!string.Equals(msg.NewHonorificTitle, _playerData.HonorificData, StringComparison.Ordinal))
await AddPlayerCacheToCreate().ConfigureAwait(false); {
Logger.LogDebug("Received Honorific change, updating player");
HonorificChanged();
}
}); });
Mediator.Subscribe<PenumbraModSettingChangedMessage>(this, async (msg) => Mediator.Subscribe<PenumbraModSettingChangedMessage>(this, async (msg) =>
{ {
@@ -97,6 +101,20 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
_cacheCreateLock.Release(); _cacheCreateLock.Release();
} }
private void HonorificChanged()
{
_honorificCts?.Cancel();
_honorificCts?.Dispose();
_honorificCts = new();
var token = _honorificCts.Token;
Task.Run(async () =>
{
await Task.Delay(TimeSpan.FromSeconds(3), token).ConfigureAwait(false);
await AddPlayerCacheToCreate().ConfigureAwait(false);
}, token);
}
private void PalettePlusChanged() private void PalettePlusChanged()
{ {
_palettePlusCts?.Cancel(); _palettePlusCts?.Cancel();

View File

@@ -35,7 +35,7 @@ public record HeelsOffsetMessage : IMessage;
public record PenumbraResourceLoadMessage(IntPtr GameObject, string GamePath, string FilePath) : IMessage; public record PenumbraResourceLoadMessage(IntPtr GameObject, string GamePath, string FilePath) : IMessage;
public record CustomizePlusMessage : IMessage; public record CustomizePlusMessage : IMessage;
public record PalettePlusMessage(Character Character) : IMessage; public record PalettePlusMessage(Character Character) : IMessage;
public record HonorificMessage : IMessage; public record HonorificMessage(string NewHonorificTitle) : IMessage;
public record PlayerChangedMessage(API.Data.CharacterData Data) : IMessage; public record PlayerChangedMessage(API.Data.CharacterData Data) : IMessage;
public record CharacterChangedMessage(GameObjectHandler GameObjectHandler) : IMessage; public record CharacterChangedMessage(GameObjectHandler GameObjectHandler) : IMessage;
public record TransientResourceChangedMessage(IntPtr Address) : IMessage; public record TransientResourceChangedMessage(IntPtr Address) : IMessage;

View File

@@ -229,8 +229,8 @@ public class DrawUserPair : DrawPairBase
} }
var isDisableVFX = entry.UserPair!.OwnPermissions.IsDisableVFX(); var isDisableVFX = entry.UserPair!.OwnPermissions.IsDisableVFX();
string disableVFXText = isDisableAnims ? "Enable VFX sync" : "Disable VFX sync"; string disableVFXText = isDisableVFX ? "Enable VFX sync" : "Disable VFX sync";
var disableVFXIcon = isDisableAnims ? FontAwesomeIcon.Sun : FontAwesomeIcon.Circle; var disableVFXIcon = isDisableVFX ? FontAwesomeIcon.Sun : FontAwesomeIcon.Circle;
if (UiSharedService.IconTextButton(disableVFXIcon, disableVFXText)) if (UiSharedService.IconTextButton(disableVFXIcon, disableVFXText))
{ {
var permissions = entry.UserPair.OwnPermissions; var permissions = entry.UserPair.OwnPermissions;

View File

@@ -626,7 +626,7 @@ internal sealed class GroupPanel
+ Environment.NewLine + "Note: this setting does not apply to individual pairs that are also in the syncshell."); + Environment.NewLine + "Note: this setting does not apply to individual pairs that are also in the syncshell.");
var vfxText = userVFXDisabled ? "Enable VFX sync" : "Disable VFX sync"; var vfxText = userVFXDisabled ? "Enable VFX sync" : "Disable VFX sync";
if (UiSharedService.IconTextButton(userAnimIcon, vfxText)) if (UiSharedService.IconTextButton(userVFXIcon, vfxText))
{ {
ImGui.CloseCurrentPopup(); ImGui.CloseCurrentPopup();
var perm = groupDto.GroupUserPermissions; var perm = groupDto.GroupUserPermissions;