From 0406557d4da8cacfccc321e51417269a06fa51e6 Mon Sep 17 00:00:00 2001 From: r00telement <47005506+r00telement@users.noreply.github.com> Date: Sun, 12 Dec 2021 05:42:35 +0000 Subject: [PATCH] Some cleanup --- PlayerTags/Data/DefaultPluginData.cs | 2 + PlayerTags/Features/ChatTagTargetFeature.cs | 118 ++++++++---------- .../Features/NameplatesTagTargetFeature.cs | 46 +++---- PlayerTags/Features/TagTargetFeature.cs | 94 +++++++++----- PlayerTags/PlayerTags.csproj | 4 +- PlayerTags/Resources/Strings.Designer.cs | 72 +++++++++++ PlayerTags/Resources/Strings.resx | 27 ++++ 7 files changed, 236 insertions(+), 127 deletions(-) diff --git a/PlayerTags/Data/DefaultPluginData.cs b/PlayerTags/Data/DefaultPluginData.cs index 226b9a1..07bdee7 100644 --- a/PlayerTags/Data/DefaultPluginData.cs +++ b/PlayerTags/Data/DefaultPluginData.cs @@ -14,9 +14,11 @@ namespace PlayerTags.Data public Dictionary RolesByJobAbbreviation { get; } public Dictionary AllTagsChanges { get; } + public Dictionary AllRoleTagsChanges { get; } public Dictionary> RoleTagsChanges { get; } public Dictionary> JobTagsChanges { get; } + public Dictionary AllCustomTagsChanges { get; } public DefaultPluginData() diff --git a/PlayerTags/Features/ChatTagTargetFeature.cs b/PlayerTags/Features/ChatTagTargetFeature.cs index b350911..b324973 100644 --- a/PlayerTags/Features/ChatTagTargetFeature.cs +++ b/PlayerTags/Features/ChatTagTargetFeature.cs @@ -13,50 +13,6 @@ namespace PlayerTags.Features { public class ChatTagTargetFeature : TagTargetFeature { - private PluginConfiguration m_PluginConfiguration; - private PluginData m_PluginData; - - public ChatTagTargetFeature(PluginConfiguration pluginConfiguration, PluginData pluginData) - : base(pluginConfiguration) - { - m_PluginConfiguration = pluginConfiguration; - m_PluginData = pluginData; - - PluginServices.ChatGui.ChatMessage += Chat_ChatMessage; - } - - public override void Dispose() - { - PluginServices.ChatGui.ChatMessage -= Chat_ChatMessage; - base.Dispose(); - } - - private void Chat_ChatMessage(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled) - { - AddTagsToChat(sender, out _); - AddTagsToChat(message, out _); - } - - protected override BitmapFontIcon? GetIcon(Tag tag) - { - if (tag.IsIconVisibleInChat.InheritedValue != null && tag.IsIconVisibleInChat.InheritedValue.Value) - { - return tag.Icon.InheritedValue; - } - - return null; - } - - protected override string? GetText(Tag tag) - { - if (tag.IsTextVisibleInChat.InheritedValue != null && tag.IsTextVisibleInChat.InheritedValue.Value) - { - return tag.Text.InheritedValue; - } - - return null; - } - /// /// A match found within a string. /// @@ -103,6 +59,50 @@ namespace PlayerTags.Features } } + private PluginConfiguration m_PluginConfiguration; + private PluginData m_PluginData; + + public ChatTagTargetFeature(PluginConfiguration pluginConfiguration, PluginData pluginData) + : base(pluginConfiguration) + { + m_PluginConfiguration = pluginConfiguration; + m_PluginData = pluginData; + + PluginServices.ChatGui.ChatMessage += Chat_ChatMessage; + } + + public override void Dispose() + { + PluginServices.ChatGui.ChatMessage -= Chat_ChatMessage; + base.Dispose(); + } + + private void Chat_ChatMessage(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled) + { + AddTagsToChat(sender, out _); + AddTagsToChat(message, out _); + } + + protected override bool IsIconVisible(Tag tag) + { + if (tag.IsIconVisibleInChat.InheritedValue != null) + { + return tag.IsIconVisibleInChat.InheritedValue.Value; + } + + return false; + } + + protected override bool IsTextVisible(Tag tag) + { + if (tag.IsTextVisibleInChat.InheritedValue != null) + { + return tag.IsTextVisibleInChat.InheritedValue.Value; + } + + return false; + } + /// /// Searches the given string for game object matches. /// @@ -182,18 +182,12 @@ namespace PlayerTags.Features // Add the job tag if (m_PluginData.JobTags.TryGetValue(character.ClassJob.GameData.Abbreviation, out var jobTag)) { - bool isVisible = IsVisibleInActivity(jobTag) && - (!(stringMatch.GameObject is PlayerCharacter playerCharacter) || IsVisibleForPlayer(jobTag, playerCharacter)); - - if (isVisible) + if (jobTag.TagPositionInChat.InheritedValue != null) { - if (jobTag.TagPositionInChat.InheritedValue != null) + var payloads = GetPayloads(stringMatch.GameObject, jobTag); + if (payloads.Any()) { - var payloads = GetPayloads(jobTag); - if (payloads.Any()) - { - AddPayloadChanges(jobTag.TagPositionInChat.InheritedValue.Value, payloads, stringChanges); - } + AddPayloadChanges(jobTag.TagPositionInChat.InheritedValue.Value, payloads, stringChanges); } } } @@ -216,20 +210,14 @@ namespace PlayerTags.Features // Add the custom tag payloads foreach (var customTag in m_PluginData.CustomTags) { - bool isVisible = IsVisibleInActivity(customTag) && - (!(stringMatch.GameObject is PlayerCharacter playerCharacter) || IsVisibleForPlayer(customTag, playerCharacter)); - - if (isVisible) + if (customTag.TagPositionInChat.InheritedValue != null) { - if (customTag.TagPositionInChat.InheritedValue != null) + if (customTag.IncludesGameObjectNameToApplyTo(stringMatch.GetMatchText())) { - if (customTag.IncludesGameObjectNameToApplyTo(stringMatch.GetMatchText())) + var customTagPayloads = GetPayloads(stringMatch.GameObject, customTag); + if (customTagPayloads.Any()) { - var customTagPayloads = GetPayloads(customTag); - if (customTagPayloads.Any()) - { - AddPayloadChanges(customTag.TagPositionInChat.InheritedValue.Value, customTagPayloads, stringChanges); - } + AddPayloadChanges(customTag.TagPositionInChat.InheritedValue.Value, customTagPayloads, stringChanges); } } } diff --git a/PlayerTags/Features/NameplatesTagTargetFeature.cs b/PlayerTags/Features/NameplatesTagTargetFeature.cs index 06d7846..ccef704 100644 --- a/PlayerTags/Features/NameplatesTagTargetFeature.cs +++ b/PlayerTags/Features/NameplatesTagTargetFeature.cs @@ -64,24 +64,24 @@ namespace PlayerTags.Features Unhook(); } - protected override BitmapFontIcon? GetIcon(Tag tag) + protected override bool IsIconVisible(Tag tag) { - if (tag.IsIconVisibleInNameplates.InheritedValue != null && tag.IsIconVisibleInNameplates.InheritedValue.Value) + if (tag.IsIconVisibleInNameplates.InheritedValue != null) { - return tag.Icon.InheritedValue; + return tag.IsIconVisibleInNameplates.InheritedValue.Value; } - return null; + return false; } - protected override string? GetText(Tag tag) + protected override bool IsTextVisible(Tag tag) { - if (tag.IsTextVisibleInNameplates.InheritedValue != null && tag.IsTextVisibleInNameplates.InheritedValue.Value) + if (tag.IsTextVisibleInNameplates.InheritedValue != null) { - return tag.Text.InheritedValue; + return tag.IsTextVisibleInNameplates.InheritedValue.Value; } - return null; + return false; } /// @@ -181,18 +181,12 @@ namespace PlayerTags.Features // Add the job tag if (m_PluginData.JobTags.TryGetValue(character.ClassJob.GameData.Abbreviation, out var jobTag)) { - bool isVisible = IsVisibleInActivity(jobTag) && - (!(gameObject is PlayerCharacter playerCharacter) || IsVisibleForPlayer(jobTag, playerCharacter)); - - if (isVisible) + if (jobTag.TagTargetInNameplates.InheritedValue != null && jobTag.TagPositionInNameplates.InheritedValue != null) { - if (jobTag.TagTargetInNameplates.InheritedValue != null && jobTag.TagPositionInNameplates.InheritedValue != null) + var payloads = GetPayloads(gameObject, jobTag); + if (payloads.Any()) { - var payloads = GetPayloads(jobTag); - if (payloads.Any()) - { - AddPayloadChanges(jobTag.TagTargetInNameplates.InheritedValue.Value, jobTag.TagPositionInNameplates.InheritedValue.Value, payloads, nameplateChanges); - } + AddPayloadChanges(jobTag.TagTargetInNameplates.InheritedValue.Value, jobTag.TagPositionInNameplates.InheritedValue.Value, payloads, nameplateChanges); } } } @@ -215,20 +209,14 @@ namespace PlayerTags.Features // Add the custom tag payloads foreach (var customTag in m_PluginData.CustomTags) { - bool isVisible = IsVisibleInActivity(customTag) && - (!(gameObject is PlayerCharacter playerCharacter) || IsVisibleForPlayer(customTag, playerCharacter)); - - if (isVisible) + if (customTag.TagTargetInNameplates.InheritedValue != null && customTag.TagPositionInNameplates.InheritedValue != null) { - if (customTag.TagTargetInNameplates.InheritedValue != null && customTag.TagPositionInNameplates.InheritedValue != null) + if (customTag.IncludesGameObjectNameToApplyTo(gameObject.Name.TextValue)) { - if (customTag.IncludesGameObjectNameToApplyTo(gameObject.Name.TextValue)) + var payloads = GetPayloads(gameObject, customTag); + if (payloads.Any()) { - var payloads = GetPayloads(customTag); - if (payloads.Any()) - { - AddPayloadChanges(customTag.TagTargetInNameplates.InheritedValue.Value, customTag.TagPositionInNameplates.InheritedValue.Value, payloads, nameplateChanges); - } + AddPayloadChanges(customTag.TagTargetInNameplates.InheritedValue.Value, customTag.TagPositionInNameplates.InheritedValue.Value, payloads, nameplateChanges); } } } diff --git a/PlayerTags/Features/TagTargetFeature.cs b/PlayerTags/Features/TagTargetFeature.cs index 9b4ff48..28ce830 100644 --- a/PlayerTags/Features/TagTargetFeature.cs +++ b/PlayerTags/Features/TagTargetFeature.cs @@ -1,7 +1,9 @@ using Dalamud.Game.ClientState.Objects.Enums; using Dalamud.Game.ClientState.Objects.SubKinds; +using Dalamud.Game.ClientState.Objects.Types; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; +using Dalamud.Logging; using Lumina.Excel.GeneratedSheets; using PlayerTags.Configuration; using PlayerTags.Data; @@ -9,6 +11,7 @@ using PlayerTags.Inheritables; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices; namespace PlayerTags.Features { @@ -17,36 +20,24 @@ namespace PlayerTags.Features private PluginConfiguration m_PluginConfiguration; private ActivityContext m_ActivityContext; - private Dictionary m_TagPayloads; - private TextPayload m_SpaceTextPayload; public TagTargetFeature(PluginConfiguration pluginConfiguration) { m_PluginConfiguration = pluginConfiguration; m_ActivityContext = ActivityContext.Overworld; - m_TagPayloads = new Dictionary(); - m_SpaceTextPayload = new TextPayload($" "); - m_PluginConfiguration.Saved += PluginConfiguration_Saved; PluginServices.ClientState.TerritoryChanged += ClientState_TerritoryChanged; } public virtual void Dispose() { PluginServices.ClientState.TerritoryChanged -= ClientState_TerritoryChanged; - m_PluginConfiguration.Saved -= PluginConfiguration_Saved; } - protected abstract BitmapFontIcon? GetIcon(Tag tag); + protected abstract bool IsIconVisible(Tag tag); - protected abstract string? GetText(Tag tag); - - private void PluginConfiguration_Saved() - { - // Invalidate the cached payloads so they get remade - m_TagPayloads.Clear(); - } + protected abstract bool IsTextVisible(Tag tag); private void ClientState_TerritoryChanged(object? sender, ushort e) { @@ -68,25 +59,29 @@ namespace PlayerTags.Features } } } - - // Invalidate the cached payloads so they get remade - m_TagPayloads.Clear(); } /// - /// Gets the payloads for the given tag. If the payloads don't yet exist then they will be created. + /// Gets the payloads for the given game object tag. If the payloads don't yet exist then they will be created. /// + /// The game object to get payloads for. /// The tag config to get payloads for. /// A list of payloads for the given tag. - protected IEnumerable GetPayloads(Tag tag) + protected IEnumerable GetPayloads(GameObject gameObject, Tag tag) { - if (m_TagPayloads.TryGetValue(tag, out var payloads)) + // Only get payloads when in allowed activity contexts + if (!IsVisibleInActivity(tag)) { - return payloads; + return Enumerable.Empty(); } - m_TagPayloads[tag] = CreatePayloads(tag); - return m_TagPayloads[tag]; + // Only get payloads for player characters for allowed player contexts + if (gameObject is PlayerCharacter playerCharacter && !IsVisibleForPlayer(tag, playerCharacter)) + { + return Enumerable.Empty(); + } + + return CreatePayloads(gameObject, tag); } private InheritableValue? GetInheritableVisibilityForActivity(Tag tag, ActivityContext activityContext) @@ -104,7 +99,7 @@ namespace PlayerTags.Features return null; } - public bool IsVisibleInActivity(Tag tag) + private bool IsVisibleInActivity(Tag tag) { var inheritable = GetInheritableVisibilityForActivity(tag, m_ActivityContext); if (inheritable == null) @@ -171,7 +166,7 @@ namespace PlayerTags.Features return null; } - public bool IsVisibleForPlayer(Tag tag, PlayerCharacter playerCharacter) + private bool IsVisibleForPlayer(Tag tag, PlayerCharacter playerCharacter) { var inheritable = GetInheritableVisibilityForPlayer(tag, GetContextForPlayer(playerCharacter)); if (inheritable == null) @@ -187,19 +182,56 @@ namespace PlayerTags.Features return true; } - private Payload[] CreatePayloads(Tag tag) + private string ExpandTextParameters(GameObject gameObject, string text) + { + if (gameObject is PlayerCharacter playerCharacter) + { + var parameterIndex = text.ToLower().IndexOf("{PlayerAverageItemLevel}".ToLower()); + if (parameterIndex >= 0) + { + unsafe + { + FFXIVClientStructs.FFXIV.Client.Game.Character.Character character = Marshal.PtrToStructure(playerCharacter.Address); + byte[] equipSlotData = new byte[40]; + + for (int index = 0; index < equipSlotData.Length; ++index) + { + equipSlotData[index] = character.EquipSlotData[index]; + } + + PluginLog.Debug(string.Join(" ", equipSlotData.Select(d => d.ToString("X2")))); + } + } + } + + return text; + } + + private Payload[] CreatePayloads(GameObject gameObject, Tag tag) { List newPayloads = new List(); - BitmapFontIcon? icon = GetIcon(tag); + BitmapFontIcon? icon = null; + if (IsIconVisible(tag)) + { + icon = tag.Icon.InheritedValue; + } + if (icon != null && icon.Value != BitmapFontIcon.None) { newPayloads.Add(new IconPayload(icon.Value)); } - string? text = GetText(tag); + string? text = null; + if (IsTextVisible(tag)) + { + text = tag.Text.InheritedValue; + } + if (!string.IsNullOrWhiteSpace(text)) { + text = ExpandTextParameters(gameObject, text); + if (tag.IsTextItalic.InheritedValue != null && tag.IsTextItalic.InheritedValue.Value) { newPayloads.Add(new EmphasisItalicPayload(true)); @@ -275,7 +307,7 @@ namespace PlayerTags.Features foreach (var indexToInsertSpaceAt in indicesToInsertSpacesAt) { - payloads.Insert(indexToInsertSpaceAt, m_SpaceTextPayload); + payloads.Insert(indexToInsertSpaceAt, new TextPayload($" ")); } // Decide whether to add a space to the end @@ -284,7 +316,7 @@ namespace PlayerTags.Features var significantPayloads = payloads.Where(payload => payload is TextPayload || payload is IconPayload); if (significantPayloads.Last() is TextPayload) { - payloads.Add(m_SpaceTextPayload); + payloads.Add(new TextPayload($" ")); } } // Decide whether to add a space to the beginning @@ -293,7 +325,7 @@ namespace PlayerTags.Features var significantPayloads = payloads.Where(payload => payload is TextPayload || payload is IconPayload); if (significantPayloads.First() is TextPayload) { - payloads.Insert(0, m_SpaceTextPayload); + payloads.Insert(0, new TextPayload($" ")); } } } diff --git a/PlayerTags/PlayerTags.csproj b/PlayerTags/PlayerTags.csproj index 9af4040..bb02413 100644 --- a/PlayerTags/PlayerTags.csproj +++ b/PlayerTags/PlayerTags.csproj @@ -1,7 +1,7 @@  r00telement - 1.1.2.0 + 1.1.3.0 @@ -21,7 +21,7 @@ - + $(DalamudLibPath)FFXIVClientStructs.dll false diff --git a/PlayerTags/Resources/Strings.Designer.cs b/PlayerTags/Resources/Strings.Designer.cs index a9a0d9e..7d8c04b 100644 --- a/PlayerTags/Resources/Strings.Designer.cs +++ b/PlayerTags/Resources/Strings.Designer.cs @@ -357,6 +357,15 @@ namespace PlayerTags.Resources { } } + /// + /// Looks up a localized string similar to Whether the tag should be visible for alliance members who are not in the current party.. + /// + public static string Loc_IsVisibleForAlliancePlayers_Description { + get { + return ResourceManager.GetString("Loc_IsVisibleForAlliancePlayers_Description", resourceCulture); + } + } + /// /// Looks up a localized string similar to Show for enemies. /// @@ -366,6 +375,15 @@ namespace PlayerTags.Resources { } } + /// + /// Looks up a localized string similar to Whether the tag should be visible for enemies in pvp.. + /// + public static string Loc_IsVisibleForEnemyPlayers_Description { + get { + return ResourceManager.GetString("Loc_IsVisibleForEnemyPlayers_Description", resourceCulture); + } + } + /// /// Looks up a localized string similar to Show for friends. /// @@ -375,6 +393,15 @@ namespace PlayerTags.Resources { } } + /// + /// Looks up a localized string similar to Whether the tag should be visible for friends.. + /// + public static string Loc_IsVisibleForFriendPlayers_Description { + get { + return ResourceManager.GetString("Loc_IsVisibleForFriendPlayers_Description", resourceCulture); + } + } + /// /// Looks up a localized string similar to Show for others. /// @@ -384,6 +411,15 @@ namespace PlayerTags.Resources { } } + /// + /// Looks up a localized string similar to Whether the tag should be visible for players in other circumstances for which there is no specific option.. + /// + public static string Loc_IsVisibleForOtherPlayers_Description { + get { + return ResourceManager.GetString("Loc_IsVisibleForOtherPlayers_Description", resourceCulture); + } + } + /// /// Looks up a localized string similar to Show for party members. /// @@ -393,6 +429,15 @@ namespace PlayerTags.Resources { } } + /// + /// Looks up a localized string similar to Whether the tag should be visible for party members.. + /// + public static string Loc_IsVisibleForPartyPlayers_Description { + get { + return ResourceManager.GetString("Loc_IsVisibleForPartyPlayers_Description", resourceCulture); + } + } + /// /// Looks up a localized string similar to Show for self. /// @@ -402,6 +447,15 @@ namespace PlayerTags.Resources { } } + /// + /// Looks up a localized string similar to Whether the tag should be visible for the local player.. + /// + public static string Loc_IsVisibleForSelf_Description { + get { + return ResourceManager.GetString("Loc_IsVisibleForSelf_Description", resourceCulture); + } + } + /// /// Looks up a localized string similar to Show elsewhere. /// @@ -411,6 +465,15 @@ namespace PlayerTags.Resources { } } + /// + /// Looks up a localized string similar to Whether the tag should be visible in other circumstances for which there is no specific option.. + /// + public static string Loc_IsVisibleInOverworld_Description { + get { + return ResourceManager.GetString("Loc_IsVisibleInOverworld_Description", resourceCulture); + } + } + /// /// Looks up a localized string similar to Show in pve duties. /// @@ -420,6 +483,15 @@ namespace PlayerTags.Resources { } } + /// + /// Looks up a localized string similar to Whether the tag should be visible in pvp duties.. + /// + public static string Loc_IsVisibleInPveDuties_Description { + get { + return ResourceManager.GetString("Loc_IsVisibleInPveDuties_Description", resourceCulture); + } + } + /// /// Looks up a localized string similar to Show in pvp duties. /// diff --git a/PlayerTags/Resources/Strings.resx b/PlayerTags/Resources/Strings.resx index 4a97185..0b69842 100644 --- a/PlayerTags/Resources/Strings.resx +++ b/PlayerTags/Resources/Strings.resx @@ -427,31 +427,58 @@ Show in pve duties + + Whether the tag should be visible in pve duties. + Show in pvp duties + + Whether the tag should be visible in pvp duties. + Show elsewhere + + Whether the tag should be visible in other circumstances for which there is no specific option. + Show for self + + Whether the tag should be visible for the local player. + Show for party members + + Whether the tag should be visible for party members. + Show for alliance members + + Whether the tag should be visible for alliance members who are not in the current party. + Show for friends + + Whether the tag should be visible for friends. + Show for enemies + + Whether the tag should be visible for enemies in pvp. + Show for others + + Whether the tag should be visible for players in other circumstances for which there is no specific option. + Sort by proximity