From 6047afcd19c4e2a96918c7b28779fea0cb6bc291 Mon Sep 17 00:00:00 2001 From: SheepGoMeh Date: Fri, 5 Jul 2024 21:36:42 +0300 Subject: [PATCH] Further APIX changes --- Visibility/ContextMenu.cs | 207 --------------------------------- Visibility/Service.cs | 2 +- Visibility/Visibility.csproj | 1 - Visibility/VisibilityPlugin.cs | 2 +- Visibility/packages.lock.json | 6 - 5 files changed, 2 insertions(+), 216 deletions(-) delete mode 100644 Visibility/ContextMenu.cs diff --git a/Visibility/ContextMenu.cs b/Visibility/ContextMenu.cs deleted file mode 100644 index 08f107f..0000000 --- a/Visibility/ContextMenu.cs +++ /dev/null @@ -1,207 +0,0 @@ -using System; -using System.Linq; - -using Dalamud.Game.Text.SeStringHandling; -using Dalamud.Game.Text.SeStringHandling.Payloads; - -using Lumina.Excel.GeneratedSheets; - -using Dalamud.ContextMenu; -using Dalamud.Game.Text; - -using Visibility.Void; - -namespace Visibility; - -public class ContextMenu: IDisposable -{ - private bool enabled; - private readonly DalamudContextMenu dalamudContextMenu = new(Service.PluginInterface); - - public void Toggle() - { - if (this.enabled) - { - this.dalamudContextMenu.OnOpenGameObjectContextMenu -= OnOpenContextMenu; - } - else - { - this.dalamudContextMenu.OnOpenGameObjectContextMenu += OnOpenContextMenu; - } - - this.enabled = !this.enabled; - } - - public void Toggle(bool value, bool toggle) - { - if (this.enabled != value || toggle) - { - this.Toggle(); - } - } - - private void Dispose(bool disposing) - { - if (!disposing) - { - return; - } - - this.dalamudContextMenu.OnOpenGameObjectContextMenu -= OnOpenContextMenu; - this.dalamudContextMenu.Dispose(); - } - - public void Dispose() - { - this.Dispose(true); - GC.SuppressFinalize(this); - } - - private static void OnOpenContextMenu(GameObjectContextMenuOpenArgs args) - { - if (args.ParentAddonName is not "ChatLog") - { - return; - } - - if (args.ObjectWorld is ushort.MaxValue or 0 || args.Text?.Payloads.Count != 1 || - args.Text?.Payloads[0] is not TextPayload textPayload) - { - return; - } - - args.AddCustomItem( - VisibilityPlugin.Instance.Configuration.VoidList.SingleOrDefault( - x => x.Name == textPayload.Text && x.HomeworldId == args.ObjectWorld) == null - ? new GameObjectContextMenuItem( - new SeString( - new UIForegroundPayload(539), - new TextPayload($"{SeIconChar.BoxedLetterV.ToIconString()} "), - new UIForegroundPayload(0), - new TextPayload( - VisibilityPlugin.Instance.PluginLocalization.ContextMenuAdd( - VisibilityPlugin.Instance.PluginLocalization.VoidListName))), - AddToVoidList) - : new GameObjectContextMenuItem( - new SeString( - new UIForegroundPayload(539), - new TextPayload($"{SeIconChar.BoxedLetterV.ToIconString()} "), - new UIForegroundPayload(0), - new TextPayload( - VisibilityPlugin.Instance.PluginLocalization.ContextMenuRemove( - VisibilityPlugin.Instance.PluginLocalization.VoidListName))), - RemoveFromVoidList)); - - args.AddCustomItem( - VisibilityPlugin.Instance.Configuration.Whitelist.SingleOrDefault( - x => x.Name == textPayload.Text && x.HomeworldId == args.ObjectWorld) == null - ? new GameObjectContextMenuItem( - new SeString( - new UIForegroundPayload(539), - new TextPayload($"{SeIconChar.BoxedLetterV.ToIconString()} "), - new UIForegroundPayload(0), - new TextPayload( - VisibilityPlugin.Instance.PluginLocalization.ContextMenuAdd( - VisibilityPlugin.Instance.PluginLocalization.WhitelistName))), - AddToWhitelist) - : new GameObjectContextMenuItem( - new SeString( - new UIForegroundPayload(539), - new TextPayload($"{SeIconChar.BoxedLetterV.ToIconString()} "), - new UIForegroundPayload(0), - new TextPayload( - VisibilityPlugin.Instance.PluginLocalization.ContextMenuRemove( - VisibilityPlugin.Instance.PluginLocalization.WhitelistName))), - RemoveFromWhitelist)); - } - - private static void AddToVoidList(GameObjectContextMenuItemSelectedArgs args) - { - World? world = Service.DataManager.GetExcelSheet()? - .SingleOrDefault(x => x.RowId == args.ObjectWorld); - - if (world == null) - { - return; - } - - VisibilityPlugin.Instance.VoidPlayer("ContextMenu", $"{args.Text} {world.Name}"); - } - - private static void RemoveFromVoidList(GameObjectContextMenuItemSelectedArgs args) - { - VoidItem? entry = VisibilityPlugin.Instance.Configuration.VoidList.SingleOrDefault( - x => - x.Name == args.Text?.TextValue && x.HomeworldId == args.ObjectWorld); - - if (entry == null) - { - return; - } - - SeString message = new( - new TextPayload("VoidList: "), - new PlayerPayload(entry.Name, entry.HomeworldId), - new IconPayload(BitmapFontIcon.CrossWorld), - new TextPayload($"{entry.HomeworldName} has been removed.")); - - VisibilityPlugin.Instance.Configuration.VoidList.Remove(entry); - VisibilityPlugin.Instance.Configuration.Save(); - if (entry.ObjectId > 0) - { - VisibilityPlugin.Instance.RemoveChecked(entry.ObjectId); - VisibilityPlugin.Instance.ShowPlayer(entry.ObjectId); - } - else - { - VisibilityPlugin.Instance.RemoveChecked(entry.Name); - VisibilityPlugin.Instance.ShowPlayer(entry.Name); - } - - Service.ChatGui.Print(message); - } - - private static void AddToWhitelist(GameObjectContextMenuItemSelectedArgs args) - { - World? world = Service.DataManager.GetExcelSheet()? - .SingleOrDefault(x => x.RowId == args.ObjectWorld); - - if (world == null) - { - return; - } - - VisibilityPlugin.Instance.WhitelistPlayer("ContextMenu", $"{args.Text} {world.Name}"); - } - - private static void RemoveFromWhitelist(GameObjectContextMenuItemSelectedArgs args) - { - VoidItem? entry = VisibilityPlugin.Instance.Configuration.Whitelist.SingleOrDefault( - x => - x.Name == args.Text?.TextValue && x.HomeworldId == args.ObjectWorld); - - if (entry == null) - { - return; - } - - SeString message = new( - new TextPayload("Whitelist: "), - new PlayerPayload(entry.Name, entry.HomeworldId), - new IconPayload(BitmapFontIcon.CrossWorld), - new TextPayload($"{entry.HomeworldName} has been removed.")); - - VisibilityPlugin.Instance.Configuration.Whitelist.Remove(entry); - VisibilityPlugin.Instance.Configuration.Save(); - if (entry.ObjectId > 0) - { - VisibilityPlugin.Instance.RemoveChecked(entry.ObjectId); - } - else - { - VisibilityPlugin.Instance.RemoveChecked(entry.Name); - } - - Service.ChatGui.Print(message); - } -} diff --git a/Visibility/Service.cs b/Visibility/Service.cs index 519bde2..12495ad 100644 --- a/Visibility/Service.cs +++ b/Visibility/Service.cs @@ -6,7 +6,7 @@ namespace Visibility; public class Service { - [PluginService] public static DalamudPluginInterface PluginInterface { get; set; } = null!; + [PluginService] public static IDalamudPluginInterface PluginInterface { get; set; } = null!; [PluginService] public static ICommandManager CommandManager { get; set; } = null!; diff --git a/Visibility/Visibility.csproj b/Visibility/Visibility.csproj index 0b29782..aff861d 100644 --- a/Visibility/Visibility.csproj +++ b/Visibility/Visibility.csproj @@ -61,7 +61,6 @@ - diff --git a/Visibility/VisibilityPlugin.cs b/Visibility/VisibilityPlugin.cs index 7baa1fd..7c1faa6 100644 --- a/Visibility/VisibilityPlugin.cs +++ b/Visibility/VisibilityPlugin.cs @@ -56,7 +56,7 @@ public class VisibilityPlugin: IDalamudPlugin public Windows.Configuration ConfigurationWindow { get; } - public VisibilityPlugin(DalamudPluginInterface pluginInterface) + public VisibilityPlugin(IDalamudPluginInterface pluginInterface) { Instance = this; diff --git a/Visibility/packages.lock.json b/Visibility/packages.lock.json index 37a34a7..19fcea9 100644 --- a/Visibility/packages.lock.json +++ b/Visibility/packages.lock.json @@ -2,12 +2,6 @@ "version": 1, "dependencies": { "net8.0-windows7.0": { - "Dalamud.ContextMenu": { - "type": "Direct", - "requested": "[1.3.1, )", - "resolved": "1.3.1", - "contentHash": "ptAxut5PiLnzZ4G/KQdHJVcyklC/BF3otHJ7zYVUPiKBjsOCoF0n/6h2jK7e+8ev2Y1yAY3Wtx2GuXLFQgt9Uw==" - }, "DalamudPackager": { "type": "Direct", "requested": "[2.1.13, )",