tryout of context menu
This commit is contained in:
		| @@ -26,6 +26,7 @@ | ||||
|   </PropertyGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Dalamud.ContextMenu" Version="1.2.2" /> | ||||
|     <PackageReference Include="DalamudPackager" Version="2.1.11" /> | ||||
|     <PackageReference Include="lz4net" Version="1.0.15.93" /> | ||||
|     <PackageReference Include="Meziantou.Analyzer" Version="2.0.19"> | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| using Dalamud.Interface.Internal.Notifications; | ||||
| using Dalamud.Logging; | ||||
| using FFXIVClientStructs.FFXIV.Client.Game.Object; | ||||
| using MareSynchronos.API.Data; | ||||
| using MareSynchronos.API.Data.Enum; | ||||
| using MareSynchronos.API.Dto.User; | ||||
| using MareSynchronos.FileCache; | ||||
| using MareSynchronos.Interop; | ||||
| @@ -12,6 +12,7 @@ using MareSynchronos.Utils; | ||||
| using MareSynchronos.WebAPI.Files; | ||||
| using Microsoft.Extensions.Hosting; | ||||
| using Microsoft.Extensions.Logging; | ||||
| using ObjectKind = MareSynchronos.API.Data.Enum.ObjectKind; | ||||
|  | ||||
| namespace MareSynchronos.PlayerData.Pairs; | ||||
|  | ||||
| @@ -59,7 +60,11 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase | ||||
|     public string? PlayerName { get; private set; } | ||||
|     public string PlayerNameHash => OnlineUser.Ident; | ||||
|     private OnlineUserIdentDto OnlineUser { get; set; } | ||||
|     private IntPtr PlayerCharacter => _charaHandler?.Address ?? IntPtr.Zero; | ||||
|     public IntPtr PlayerCharacter => _charaHandler?.Address ?? IntPtr.Zero; | ||||
|  | ||||
|     public unsafe uint PlayerCharacterId => (_charaHandler?.Address ?? IntPtr.Zero) == IntPtr.Zero | ||||
|         ? uint.MaxValue | ||||
|         : ((GameObject*)_charaHandler.Address)->ObjectID; | ||||
|  | ||||
|     public void ApplyCharacterData(CharacterData characterData, OptionalPluginWarning warning, bool forced = false) | ||||
|     { | ||||
|   | ||||
| @@ -1,4 +1,6 @@ | ||||
| using Dalamud.Utility; | ||||
| using Dalamud.ContextMenu; | ||||
| using Dalamud.Game.Text.SeStringHandling; | ||||
| using Dalamud.Utility; | ||||
| using MareSynchronos.API.Data; | ||||
| using MareSynchronos.API.Data.Comparer; | ||||
| using MareSynchronos.API.Data.Extensions; | ||||
| @@ -170,4 +172,14 @@ public class Pair | ||||
|  | ||||
|         return data; | ||||
|     } | ||||
|  | ||||
|     public void AddContextMenu(GameObjectContextMenuOpenArgs args) | ||||
|     { | ||||
|         if (CachedPlayer == null || args.ObjectId != CachedPlayer.PlayerCharacterId) return; | ||||
|  | ||||
|         args.AddCustomItem(new GameObjectContextMenuItem("Reapply last data", (a) => | ||||
|         { | ||||
|             ApplyLastReceivedData(true); | ||||
|         } ,true)); | ||||
|     } | ||||
| } | ||||
| @@ -1,4 +1,5 @@ | ||||
| using Dalamud.Game.ClientState.Objects.SubKinds; | ||||
| using Dalamud.ContextMenu; | ||||
| using Dalamud.Game.ClientState.Objects.SubKinds; | ||||
| using Dalamud.Interface.Internal.Notifications; | ||||
| using Dalamud.Utility; | ||||
| using MareSynchronos.API.Data; | ||||
| @@ -19,21 +20,36 @@ public sealed class PairManager : DisposableMediatorSubscriberBase | ||||
|     private readonly ConcurrentDictionary<UserData, Pair> _allClientPairs = new(UserDataComparer.Instance); | ||||
|     private readonly ConcurrentDictionary<GroupData, GroupFullInfoDto> _allGroups = new(GroupDataComparer.Instance); | ||||
|     private readonly MareConfigService _configurationService; | ||||
|     private readonly DalamudContextMenu _dalamudContextMenu; | ||||
|     private readonly Func<Pair> _pairFactory; | ||||
|     private Lazy<List<Pair>> _directPairsInternal; | ||||
|  | ||||
|     private Lazy<Dictionary<GroupFullInfoDto, List<Pair>>> _groupPairsInternal; | ||||
|  | ||||
|     public PairManager(ILogger<PairManager> logger, Func<Pair> pairFactory, | ||||
|                 MareConfigService configurationService, MareMediator mediator) : base(logger, mediator) | ||||
|                 MareConfigService configurationService, MareMediator mediator, | ||||
|                 DalamudContextMenu dalamudContextMenu) : base(logger, mediator) | ||||
|     { | ||||
|         _pairFactory = pairFactory; | ||||
|         _configurationService = configurationService; | ||||
|         _dalamudContextMenu = dalamudContextMenu; | ||||
|         Mediator.Subscribe<ZoneSwitchStartMessage>(this, (_) => DalamudUtilOnZoneSwitched()); | ||||
|         Mediator.Subscribe<DelayedFrameworkUpdateMessage>(this, (_) => DalamudUtilOnDelayedFrameworkUpdate()); | ||||
|         Mediator.Subscribe<DisconnectedMessage>(this, (_) => ClearPairs()); | ||||
|         _directPairsInternal = DirectPairsLazy(); | ||||
|         _groupPairsInternal = GroupPairsLazy(); | ||||
|  | ||||
|         _dalamudContextMenu.OnOpenGameObjectContextMenu += DalamudContextMenuOnOnOpenGameObjectContextMenu; | ||||
|     } | ||||
|  | ||||
|     private void DalamudContextMenuOnOnOpenGameObjectContextMenu(GameObjectContextMenuOpenArgs args) | ||||
|     { | ||||
|         if (args.ObjectId == 0xE000000) return; | ||||
|  | ||||
|         foreach (var pair in _allClientPairs.Where((p => p.Value.IsVisible))) | ||||
|         { | ||||
|             pair.Value.AddContextMenu(args); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public List<Pair> DirectPairs => _directPairsInternal.Value; | ||||
| @@ -318,6 +334,8 @@ public sealed class PairManager : DisposableMediatorSubscriberBase | ||||
|     { | ||||
|         base.Dispose(disposing); | ||||
|  | ||||
|         _dalamudContextMenu.OnOpenGameObjectContextMenu -= DalamudContextMenuOnOnOpenGameObjectContextMenu; | ||||
|  | ||||
|         DisposePairs(); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1,4 +1,5 @@ | ||||
| using Dalamud.Data; | ||||
| using Dalamud.ContextMenu; | ||||
| using Dalamud.Data; | ||||
| using Dalamud.Game; | ||||
| using Dalamud.Game.ClientState; | ||||
| using Dalamud.Game.ClientState.Conditions; | ||||
| @@ -57,6 +58,7 @@ public sealed class Plugin : IDalamudPlugin | ||||
|             // add mare related singletons | ||||
|             collection.AddSingleton<MareMediator>(); | ||||
|             collection.AddSingleton<FileCacheManager>(); | ||||
|             collection.AddSingleton<DalamudContextMenu>(); | ||||
|             collection.AddSingleton<ServerConfigurationManager>(); | ||||
|             collection.AddSingleton<PairManager>(); | ||||
|             collection.AddSingleton<ApiController>(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Stanley Dimant
					Stanley Dimant