Moved ContextMenu from UI to Service.
This commit is contained in:
@@ -147,8 +147,8 @@ public sealed class Plugin : IDalamudPlugin
|
|||||||
collection.AddSingleton<RedrawManager>();
|
collection.AddSingleton<RedrawManager>();
|
||||||
collection.AddSingleton<BroadcastService>();
|
collection.AddSingleton<BroadcastService>();
|
||||||
collection.AddSingleton(addonLifecycle);
|
collection.AddSingleton(addonLifecycle);
|
||||||
collection.AddSingleton(p => new ContextMenu(contextMenu, pluginInterface, gameData,
|
collection.AddSingleton(p => new ContextMenuService(contextMenu, pluginInterface, gameData,
|
||||||
p.GetRequiredService<ILogger<ContextMenu>>(), p.GetRequiredService<DalamudUtilService>(), p.GetRequiredService<ApiController>(), objectTable,
|
p.GetRequiredService<ILogger<ContextMenuService>>(), p.GetRequiredService<DalamudUtilService>(), p.GetRequiredService<ApiController>(), objectTable,
|
||||||
p.GetRequiredService<LightlessConfigService>(), p.GetRequiredService<PairManager>(), clientState));
|
p.GetRequiredService<LightlessConfigService>(), p.GetRequiredService<PairManager>(), clientState));
|
||||||
collection.AddSingleton((s) => new IpcCallerPenumbra(s.GetRequiredService<ILogger<IpcCallerPenumbra>>(), pluginInterface,
|
collection.AddSingleton((s) => new IpcCallerPenumbra(s.GetRequiredService<ILogger<IpcCallerPenumbra>>(), pluginInterface,
|
||||||
s.GetRequiredService<DalamudUtilService>(), s.GetRequiredService<LightlessMediator>(), s.GetRequiredService<RedrawManager>()));
|
s.GetRequiredService<DalamudUtilService>(), s.GetRequiredService<LightlessMediator>(), s.GetRequiredService<RedrawManager>()));
|
||||||
@@ -263,7 +263,7 @@ public sealed class Plugin : IDalamudPlugin
|
|||||||
collection.AddHostedService(p => p.GetRequiredService<EventAggregator>());
|
collection.AddHostedService(p => p.GetRequiredService<EventAggregator>());
|
||||||
collection.AddHostedService(p => p.GetRequiredService<IpcProvider>());
|
collection.AddHostedService(p => p.GetRequiredService<IpcProvider>());
|
||||||
collection.AddHostedService(p => p.GetRequiredService<LightlessPlugin>());
|
collection.AddHostedService(p => p.GetRequiredService<LightlessPlugin>());
|
||||||
collection.AddHostedService(p => p.GetRequiredService<ContextMenu>());
|
collection.AddHostedService(p => p.GetRequiredService<ContextMenuService>());
|
||||||
collection.AddHostedService(p => p.GetRequiredService<BroadcastService>());
|
collection.AddHostedService(p => p.GetRequiredService<BroadcastService>());
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|||||||
@@ -4,21 +4,20 @@ using Dalamud.Plugin;
|
|||||||
using Dalamud.Plugin.Services;
|
using Dalamud.Plugin.Services;
|
||||||
using LightlessSync.LightlessConfiguration;
|
using LightlessSync.LightlessConfiguration;
|
||||||
using LightlessSync.PlayerData.Pairs;
|
using LightlessSync.PlayerData.Pairs;
|
||||||
using LightlessSync.Services;
|
|
||||||
using LightlessSync.Utils;
|
using LightlessSync.Utils;
|
||||||
using LightlessSync.WebAPI;
|
using LightlessSync.WebAPI;
|
||||||
using Lumina.Excel.Sheets;
|
using Lumina.Excel.Sheets;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace LightlessSync.UI;
|
namespace LightlessSync.Services;
|
||||||
|
|
||||||
internal class ContextMenu : IHostedService
|
internal class ContextMenuService : IHostedService
|
||||||
{
|
{
|
||||||
private readonly IContextMenu _contextMenu;
|
private readonly IContextMenu _contextMenu;
|
||||||
private readonly IDalamudPluginInterface _pluginInterface;
|
private readonly IDalamudPluginInterface _pluginInterface;
|
||||||
private readonly IDataManager _gameData;
|
private readonly IDataManager _gameData;
|
||||||
private readonly ILogger<ContextMenu> _logger;
|
private readonly ILogger<ContextMenuService> _logger;
|
||||||
private readonly DalamudUtilService _dalamudUtil;
|
private readonly DalamudUtilService _dalamudUtil;
|
||||||
private readonly LightlessConfigService _configService;
|
private readonly LightlessConfigService _configService;
|
||||||
private readonly IClientState _clientState;
|
private readonly IClientState _clientState;
|
||||||
@@ -34,11 +33,11 @@ internal class ContextMenu : IHostedService
|
|||||||
"SocialList", "ContactList", "BeginnerChatList", "MuteList"
|
"SocialList", "ContactList", "BeginnerChatList", "MuteList"
|
||||||
];
|
];
|
||||||
|
|
||||||
public ContextMenu(
|
public ContextMenuService(
|
||||||
IContextMenu contextMenu,
|
IContextMenu contextMenu,
|
||||||
IDalamudPluginInterface pluginInterface,
|
IDalamudPluginInterface pluginInterface,
|
||||||
IDataManager gameData,
|
IDataManager gameData,
|
||||||
ILogger<ContextMenu> logger,
|
ILogger<ContextMenuService> logger,
|
||||||
DalamudUtilService dalamudUtil,
|
DalamudUtilService dalamudUtil,
|
||||||
ApiController apiController,
|
ApiController apiController,
|
||||||
IObjectTable objectTable,
|
IObjectTable objectTable,
|
||||||
@@ -100,7 +99,7 @@ internal class ContextMenu : IHostedService
|
|||||||
|
|
||||||
//Check if it is a real target.
|
//Check if it is a real target.
|
||||||
IPlayerCharacter? targetData = GetPlayerFromObjectTable(target);
|
IPlayerCharacter? targetData = GetPlayerFromObjectTable(target);
|
||||||
if (targetData == null || targetData.Address == IntPtr.Zero)
|
if (targetData == null || targetData.Address == nint.Zero)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//Check if user is paired or is own.
|
//Check if user is paired or is own.
|
||||||
@@ -139,7 +138,7 @@ internal class ContextMenu : IHostedService
|
|||||||
{
|
{
|
||||||
IPlayerCharacter? targetData = GetPlayerFromObjectTable(target);
|
IPlayerCharacter? targetData = GetPlayerFromObjectTable(target);
|
||||||
|
|
||||||
if (targetData == null || targetData.Address == IntPtr.Zero)
|
if (targetData == null || targetData.Address == nint.Zero)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Target player {TargetName}@{World} not found in object table.", target.TargetName, world.Name);
|
_logger.LogWarning("Target player {TargetName}@{World} not found in object table.", target.TargetName, world.Name);
|
||||||
return;
|
return;
|
||||||
@@ -156,10 +155,9 @@ internal class ContextMenu : IHostedService
|
|||||||
_logger.LogError(ex, "Error sending pair request.");
|
_logger.LogError(ex, "Error sending pair request.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private HashSet<ulong> VisibleUserIds => _pairManager.GetOnlineUserPairs()
|
private HashSet<ulong> VisibleUserIds => [.. _pairManager.GetOnlineUserPairs()
|
||||||
.Where(u => u.IsVisible && u.PlayerCharacterId != uint.MaxValue)
|
.Where(u => u.IsVisible && u.PlayerCharacterId != uint.MaxValue)
|
||||||
.Select(u => (ulong)u.PlayerCharacterId)
|
.Select(u => (ulong)u.PlayerCharacterId)];
|
||||||
.ToHashSet();
|
|
||||||
|
|
||||||
private IPlayerCharacter? GetPlayerFromObjectTable(MenuTargetDefault target)
|
private IPlayerCharacter? GetPlayerFromObjectTable(MenuTargetDefault target)
|
||||||
{
|
{
|
||||||
@@ -196,7 +194,7 @@ internal class ContextMenu : IHostedService
|
|||||||
|
|
||||||
private static bool IsChineseJapaneseKoreanString(string text) => text.All(IsChineseJapaneseKoreanCharacter);
|
private static bool IsChineseJapaneseKoreanString(string text) => text.All(IsChineseJapaneseKoreanCharacter);
|
||||||
|
|
||||||
private static bool IsChineseJapaneseKoreanCharacter(char c) => (c >= 0x4E00 && c <= 0x9FFF);
|
private static bool IsChineseJapaneseKoreanCharacter(char c) => c >= 0x4E00 && c <= 0x9FFF;
|
||||||
|
|
||||||
public bool IsWorldValid(uint worldId) => IsWorldValid(GetWorld(worldId));
|
public bool IsWorldValid(uint worldId) => IsWorldValid(GetWorld(worldId));
|
||||||
|
|
||||||
Reference in New Issue
Block a user