From fb4ffd3f2236ede632681c4ad02c6390136e7a81 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Wed, 9 Nov 2022 15:56:05 +0100 Subject: [PATCH] fix settings finally --- .../Configuration/PluginConfigurationUI.cs | 24 ++++---- PlayerTags/Data/DefaultPluginData.cs | 2 +- PlayerTags/Data/Tag.cs | 30 +++++++++- PlayerTags/Data/XivChatTypeList.cs | 56 ------------------- .../Inheritables/InheritableReference.cs | 1 + 5 files changed, 44 insertions(+), 69 deletions(-) delete mode 100644 PlayerTags/Data/XivChatTypeList.cs diff --git a/PlayerTags/Configuration/PluginConfigurationUI.cs b/PlayerTags/Configuration/PluginConfigurationUI.cs index 9f09e0f..aba314f 100644 --- a/PlayerTags/Configuration/PluginConfigurationUI.cs +++ b/PlayerTags/Configuration/PluginConfigurationUI.cs @@ -703,7 +703,7 @@ namespace PlayerTags.Configuration { DrawInheritable(selectedInheritable.Inheritable.Key, false, false, inheritableJobIconSetName); } - else if (selectedInheritable.Inheritable.Value is InheritableReference> inheritableXivChatType) + else if (selectedInheritable.Inheritable.Value is InheritableReference> inheritableXivChatType) { DrawMultiselect(selectedInheritable.Inheritable.Key, inheritableXivChatType); } @@ -1068,10 +1068,10 @@ namespace PlayerTags.Configuration ImGui.TextColored(new Vector4(0.7f, 0.6f, 1f, 1f), label); } - private void DrawMultiselect(string localizedStringName, InheritableReference> inheritable) where TEnum : Enum + private void DrawMultiselect(string localizedStringName, InheritableReference> inheritable) where TEnum : Enum { bool isDisabled = inheritable.Behavior == InheritableBehavior.Inherit; - EnumList proxyKey = isDisabled ? inheritable.InheritedValue : inheritable.Value; + List proxyKey = isDisabled ? inheritable.InheritedValue : inheritable.Value; if (isDisabled) proxyKey = inheritable.InheritedValue; @@ -1112,15 +1112,19 @@ namespace PlayerTags.Configuration { var entryName = Enum.GetName(typeofEnum, entry.Value); var tempval = entry.Enabled; + isClicked = ImGui.Checkbox(Localizer.GetString(entryName), ref isDisabled ? ref tempval : ref entry.Enabled); + if (ImGui.IsItemHovered()) ImGui.SetTooltip(Localizer.GetString(entryName, true)); - } - if (!isDisabled && isClicked) - { - proxy.ApplyTo(proxyKey); - SaveSettings(); + if (isClicked && !isDisabled) + { + var newList = proxyKey.ToList(); + proxy.ApplyTo(newList); + inheritable.Value = newList; + SaveSettings(); + } } } @@ -1353,13 +1357,13 @@ namespace PlayerTags.Configuration { public List Entries { get; } = new(); - public EnumMultiselectProxy(EnumList target) + public EnumMultiselectProxy(List target) { foreach (TEnum value in Enum.GetValues(typeof(TEnum))) Entries.Add(new(value, target.Contains(value))); } - public void ApplyTo(EnumList target) + public void ApplyTo(List target) { foreach (var entry in Entries) { diff --git a/PlayerTags/Data/DefaultPluginData.cs b/PlayerTags/Data/DefaultPluginData.cs index 71a43ea..1ee8fb9 100644 --- a/PlayerTags/Data/DefaultPluginData.cs +++ b/PlayerTags/Data/DefaultPluginData.cs @@ -47,7 +47,7 @@ namespace PlayerTags.Data IsVisibleForEnemyPlayers = true, IsVisibleForOtherPlayers = true, - TargetChatTypes = new EnumList(Enum.GetValues()), + TargetChatTypes = new List(Enum.GetValues()), }; AllRoleTags = new Tag() diff --git a/PlayerTags/Data/Tag.cs b/PlayerTags/Data/Tag.cs index 6338078..a168890 100644 --- a/PlayerTags/Data/Tag.cs +++ b/PlayerTags/Data/Tag.cs @@ -8,6 +8,7 @@ using PlayerTags.PluginStrings; using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; namespace PlayerTags.Data { @@ -175,7 +176,7 @@ namespace PlayerTags.Data public InheritableValue IsVisibleForOtherPlayers = new InheritableValue(false); [InheritableCategory("ChatFeatureCategory")] - public InheritableReference> TargetChatTypes = new(new EnumList(Enum.GetValues())); + public InheritableReference> TargetChatTypes = new(new List(Enum.GetValues())); [JsonIgnore] public string[] IdentitiesToAddTo @@ -228,7 +229,7 @@ namespace PlayerTags.Data { var inheritableData = inheritable.GetData(); if (inheritableData.Behavior != defaultInheritableData.Behavior || - !inheritableData.Value.Equals(defaultInheritableData.Value)) + !EqualsInheritableData(inheritableData, defaultInheritableData)) { changes[name] = inheritable.GetData(); } @@ -243,6 +244,31 @@ namespace PlayerTags.Data return changes; } + private static bool EqualsInheritableData(InheritableData data1, InheritableData data2) + { + if (data1.Value is List) + return EqualsInheritableDataListXivChatType(data1, data2); + else + return data1.Value.Equals(data2.Value); + } + + private static bool EqualsInheritableDataListXivChatType(InheritableData data1, InheritableData data2) + { + var list1 = data1.Value as List; + var list2 = data2.Value as List; + + if (list1 is null || list2 is null || list1.Count != list2.Count) + return false; + + for (int i = 0; i < list1.Count; i++) + { + if (!list1[i].Equals(list2[i])) + return false; + } + + return true; + } + public void SetChanges(IEnumerable> changes) { foreach ((var name, var inheritableData) in changes) diff --git a/PlayerTags/Data/XivChatTypeList.cs b/PlayerTags/Data/XivChatTypeList.cs deleted file mode 100644 index e05fdb8..0000000 --- a/PlayerTags/Data/XivChatTypeList.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PlayerTags.Data -{ - public class EnumList : List where TEnum : Enum - { - public EnumList() : base() - { - } - - public EnumList(IEnumerable collection) : base(collection) - { - } - - //// this is first one '==' - //public static bool operator ==(EnumList obj1, EnumList obj2) - //{ - - //} - - //// this is second one '!=' - //public static bool operator !=(EnumList obj1, EnumList obj2) - //{ - // return !(obj1 == obj2); - //} - - public override bool Equals(object? obj) - { - var obj1 = this; - var obj2 = obj as EnumList; - - if (obj1 is not null && obj2 is not null) - { - if (obj1.Count != obj2.Count) - return false; - - for (int i = 0; i < obj1.Count; i++) - { - if (!obj1[i]?.Equals(obj2[i]) ?? true) - return false; - } - } - - return true; - } - - public override int GetHashCode() - { - return base.GetHashCode(); - } - } -} diff --git a/PlayerTags/Inheritables/InheritableReference.cs b/PlayerTags/Inheritables/InheritableReference.cs index 21bab63..cabcf62 100644 --- a/PlayerTags/Inheritables/InheritableReference.cs +++ b/PlayerTags/Inheritables/InheritableReference.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; +using System.Collections.Generic; namespace PlayerTags.Inheritables {