From 3f0d7e776eeca671645e776ea6793ee1945f650f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E6=B0=B4?= <1123993881@qq.com> Date: Thu, 21 Mar 2024 16:09:35 +0800 Subject: [PATCH] fix: changed the way to add rotation config. --- .../Actions/ActionTargetInfo.cs | 2 +- .../Attributes/RotationConfigAttribute.cs | 19 +++ RotationSolver.Basic/Configuration/Configs.cs | 2 +- .../RotationConfig/IRotationConfigSet.cs | 106 ---------------- .../RotationConfig/RotationConfigBase.cs | 77 ++++++++++-- .../RotationConfig/RotationConfigBoolean.cs | 8 +- .../RotationConfig/RotationConfigCombo.cs | 24 +++- .../RotationConfig/RotationConfigComparer.cs | 17 ++- .../RotationConfig/RotationConfigFloat.cs | 25 ++-- .../RotationConfig/RotationConfigInt.cs | 22 +++- .../RotationConfig/RotationConfigSet.cs | 117 ++++++------------ .../RotationConfig/RotationConfigString.cs | 12 +- .../Rotations/Basic/SamuraiRotation.cs | 6 +- .../Rotations/CustomRotation_BasicInfo.cs | 15 +-- .../Rotations/ICustomRotation.cs | 5 +- .../Commands/RSCommands_OtherCommand.cs | 4 +- RotationSolver/UI/RotationConfigWindow.cs | 26 ++-- .../UI/SearchableConfigs/EnumSearch.cs | 13 +- 18 files changed, 228 insertions(+), 272 deletions(-) create mode 100644 RotationSolver.Basic/Attributes/RotationConfigAttribute.cs diff --git a/RotationSolver.Basic/Actions/ActionTargetInfo.cs b/RotationSolver.Basic/Actions/ActionTargetInfo.cs index b52cf2057..2143d4953 100644 --- a/RotationSolver.Basic/Actions/ActionTargetInfo.cs +++ b/RotationSolver.Basic/Actions/ActionTargetInfo.cs @@ -69,7 +69,7 @@ private readonly IEnumerable GetCanTargets(bool skipStatusProvideCh return objs.Where(CanUseTo).Where(InViewTarget).Where(action.Setting.CanTarget); } - private readonly IEnumerable GetCanAffects(bool skipStatusProvideCheck, TargetType type) + private readonly List GetCanAffects(bool skipStatusProvideCheck, TargetType type) { if (EffectRange == 0) return []; diff --git a/RotationSolver.Basic/Attributes/RotationConfigAttribute.cs b/RotationSolver.Basic/Attributes/RotationConfigAttribute.cs new file mode 100644 index 000000000..cc47a7106 --- /dev/null +++ b/RotationSolver.Basic/Attributes/RotationConfigAttribute.cs @@ -0,0 +1,19 @@ +namespace RotationSolver.Basic.Attributes; + +/// +/// +/// +/// +[AttributeUsage(AttributeTargets.Property)] +public class RotationConfigAttribute(CombatType type) : Attribute +{ + /// + /// The type of this config. + /// + public CombatType Type => type; + + /// + /// The display name for this config. + /// + public string Name { get; set; } = string.Empty; +} diff --git a/RotationSolver.Basic/Configuration/Configs.cs b/RotationSolver.Basic/Configuration/Configs.cs index 9f1183ccc..da4cee62f 100644 --- a/RotationSolver.Basic/Configuration/Configs.cs +++ b/RotationSolver.Basic/Configuration/Configs.cs @@ -732,7 +732,7 @@ public const string private readonly Dictionary _rotationItemConfig = []; [JobChoiceConfig] - private readonly Dictionary _rotationsConfigurations = []; + private readonly Dictionary _rotationConfigurations = []; public Dictionary DutyRotationChoice { get; set; } = []; diff --git a/RotationSolver.Basic/Configuration/RotationConfig/IRotationConfigSet.cs b/RotationSolver.Basic/Configuration/RotationConfig/IRotationConfigSet.cs index 698df7d5a..f60281ccf 100644 --- a/RotationSolver.Basic/Configuration/RotationConfig/IRotationConfigSet.cs +++ b/RotationSolver.Basic/Configuration/RotationConfig/IRotationConfigSet.cs @@ -9,110 +9,4 @@ public interface IRotationConfigSet : IEnumerable /// The configs. /// HashSet Configs { get; } - - /// - /// Set the float. - /// - /// tye unit type - /// the combat type - /// - /// - /// - /// - /// - /// - IRotationConfigSet SetFloat(ConfigUnitType unit, CombatType type, string name, float value, string displayName, float min = 0, float max = 1, float speed = 0.002f); - - /// - /// Set the string. - /// - /// the combat type - /// - /// - /// - /// - IRotationConfigSet SetString(CombatType type, string name, string value, string displayName); - - /// - /// - /// - /// the combat type - /// - /// - /// - /// - IRotationConfigSet SetBool(CombatType type, string name, bool value, string displayName); - - /// - /// - /// - /// - /// - /// - /// - /// - /// - IRotationConfigSet SetCombo(CombatType type, string name, int value, string displayName, params string[] items); - - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - IRotationConfigSet SetInt(CombatType type, string name, int value, string displayName, int min = 0, int max = 10, int speed = 1); - - /// - /// Set the value. - /// - /// - /// - void SetValue(string name, string value); - - /// - /// Get the combo. - /// - /// - /// - int GetCombo(string name); - - /// - /// Get the bool. - /// - /// - /// - bool GetBool(string name); - - /// - /// Get the float. - /// - /// - /// - float GetFloat(string name); - - /// - /// Get the int. - /// - /// - /// - int GetInt(string name); - - /// - /// Get the raw string value in the saved dictionary, is not readable. - /// - /// - /// - string GetString(string name); - - /// - /// Get the readable string for display. - /// - /// - /// - string GetDisplayString(string name); } diff --git a/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigBase.cs b/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigBase.cs index 833e1c37a..e661b4fcf 100644 --- a/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigBase.cs +++ b/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigBase.cs @@ -1,24 +1,85 @@ -namespace RotationSolver.Basic.Configuration.RotationConfig; +using ECommons.DalamudServices; -internal abstract class RotationConfigBase(string name, string value, string displayName, CombatType type) +namespace RotationSolver.Basic.Configuration.RotationConfig; + +internal abstract class RotationConfigBase : IRotationConfig { - public string Name { get; } = name; - public string DefaultValue { get; } = value; - public string DisplayName { get; } = displayName; - public CombatType Type { get; } = type; + readonly PropertyInfo _property; + readonly ICustomRotation _rotation; + public string Name { get; } + public string DefaultValue { get; } + public string DisplayName { get; } + public CombatType Type { get; } public string Value { get { - if (!Service.Config.RotationsConfigurations.TryGetValue(Name, out var config)) return DefaultValue; + if (!Service.Config.RotationConfigurations.TryGetValue(Name, out var config)) return DefaultValue; return config; } set { - Service.Config.RotationsConfigurations[Name] = value; + Service.Config.RotationConfigurations[Name] = value; + SetValue(value); + } + } + + protected RotationConfigBase(ICustomRotation rotation, PropertyInfo property) + { + _property = property; + _rotation = rotation; + + Name = property.Name; + DefaultValue = property.GetValue(rotation)?.ToString() ?? string.Empty; + var attr = property.GetCustomAttribute(); + if (attr != null) + { + DisplayName = attr.Name; + Type = attr.Type; + } + else + { + DisplayName = Name; + Type = CombatType.None; + } + + //Set Up + if (Service.Config.RotationConfigurations.TryGetValue(Name, out var value)) + { + SetValue(value); + } + } + + private void SetValue(string value) + { + var type = _property.PropertyType; + if (type == null) return; + + try + { + _property.SetValue(_rotation, ChangeType(value, type)); + } + catch (Exception ex) + { + Svc.Log.Error(ex, "Failed to convert type."); + _property.SetValue(_rotation, ChangeType(DefaultValue, type)); + } + } + + private static object ChangeType(string value, Type type) + { + if (type.IsEnum) + { + return Enum.Parse(type, value); } + else if(type == typeof(bool)) + { + return bool.Parse(value); + } + + return Convert.ChangeType(value, type); } public virtual bool DoCommand(IRotationConfigSet set, string str) => str.StartsWith(Name); diff --git a/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigBoolean.cs b/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigBoolean.cs index 0316cc9b3..9e304bba1 100644 --- a/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigBoolean.cs +++ b/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigBoolean.cs @@ -1,7 +1,7 @@ namespace RotationSolver.Basic.Configuration.RotationConfig; -internal class RotationConfigBoolean(string name, bool value, string displayName, CombatType type) - : RotationConfigBase(name, value.ToString(), displayName, type) +internal class RotationConfigBoolean(ICustomRotation rotation, PropertyInfo property) + : RotationConfigBase(rotation, property) { public override bool DoCommand(IRotationConfigSet set, string str) { @@ -11,11 +11,11 @@ public override bool DoCommand(IRotationConfigSet set, string str) if (bool.TryParse(numStr, out _)) { - set.SetValue(Name, numStr.ToString()); + Value = numStr.ToString(); } else { - set.SetValue(Name, (!set.GetBool(Name)).ToString()); + Value = (!bool.Parse(Value)).ToString(); } return true; } diff --git a/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigCombo.cs b/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigCombo.cs index 7a2b82d0f..2521b1721 100644 --- a/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigCombo.cs +++ b/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigCombo.cs @@ -1,9 +1,21 @@ -namespace RotationSolver.Basic.Configuration.RotationConfig; +using Dalamud.Utility; -internal class RotationConfigCombo(string name, int value, string displayName, string[] items, CombatType type) - : RotationConfigBase(name, value.ToString(), displayName, type) +namespace RotationSolver.Basic.Configuration.RotationConfig; + +internal class RotationConfigCombo: RotationConfigBase { - public string[] Items { get; set; } = items; + public string[] Items { get; set; } + + public RotationConfigCombo(ICustomRotation rotation, PropertyInfo property) + :base(rotation, property) + { + var names = new List(); + foreach (Enum v in Enum.GetValues(property.PropertyType)) + { + names.Add(v.GetAttribute()?.Description ?? v.ToString()); + } + Items = [.. names]; + } public override string ToString() { @@ -19,7 +31,7 @@ public override bool DoCommand(IRotationConfigSet set, string str) string numStr = str[Name.Length..].Trim(); var length = Items.Length; - int nextId = (set.GetCombo(Name) + 1) % length; + int nextId = (int.Parse(Value) + 1) % length; if (int.TryParse(numStr, out int num)) { nextId = num % length; @@ -35,7 +47,7 @@ public override bool DoCommand(IRotationConfigSet set, string str) } } - set.SetValue(Name, nextId.ToString()); + Value = nextId.ToString(); return true; } } diff --git a/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigComparer.cs b/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigComparer.cs index 38871c171..28c815891 100644 --- a/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigComparer.cs +++ b/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigComparer.cs @@ -1,15 +1,14 @@ using System.Diagnostics.CodeAnalysis; -namespace RotationSolver.Basic.Configuration.RotationConfig +namespace RotationSolver.Basic.Configuration.RotationConfig; + +internal class RotationConfigComparer : IEqualityComparer { - internal class RotationConfigComparer : IEqualityComparer + public bool Equals(IRotationConfig? x, IRotationConfig? y) { - public bool Equals(IRotationConfig? x, IRotationConfig? y) - { - if (x == null || y == null) return false; - return x.Name.Equals(y.Name); - } - - public int GetHashCode([DisallowNull] IRotationConfig obj) => obj.Name.GetHashCode(); + if (x == null || y == null) return false; + return x.Name.Equals(y.Name); } + + public int GetHashCode([DisallowNull] IRotationConfig obj) => obj.Name.GetHashCode(); } diff --git a/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigFloat.cs b/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigFloat.cs index 7c7beb25e..4f2f7d6a0 100644 --- a/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigFloat.cs +++ b/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigFloat.cs @@ -6,13 +6,24 @@ internal class RotationConfigFloat : RotationConfigBase public ConfigUnitType UnitType { get; set; } - - public RotationConfigFloat(string name, float value, string displayName, float min, float max, float speed, ConfigUnitType unitType, CombatType type) : base(name, value.ToString(), displayName, type) + public RotationConfigFloat(ICustomRotation rotation, PropertyInfo property) + : base(rotation, property) { - Min = min; - Max = max; - Speed = speed; - UnitType = unitType; + var attr = property.GetCustomAttribute(); + if(attr != null) + { + Min = attr.MinValue; + Max = attr.MaxValue; + Speed = attr.Speed; + UnitType = attr.UnitType; + } + else + { + Min = 0.0f; + Max = 1.0f; + Speed = 0.005f; + UnitType = ConfigUnitType.Percent; + } } public override bool DoCommand(IRotationConfigSet set, string str) @@ -23,7 +34,7 @@ public override bool DoCommand(IRotationConfigSet set, string str) if (float.TryParse(numStr, out _)) { - set.SetValue(Name, numStr.ToString()); + Value = numStr.ToString(); } return true; } diff --git a/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigInt.cs b/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigInt.cs index eb7be5a22..d5d1afc11 100644 --- a/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigInt.cs +++ b/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigInt.cs @@ -4,12 +4,22 @@ internal class RotationConfigInt : RotationConfigBase { public int Min, Max, Speed; - public RotationConfigInt(string name, int value, string displayName, int min, int max, int speed, CombatType type) - : base(name, value.ToString(), displayName, type) + public RotationConfigInt(ICustomRotation rotation, PropertyInfo property) + : base(rotation, property) { - Min = min; - Max = max; - Speed = speed; + var attr = property.GetCustomAttribute(); + if (attr != null) + { + Min = (int)attr.MinValue; + Max = (int)attr.MaxValue; + Speed = (int)attr.Speed; + } + else + { + Min = 0; + Max = 10; + Speed = 1; + } } public override bool DoCommand(IRotationConfigSet set, string str) @@ -20,7 +30,7 @@ public override bool DoCommand(IRotationConfigSet set, string str) if (int.TryParse(numStr, out _)) { - set.SetValue(Name, numStr.ToString()); + Value = numStr.ToString(); } return true; } diff --git a/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigSet.cs b/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigSet.cs index 78f10b4b7..ff4af814b 100644 --- a/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigSet.cs +++ b/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigSet.cs @@ -1,4 +1,5 @@ -using System.Collections; +using ECommons.DalamudServices; +using System.Collections; namespace RotationSolver.Basic.Configuration.RotationConfig; @@ -6,87 +7,43 @@ internal class RotationConfigSet : IRotationConfigSet { public HashSet Configs { get; } = new HashSet(new RotationConfigComparer()); - public IRotationConfigSet SetFloat(ConfigUnitType unit, CombatType type, string name, float value, string displayName, float min = 0, float max = 1, float speed = 0.002f) - { - Configs.Add(new RotationConfigFloat(name, value, displayName, min, max, speed, unit, type)); - return this; - } - - public IRotationConfigSet SetString(CombatType type, string name, string value, string displayName) - { - Configs.Add(new RotationConfigString(name, value, displayName, type)); - return this; - } - - public IRotationConfigSet SetBool(CombatType type, string name, bool value, string displayName) - { - Configs.Add(new RotationConfigBoolean(name, value, displayName, type)); - return this; - } - - public IRotationConfigSet SetCombo(CombatType type, string name, int value, string displayName, params string[] items) - { - Configs.Add(new RotationConfigCombo(name, value, displayName, items, type)); - return this; + public RotationConfigSet(ICustomRotation rotation) + { + foreach (var prop in rotation.GetType().GetAllPropertyInfo()) + { + var attr = prop.GetCustomAttribute(); + if (attr == null) continue; + + var type = prop.PropertyType; + if (type == null) continue; + + if (type == typeof(bool)) + { + Configs.Add(new RotationConfigBoolean(rotation, prop)); + } + else if (type.IsEnum) + { + Configs.Add(new RotationConfigCombo(rotation, prop)); + } + else if(type == typeof(float)) + { + Configs.Add(new RotationConfigFloat(rotation, prop)); + } + else if(type == typeof(int)) + { + Configs.Add(new RotationConfigInt(rotation, prop)); + } + else if(type == typeof(string)) + { + Configs.Add(new RotationConfigString(rotation, prop)); + } + else + { + Svc.Log.Error($"Failed to find the rotation config type {type.FullName ?? type.Name}"); + } + } } - public IRotationConfigSet SetInt(CombatType type, string name, int value, string displayName, int min = 0, int max = 10, int speed = 1) - { - Configs.Add(new RotationConfigInt(name, value, displayName, min, max, speed, type)); - return this; - } - - public void SetValue(string name, string value) - { - var config = Configs.FirstOrDefault(config => config.Name == name); - if (config == null) return; - config.Value = value; - } - - #region Get - public int GetCombo(string name) - { - var result = GetString(name); - if (int.TryParse(result, out var f)) return f; - return 0; - } - - public bool GetBool(string name) - { - var result = GetString(name); - if (bool.TryParse(result, out var f)) return f; - return false; - } - - public float GetFloat(string name) - { - var result = GetString(name); - if (float.TryParse(result, out var f)) return f; - return float.NaN; - } - - public string GetString(string name) - { - var config = GetConfig(name); - return config?.Value ?? string.Empty; - } - - public int GetInt(string name) - { - var result = GetString(name); - if (int.TryParse(result, out var f)) return f; - return 0; - } - - public string GetDisplayString(string name) - { - var config = GetConfig(name); - return config?.ToString() ?? string.Empty; - } - - private IRotationConfig? GetConfig(string name) => Configs.FirstOrDefault(config => config.Name == name); - #endregion - public IEnumerator GetEnumerator() => Configs.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => Configs.GetEnumerator(); diff --git a/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigString.cs b/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigString.cs index 4dc468360..1ceec36de 100644 --- a/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigString.cs +++ b/RotationSolver.Basic/Configuration/RotationConfig/RotationConfigString.cs @@ -1,19 +1,13 @@ namespace RotationSolver.Basic.Configuration.RotationConfig; -internal class RotationConfigString : RotationConfigBase +internal class RotationConfigString(ICustomRotation rotation, PropertyInfo property) + : RotationConfigBase(rotation, property) { - public RotationConfigString(string name, string value, string displayName, CombatType type) - : base(name, value, displayName, type) - { - } - public override bool DoCommand(IRotationConfigSet set, string str) { if (!base.DoCommand(set, str)) return false; - string numStr = str[Name.Length..].Trim(); - - set.SetValue(Name, numStr.ToString()); + Value = str[Name.Length..].Trim(); return true; } diff --git a/RotationSolver.Basic/Rotations/Basic/SamuraiRotation.cs b/RotationSolver.Basic/Rotations/Basic/SamuraiRotation.cs index f35a31639..caf96cfe8 100644 --- a/RotationSolver.Basic/Rotations/Basic/SamuraiRotation.cs +++ b/RotationSolver.Basic/Rotations/Basic/SamuraiRotation.cs @@ -91,18 +91,18 @@ static partial void ModifyKaeshiNamikiriPvE(ref ActionSetting setting) static partial void ModifyHiganbanaPvE(ref ActionSetting setting) { - setting.ActionCheck = () => !IsMoving && SenCount == 1; + setting.ActionCheck = () => SenCount == 1; setting.TargetStatusProvide = [StatusID.Higanbana]; } static partial void ModifyTenkaGokenPvE(ref ActionSetting setting) { - setting.ActionCheck = () => !IsMoving && SenCount == 2; + setting.ActionCheck = () => SenCount == 2; setting.IsFriendly = false; } static partial void ModifyMidareSetsugekkaPvE(ref ActionSetting setting) { - setting.ActionCheck = () => !IsMoving && SenCount == 3; + setting.ActionCheck = () => SenCount == 3; } static partial void ModifyKaeshiGokenPvE(ref ActionSetting setting) diff --git a/RotationSolver.Basic/Rotations/CustomRotation_BasicInfo.cs b/RotationSolver.Basic/Rotations/CustomRotation_BasicInfo.cs index 07d9690fd..f57c08bda 100644 --- a/RotationSolver.Basic/Rotations/CustomRotation_BasicInfo.cs +++ b/RotationSolver.Basic/Rotations/CustomRotation_BasicInfo.cs @@ -50,8 +50,10 @@ public bool IsEnabled /// public uint IconID { get; } + private readonly IRotationConfigSet _configs; + /// - public IRotationConfigSet Configs { get; } + IRotationConfigSet ICustomRotation.Configs => _configs; /// public static Vector3? MoveTarget { get; internal set; } @@ -130,16 +132,7 @@ public bool IsEnabled private protected CustomRotation() { IconID = IconSet.GetJobIcon(this.Job); - Configs = CreateConfiguration(); - } - - /// - /// The way to create the configurations. - /// - /// - protected virtual IRotationConfigSet CreateConfiguration() - { - return new RotationConfigSet(); + _configs = new RotationConfigSet(this); } /// diff --git a/RotationSolver.Basic/Rotations/ICustomRotation.cs b/RotationSolver.Basic/Rotations/ICustomRotation.cs index 0259ca16e..faa820905 100644 --- a/RotationSolver.Basic/Rotations/ICustomRotation.cs +++ b/RotationSolver.Basic/Rotations/ICustomRotation.cs @@ -54,10 +54,7 @@ public interface ICustomRotation : ITexture /// JobRole Role { get; } - /// - /// Configurations about this rotation. - /// - IRotationConfigSet Configs { get; } + internal IRotationConfigSet Configs { get; } /// /// The type of medicine. diff --git a/RotationSolver/Commands/RSCommands_OtherCommand.cs b/RotationSolver/Commands/RSCommands_OtherCommand.cs index 651b66435..f62ea67a4 100644 --- a/RotationSolver/Commands/RSCommands_OtherCommand.cs +++ b/RotationSolver/Commands/RSCommands_OtherCommand.cs @@ -147,8 +147,8 @@ private static void DoRotationCommand(ICustomRotation customCombo, string str) { if (config.DoCommand(configs, str)) { - Svc.Chat.Print(string.Format(UiString.CommandsInsertAction.Local(), - config.DisplayName, configs.GetDisplayString(config.Name))); + Svc.Chat.Print(string.Format(UiString.CommandsChangeSettingsValue.Local(), + config.DisplayName, config.Value)); return; } diff --git a/RotationSolver/UI/RotationConfigWindow.cs b/RotationSolver/UI/RotationConfigWindow.cs index e7e4c5a3b..be469d5bd 100644 --- a/RotationSolver/UI/RotationConfigWindow.cs +++ b/RotationSolver/UI/RotationConfigWindow.cs @@ -567,7 +567,7 @@ private void DrawBody() using var child = ImRaii.Child("Rotation Solver Body", -Vector2.One); if (child) { - if (_searchResults != null && _searchResults.Any()) + if (_searchResults != null && _searchResults.Length != 0) { using (var font = ImRaii.PushFont(DrawingExtensions.GetFont(18))) { @@ -1199,13 +1199,13 @@ private static void DrawRotationConfiguration() var key = rotation.GetType().FullName ?? rotation.GetType().Name + "." + config.Name; var name = $"##{config.GetHashCode()}_{(key + ".Name").Local(config.Name)}"; string command = ToCommandStr(OtherCommandType.Rotations, config.Name, config.DefaultValue); - void Reset() => set.SetValue(config.Name, config.DefaultValue); + void Reset() => config.Value = config.DefaultValue; ImGuiHelper.PrepareGroup(key, command, Reset); if (config is RotationConfigCombo c) { - var val = set.GetCombo(c.Name); + var val = int.Parse(c.Value); ImGui.SetNextItemWidth(ImGui.CalcTextSize(c.Items[val]).X + 50 * Scale); var openCombo = ImGui.BeginCombo(name, c.Items[val]); ImGuiHelper.ReactPopup(key, command, Reset); @@ -1215,7 +1215,7 @@ private static void DrawRotationConfiguration() { if (ImGui.Selectable(c.Items[comboIndex])) { - set.SetValue(config.Name, comboIndex.ToString()); + config.Value = comboIndex.ToString(); } } ImGui.EndCombo(); @@ -1223,31 +1223,31 @@ private static void DrawRotationConfiguration() } else if (config is RotationConfigBoolean b) { - bool val = set.GetBool(config.Name); + bool val = bool.Parse(config.Value); if (ImGui.Checkbox(name, ref val)) { - set.SetValue(config.Name, val.ToString()); + config.Value = val.ToString(); } ImGuiHelper.ReactPopup(key, command, Reset); } else if (config is RotationConfigFloat f) { - float val = set.GetFloat(config.Name); + float val = float.Parse(config.Value); ImGui.SetNextItemWidth(Scale * Searchable.DRAG_WIDTH); if (f.UnitType == ConfigUnitType.Percent) { if (ImGui.SliderFloat(name, ref val, f.Min, f.Max, $"{val * 100:F1}{f.UnitType.ToSymbol()}")) { - set.SetValue(config.Name, val.ToString()); + config.Value = val.ToString(); } } else { if (ImGui.DragFloat(name, ref val, f.Speed, f.Min, f.Max, $"{val:F2}{f.UnitType.ToSymbol()}")) { - set.SetValue(config.Name, val.ToString()); + config.Value = val.ToString(); } } ImguiTooltips.HoveredTooltip(f.UnitType.Local()); @@ -1256,23 +1256,23 @@ private static void DrawRotationConfiguration() } else if (config is RotationConfigString s) { - string val = set.GetString(config.Name); + string val = config.Value; ImGui.SetNextItemWidth(ImGui.GetWindowWidth()); if (ImGui.InputTextWithHint(name, config.DisplayName, ref val, 128)) { - set.SetValue(config.Name, val.ToString()); + config.Value = val; } ImGuiHelper.ReactPopup(key, command, Reset); continue; } else if (config is RotationConfigInt i) { - int val = set.GetInt(config.Name); + int val = int.Parse(config.Value); ImGui.SetNextItemWidth(Scale * Searchable.DRAG_WIDTH); if (ImGui.DragInt(name, ref val, i.Speed, i.Min, i.Max)) { - set.SetValue(config.Name, val.ToString()); + config.Value = val.ToString(); } ImGuiHelper.ReactPopup(key, command, Reset); } diff --git a/RotationSolver/UI/SearchableConfigs/EnumSearch.cs b/RotationSolver/UI/SearchableConfigs/EnumSearch.cs index 26b973d79..8a8a8f718 100644 --- a/RotationSolver/UI/SearchableConfigs/EnumSearch.cs +++ b/RotationSolver/UI/SearchableConfigs/EnumSearch.cs @@ -1,4 +1,8 @@ -namespace RotationSolver.UI.SearchableConfigs; +using Newtonsoft.Json.Linq; +using RotationSolver.Localization; +using System; + +namespace RotationSolver.UI.SearchableConfigs; internal class EnumSearch(PropertyInfo property) : Searchable(property) { @@ -12,7 +16,12 @@ protected override void DrawMain() { var value = Value; - var strs = Enum.GetNames(_property.PropertyType); + var names = new List(); + foreach (Enum v in Enum.GetValues(_property.PropertyType)) + { + names.Add(v.Local()); + } + var strs = names.ToArray(); if (strs.Length > 0) {