6 Commits

13 changed files with 650 additions and 494 deletions

View File

@@ -0,0 +1,18 @@
using PlayerTags.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PlayerTags.Configuration
{
public class GeneralConfiguration : ZoneConfigurationBase
{
public NameplateFreeCompanyVisibility NameplateFreeCompanyVisibility = NameplateFreeCompanyVisibility.Default;
public NameplateTitleVisibility NameplateTitleVisibility = NameplateTitleVisibility.WhenHasTags;
public NameplateTitlePosition NameplateTitlePosition = NameplateTitlePosition.AlwaysAboveName;
public DeadPlayerHandling NameplateDeadPlayerHandling = DeadPlayerHandling.Include;
public bool IsApplyTagsToAllChatMessagesEnabled = true;
}
}

View File

@@ -15,7 +15,7 @@ using System.Runtime.CompilerServices;
namespace PlayerTags.Configuration
{
[Serializable]
public class PluginConfiguration : IPluginConfiguration
public partial class PluginConfiguration : IPluginConfiguration
{
private const int DEFAULT_CONFIG_VERSION = 1;
@@ -24,15 +24,8 @@ namespace PlayerTags.Configuration
public int Version { get; set; } = DEFAULT_CONFIG_VERSION;
public bool IsVisible = false;
[JsonProperty("GeneralOptionsV2")]
public Dictionary<ActivityType, GeneralOptionsClass> GeneralOptions = new()
{
{ ActivityType.None, new GeneralOptionsClass() },
{ ActivityType.PveDuty, new GeneralOptionsClass() },
{ ActivityType.PvpDuty, new GeneralOptionsClass() }
};
public DefaultPluginDataTemplate DefaultPluginDataTemplate = DefaultPluginDataTemplate.Simple;
public ZoneConfiguration<GeneralConfiguration> GeneralConfigs = new();
public ZoneConfiguration<TagsConfiguration> TagsConfigs = new();
public StatusIconPriorizerSettings StatusIconPriorizerSettings = new(true);
public bool MoveStatusIconToNameplateTextIfPossible = true;
public bool IsPlayerNameRandomlyGenerated = false;
@@ -45,88 +38,74 @@ namespace PlayerTags.Configuration
public bool IsPlayersTabAllianceVisible = true;
public bool IsPlayersTabEnemiesVisible = true;
public bool IsPlayersTabOthersVisible = false;
public bool IsGeneralOptionsAllTheSameEnabled = true;
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public Dictionary<string, InheritableData> AllTagsChanges = new Dictionary<string, InheritableData>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public Dictionary<string, InheritableData> AllRoleTagsChanges = new Dictionary<string, InheritableData>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public Dictionary<Role, Dictionary<string, InheritableData>> RoleTagsChanges = new Dictionary<Role, Dictionary<string, InheritableData>>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public Dictionary<DpsRole, Dictionary<string, InheritableData>> DpsRoleTagsChanges = new Dictionary<DpsRole, Dictionary<string, InheritableData>>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public Dictionary<RangedDpsRole, Dictionary<string, InheritableData>> RangedDpsRoleTagsChanges = new Dictionary<RangedDpsRole, Dictionary<string, InheritableData>>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public Dictionary<LandHandRole, Dictionary<string, InheritableData>> LandHandRoleTagsChanges = new Dictionary<LandHandRole, Dictionary<string, InheritableData>>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public Dictionary<string, Dictionary<string, InheritableData>> JobTagsChanges = new Dictionary<string, Dictionary<string, InheritableData>>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public Dictionary<string, InheritableData> AllCustomTagsChanges = new Dictionary<string, InheritableData>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public List<Dictionary<string, InheritableData>> CustomTagsChanges = new List<Dictionary<string, InheritableData>>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public List<Identity> Identities = new List<Identity>();
public bool IsSimpleUIEnabled = true;
#region Obsulate Properties
[Obsolete]
[JsonProperty("GeneralOptions")]
private Dictionary<Data.ActivityContext, GeneralOptionsClass> GeneralOptionsV1
[JsonProperty("GeneralOptionsV2"), Obsolete]
private Dictionary<ActivityType, GeneralConfiguration> GeneralOptionsV2
{
set
{
GeneralOptions.Clear();
foreach (var kvp in value)
GeneralOptions.Add((ActivityType)kvp.Key, kvp.Value);
void copyOverSettings(ActivityType srcType, ZoneType destType)
{
var src = value[srcType];
var dest = GeneralConfigs.GetConfig(destType);
dest.IsApplyTagsToAllChatMessagesEnabled = src.IsApplyTagsToAllChatMessagesEnabled;
dest.NameplateDeadPlayerHandling = src.NameplateDeadPlayerHandling;
dest.NameplateFreeCompanyVisibility = src.NameplateFreeCompanyVisibility;
dest.NameplateTitlePosition = src.NameplateTitlePosition;
dest.NameplateTitleVisibility = src.NameplateTitleVisibility;
}
copyOverSettings(ActivityType.None, ZoneType.Everywhere);
copyOverSettings(ActivityType.None, ZoneType.Overworld);
copyOverSettings(ActivityType.PvpDuty, ZoneType.Pvp);
copyOverSettings(ActivityType.PveDuty, ZoneType.Doungen);
copyOverSettings(ActivityType.PveDuty, ZoneType.Raid);
copyOverSettings(ActivityType.PveDuty, ZoneType.AllianceRaid);
copyOverSettings(ActivityType.PveDuty, ZoneType.Foray);
}
}
[JsonProperty]
[Obsolete]
public bool IsApplyToEverywhereEnabled
{
set
{
GeneralConfigs.IsEverywhere = value;
TagsConfigs.IsEverywhere = value;
}
}
[JsonProperty]
[Obsolete]
private bool IsGeneralOptionsAllTheSameEnabled
{
set => IsApplyToEverywhereEnabled = value;
}
[JsonProperty("NameplateFreeCompanyVisibility"), Obsolete]
private NameplateFreeCompanyVisibility NameplateFreeCompanyVisibilityV1
{
set
{
foreach (var key in GeneralOptions.Keys)
GeneralOptions[key].NameplateFreeCompanyVisibility = value;
}
set => GeneralConfigs.GetConfig(ZoneType.Everywhere).NameplateFreeCompanyVisibility = value;
}
[JsonProperty("NameplateTitleVisibility"), Obsolete]
public NameplateTitleVisibility NameplateTitleVisibilityV1
{
set
{
foreach (var key in GeneralOptions.Keys)
GeneralOptions[key].NameplateTitleVisibility = value;
}
set => GeneralConfigs.GetConfig(ZoneType.Everywhere).NameplateTitleVisibility = value;
}
[JsonProperty("NameplateTitlePosition"), Obsolete]
public NameplateTitlePosition NameplateTitlePositionV1
{
set
{
foreach (var key in GeneralOptions.Keys)
GeneralOptions[key].NameplateTitlePosition = value;
}
set => GeneralConfigs.GetConfig(ZoneType.Everywhere).NameplateTitlePosition = value;
}
[JsonProperty("IsApplyTagsToAllChatMessagesEnabled"), Obsolete]
private bool IsApplyTagsToAllChatMessagesEnabledV1
{
set
{
foreach (var key in GeneralOptions.Keys)
GeneralOptions[key].IsApplyTagsToAllChatMessagesEnabled = value;
}
set => GeneralConfigs.GetConfig(ZoneType.Everywhere).IsApplyTagsToAllChatMessagesEnabled = value;
}
#endregion
@@ -135,105 +114,15 @@ namespace PlayerTags.Configuration
public void Save(PluginData pluginData)
{
AllTagsChanges = pluginData.AllTags.GetChanges(pluginData.Default.AllTags.GetChanges());
AllRoleTagsChanges = pluginData.AllRoleTags.GetChanges(pluginData.Default.AllRoleTags.GetChanges());
RoleTagsChanges = new Dictionary<Role, Dictionary<string, InheritableData>>();
foreach ((var role, var roleTag) in pluginData.RoleTags)
{
Dictionary<string, InheritableData>? defaultChanges = new Dictionary<string, InheritableData>();
if (pluginData.Default.RoleTags.TryGetValue(role, out var defaultTag))
{
defaultChanges = defaultTag.GetChanges();
}
var changes = roleTag.GetChanges(defaultChanges);
if (changes.Any())
{
RoleTagsChanges[role] = changes;
}
}
DpsRoleTagsChanges = new Dictionary<DpsRole, Dictionary<string, InheritableData>>();
foreach ((var dpsRole, var dpsRoleTag) in pluginData.DpsRoleTags)
{
Dictionary<string, InheritableData>? defaultChanges = new Dictionary<string, InheritableData>();
if (pluginData.Default.DpsRoleTags.TryGetValue(dpsRole, out var defaultTag))
{
defaultChanges = defaultTag.GetChanges();
}
var changes = dpsRoleTag.GetChanges(defaultChanges);
if (changes.Any())
{
DpsRoleTagsChanges[dpsRole] = changes;
}
}
RangedDpsRoleTagsChanges = new Dictionary<RangedDpsRole, Dictionary<string, InheritableData>>();
foreach ((var rangedDpsRole, var rangedDpsRoleTag) in pluginData.RangedDpsRoleTags)
{
Dictionary<string, InheritableData>? defaultChanges = new Dictionary<string, InheritableData>();
if (pluginData.Default.RangedDpsRoleTags.TryGetValue(rangedDpsRole, out var defaultTag))
{
defaultChanges = defaultTag.GetChanges();
}
var changes = rangedDpsRoleTag.GetChanges(defaultChanges);
if (changes.Any())
{
RangedDpsRoleTagsChanges[rangedDpsRole] = changes;
}
}
LandHandRoleTagsChanges = new Dictionary<LandHandRole, Dictionary<string, InheritableData>>();
foreach ((var landHandRole, var landHandRoleTag) in pluginData.LandHandRoleTags)
{
Dictionary<string, InheritableData>? defaultChanges = new Dictionary<string, InheritableData>();
if (pluginData.Default.LandHandRoleTags.TryGetValue(landHandRole, out var defaultTag))
{
defaultChanges = defaultTag.GetChanges();
}
var changes = landHandRoleTag.GetChanges(defaultChanges);
if (changes.Any())
{
LandHandRoleTagsChanges[landHandRole] = changes;
}
}
JobTagsChanges = new Dictionary<string, Dictionary<string, InheritableData>>();
foreach ((var jobAbbreviation, var jobTag) in pluginData.JobTags)
{
Dictionary<string, InheritableData>? defaultChanges = new Dictionary<string, InheritableData>();
if (pluginData.Default.JobTags.TryGetValue(jobAbbreviation, out var defaultTag))
{
defaultChanges = defaultTag.GetChanges();
}
var changes = jobTag.GetChanges(defaultChanges);
if (changes.Any())
{
JobTagsChanges[jobAbbreviation] = changes;
}
}
AllCustomTagsChanges = pluginData.AllCustomTags.GetChanges(pluginData.Default.AllCustomTags.GetChanges());
CustomTagsChanges = new List<Dictionary<string, InheritableData>>();
foreach (var customTag in pluginData.CustomTags)
{
CustomTagsChanges.Add(customTag.GetChanges());
}
Identities = pluginData.Identities;
foreach (var tagConfig in TagsConfigs)
tagConfig.Value.ApplyTagsData(pluginData.GetTagsData(tagConfig.Key));
SavePluginConfig();
Saved?.Invoke();
}
private void SavePluginConfig()
public void SavePluginConfig()
{
Version = DEFAULT_CONFIG_VERSION;
var configFilePath = GetConfigFilePath();
@@ -279,13 +168,4 @@ namespace PlayerTags.Configuration
return jsonSettings;
}
}
public class GeneralOptionsClass
{
public NameplateFreeCompanyVisibility NameplateFreeCompanyVisibility = NameplateFreeCompanyVisibility.Default;
public NameplateTitleVisibility NameplateTitleVisibility = NameplateTitleVisibility.WhenHasTags;
public NameplateTitlePosition NameplateTitlePosition = NameplateTitlePosition.AlwaysAboveName;
public DeadPlayerHandling NameplateDeadPlayerHandling = DeadPlayerHandling.Include;
public bool IsApplyTagsToAllChatMessagesEnabled = true;
}
}

View File

@@ -0,0 +1,142 @@
using Newtonsoft.Json;
using PlayerTags.Data;
using PlayerTags.Inheritables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PlayerTags.Configuration
{
public class TagsConfiguration : ZoneConfigurationBase
{
public DefaultPluginDataTemplate DefaultPluginDataTemplate = DefaultPluginDataTemplate.Simple;
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public Dictionary<string, InheritableData> AllTagsChanges = new Dictionary<string, InheritableData>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public Dictionary<string, InheritableData> AllRoleTagsChanges = new Dictionary<string, InheritableData>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public Dictionary<Role, Dictionary<string, InheritableData>> RoleTagsChanges = new Dictionary<Role, Dictionary<string, InheritableData>>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public Dictionary<DpsRole, Dictionary<string, InheritableData>> DpsRoleTagsChanges = new Dictionary<DpsRole, Dictionary<string, InheritableData>>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public Dictionary<RangedDpsRole, Dictionary<string, InheritableData>> RangedDpsRoleTagsChanges = new Dictionary<RangedDpsRole, Dictionary<string, InheritableData>>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public Dictionary<LandHandRole, Dictionary<string, InheritableData>> LandHandRoleTagsChanges = new Dictionary<LandHandRole, Dictionary<string, InheritableData>>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public Dictionary<string, Dictionary<string, InheritableData>> JobTagsChanges = new Dictionary<string, Dictionary<string, InheritableData>>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public Dictionary<string, InheritableData> AllCustomTagsChanges = new Dictionary<string, InheritableData>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public List<Dictionary<string, InheritableData>> CustomTagsChanges = new List<Dictionary<string, InheritableData>>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)]
public List<Identity> Identities = new List<Identity>();
public void ApplyTagsData(PluginTagsData tagsData)
{
AllTagsChanges = tagsData.AllTags.GetChanges(tagsData.Default.AllTags.GetChanges());
AllRoleTagsChanges = tagsData.AllRoleTags.GetChanges(tagsData.Default.AllRoleTags.GetChanges());
RoleTagsChanges = new Dictionary<Role, Dictionary<string, InheritableData>>();
foreach ((var role, var roleTag) in tagsData.RoleTags)
{
Dictionary<string, InheritableData>? defaultChanges = new Dictionary<string, InheritableData>();
if (tagsData.Default.RoleTags.TryGetValue(role, out var defaultTag))
{
defaultChanges = defaultTag.GetChanges();
}
var changes = roleTag.GetChanges(defaultChanges);
if (changes.Any())
{
RoleTagsChanges[role] = changes;
}
}
DpsRoleTagsChanges = new Dictionary<DpsRole, Dictionary<string, InheritableData>>();
foreach ((var dpsRole, var dpsRoleTag) in tagsData.DpsRoleTags)
{
Dictionary<string, InheritableData>? defaultChanges = new Dictionary<string, InheritableData>();
if (tagsData.Default.DpsRoleTags.TryGetValue(dpsRole, out var defaultTag))
{
defaultChanges = defaultTag.GetChanges();
}
var changes = dpsRoleTag.GetChanges(defaultChanges);
if (changes.Any())
{
DpsRoleTagsChanges[dpsRole] = changes;
}
}
RangedDpsRoleTagsChanges = new Dictionary<RangedDpsRole, Dictionary<string, InheritableData>>();
foreach ((var rangedDpsRole, var rangedDpsRoleTag) in tagsData.RangedDpsRoleTags)
{
Dictionary<string, InheritableData>? defaultChanges = new Dictionary<string, InheritableData>();
if (tagsData.Default.RangedDpsRoleTags.TryGetValue(rangedDpsRole, out var defaultTag))
{
defaultChanges = defaultTag.GetChanges();
}
var changes = rangedDpsRoleTag.GetChanges(defaultChanges);
if (changes.Any())
{
RangedDpsRoleTagsChanges[rangedDpsRole] = changes;
}
}
LandHandRoleTagsChanges = new Dictionary<LandHandRole, Dictionary<string, InheritableData>>();
foreach ((var landHandRole, var landHandRoleTag) in tagsData.LandHandRoleTags)
{
Dictionary<string, InheritableData>? defaultChanges = new Dictionary<string, InheritableData>();
if (tagsData.Default.LandHandRoleTags.TryGetValue(landHandRole, out var defaultTag))
{
defaultChanges = defaultTag.GetChanges();
}
var changes = landHandRoleTag.GetChanges(defaultChanges);
if (changes.Any())
{
LandHandRoleTagsChanges[landHandRole] = changes;
}
}
JobTagsChanges = new Dictionary<string, Dictionary<string, InheritableData>>();
foreach ((var jobAbbreviation, var jobTag) in tagsData.JobTags)
{
Dictionary<string, InheritableData>? defaultChanges = new Dictionary<string, InheritableData>();
if (tagsData.Default.JobTags.TryGetValue(jobAbbreviation, out var defaultTag))
{
defaultChanges = defaultTag.GetChanges();
}
var changes = jobTag.GetChanges(defaultChanges);
if (changes.Any())
{
JobTagsChanges[jobAbbreviation] = changes;
}
}
AllCustomTagsChanges = tagsData.AllCustomTags.GetChanges(tagsData.Default.AllCustomTags.GetChanges());
CustomTagsChanges = new List<Dictionary<string, InheritableData>>();
foreach (var customTag in tagsData.CustomTags)
{
CustomTagsChanges.Add(customTag.GetChanges());
}
Identities = tagsData.Identities;
}
}
}

View File

@@ -0,0 +1,28 @@
using Newtonsoft.Json;
using Pilz.Dalamud.ActivityContexts;
using PlayerTags.Data;
using PlayerTags.Inheritables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PlayerTags.Configuration
{
public class ZoneConfiguration<TConfig> : Dictionary<ZoneType, TConfig> where TConfig : ZoneConfigurationBase, new()
{
public bool IsEverywhere { get; set; } = true;
public TConfig GetConfig(ZoneType zoneType)
{
if (IsEverywhere)
zoneType = ZoneType.Everywhere;
if (!ContainsKey(zoneType))
Add(zoneType, new TConfig());
return this[zoneType];
}
}
}

View File

@@ -0,0 +1,13 @@
using Lumina.Excel.GeneratedSheets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PlayerTags.Configuration
{
public abstract class ZoneConfigurationBase
{
}
}

View File

@@ -1,15 +0,0 @@
using Newtonsoft.Json;
using System;
namespace PlayerTags.Data
{
[Obsolete]
[Flags]
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public enum ActivityContext
{
None = 0x0,
PveDuty = 0x1,
PvpDuty = 0x2,
}
}

View File

@@ -3,6 +3,7 @@ using Dalamud.Game.ClientState.Objects.SubKinds;
using Dalamud.Game.ClientState.Party;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Logging;
using Pilz.Dalamud.ActivityContexts;
using PlayerTags.Configuration;
using PlayerTags.PluginStrings;
using System;
@@ -13,19 +14,8 @@ namespace PlayerTags.Data
{
public class PluginData
{
public DefaultPluginData Default;
public Tag AllTags;
public Tag AllRoleTags;
public Dictionary<Role, Tag> RoleTags;
public Dictionary<DpsRole, Tag> DpsRoleTags;
public Dictionary<RangedDpsRole, Tag> RangedDpsRoleTags;
public Dictionary<LandHandRole, Tag> LandHandRoleTags;
public Dictionary<string, Tag> JobTags;
public Tag AllCustomTags;
public List<Tag> CustomTags;
public List<Identity> Identities;
private PluginConfiguration pluginConfiguration;
public Dictionary<ZoneType, PluginTagsData> TagsData = new();
private readonly PluginConfiguration pluginConfiguration;
public PluginData(PluginConfiguration pluginConfiguration)
{
@@ -33,275 +23,38 @@ namespace PlayerTags.Data
ReloadDefault();
}
private void EnsureDataExists(ref ZoneType zoneType)
{
if (pluginConfiguration.TagsConfigs.IsEverywhere)
zoneType = ZoneType.Everywhere;
if (!TagsData.ContainsKey(zoneType))
TagsData.Add(zoneType, new PluginTagsData(pluginConfiguration, pluginConfiguration.TagsConfigs.GetConfig(zoneType)));
}
public PluginTagsData GetTagsData(ZoneType zoneType)
{
EnsureDataExists(ref zoneType);
return TagsData[zoneType];
}
public void ReloadDefault(ZoneType zoneType)
{
EnsureDataExists(ref zoneType);
if (TagsData[zoneType].ReloadDefault())
pluginConfiguration.Save(this);
}
public void ReloadDefault()
{
Default = new DefaultPluginData(pluginConfiguration.DefaultPluginDataTemplate);
var needToSave = false;
foreach (var tagsData in TagsData.Values)
needToSave |= tagsData.ReloadDefault();
// Set the default changes and saved changes
AllTags = new Tag(new LocalizedPluginString(nameof(AllTags)), Default.AllTags);
AllTags.SetChanges(pluginConfiguration.AllTagsChanges);
AllRoleTags = new Tag(new LocalizedPluginString(nameof(AllRoleTags)), Default.AllRoleTags);
AllRoleTags.SetChanges(pluginConfiguration.AllRoleTagsChanges);
RoleTags = new Dictionary<Role, Tag>();
foreach (var role in Enum.GetValues<Role>())
{
if (Default.RoleTags.TryGetValue(role, out var defaultTag))
{
RoleTags[role] = new Tag(new LocalizedPluginString(Localizer.GetName(role)), defaultTag);
if (pluginConfiguration.RoleTagsChanges.TryGetValue(role, out var savedChanges))
{
RoleTags[role].SetChanges(savedChanges);
}
}
}
DpsRoleTags = new Dictionary<DpsRole, Tag>();
foreach (var dpsRole in Enum.GetValues<DpsRole>())
{
if (Default.DpsRoleTags.TryGetValue(dpsRole, out var defaultTag))
{
DpsRoleTags[dpsRole] = new Tag(new LocalizedPluginString(Localizer.GetName(dpsRole)), defaultTag);
if (pluginConfiguration.DpsRoleTagsChanges.TryGetValue(dpsRole, out var savedChanges))
{
DpsRoleTags[dpsRole].SetChanges(savedChanges);
}
}
}
RangedDpsRoleTags = new Dictionary<RangedDpsRole, Tag>();
foreach (var rangedDpsRole in Enum.GetValues<RangedDpsRole>())
{
if (Default.RangedDpsRoleTags.TryGetValue(rangedDpsRole, out var defaultTag))
{
RangedDpsRoleTags[rangedDpsRole] = new Tag(new LocalizedPluginString(Localizer.GetName(rangedDpsRole)), defaultTag);
if (pluginConfiguration.RangedDpsRoleTagsChanges.TryGetValue(rangedDpsRole, out var savedChanges))
{
RangedDpsRoleTags[rangedDpsRole].SetChanges(savedChanges);
}
}
}
LandHandRoleTags = new Dictionary<LandHandRole, Tag>();
foreach (var landHandRole in Enum.GetValues<LandHandRole>())
{
if (Default.LandHandRoleTags.TryGetValue(landHandRole, out var defaultChanges))
{
LandHandRoleTags[landHandRole] = new Tag(new LocalizedPluginString(Localizer.GetName(landHandRole)), defaultChanges);
if (pluginConfiguration.LandHandRoleTagsChanges.TryGetValue(landHandRole, out var savedChanges))
{
LandHandRoleTags[landHandRole].SetChanges(savedChanges);
}
}
}
JobTags = new Dictionary<string, Tag>();
foreach ((var jobAbbreviation, var role) in RoleHelper.RolesByJobAbbreviation)
{
if (Default.JobTags.TryGetValue(jobAbbreviation, out var defaultChanges))
{
JobTags[jobAbbreviation] = new Tag(new LiteralPluginString(jobAbbreviation), defaultChanges);
if (pluginConfiguration.JobTagsChanges.TryGetValue(jobAbbreviation, out var savedChanges))
{
JobTags[jobAbbreviation].SetChanges(savedChanges);
}
}
}
AllCustomTags = new Tag(new LocalizedPluginString(nameof(AllCustomTags)), Default.AllCustomTags);
AllCustomTags.SetChanges(pluginConfiguration.AllCustomTagsChanges);
CustomTags = new List<Tag>();
foreach (var savedChanges in pluginConfiguration.CustomTagsChanges)
{
var tag = new Tag(new LocalizedPluginString(nameof(CustomTags)));
tag.SetChanges(savedChanges);
CustomTags.Add(tag);
}
// Set up the inheritance heirarchy
AllRoleTags.Parent = AllTags;
foreach ((var role, var roleTag) in RoleTags)
{
roleTag.Parent = AllRoleTags;
if (role == Role.Dps)
{
foreach ((var dpsRole, var dpsRoleTag) in DpsRoleTags)
{
dpsRoleTag.Parent = roleTag;
if (dpsRole == DpsRole.Ranged)
{
foreach ((var rangedDpsRole, var rangedDpsRoleTag) in RangedDpsRoleTags)
{
rangedDpsRoleTag.Parent = dpsRoleTag;
}
}
}
}
else if (role == Role.LandHand)
{
foreach ((var landHandRole, var landHandRoleTag) in LandHandRoleTags)
{
landHandRoleTag.Parent = roleTag;
}
}
}
foreach ((var jobAbbreviation, var jobTag) in JobTags)
{
if (RoleHelper.RolesByJobAbbreviation.TryGetValue(jobAbbreviation, out var role))
{
if (RoleHelper.DpsRolesByJobAbbreviation.TryGetValue(jobAbbreviation, out var dpsRole))
{
if (RoleHelper.RangedDpsRolesByJobAbbreviation.TryGetValue(jobAbbreviation, out var rangedDpsRole))
{
jobTag.Parent = RangedDpsRoleTags[rangedDpsRole];
}
else
{
jobTag.Parent = DpsRoleTags[dpsRole];
}
}
else if (RoleHelper.LandHandRolesByJobAbbreviation.TryGetValue(jobAbbreviation, out var landHandRole))
{
jobTag.Parent = LandHandRoleTags[landHandRole];
}
else
{
jobTag.Parent = RoleTags[RoleHelper.RolesByJobAbbreviation[jobAbbreviation]];
}
}
}
AllCustomTags.Parent = AllTags;
foreach (var tag in CustomTags)
{
tag.Parent = AllCustomTags;
}
Identities = pluginConfiguration.Identities;
// Migrate old custom tag identity assignments
bool customTagsMigrated = false;
foreach (var customTag in CustomTags)
{
if (customTag.CustomId.Value == Guid.Empty)
{
customTag.CustomId.Behavior = Inheritables.InheritableBehavior.Enabled;
customTag.CustomId.Value = Guid.NewGuid();
customTagsMigrated = true;
}
foreach (string identityToAddTo in customTag.IdentitiesToAddTo)
{
Identity? identity = Identities.FirstOrDefault(identity => identity.Name.ToLower() == identityToAddTo.ToLower());
if (identity == null)
{
identity = new Identity(identityToAddTo);
Identities.Add(identity);
}
if (identity != null)
{
identity.CustomTagIds.Add(customTag.CustomId.Value);
customTagsMigrated = true;
}
}
if (customTag.GameObjectNamesToApplyTo.Behavior != Inheritables.InheritableBehavior.Inherit)
{
customTag.GameObjectNamesToApplyTo.Behavior = Inheritables.InheritableBehavior.Inherit;
customTag.GameObjectNamesToApplyTo.Value = "";
customTagsMigrated = true;
}
}
if (customTagsMigrated)
{
if (needToSave)
pluginConfiguration.Save(this);
}
}
public void AddCustomTagToIdentity(Tag customTag, Identity identity)
{
if (!identity.CustomTagIds.Contains(customTag.CustomId.Value))
{
identity.CustomTagIds.Add(customTag.CustomId.Value);
}
if (!Identities.Contains(identity))
{
Identities.Add(identity);
}
}
public void RemoveCustomTagFromIdentity(Tag customTag, Identity identity)
{
identity.CustomTagIds.Remove(customTag.CustomId.Value);
if (!identity.CustomTagIds.Any())
{
Identities.Remove(identity);
}
}
public void RemoveCustomTagFromIdentities(Tag customTag)
{
foreach (var identity in Identities.ToArray())
{
RemoveCustomTagFromIdentity(customTag, identity);
}
}
public Identity GetIdentity(string name, uint? worldId)
{
foreach (var identity in Identities)
{
if (identity.Name.ToLower().Trim() == name.ToLower().Trim())
{
if (identity.WorldId == null && worldId != null)
{
identity.WorldId = worldId;
pluginConfiguration.Save(this);
}
return identity;
}
}
return new Identity(name)
{
WorldId = worldId
};
}
public Identity? GetIdentity(GameObjectContextMenuOpenArgs contextMenuOpenedArgs)
{
if (string.IsNullOrEmpty(contextMenuOpenedArgs.Text?.TextValue)
|| contextMenuOpenedArgs.ObjectWorld == 0
|| contextMenuOpenedArgs.ObjectWorld == 65535)
{
return null;
}
return GetIdentity(contextMenuOpenedArgs.Text?.TextValue ?? string.Empty, contextMenuOpenedArgs.ObjectWorld);
}
public Identity GetIdentity(PlayerCharacter playerCharacter)
{
return GetIdentity(playerCharacter.Name.TextValue, playerCharacter.HomeWorld.Id);
}
public Identity GetIdentity(PartyMember partyMember)
{
return GetIdentity(partyMember.Name.TextValue, partyMember.World.Id);
}
public Identity GetIdentity(PlayerPayload playerPayload)
{
return GetIdentity(playerPayload.PlayerName, playerPayload.World.RowId);
}
}
}

View File

@@ -0,0 +1,308 @@
using Dalamud.ContextMenu;
using Dalamud.Game.ClientState.Objects.SubKinds;
using Dalamud.Game.ClientState.Party;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using PlayerTags.Configuration;
using PlayerTags.PluginStrings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PlayerTags.Data
{
public class PluginTagsData
{
public DefaultPluginData Default;
public Tag AllTags;
public Tag AllRoleTags;
public Dictionary<Role, Tag> RoleTags;
public Dictionary<DpsRole, Tag> DpsRoleTags;
public Dictionary<RangedDpsRole, Tag> RangedDpsRoleTags;
public Dictionary<LandHandRole, Tag> LandHandRoleTags;
public Dictionary<string, Tag> JobTags;
public Tag AllCustomTags;
public List<Tag> CustomTags;
public List<Identity> Identities;
private readonly TagsConfiguration pluginZonedConfig;
public PluginTagsData(PluginConfiguration pluginconfiguration, TagsConfiguration pluginZonedConfiguration)
{
pluginZonedConfig = pluginZonedConfiguration;
ReloadDefault();
}
public bool ReloadDefault()
{
var needToSave = false;
Default = new DefaultPluginData(pluginZonedConfig.DefaultPluginDataTemplate);
// Set the default changes and saved changes
AllTags = new Tag(new LocalizedPluginString(nameof(AllTags)), Default.AllTags);
AllTags.SetChanges(pluginZonedConfig.AllTagsChanges);
AllRoleTags = new Tag(new LocalizedPluginString(nameof(AllRoleTags)), Default.AllRoleTags);
AllRoleTags.SetChanges(pluginZonedConfig.AllRoleTagsChanges);
RoleTags = new Dictionary<Role, Tag>();
foreach (var role in Enum.GetValues<Role>())
{
if (Default.RoleTags.TryGetValue(role, out var defaultTag))
{
RoleTags[role] = new Tag(new LocalizedPluginString(Localizer.GetName(role)), defaultTag);
if (pluginZonedConfig.RoleTagsChanges.TryGetValue(role, out var savedChanges))
{
RoleTags[role].SetChanges(savedChanges);
}
}
}
DpsRoleTags = new Dictionary<DpsRole, Tag>();
foreach (var dpsRole in Enum.GetValues<DpsRole>())
{
if (Default.DpsRoleTags.TryGetValue(dpsRole, out var defaultTag))
{
DpsRoleTags[dpsRole] = new Tag(new LocalizedPluginString(Localizer.GetName(dpsRole)), defaultTag);
if (pluginZonedConfig.DpsRoleTagsChanges.TryGetValue(dpsRole, out var savedChanges))
{
DpsRoleTags[dpsRole].SetChanges(savedChanges);
}
}
}
RangedDpsRoleTags = new Dictionary<RangedDpsRole, Tag>();
foreach (var rangedDpsRole in Enum.GetValues<RangedDpsRole>())
{
if (Default.RangedDpsRoleTags.TryGetValue(rangedDpsRole, out var defaultTag))
{
RangedDpsRoleTags[rangedDpsRole] = new Tag(new LocalizedPluginString(Localizer.GetName(rangedDpsRole)), defaultTag);
if (pluginZonedConfig.RangedDpsRoleTagsChanges.TryGetValue(rangedDpsRole, out var savedChanges))
{
RangedDpsRoleTags[rangedDpsRole].SetChanges(savedChanges);
}
}
}
LandHandRoleTags = new Dictionary<LandHandRole, Tag>();
foreach (var landHandRole in Enum.GetValues<LandHandRole>())
{
if (Default.LandHandRoleTags.TryGetValue(landHandRole, out var defaultChanges))
{
LandHandRoleTags[landHandRole] = new Tag(new LocalizedPluginString(Localizer.GetName(landHandRole)), defaultChanges);
if (pluginZonedConfig.LandHandRoleTagsChanges.TryGetValue(landHandRole, out var savedChanges))
{
LandHandRoleTags[landHandRole].SetChanges(savedChanges);
}
}
}
JobTags = new Dictionary<string, Tag>();
foreach ((var jobAbbreviation, var role) in RoleHelper.RolesByJobAbbreviation)
{
if (Default.JobTags.TryGetValue(jobAbbreviation, out var defaultChanges))
{
JobTags[jobAbbreviation] = new Tag(new LiteralPluginString(jobAbbreviation), defaultChanges);
if (pluginZonedConfig.JobTagsChanges.TryGetValue(jobAbbreviation, out var savedChanges))
{
JobTags[jobAbbreviation].SetChanges(savedChanges);
}
}
}
AllCustomTags = new Tag(new LocalizedPluginString(nameof(AllCustomTags)), Default.AllCustomTags);
AllCustomTags.SetChanges(pluginZonedConfig.AllCustomTagsChanges);
CustomTags = new List<Tag>();
foreach (var savedChanges in pluginZonedConfig.CustomTagsChanges)
{
var tag = new Tag(new LocalizedPluginString(nameof(CustomTags)));
tag.SetChanges(savedChanges);
CustomTags.Add(tag);
}
// Set up the inheritance heirarchy
AllRoleTags.Parent = AllTags;
foreach ((var role, var roleTag) in RoleTags)
{
roleTag.Parent = AllRoleTags;
if (role == Role.Dps)
{
foreach ((var dpsRole, var dpsRoleTag) in DpsRoleTags)
{
dpsRoleTag.Parent = roleTag;
if (dpsRole == DpsRole.Ranged)
{
foreach ((var rangedDpsRole, var rangedDpsRoleTag) in RangedDpsRoleTags)
{
rangedDpsRoleTag.Parent = dpsRoleTag;
}
}
}
}
else if (role == Role.LandHand)
{
foreach ((var landHandRole, var landHandRoleTag) in LandHandRoleTags)
{
landHandRoleTag.Parent = roleTag;
}
}
}
foreach ((var jobAbbreviation, var jobTag) in JobTags)
{
if (RoleHelper.RolesByJobAbbreviation.TryGetValue(jobAbbreviation, out var role))
{
if (RoleHelper.DpsRolesByJobAbbreviation.TryGetValue(jobAbbreviation, out var dpsRole))
{
if (RoleHelper.RangedDpsRolesByJobAbbreviation.TryGetValue(jobAbbreviation, out var rangedDpsRole))
{
jobTag.Parent = RangedDpsRoleTags[rangedDpsRole];
}
else
{
jobTag.Parent = DpsRoleTags[dpsRole];
}
}
else if (RoleHelper.LandHandRolesByJobAbbreviation.TryGetValue(jobAbbreviation, out var landHandRole))
{
jobTag.Parent = LandHandRoleTags[landHandRole];
}
else
{
jobTag.Parent = RoleTags[RoleHelper.RolesByJobAbbreviation[jobAbbreviation]];
}
}
}
AllCustomTags.Parent = AllTags;
foreach (var tag in CustomTags)
{
tag.Parent = AllCustomTags;
}
Identities = pluginZonedConfig.Identities;
// Migrate old custom tag identity assignments
bool customTagsMigrated = false;
foreach (var customTag in CustomTags)
{
if (customTag.CustomId.Value == Guid.Empty)
{
customTag.CustomId.Behavior = Inheritables.InheritableBehavior.Enabled;
customTag.CustomId.Value = Guid.NewGuid();
customTagsMigrated = true;
}
foreach (string identityToAddTo in customTag.IdentitiesToAddTo)
{
Identity? identity = Identities.FirstOrDefault(identity => identity.Name.ToLower() == identityToAddTo.ToLower());
if (identity == null)
{
identity = new Identity(identityToAddTo);
Identities.Add(identity);
}
if (identity != null)
{
identity.CustomTagIds.Add(customTag.CustomId.Value);
customTagsMigrated = true;
}
}
if (customTag.GameObjectNamesToApplyTo.Behavior != Inheritables.InheritableBehavior.Inherit)
{
customTag.GameObjectNamesToApplyTo.Behavior = Inheritables.InheritableBehavior.Inherit;
customTag.GameObjectNamesToApplyTo.Value = "";
customTagsMigrated = true;
}
}
if (customTagsMigrated)
needToSave = true;
return needToSave;
}
public void AddCustomTagToIdentity(Tag customTag, Identity identity)
{
if (!identity.CustomTagIds.Contains(customTag.CustomId.Value))
{
identity.CustomTagIds.Add(customTag.CustomId.Value);
}
if (!Identities.Contains(identity))
{
Identities.Add(identity);
}
}
public void RemoveCustomTagFromIdentity(Tag customTag, Identity identity)
{
identity.CustomTagIds.Remove(customTag.CustomId.Value);
if (!identity.CustomTagIds.Any())
{
Identities.Remove(identity);
}
}
public void RemoveCustomTagFromIdentities(Tag customTag)
{
foreach (var identity in Identities.ToArray())
{
RemoveCustomTagFromIdentity(customTag, identity);
}
}
public Identity GetIdentity(string name, uint? worldId)
{
foreach (var identity in Identities)
{
if (identity.Name.ToLower().Trim() == name.ToLower().Trim())
{
if (identity.WorldId == null && worldId != null)
{
identity.WorldId = worldId;
pluginZonedConfig.ApplyTagsData(this);
}
return identity;
}
}
return new Identity(name)
{
WorldId = worldId
};
}
public Identity? GetIdentity(GameObjectContextMenuOpenArgs contextMenuOpenedArgs)
{
if (string.IsNullOrEmpty(contextMenuOpenedArgs.Text?.TextValue)
|| contextMenuOpenedArgs.ObjectWorld == 0
|| contextMenuOpenedArgs.ObjectWorld == 65535)
{
return null;
}
return GetIdentity(contextMenuOpenedArgs.Text?.TextValue ?? string.Empty, contextMenuOpenedArgs.ObjectWorld);
}
public Identity GetIdentity(PlayerCharacter playerCharacter)
{
return GetIdentity(playerCharacter.Name.TextValue, playerCharacter.HomeWorld.Id);
}
public Identity GetIdentity(PartyMember partyMember)
{
return GetIdentity(partyMember.Name.TextValue, partyMember.World.Id);
}
public Identity GetIdentity(PlayerPayload playerPayload)
{
return GetIdentity(playerPayload.PlayerName, playerPayload.World.RowId);
}
}
}

View File

@@ -121,7 +121,7 @@ namespace PlayerTags.Features
private void Chat_ChatMessage(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled)
{
if (m_PluginConfiguration.GeneralOptions[ActivityContextManager.CurrentActivityContext.ActivityType].IsApplyTagsToAllChatMessagesEnabled)
if (m_PluginConfiguration.GeneralConfigs.GetConfig(ActivityContextManager.CurrentActivityContext.ZoneType).IsApplyTagsToAllChatMessagesEnabled)
{
AddTagsToChat(sender, type, true);
AddTagsToChat(message, type, false);
@@ -335,7 +335,9 @@ namespace PlayerTags.Features
if (isSender)
SplitOffPartyNumberPrefix(message, chatType);
var tagsData = m_PluginData.GetTagsData(ActivityContextManager.CurrentActivityContext.ZoneType);
var stringMatches = GetStringMatches(message);
foreach (var stringMatch in stringMatches)
{
StringChanges stringChanges = new();
@@ -347,7 +349,7 @@ namespace PlayerTags.Features
if (stringMatch.GameObject is PlayerCharacter playerCharacter)
{
// Add the job tag
if (playerCharacter.ClassJob.GameData != null && m_PluginData.JobTags.TryGetValue(playerCharacter.ClassJob.GameData.Abbreviation, out var jobTag))
if (playerCharacter.ClassJob.GameData != null && tagsData.JobTags.TryGetValue(playerCharacter.ClassJob.GameData.Abbreviation, out var jobTag))
{
if (isTagEnabled(jobTag))
{
@@ -378,10 +380,10 @@ namespace PlayerTags.Features
// Add custom tags
if (stringMatch.PlayerPayload != null)
{
Identity identity = m_PluginData.GetIdentity(stringMatch.PlayerPayload);
Identity identity = tagsData.GetIdentity(stringMatch.PlayerPayload);
foreach (var customTagId in identity.CustomTagIds)
{
var customTag = m_PluginData.CustomTags.FirstOrDefault(tag => tag.CustomId.Value == customTagId);
var customTag = tagsData.CustomTags.FirstOrDefault(tag => tag.CustomId.Value == customTagId);
if (customTag != null)
{
if (isTagEnabled(customTag))
@@ -407,17 +409,17 @@ namespace PlayerTags.Features
// An additional step to apply text color to additional locations
if (stringMatch.PlayerPayload != null && stringMatch.DisplayTextPayloads.Any())
{
Identity identity = m_PluginData.GetIdentity(stringMatch.PlayerPayload);
Identity identity = tagsData.GetIdentity(stringMatch.PlayerPayload);
if (stringMatch.GameObject is PlayerCharacter playerCharacter1)
{
if (playerCharacter1.ClassJob.GameData != null && m_PluginData.JobTags.TryGetValue(playerCharacter1.ClassJob.GameData.Abbreviation, out var jobTag) && isTagEnabled(jobTag))
if (playerCharacter1.ClassJob.GameData != null && tagsData.JobTags.TryGetValue(playerCharacter1.ClassJob.GameData.Abbreviation, out var jobTag) && isTagEnabled(jobTag))
applyTextFormatting(jobTag);
}
foreach (var customTagId in identity.CustomTagIds)
{
var customTag = m_PluginData.CustomTags.FirstOrDefault(tag => tag.CustomId.Value == customTagId);
var customTag = tagsData.CustomTags.FirstOrDefault(tag => tag.CustomId.Value == customTagId);
if (customTag != null && isTagEnabled(customTag))
applyTextFormatting(customTag);
}

View File

@@ -1,6 +1,7 @@
using Dalamud.ContextMenu;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Logging;
using Pilz.Dalamud.ActivityContexts;
using PlayerTags.Configuration;
using PlayerTags.Data;
using PlayerTags.Resources;
@@ -13,7 +14,7 @@ namespace PlayerTags.Features
/// <summary>
/// A feature that adds options for the management of custom tags to context menus.
/// </summary>
public class CustomTagsContextMenuFeature : IDisposable
public class CustomTagsContextMenuFeature : FeatureBase
{
private string?[] SupportedAddonNames = new string?[]
{
@@ -44,7 +45,7 @@ namespace PlayerTags.Features
m_ContextMenu.OnOpenGameObjectContextMenu += ContextMenuHooks_ContextMenuOpened;
}
public void Dispose()
public override void Dispose()
{
if (m_ContextMenu != null)
{
@@ -52,21 +53,22 @@ namespace PlayerTags.Features
((IDisposable)m_ContextMenu).Dispose();
m_ContextMenu = null;
}
base.Dispose();
}
private void ContextMenuHooks_ContextMenuOpened(GameObjectContextMenuOpenArgs contextMenuOpenedArgs)
{
if (!m_PluginConfiguration.IsCustomTagsContextMenuEnabled
|| !SupportedAddonNames.Contains(contextMenuOpenedArgs.ParentAddonName))
{
return;
}
Identity? identity = m_PluginData.GetIdentity(contextMenuOpenedArgs);
var tagsData = m_PluginData.GetTagsData(ActivityContextManager.CurrentActivityContext.ZoneType);
Identity? identity = tagsData.GetIdentity(contextMenuOpenedArgs);
if (identity != null)
{
var allTags = new Dictionary<Tag, bool>();
foreach (var customTag in m_PluginData.CustomTags)
foreach (var customTag in tagsData.CustomTags)
{
var isAdded = identity.CustomTagIds.Contains(customTag.CustomId.Value);
allTags.Add(customTag, isAdded);
@@ -86,9 +88,9 @@ namespace PlayerTags.Features
new GameObjectContextMenuItem(menuItemText, openedEventArgs =>
{
if (tag.Value)
m_PluginData.RemoveCustomTagFromIdentity(tag.Key, identity);
tagsData.RemoveCustomTagFromIdentity(tag.Key, identity);
else
m_PluginData.AddCustomTagToIdentity(tag.Key, identity);
tagsData.AddCustomTagToIdentity(tag.Key, identity);
m_PluginConfiguration.Save(m_PluginData);
})
{

View File

@@ -0,0 +1,24 @@
using Pilz.Dalamud.ActivityContexts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PlayerTags.Features
{
public abstract class FeatureBase : IDisposable
{
public ActivityContextManager ActivityContextManager { get; init; }
public FeatureBase()
{
ActivityContextManager = new();
}
public virtual void Dispose()
{
ActivityContextManager.Dispose();
}
}
}

View File

@@ -113,9 +113,9 @@ namespace PlayerTags.Features
{
var beforeTitleBytes = args.Title.Encode();
var iconID = args.IconId;
var generalOptions = m_PluginConfiguration.GeneralOptions[ActivityContextManager.CurrentActivityContext.ActivityType];
var generalOptions = m_PluginConfiguration.GeneralConfigs.GetConfig(ActivityContextManager.CurrentActivityContext.ZoneType);
AddTagsToNameplate(args.PlayerCharacter, args.Name, args.Title, args.FreeCompany, ref iconID, generalOptions);
AddTagsToNameplate(args.PlayerCharacter, args.Name, args.Title, args.FreeCompany, ref iconID);
args.IconId = iconID;
@@ -172,19 +172,22 @@ namespace PlayerTags.Features
/// <param name="name">The name text to change.</param>
/// <param name="title">The title text to change.</param>
/// <param name="freeCompany">The free company text to change.</param>
private void AddTagsToNameplate(GameObject gameObject, SeString name, SeString title, SeString freeCompany, ref int statusIcon, GeneralOptionsClass generalOptions)
private void AddTagsToNameplate(GameObject gameObject, SeString name, SeString title, SeString freeCompany, ref int statusIcon)
{
var curZoneType = ActivityContextManager.CurrentActivityContext.ZoneType;
var generalConfig = m_PluginConfiguration.GeneralConfigs.GetConfig(curZoneType);
var tagsData = m_PluginData.GetTagsData(curZoneType);
var playerCharacter = gameObject as PlayerCharacter;
int? newStatusIcon = null;
NameplateChanges nameplateChanges = GenerateEmptyNameplateChanges(name, title, freeCompany);
if (playerCharacter != null && (!playerCharacter.IsDead || generalOptions.NameplateDeadPlayerHandling != DeadPlayerHandling.Ignore))
if (playerCharacter != null && (!playerCharacter.IsDead || generalConfig.NameplateDeadPlayerHandling != DeadPlayerHandling.Ignore))
{
var classJob = playerCharacter.ClassJob;
var classJobGameData = classJob?.GameData;
// Add the job tags
if (classJobGameData != null && m_PluginData.JobTags.TryGetValue(classJobGameData.Abbreviation, out var jobTag))
if (classJobGameData != null && tagsData.JobTags.TryGetValue(classJobGameData.Abbreviation, out var jobTag))
{
if (jobTag.TagTargetInNameplates.InheritedValue != null && jobTag.TagPositionInNameplates.InheritedValue != null)
checkTag(jobTag);
@@ -203,10 +206,10 @@ namespace PlayerTags.Features
}
// Add custom tags
Identity identity = m_PluginData.GetIdentity(playerCharacter);
Identity identity = tagsData.GetIdentity(playerCharacter);
foreach (var customTagId in identity.CustomTagIds)
{
var customTag = m_PluginData.CustomTags.FirstOrDefault(tag => tag.CustomId.Value == customTagId);
var customTag = tagsData.CustomTags.FirstOrDefault(tag => tag.CustomId.Value == customTagId);
if (customTag != null)
checkTag(customTag);
}
@@ -232,24 +235,24 @@ namespace PlayerTags.Features
}
// Gray out the nameplate
if (playerCharacter != null && playerCharacter.IsDead && generalOptions.NameplateDeadPlayerHandling == DeadPlayerHandling.GrayOut)
if (playerCharacter != null && playerCharacter.IsDead && generalConfig.NameplateDeadPlayerHandling == DeadPlayerHandling.GrayOut)
GrayOutNameplate(gameObject, nameplateChanges);
// Build the final strings out of the payloads
ApplyNameplateChanges(nameplateChanges);
if (playerCharacter != null && (!playerCharacter.IsDead || generalOptions.NameplateDeadPlayerHandling == DeadPlayerHandling.Include))
if (playerCharacter != null && (!playerCharacter.IsDead || generalConfig.NameplateDeadPlayerHandling == DeadPlayerHandling.Include))
{
// An additional step to apply text color to additional locations
Identity identity = m_PluginData.GetIdentity(playerCharacter);
Identity identity = tagsData.GetIdentity(playerCharacter);
foreach (var customTagId in identity.CustomTagIds)
{
var customTag = m_PluginData.CustomTags.FirstOrDefault(tag => tag.CustomId.Value == customTagId);
var customTag = tagsData.CustomTags.FirstOrDefault(tag => tag.CustomId.Value == customTagId);
if (customTag != null)
applyTextFormatting(customTag);
}
if (playerCharacter.ClassJob.GameData != null && m_PluginData.JobTags.TryGetValue(playerCharacter.ClassJob.GameData.Abbreviation, out var jobTag))
if (playerCharacter.ClassJob.GameData != null && tagsData.JobTags.TryGetValue(playerCharacter.ClassJob.GameData.Abbreviation, out var jobTag))
applyTextFormatting(jobTag);
void applyTextFormatting(Tag tag)

View File

@@ -20,18 +20,16 @@ namespace PlayerTags.Features
/// <summary>
/// The base of a feature that adds tags to UI elements.
/// </summary>
public abstract class TagTargetFeature : IDisposable
public abstract class TagTargetFeature : FeatureBase
{
public ActivityContextManager ActivityContextManager { get; init; }
public TagTargetFeature()
{
ActivityContextManager = new();
}
public virtual void Dispose()
public override void Dispose()
{
ActivityContextManager.Dispose();
base.Dispose();
}
protected abstract bool IsIconVisible(Tag tag);