diff --git a/PlayerTags/Plugin.cs b/PlayerTags/Plugin.cs index 2987c2b..1e7f017 100644 --- a/PlayerTags/Plugin.cs +++ b/PlayerTags/Plugin.cs @@ -139,68 +139,69 @@ namespace PlayerTags private void ContextMenu_OpenContextMenu(ContextMenuOpenArgs args) { - if (args.Text == null || !m_PluginConfiguration.IsCustomTagContextMenuEnabled) + if (!m_PluginConfiguration.IsCustomTagContextMenuEnabled || !CanContextMenuSupportTagOptions(args)) { return; } - string gameObjectName = args.Text.TextValue; + string gameObjectName = args.Text!.TextValue; - var removedTags = m_PluginData.CustomTags.Where(tag => !tag.IncludesGameObjectNameToApplyTo(gameObjectName)); - var addTagItem = new NormalContextSubMenuItem(Strings.Loc_Static_ContextMenu_AddTag, (itemArgs => + var notAddedTags = m_PluginData.CustomTags.Where(tag => !tag.IncludesGameObjectNameToApplyTo(gameObjectName)); + if (notAddedTags.Any()) { - foreach (var removedTag in removedTags) + args.Items.Add(new NormalContextSubMenuItem(Strings.Loc_Static_ContextMenu_AddTag, (itemArgs => { - itemArgs.Items.Add(new NormalContextMenuItem(removedTag.Text.Value, (args => + foreach (var notAddedTag in notAddedTags) { - removedTag.AddGameObjectNameToApplyTo(gameObjectName); - }))); - } - - //// TODO: Temp hack because when opening somewhere other than the chat log, the last added item for some reason is added to the { }))); - //} - })); - - if (!removedTags.Any()) - { - addTagItem.Enabled = false; - } - - if (removedTags.Any()) - { - args.Items.Add(addTagItem); + itemArgs.Items.Add(new NormalContextMenuItem(notAddedTag.Text.Value, (args => + { + notAddedTag.AddGameObjectNameToApplyTo(gameObjectName); + }))); + } + }))); } var addedTags = m_PluginData.CustomTags.Where(tag => tag.IncludesGameObjectNameToApplyTo(gameObjectName)); - - var removeTagItem = new NormalContextSubMenuItem(Strings.Loc_Static_ContextMenu_RemoveTag, (itemArgs => - { - foreach (var addedTag in addedTags) - { - itemArgs.Items.Add(new NormalContextMenuItem(addedTag.Text.Value, (args => - { - addedTag.RemoveGameObjectNameToApplyTo(gameObjectName); - }))); - } - - //// TODO: Temp hack because when opening somewhere other than the chat log, the last added item for some reason is added to the { }))); - //} - })); - - if (!addedTags.Any()) - { - removeTagItem.Enabled = false; - } - if (addedTags.Any()) { - args.Items.Add(removeTagItem); + args.Items.Add(new NormalContextSubMenuItem(Strings.Loc_Static_ContextMenu_RemoveTag, (itemArgs => + { + foreach (var addedTag in addedTags) + { + itemArgs.Items.Add(new NormalContextMenuItem(addedTag.Text.Value, (args => + { + addedTag.RemoveGameObjectNameToApplyTo(gameObjectName); + }))); + } + }))); + } + } + + private bool CanContextMenuSupportTagOptions(BaseContextMenuArgs args) + { + if (args.Text == null || args.ObjectWorld == 0 || args.ObjectWorld == 65535) + { + return false; + } + + switch (args.ParentAddonName) + { + case null: + case "_PartyList": + case "ChatLog": + case "ContactList": + case "ContentMemberList": + case "CrossWorldLinkshell": + case "FreeCompany": + case "FriendList": + case "LookingForGroup": + case "LinkShell": + case "PartyMemberList": + case "SocialList": + return true; + + default: + return false; } } diff --git a/PlayerTags/Resources/Strings.Designer.cs b/PlayerTags/Resources/Strings.Designer.cs index 704c029..88b9738 100644 --- a/PlayerTags/Resources/Strings.Designer.cs +++ b/PlayerTags/Resources/Strings.Designer.cs @@ -168,6 +168,15 @@ namespace PlayerTags.Resources { } } + /// + /// Looks up a localized string similar to Expanded. + /// + public static string Loc_IsExpanded { + get { + return ResourceManager.GetString("Loc_IsExpanded", resourceCulture); + } + } + /// /// Looks up a localized string similar to Icon visible in chat. /// diff --git a/PlayerTags/Resources/Strings.resx b/PlayerTags/Resources/Strings.resx index e09c8b8..7d8af61 100644 --- a/PlayerTags/Resources/Strings.resx +++ b/PlayerTags/Resources/Strings.resx @@ -144,6 +144,9 @@ Add '{0}' to {1}. + + Expanded + Enable context menu options for custom tags