fix settings finally
This commit is contained in:
@@ -703,7 +703,7 @@ namespace PlayerTags.Configuration
|
||||
{
|
||||
DrawInheritable(selectedInheritable.Inheritable.Key, false, false, inheritableJobIconSetName);
|
||||
}
|
||||
else if (selectedInheritable.Inheritable.Value is InheritableReference<EnumList<XivChatType>> inheritableXivChatType)
|
||||
else if (selectedInheritable.Inheritable.Value is InheritableReference<List<XivChatType>> 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<TEnum>(string localizedStringName, InheritableReference<EnumList<TEnum>> inheritable) where TEnum : Enum
|
||||
private void DrawMultiselect<TEnum>(string localizedStringName, InheritableReference<List<TEnum>> inheritable) where TEnum : Enum
|
||||
{
|
||||
bool isDisabled = inheritable.Behavior == InheritableBehavior.Inherit;
|
||||
EnumList<TEnum> proxyKey = isDisabled ? inheritable.InheritedValue : inheritable.Value;
|
||||
List<TEnum> 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<Entry> Entries { get; } = new();
|
||||
|
||||
public EnumMultiselectProxy(EnumList<TEnum> target)
|
||||
public EnumMultiselectProxy(List<TEnum> target)
|
||||
{
|
||||
foreach (TEnum value in Enum.GetValues(typeof(TEnum)))
|
||||
Entries.Add(new(value, target.Contains(value)));
|
||||
}
|
||||
|
||||
public void ApplyTo(EnumList<TEnum> target)
|
||||
public void ApplyTo(List<TEnum> target)
|
||||
{
|
||||
foreach (var entry in Entries)
|
||||
{
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace PlayerTags.Data
|
||||
IsVisibleForEnemyPlayers = true,
|
||||
IsVisibleForOtherPlayers = true,
|
||||
|
||||
TargetChatTypes = new EnumList<XivChatType>(Enum.GetValues<XivChatType>()),
|
||||
TargetChatTypes = new List<XivChatType>(Enum.GetValues<XivChatType>()),
|
||||
};
|
||||
|
||||
AllRoleTags = new Tag()
|
||||
|
||||
@@ -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<bool> IsVisibleForOtherPlayers = new InheritableValue<bool>(false);
|
||||
|
||||
[InheritableCategory("ChatFeatureCategory")]
|
||||
public InheritableReference<EnumList<XivChatType>> TargetChatTypes = new(new EnumList<XivChatType>(Enum.GetValues<XivChatType>()));
|
||||
public InheritableReference<List<XivChatType>> TargetChatTypes = new(new List<XivChatType>(Enum.GetValues<XivChatType>()));
|
||||
|
||||
[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<XivChatType>)
|
||||
return EqualsInheritableDataListXivChatType<XivChatType>(data1, data2);
|
||||
else
|
||||
return data1.Value.Equals(data2.Value);
|
||||
}
|
||||
|
||||
private static bool EqualsInheritableDataListXivChatType<TEnum>(InheritableData data1, InheritableData data2)
|
||||
{
|
||||
var list1 = data1.Value as List<TEnum>;
|
||||
var list2 = data2.Value as List<TEnum>;
|
||||
|
||||
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<KeyValuePair<string, InheritableData>> changes)
|
||||
{
|
||||
foreach ((var name, var inheritableData) in changes)
|
||||
|
||||
@@ -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<TEnum> : List<TEnum> where TEnum : Enum
|
||||
{
|
||||
public EnumList() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public EnumList(IEnumerable<TEnum> collection) : base(collection)
|
||||
{
|
||||
}
|
||||
|
||||
//// this is first one '=='
|
||||
//public static bool operator ==(EnumList<TEnum> obj1, EnumList<TEnum> obj2)
|
||||
//{
|
||||
|
||||
//}
|
||||
|
||||
//// this is second one '!='
|
||||
//public static bool operator !=(EnumList<TEnum> obj1, EnumList<TEnum> obj2)
|
||||
//{
|
||||
// return !(obj1 == obj2);
|
||||
//}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
var obj1 = this;
|
||||
var obj2 = obj as EnumList<TEnum>;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PlayerTags.Inheritables
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user