From 9ca8480922308b1b3dfb104ad1afc6e9006c3666 Mon Sep 17 00:00:00 2001 From: r00telement <47005506+r00telement@users.noreply.github.com> Date: Fri, 10 Dec 2021 04:38:20 +0000 Subject: [PATCH] Add activity and player context visibility options - Options for show in pve/pvp duties, showing for self/friends/party/alliance/enemies --- .../Configuration/PluginConfiguration.cs | 15 +- .../Configuration/PluginConfigurationUI.cs | 192 +++++++++++------- PlayerTags/Data/ActivityContext.cs | 9 + PlayerTags/Data/DefaultPluginData.cs | 11 + .../Data/InheritableCategoryAttribute.cs | 14 ++ PlayerTags/Data/PlayerContext.cs | 12 ++ PlayerTags/Data/Tag.cs | 35 +++- PlayerTags/Data/TagTarget.cs | 2 +- PlayerTags/Features/ChatTagTargetFeature.cs | 33 ++- .../Features/NameplatesTagTargetFeature.cs | 30 ++- PlayerTags/Features/TagTargetFeature.cs | 133 +++++++++++- PlayerTags/Plugin.cs | 10 - PlayerTags/Resources/Strings.Designer.cs | 112 +++++++++- PlayerTags/Resources/Strings.resx | 46 ++++- 14 files changed, 534 insertions(+), 120 deletions(-) create mode 100644 PlayerTags/Data/ActivityContext.cs create mode 100644 PlayerTags/Data/InheritableCategoryAttribute.cs create mode 100644 PlayerTags/Data/PlayerContext.cs diff --git a/PlayerTags/Configuration/PluginConfiguration.cs b/PlayerTags/Configuration/PluginConfiguration.cs index bfad873..d7c8dc8 100644 --- a/PlayerTags/Configuration/PluginConfiguration.cs +++ b/PlayerTags/Configuration/PluginConfiguration.cs @@ -39,16 +39,8 @@ namespace PlayerTags.Configuration [JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)] public List> CustomTagsChanges = new List>(); - [NonSerialized] - private DalamudPluginInterface? m_PluginInterface; - public event System.Action? Saved; - public void Initialize(DalamudPluginInterface pluginInterface) - { - m_PluginInterface = pluginInterface; - } - public void Save(PluginData pluginData) { AllTagsChanges = pluginData.AllTags.GetChanges(pluginData.Default.AllTagsChanges); @@ -88,11 +80,8 @@ namespace PlayerTags.Configuration CustomTagsChanges.Add(customTag.GetChanges()); } - if (m_PluginInterface != null) - { - m_PluginInterface.SavePluginConfig(this); - Saved?.Invoke(); - }; + PluginServices.DalamudPluginInterface.SavePluginConfig(this); + Saved?.Invoke(); } } } diff --git a/PlayerTags/Configuration/PluginConfigurationUI.cs b/PlayerTags/Configuration/PluginConfigurationUI.cs index 9ada69d..74df546 100644 --- a/PlayerTags/Configuration/PluginConfigurationUI.cs +++ b/PlayerTags/Configuration/PluginConfigurationUI.cs @@ -1,5 +1,7 @@ using Dalamud.Game.ClientState.Objects.SubKinds; +using Dalamud.Game.Text.SeStringHandling; using Dalamud.Interface; +using Dalamud.Logging; using ImGuiNET; using Lumina.Excel.GeneratedSheets; using PlayerTags.Data; @@ -448,7 +450,7 @@ namespace PlayerTags.Configuration public void DrawControls(Tag tag) { ImGui.PushID(tag.GetHashCode().ToString()); - ImGui.TreePush(); + //ImGui.TreePush(); // Render the add property override button and popup if (ImGui.IsPopupOpen("AddPopup")) @@ -483,36 +485,68 @@ namespace PlayerTags.Configuration ImGui.PushStyleColor(ImGuiCol.FrameBg, new Vector4(0f, 0f, 0f, 0)); if (ImGui.BeginListBox("###SelectableInheritables")) { - var selectableInheritables = tag.Inheritables.Where(inheritable => inheritable.Value.Behavior == InheritableBehavior.Inherit).ToDictionary(item => item.Key, item => item.Value); - var selectableInheritablesWithLocalizedNames = selectableInheritables - .Select(inheritable => new { Name = inheritable.Key, LocalizedName = Localizer.GetString(inheritable.Key, false) }) - .OrderBy(item => item.LocalizedName); - - foreach (var inheritableLocalizedName in selectableInheritablesWithLocalizedNames) - { - bool isSelected = false; - if (ImGui.Selectable(inheritableLocalizedName.LocalizedName, isSelected)) + IEnumerable> inheritables1 = tag.Inheritables.Where(inheritable => inheritable.Value.Behavior == InheritableBehavior.Inherit); + var selectedInheritables1 = inheritables1 + .Select(inheritable => { - selectableInheritables[inheritableLocalizedName.Name].Behavior = InheritableBehavior.Enabled; + string? categoryId = null; - if (selectableInheritables[inheritableLocalizedName.Name] is InheritableValue inheritableBool) + var field = tag.GetType().GetField(inheritable.Key); + if (field != null) { - inheritableBool.Value = true; + var inheritableCategory = field.GetCustomAttributes(typeof(InheritableCategoryAttribute), false).Cast().FirstOrDefault(); + if (inheritableCategory != null) + { + categoryId = inheritableCategory.CategoryId; + } } - m_PluginConfiguration.Save(m_PluginData); - ImGui.CloseCurrentPopup(); + return new + { + Inheritable = inheritable, + CategoryId = categoryId, + LocalizedName = Localizer.GetString(inheritable.Key, false) + }; + }).Where(inheritable => inheritable.CategoryId != null); + + var inheritableGroups1 = selectedInheritables1.GroupBy(inheritable => inheritable.CategoryId); + + foreach (var inheritableGroup in inheritableGroups1) + { + + if (inheritableGroup.Key != null) + { + DrawHeading(Localizer.GetString(inheritableGroup.Key, false)); } - if (isSelected) + ImGui.TreePush(); + foreach (var selectedInheritable in inheritableGroup) { - ImGui.SetItemDefaultFocus(); - } + bool isSelected = false; + if (ImGui.Selectable(selectedInheritable.LocalizedName, isSelected)) + { + selectedInheritable.Inheritable.Value.Behavior = InheritableBehavior.Enabled; - if (ImGui.IsItemHovered()) - { - ImGui.SetTooltip(Localizer.GetString(inheritableLocalizedName.Name, true)); + if (selectedInheritable.Inheritable.Value is InheritableValue inheritableBool) + { + inheritableBool.Value = true; + } + + m_PluginConfiguration.Save(m_PluginData); + ImGui.CloseCurrentPopup(); + } + + if (isSelected) + { + ImGui.SetItemDefaultFocus(); + } + + if (ImGui.IsItemHovered()) + { + ImGui.SetTooltip(Localizer.GetString(selectedInheritable.Inheritable.Key, true)); + } } + ImGui.TreePop(); } ImGui.EndListBox(); @@ -538,61 +572,77 @@ namespace PlayerTags.Configuration inheritables = inheritables.Where(inheritable => inheritable.Value.Behavior != InheritableBehavior.Inherit); } - var selectedInheritables = inheritables.ToDictionary(item => item.Key, item => item.Value); - var selectedInheritablesWithLocalizedNames = selectedInheritables - .Select(inheritable => new { Name = inheritable.Key, LocalizedName = Localizer.GetString(inheritable.Key, false) }) - .OrderBy(item => item.LocalizedName); - - foreach (var selectedInheritablesWithLocalizedName in selectedInheritablesWithLocalizedNames) - { - switch (selectedInheritablesWithLocalizedName.Name) + var selectedInheritables = inheritables + .Select(inheritable => { - case nameof(tag.Icon): - DrawInheritable(nameof(tag.Icon), false, true, tag.Icon); - break; - case nameof(tag.IsIconVisibleInChat): - DrawInheritable(nameof(tag.IsIconVisibleInChat), tag.IsIconVisibleInChat); - break; - case nameof(tag.IsIconVisibleInNameplates): - DrawInheritable(nameof(tag.IsIconVisibleInNameplates), tag.IsIconVisibleInNameplates); - break; - case nameof(tag.Text): - DrawInheritable(nameof(tag.Text), tag.Text); - break; - case nameof(tag.TextColor): - DrawInheritable(nameof(tag.TextColor), tag.TextColor); - break; - case nameof(tag.TextGlowColor): - DrawInheritable(nameof(tag.TextGlowColor), tag.TextGlowColor); - break; - case nameof(tag.IsTextItalic): - DrawInheritable(nameof(tag.IsTextItalic), tag.IsTextItalic); - break; - case nameof(tag.IsTextVisibleInChat): - DrawInheritable(nameof(tag.IsTextVisibleInChat), tag.IsTextVisibleInChat); - break; - case nameof(tag.IsTextVisibleInNameplates): - DrawInheritable(nameof(tag.IsTextVisibleInNameplates), tag.IsTextVisibleInNameplates); - break; - case nameof(tag.TagPositionInChat): - DrawInheritable(nameof(tag.TagPositionInChat), true, false, tag.TagPositionInChat); - break; - case nameof(tag.TagPositionInNameplates): - DrawInheritable(nameof(tag.TagPositionInNameplates), true, false, tag.TagPositionInNameplates); - break; - case nameof(tag.TagTargetInNameplates): - DrawInheritable(nameof(tag.TagTargetInNameplates), true, false, tag.TagTargetInNameplates); - break; - case nameof(tag.GameObjectNamesToApplyTo): - DrawInheritable(nameof(tag.GameObjectNamesToApplyTo), tag.GameObjectNamesToApplyTo); - break; - default: - break; + string? categoryId = null; + + var field = tag.GetType().GetField(inheritable.Key); + if (field != null) + { + var inheritableCategory = field.GetCustomAttributes(typeof(InheritableCategoryAttribute), false).Cast().FirstOrDefault(); + if (inheritableCategory != null) + { + categoryId = inheritableCategory.CategoryId; + } + } + + return new + { + Inheritable = inheritable, + CategoryId = categoryId, + LocalizedName = Localizer.GetString(inheritable.Key, false) + }; + }).Where(inheritable => inheritable.CategoryId != null); + + var inheritableGroups = selectedInheritables.GroupBy(inheritable => inheritable.CategoryId); + + foreach (var inheritableGroup in inheritableGroups) + { + ImGui.Spacing(); + ImGui.Spacing(); + if (inheritableGroup.Key != null) + { + DrawHeading(Localizer.GetString(inheritableGroup.Key, false)); } + + ImGui.TreePush(); + foreach (var selectedInheritable in inheritableGroup) + { + if (selectedInheritable.Inheritable.Value is InheritableValue inheritableBool) + { + DrawInheritable(selectedInheritable.Inheritable.Key, inheritableBool); + } + else if (selectedInheritable.Inheritable.Value is InheritableValue inheritableUshort) + { + DrawInheritable(selectedInheritable.Inheritable.Key, inheritableUshort); + } + else if (selectedInheritable.Inheritable.Value is InheritableValue inheritableBitmapFontIcon) + { + DrawInheritable(selectedInheritable.Inheritable.Key, false, true, inheritableBitmapFontIcon); + } + else if (selectedInheritable.Inheritable.Value is InheritableValue inheritableTagPosition) + { + DrawInheritable(selectedInheritable.Inheritable.Key, false, true, inheritableTagPosition); + } + else if (selectedInheritable.Inheritable.Value is InheritableValue inheritableNameplateElement) + { + DrawInheritable(selectedInheritable.Inheritable.Key, true, false, inheritableNameplateElement); + } + else if (selectedInheritable.Inheritable.Value is InheritableReference inheritableString) + { + DrawInheritable(selectedInheritable.Inheritable.Key, inheritableString); + } + else + { + PluginLog.Warning($"Rendering for inheritable option not implemented: {selectedInheritable.Inheritable.Key}"); + } + } + ImGui.TreePop(); } - ImGui.TreePop(); + //ImGui.TreePop(); ImGui.PopID(); } diff --git a/PlayerTags/Data/ActivityContext.cs b/PlayerTags/Data/ActivityContext.cs new file mode 100644 index 0000000..878a1a4 --- /dev/null +++ b/PlayerTags/Data/ActivityContext.cs @@ -0,0 +1,9 @@ +namespace PlayerTags.Data +{ + public enum ActivityContext + { + Overworld, + PveDuty, + PvpDuty, + } +} diff --git a/PlayerTags/Data/DefaultPluginData.cs b/PlayerTags/Data/DefaultPluginData.cs index b6f5357..226b9a1 100644 --- a/PlayerTags/Data/DefaultPluginData.cs +++ b/PlayerTags/Data/DefaultPluginData.cs @@ -40,6 +40,17 @@ namespace PlayerTags.Data TagPositionInNameplates = TagPosition.Replace, TagTargetInNameplates = NameplateElement.Title, IsTextItalic = true, + + IsVisibleInOverworld = true, + IsVisibleInPveDuties = true, + IsVisibleInPvpDuties = true, + + IsVisibleForSelf = true, + IsVisibleForFriendPlayers = true, + IsVisibleForPartyPlayers = true, + IsVisibleForAlliancePlayers = true, + IsVisibleForEnemyPlayers = true, + IsVisibleForOtherPlayers = true, }.GetChanges(); AllRoleTagsChanges = new Tag(new LiteralPluginString("")) diff --git a/PlayerTags/Data/InheritableCategoryAttribute.cs b/PlayerTags/Data/InheritableCategoryAttribute.cs new file mode 100644 index 0000000..bc0e629 --- /dev/null +++ b/PlayerTags/Data/InheritableCategoryAttribute.cs @@ -0,0 +1,14 @@ +using System; + +namespace PlayerTags.Data +{ + public class InheritableCategoryAttribute : Attribute + { + public string CategoryId { get; private set; } + + public InheritableCategoryAttribute(string categoryId) + { + CategoryId = categoryId; + } + } +} diff --git a/PlayerTags/Data/PlayerContext.cs b/PlayerTags/Data/PlayerContext.cs new file mode 100644 index 0000000..52a113c --- /dev/null +++ b/PlayerTags/Data/PlayerContext.cs @@ -0,0 +1,12 @@ +namespace PlayerTags.Data +{ + public enum PlayerContext + { + Self, + Party, + Alliance, + Enemy, + Friend, + Other + } +} diff --git a/PlayerTags/Data/Tag.cs b/PlayerTags/Data/Tag.cs index 6ca34ee..5843610 100644 --- a/PlayerTags/Data/Tag.cs +++ b/PlayerTags/Data/Tag.cs @@ -84,22 +84,55 @@ namespace PlayerTags.Data public InheritableValue IsSelected = new InheritableValue(false); public InheritableValue IsExpanded = new InheritableValue(false); + [InheritableCategory("General")] + public InheritableReference GameObjectNamesToApplyTo = new InheritableReference(""); + + [InheritableCategory("Icon")] public InheritableValue Icon = new InheritableValue(BitmapFontIcon.Aethernet); + [InheritableCategory("Icon")] public InheritableValue IsIconVisibleInChat = new InheritableValue(false); + [InheritableCategory("Icon")] public InheritableValue IsIconVisibleInNameplates = new InheritableValue(false); + [InheritableCategory("Text")] public InheritableReference Text = new InheritableReference(""); + [InheritableCategory("Text")] public InheritableValue TextColor = new InheritableValue(6); + [InheritableCategory("Text")] public InheritableValue TextGlowColor = new InheritableValue(6); + [InheritableCategory("Text")] public InheritableValue IsTextItalic = new InheritableValue(false); + [InheritableCategory("Text")] public InheritableValue IsTextVisibleInChat = new InheritableValue(false); + [InheritableCategory("Text")] public InheritableValue IsTextVisibleInNameplates = new InheritableValue(false); + [InheritableCategory("Position")] public InheritableValue TagPositionInChat = new InheritableValue(TagPosition.Before); + [InheritableCategory("Position")] public InheritableValue TagPositionInNameplates = new InheritableValue(TagPosition.Before); + [InheritableCategory("Position")] public InheritableValue TagTargetInNameplates = new InheritableValue(NameplateElement.Name); - public InheritableReference GameObjectNamesToApplyTo = new InheritableReference(""); + [InheritableCategory("ActivityVisibility")] + public InheritableValue IsVisibleInPveDuties = new InheritableValue(false); + [InheritableCategory("ActivityVisibility")] + public InheritableValue IsVisibleInPvpDuties = new InheritableValue(false); + [InheritableCategory("ActivityVisibility")] + public InheritableValue IsVisibleInOverworld = new InheritableValue(false); + + [InheritableCategory("PlayerVisibility")] + public InheritableValue IsVisibleForSelf = new InheritableValue(false); + [InheritableCategory("PlayerVisibility")] + public InheritableValue IsVisibleForFriendPlayers = new InheritableValue(false); + [InheritableCategory("PlayerVisibility")] + public InheritableValue IsVisibleForPartyPlayers = new InheritableValue(false); + [InheritableCategory("PlayerVisibility")] + public InheritableValue IsVisibleForAlliancePlayers = new InheritableValue(false); + [InheritableCategory("PlayerVisibility")] + public InheritableValue IsVisibleForEnemyPlayers = new InheritableValue(false); + [InheritableCategory("PlayerVisibility")] + public InheritableValue IsVisibleForOtherPlayers = new InheritableValue(false); public string[] SplitGameObjectNamesToApplyTo { diff --git a/PlayerTags/Data/TagTarget.cs b/PlayerTags/Data/TagTarget.cs index 8cb97af..c26d362 100644 --- a/PlayerTags/Data/TagTarget.cs +++ b/PlayerTags/Data/TagTarget.cs @@ -1,4 +1,4 @@ -namespace PlayerTags.Data + namespace PlayerTags.Data { public enum TagTarget { diff --git a/PlayerTags/Features/ChatTagTargetFeature.cs b/PlayerTags/Features/ChatTagTargetFeature.cs index 49fc305..b350911 100644 --- a/PlayerTags/Features/ChatTagTargetFeature.cs +++ b/PlayerTags/Features/ChatTagTargetFeature.cs @@ -1,4 +1,5 @@ -using Dalamud.Game.ClientState.Objects.Types; +using Dalamud.Game.ClientState.Objects.SubKinds; +using Dalamud.Game.ClientState.Objects.Types; using Dalamud.Game.Text; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; @@ -181,12 +182,18 @@ namespace PlayerTags.Features // Add the job tag if (m_PluginData.JobTags.TryGetValue(character.ClassJob.GameData.Abbreviation, out var jobTag)) { - if (jobTag.TagPositionInChat.InheritedValue != null) + bool isVisible = IsVisibleInActivity(jobTag) && + (!(stringMatch.GameObject is PlayerCharacter playerCharacter) || IsVisibleForPlayer(jobTag, playerCharacter)); + + if (isVisible) { - var payloads = GetPayloads(jobTag); - if (payloads.Any()) + if (jobTag.TagPositionInChat.InheritedValue != null) { - AddPayloadChanges(jobTag.TagPositionInChat.InheritedValue.Value, payloads, stringChanges); + var payloads = GetPayloads(jobTag); + if (payloads.Any()) + { + AddPayloadChanges(jobTag.TagPositionInChat.InheritedValue.Value, payloads, stringChanges); + } } } } @@ -209,14 +216,20 @@ namespace PlayerTags.Features // Add the custom tag payloads foreach (var customTag in m_PluginData.CustomTags) { - if (customTag.TagPositionInChat.InheritedValue != null) + bool isVisible = IsVisibleInActivity(customTag) && + (!(stringMatch.GameObject is PlayerCharacter playerCharacter) || IsVisibleForPlayer(customTag, playerCharacter)); + + if (isVisible) { - if (customTag.IncludesGameObjectNameToApplyTo(stringMatch.GetMatchText())) + if (customTag.TagPositionInChat.InheritedValue != null) { - var customTagPayloads = GetPayloads(customTag); - if (customTagPayloads.Any()) + if (customTag.IncludesGameObjectNameToApplyTo(stringMatch.GetMatchText())) { - AddPayloadChanges(customTag.TagPositionInChat.InheritedValue.Value, customTagPayloads, stringChanges); + var customTagPayloads = GetPayloads(customTag); + if (customTagPayloads.Any()) + { + AddPayloadChanges(customTag.TagPositionInChat.InheritedValue.Value, customTagPayloads, stringChanges); + } } } } diff --git a/PlayerTags/Features/NameplatesTagTargetFeature.cs b/PlayerTags/Features/NameplatesTagTargetFeature.cs index 8ff3dd6..06d7846 100644 --- a/PlayerTags/Features/NameplatesTagTargetFeature.cs +++ b/PlayerTags/Features/NameplatesTagTargetFeature.cs @@ -181,12 +181,18 @@ namespace PlayerTags.Features // Add the job tag if (m_PluginData.JobTags.TryGetValue(character.ClassJob.GameData.Abbreviation, out var jobTag)) { - if (jobTag.TagTargetInNameplates.InheritedValue != null && jobTag.TagPositionInNameplates.InheritedValue != null) + bool isVisible = IsVisibleInActivity(jobTag) && + (!(gameObject is PlayerCharacter playerCharacter) || IsVisibleForPlayer(jobTag, playerCharacter)); + + if (isVisible) { - var payloads = GetPayloads(jobTag); - if (payloads.Any()) + if (jobTag.TagTargetInNameplates.InheritedValue != null && jobTag.TagPositionInNameplates.InheritedValue != null) { - AddPayloadChanges(jobTag.TagTargetInNameplates.InheritedValue.Value, jobTag.TagPositionInNameplates.InheritedValue.Value, payloads, nameplateChanges); + var payloads = GetPayloads(jobTag); + if (payloads.Any()) + { + AddPayloadChanges(jobTag.TagTargetInNameplates.InheritedValue.Value, jobTag.TagPositionInNameplates.InheritedValue.Value, payloads, nameplateChanges); + } } } } @@ -209,14 +215,20 @@ namespace PlayerTags.Features // Add the custom tag payloads foreach (var customTag in m_PluginData.CustomTags) { - if (customTag.TagTargetInNameplates.InheritedValue != null && customTag.TagPositionInNameplates.InheritedValue != null) + bool isVisible = IsVisibleInActivity(customTag) && + (!(gameObject is PlayerCharacter playerCharacter) || IsVisibleForPlayer(customTag, playerCharacter)); + + if (isVisible) { - if (customTag.IncludesGameObjectNameToApplyTo(gameObject.Name.TextValue)) + if (customTag.TagTargetInNameplates.InheritedValue != null && customTag.TagPositionInNameplates.InheritedValue != null) { - var payloads = GetPayloads(customTag); - if (payloads.Any()) + if (customTag.IncludesGameObjectNameToApplyTo(gameObject.Name.TextValue)) { - AddPayloadChanges(customTag.TagTargetInNameplates.InheritedValue.Value, customTag.TagPositionInNameplates.InheritedValue.Value, payloads, nameplateChanges); + var payloads = GetPayloads(customTag); + if (payloads.Any()) + { + AddPayloadChanges(customTag.TagTargetInNameplates.InheritedValue.Value, customTag.TagPositionInNameplates.InheritedValue.Value, payloads, nameplateChanges); + } } } } diff --git a/PlayerTags/Features/TagTargetFeature.cs b/PlayerTags/Features/TagTargetFeature.cs index 6734fa4..9b4ff48 100644 --- a/PlayerTags/Features/TagTargetFeature.cs +++ b/PlayerTags/Features/TagTargetFeature.cs @@ -1,7 +1,11 @@ -using Dalamud.Game.Text.SeStringHandling; +using Dalamud.Game.ClientState.Objects.Enums; +using Dalamud.Game.ClientState.Objects.SubKinds; +using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; +using Lumina.Excel.GeneratedSheets; using PlayerTags.Configuration; using PlayerTags.Data; +using PlayerTags.Inheritables; using System; using System.Collections.Generic; using System.Linq; @@ -12,6 +16,7 @@ namespace PlayerTags.Features { private PluginConfiguration m_PluginConfiguration; + private ActivityContext m_ActivityContext; private Dictionary m_TagPayloads; private TextPayload m_SpaceTextPayload; @@ -19,14 +24,17 @@ namespace PlayerTags.Features { 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; } @@ -40,6 +48,31 @@ namespace PlayerTags.Features m_TagPayloads.Clear(); } + private void ClientState_TerritoryChanged(object? sender, ushort e) + { + m_ActivityContext = ActivityContext.Overworld; + + var contentFinderConditionsSheet = PluginServices.DataManager.GameData.GetExcelSheet(); + if (contentFinderConditionsSheet != null) + { + var foundContentFinderCondition = contentFinderConditionsSheet.FirstOrDefault(contentFinderCondition => contentFinderCondition.TerritoryType.Row == PluginServices.ClientState.TerritoryType); + if (foundContentFinderCondition != null) + { + if (foundContentFinderCondition.PvP) + { + m_ActivityContext = ActivityContext.PvpDuty; + } + else + { + m_ActivityContext = ActivityContext.PveDuty; + } + } + } + + // 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. /// @@ -56,6 +89,104 @@ namespace PlayerTags.Features return m_TagPayloads[tag]; } + private InheritableValue? GetInheritableVisibilityForActivity(Tag tag, ActivityContext activityContext) + { + switch (activityContext) + { + case ActivityContext.Overworld: + return tag.IsVisibleInOverworld; + case ActivityContext.PveDuty: + return tag.IsVisibleInPveDuties; + case ActivityContext.PvpDuty: + return tag.IsVisibleInPvpDuties; + } + + return null; + } + + public bool IsVisibleInActivity(Tag tag) + { + var inheritable = GetInheritableVisibilityForActivity(tag, m_ActivityContext); + if (inheritable == null) + { + return false; + } + + if (inheritable.InheritedValue == null || !inheritable.InheritedValue.Value) + { + return false; + } + + return true; + } + + private PlayerContext GetContextForPlayer(PlayerCharacter playerCharacter) + { + if (PluginServices.ClientState.LocalPlayer == playerCharacter) + { + return PlayerContext.Self; + } + + if (playerCharacter.StatusFlags.HasFlag(StatusFlags.Friend)) + { + return PlayerContext.Friend; + } + + if (playerCharacter.StatusFlags.HasFlag(StatusFlags.PartyMember)) + { + return PlayerContext.Party; + } + + if (playerCharacter.StatusFlags.HasFlag(StatusFlags.AllianceMember)) + { + return PlayerContext.Alliance; + } + + if (playerCharacter.StatusFlags.HasFlag(StatusFlags.Hostile)) + { + return PlayerContext.Enemy; + } + + return PlayerContext.Other; + } + + private InheritableValue? GetInheritableVisibilityForPlayer(Tag tag, PlayerContext playerContext) + { + switch (playerContext) + { + case PlayerContext.Self: + return tag.IsVisibleForSelf; + case PlayerContext.Friend: + return tag.IsVisibleForFriendPlayers; + case PlayerContext.Party: + return tag.IsVisibleForPartyPlayers; + case PlayerContext.Alliance: + return tag.IsVisibleForAlliancePlayers; + case PlayerContext.Enemy: + return tag.IsVisibleForEnemyPlayers; + case PlayerContext.Other: + return tag.IsVisibleForOtherPlayers; + } + + return null; + } + + public bool IsVisibleForPlayer(Tag tag, PlayerCharacter playerCharacter) + { + var inheritable = GetInheritableVisibilityForPlayer(tag, GetContextForPlayer(playerCharacter)); + if (inheritable == null) + { + return false; + } + + if (inheritable.InheritedValue == null || !inheritable.InheritedValue.Value) + { + return false; + } + + return true; + } + private Payload[] CreatePayloads(Tag tag) { List newPayloads = new List(); diff --git a/PlayerTags/Plugin.cs b/PlayerTags/Plugin.cs index da5bd29..8368839 100644 --- a/PlayerTags/Plugin.cs +++ b/PlayerTags/Plugin.cs @@ -31,7 +31,6 @@ namespace PlayerTags m_PluginConfigurationUI = new PluginConfigurationUI(m_PluginConfiguration, m_PluginData); m_XivCommon = new XivCommonBase(XivCommon.Hooks.ContextMenu); - PluginServices.ClientState.TerritoryChanged += ClientState_TerritoryChanged; PluginServices.DalamudPluginInterface.UiBuilder.Draw += UiBuilder_Draw; PluginServices.DalamudPluginInterface.UiBuilder.OpenConfigUi += UiBuilder_OpenConfigUi; PluginServices.CommandManager.AddHandler(c_CommandName, new CommandInfo((string command, string arguments) => @@ -44,14 +43,6 @@ namespace PlayerTags m_ChatTagTargetFeature = new ChatTagTargetFeature(m_PluginConfiguration, m_PluginData); } - //private ExcelSheet _contentFinderConditionsSheet; - private void ClientState_TerritoryChanged(object? sender, ushort e) - { - //_contentFinderConditionsSheet = DataManager.GameData.GetExcelSheet(); - //var content = _contentFinderConditionsSheet.FirstOrDefault(t => t.TerritoryType.Row == PluginServices.ClientState.TerritoryType); - //content.ContentMemberType.Row - } - public void Dispose() { m_ChatTagTargetFeature.Dispose(); @@ -60,7 +51,6 @@ namespace PlayerTags PluginServices.CommandManager.RemoveHandler(c_CommandName); PluginServices.DalamudPluginInterface.UiBuilder.OpenConfigUi -= UiBuilder_OpenConfigUi; PluginServices.DalamudPluginInterface.UiBuilder.Draw -= UiBuilder_Draw; - PluginServices.ClientState.TerritoryChanged -= ClientState_TerritoryChanged; m_XivCommon.Dispose(); } diff --git a/PlayerTags/Resources/Strings.Designer.cs b/PlayerTags/Resources/Strings.Designer.cs index ae6b367..a5f7535 100644 --- a/PlayerTags/Resources/Strings.Designer.cs +++ b/PlayerTags/Resources/Strings.Designer.cs @@ -60,6 +60,15 @@ namespace PlayerTags.Resources { } } + /// + /// Looks up a localized string similar to Activities. + /// + public static string Loc_ActivityVisibility { + get { + return ResourceManager.GetString("Loc_ActivityVisibility", resourceCulture); + } + } + /// /// Looks up a localized string similar to All Custom. /// @@ -97,7 +106,7 @@ namespace PlayerTags.Resources { } /// - /// Looks up a localized string similar to Game object names to apply to. + /// Looks up a localized string similar to Add to players. /// public static string Loc_GameObjectNamesToApplyTo { get { @@ -106,7 +115,7 @@ namespace PlayerTags.Resources { } /// - /// Looks up a localized string similar to A list of game object names to always apply tags to, separated by commas or semi-colons. E.g. "Cloud Strife, Tifa Lockhart".. + /// Looks up a localized string similar to A list of players to add tags to, separated by commas or semi-colons. E.g. "Cloud Strife, Tifa Lockhart".. /// public static string Loc_GameObjectNamesToApplyTo_Description { get { @@ -114,6 +123,15 @@ namespace PlayerTags.Resources { } } + /// + /// Looks up a localized string similar to General. + /// + public static string Loc_General { + get { + return ResourceManager.GetString("Loc_General", resourceCulture); + } + } + /// /// Looks up a localized string similar to Icon. /// @@ -312,6 +330,78 @@ namespace PlayerTags.Resources { } } + /// + /// Looks up a localized string similar to Visible for alliance players. + /// + public static string Loc_IsVisibleForAlliancePlayers { + get { + return ResourceManager.GetString("Loc_IsVisibleForAlliancePlayers", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Visible for enemy players. + /// + public static string Loc_IsVisibleForEnemyPlayers { + get { + return ResourceManager.GetString("Loc_IsVisibleForEnemyPlayers", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Visible for other players. + /// + public static string Loc_IsVisibleForOtherPlayers { + get { + return ResourceManager.GetString("Loc_IsVisibleForOtherPlayers", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Visible for party players. + /// + public static string Loc_IsVisibleForPartyPlayers { + get { + return ResourceManager.GetString("Loc_IsVisibleForPartyPlayers", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Visible for self. + /// + public static string Loc_IsVisibleForSelf { + get { + return ResourceManager.GetString("Loc_IsVisibleForSelf", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Visible in overworld. + /// + public static string Loc_IsVisibleInOverworld { + get { + return ResourceManager.GetString("Loc_IsVisibleInOverworld", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Visible in pve duties. + /// + public static string Loc_IsVisibleInPveDuties { + get { + return ResourceManager.GetString("Loc_IsVisibleInPveDuties", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Visible in pvp duties. + /// + public static string Loc_IsVisibleInPvpDuties { + get { + return ResourceManager.GetString("Loc_IsVisibleInPvpDuties", resourceCulture); + } + } + /// /// Looks up a localized string similar to Free company. /// @@ -555,6 +645,24 @@ namespace PlayerTags.Resources { } } + /// + /// Looks up a localized string similar to Players. + /// + public static string Loc_PlayerVisibility { + get { + return ResourceManager.GetString("Loc_PlayerVisibility", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Position. + /// + public static string Loc_Position { + get { + return ResourceManager.GetString("Loc_Position", resourceCulture); + } + } + /// /// Looks up a localized string similar to DPS. /// diff --git a/PlayerTags/Resources/Strings.resx b/PlayerTags/Resources/Strings.resx index d760a18..c0d6d0c 100644 --- a/PlayerTags/Resources/Strings.resx +++ b/PlayerTags/Resources/Strings.resx @@ -382,10 +382,10 @@ - Game object names to apply to + Add to players - A list of game object names to always apply tags to, separated by commas or semi-colons. E.g. "Cloud Strife, Tifa Lockhart". + A list of players to add tags to, separated by commas or semi-colons. E.g. "Cloud Strife, Tifa Lockhart". @@ -410,4 +410,46 @@ Enabled + + + Position + + + General + + + Activities + + + Players + + + + Show in pve duties + + + Show in pvp duties + + + Show elsewhere + + + + Show for self + + + Show for party members + + + Show for alliance members + + + Show for friends + + + Show for enemies + + + Show for others + \ No newline at end of file