From 90f554df8c58fd16b1fdcd8d19f74ac064f1d8e6 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Thu, 16 Feb 2023 11:12:48 +0100 Subject: [PATCH] re-re-organize settings part 1 --- .../Configuration/GeneralConfiguration.cs | 18 ++++ .../Configuration/PluginConfiguration.cs | 99 ++++++++----------- ...eConfiguration.cs => TagsConfiguration.cs} | 7 +- PlayerTags/Configuration/ZoneConfiguration.cs | 28 ++++++ .../Configuration/ZoneConfigurationBase.cs | 13 +++ PlayerTags/Data/PluginData.cs | 12 +++ PlayerTags/Data/PluginTagsData.cs | 4 +- 7 files changed, 115 insertions(+), 66 deletions(-) create mode 100644 PlayerTags/Configuration/GeneralConfiguration.cs rename PlayerTags/Configuration/{PluginZoneConfiguration.cs => TagsConfiguration.cs} (93%) create mode 100644 PlayerTags/Configuration/ZoneConfiguration.cs create mode 100644 PlayerTags/Configuration/ZoneConfigurationBase.cs diff --git a/PlayerTags/Configuration/GeneralConfiguration.cs b/PlayerTags/Configuration/GeneralConfiguration.cs new file mode 100644 index 0000000..dba541d --- /dev/null +++ b/PlayerTags/Configuration/GeneralConfiguration.cs @@ -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; + } +} diff --git a/PlayerTags/Configuration/PluginConfiguration.cs b/PlayerTags/Configuration/PluginConfiguration.cs index 103a02a..8299a9a 100644 --- a/PlayerTags/Configuration/PluginConfiguration.cs +++ b/PlayerTags/Configuration/PluginConfiguration.cs @@ -24,15 +24,33 @@ namespace PlayerTags.Configuration public int Version { get; set; } = DEFAULT_CONFIG_VERSION; public bool IsVisible = false; + public ZoneConfiguration GeneralConfigs = new(); + public ZoneConfiguration TagsConfigs = new(); + public StatusIconPriorizerSettings StatusIconPriorizerSettings = new(true); + public bool MoveStatusIconToNameplateTextIfPossible = true; + public bool IsPlayerNameRandomlyGenerated = false; + public bool IsCustomTagsContextMenuEnabled = true; + public bool IsShowInheritedPropertiesEnabled = true; + public bool IsPlayersTabOrderedByProximity = false; + public bool IsPlayersTabSelfVisible = true; + public bool IsPlayersTabFriendsVisible = true; + public bool IsPlayersTabPartyVisible = true; + public bool IsPlayersTabAllianceVisible = true; + public bool IsPlayersTabEnemiesVisible = true; + public bool IsPlayersTabOthersVisible = false; + public bool IsSimpleUIEnabled = true; + + #region Obsulate Properties + [JsonProperty("GeneralOptionsV2"), Obsolete] - private Dictionary GeneralOptionsV2 + private Dictionary GeneralOptionsV2 { set { void copyOverSettings(ActivityType srcType, ZoneType destType) { var src = value[srcType]; - var dest = ZoneConfig[destType]; + var dest = GeneralConfigs.GetConfig(destType); dest.IsApplyTagsToAllChatMessagesEnabled = src.IsApplyTagsToAllChatMessagesEnabled; dest.NameplateDeadPlayerHandling = src.NameplateDeadPlayerHandling; dest.NameplateFreeCompanyVisibility = src.NameplateFreeCompanyVisibility; @@ -50,70 +68,44 @@ namespace PlayerTags.Configuration } } - public Dictionary ZoneConfig = new() + [JsonProperty] + [Obsolete] + public bool IsApplyToEverywhereEnabled { - { ZoneType.Overworld, new PluginZoneConfiguration() }, - { ZoneType.Doungen, new PluginZoneConfiguration() }, - { ZoneType.Raid, new PluginZoneConfiguration() }, - { ZoneType.AllianceRaid, new PluginZoneConfiguration() }, - { ZoneType.Foray, new PluginZoneConfiguration() }, - { ZoneType.Pvp, new PluginZoneConfiguration() }, - { ZoneType.Everywhere, new PluginZoneConfiguration() } - }; + set + { + GeneralConfigs.IsEverywhere = value; + TagsConfigs.IsEverywhere = value; + } + } - public StatusIconPriorizerSettings StatusIconPriorizerSettings = new(true); - public bool MoveStatusIconToNameplateTextIfPossible = true; - public bool IsPlayerNameRandomlyGenerated = false; - public bool IsCustomTagsContextMenuEnabled = true; - public bool IsShowInheritedPropertiesEnabled = true; - public bool IsPlayersTabOrderedByProximity = false; - public bool IsPlayersTabSelfVisible = true; - public bool IsPlayersTabFriendsVisible = true; - public bool IsPlayersTabPartyVisible = true; - public bool IsPlayersTabAllianceVisible = true; - public bool IsPlayersTabEnemiesVisible = true; - public bool IsPlayersTabOthersVisible = false; - public bool IsSimpleUIEnabled = true; - public bool IsApplyToEverywhereEnabled = true; - - #region Obsulate Properties + [JsonProperty] + [Obsolete] + private bool IsGeneralOptionsAllTheSameEnabled + { + set => IsApplyToEverywhereEnabled = value; + } [JsonProperty("NameplateFreeCompanyVisibility"), Obsolete] private NameplateFreeCompanyVisibility NameplateFreeCompanyVisibilityV1 { - set - { - foreach (var key in ZoneConfig.Keys) - ZoneConfig[key].NameplateFreeCompanyVisibility = value; - } + set => GeneralConfigs.GetConfig(ZoneType.Everywhere).NameplateFreeCompanyVisibility = value; } [JsonProperty("NameplateTitleVisibility"), Obsolete] public NameplateTitleVisibility NameplateTitleVisibilityV1 { - set - { - foreach (var key in ZoneConfig.Keys) - ZoneConfig[key].NameplateTitleVisibility = value; - } + set => GeneralConfigs.GetConfig(ZoneType.Everywhere).NameplateTitleVisibility = value; } [JsonProperty("NameplateTitlePosition"), Obsolete] public NameplateTitlePosition NameplateTitlePositionV1 { - set - { - foreach (var key in ZoneConfig.Keys) - ZoneConfig[key].NameplateTitlePosition = value; - } + set => GeneralConfigs.GetConfig(ZoneType.Everywhere).NameplateTitlePosition = value; } [JsonProperty("IsApplyTagsToAllChatMessagesEnabled"), Obsolete] private bool IsApplyTagsToAllChatMessagesEnabledV1 { - set - { - foreach (var key in ZoneConfig.Keys) - ZoneConfig[key].IsApplyTagsToAllChatMessagesEnabled = value; - } + set => GeneralConfigs.GetConfig(ZoneType.Everywhere).IsApplyTagsToAllChatMessagesEnabled = value; } #endregion @@ -122,8 +114,8 @@ namespace PlayerTags.Configuration public void Save(PluginData pluginData) { - foreach (var zoneConfig in ZoneConfig) - zoneConfig.Value.ApplyTagsData(pluginData.GetTagsData(zoneConfig.Key)); + foreach (var tagConfig in TagsConfigs) + tagConfig.Value.ApplyTagsData(pluginData.GetTagsData(tagConfig.Key)); SavePluginConfig(); @@ -175,14 +167,5 @@ namespace PlayerTags.Configuration return jsonSettings; } - - private 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; - } } } diff --git a/PlayerTags/Configuration/PluginZoneConfiguration.cs b/PlayerTags/Configuration/TagsConfiguration.cs similarity index 93% rename from PlayerTags/Configuration/PluginZoneConfiguration.cs rename to PlayerTags/Configuration/TagsConfiguration.cs index 7414928..df5f016 100644 --- a/PlayerTags/Configuration/PluginZoneConfiguration.cs +++ b/PlayerTags/Configuration/TagsConfiguration.cs @@ -9,14 +9,9 @@ using System.Threading.Tasks; namespace PlayerTags.Configuration { - public class PluginZoneConfiguration + public class TagsConfiguration : ZoneConfigurationBase { public DefaultPluginDataTemplate DefaultPluginDataTemplate = DefaultPluginDataTemplate.Simple; - public NameplateFreeCompanyVisibility NameplateFreeCompanyVisibility = NameplateFreeCompanyVisibility.Default; - public NameplateTitleVisibility NameplateTitleVisibility = NameplateTitleVisibility.WhenHasTags; - public NameplateTitlePosition NameplateTitlePosition = NameplateTitlePosition.AlwaysAboveName; - public DeadPlayerHandling NameplateDeadPlayerHandling = DeadPlayerHandling.Include; - public bool IsApplyTagsToAllChatMessagesEnabled = true; [JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.None)] public Dictionary AllTagsChanges = new Dictionary(); diff --git a/PlayerTags/Configuration/ZoneConfiguration.cs b/PlayerTags/Configuration/ZoneConfiguration.cs new file mode 100644 index 0000000..ccaba9b --- /dev/null +++ b/PlayerTags/Configuration/ZoneConfiguration.cs @@ -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 : Dictionary 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]; + } + } +} diff --git a/PlayerTags/Configuration/ZoneConfigurationBase.cs b/PlayerTags/Configuration/ZoneConfigurationBase.cs new file mode 100644 index 0000000..3517070 --- /dev/null +++ b/PlayerTags/Configuration/ZoneConfigurationBase.cs @@ -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 + { + } +} diff --git a/PlayerTags/Data/PluginData.cs b/PlayerTags/Data/PluginData.cs index c8ca8e0..81485c3 100644 --- a/PlayerTags/Data/PluginData.cs +++ b/PlayerTags/Data/PluginData.cs @@ -23,13 +23,25 @@ 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); } diff --git a/PlayerTags/Data/PluginTagsData.cs b/PlayerTags/Data/PluginTagsData.cs index 667bb77..d60b74f 100644 --- a/PlayerTags/Data/PluginTagsData.cs +++ b/PlayerTags/Data/PluginTagsData.cs @@ -25,9 +25,9 @@ namespace PlayerTags.Data public Tag AllCustomTags; public List CustomTags; public List Identities; - private readonly PluginZoneConfiguration pluginZonedConfig; + private readonly TagsConfiguration pluginZonedConfig; - public PluginTagsData(PluginConfiguration pluginconfiguration, PluginZoneConfiguration pluginZonedConfiguration) + public PluginTagsData(PluginConfiguration pluginconfiguration, TagsConfiguration pluginZonedConfiguration) { pluginZonedConfig = pluginZonedConfiguration; ReloadDefault();