From a7938dcd3177b2bf44162543628b1a14cb801bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E6=B0=B4?= <1123993881@qq.com> Date: Mon, 17 Jul 2023 14:59:30 +0800 Subject: [PATCH] fix: add more reset value. --- RotationSolver/Localization/Localization.json | 1 + RotationSolver/UI/ImGuiHelper.cs | 62 ++++++++++--------- .../UI/RotationConfigWindow_Major.cs | 18 ++++-- .../UI/RotationConfigWindow_Param.cs | 2 +- 4 files changed, 47 insertions(+), 36 deletions(-) diff --git a/RotationSolver/Localization/Localization.json b/RotationSolver/Localization/Localization.json index a1b1c91dc..362f12a19 100644 --- a/RotationSolver/Localization/Localization.json +++ b/RotationSolver/Localization/Localization.json @@ -114,6 +114,7 @@ "ConfigWindow_Param_UseAOEAction": "Use AOE actions", "ConfigWindow_Param_UseAOEWhenManual": "Use AOE actions in manual mode", "ConfigWindow_Param_AutoBurst": "Automatic burst", + "ConfigWindow_Param_AutoHeal": "Automatic Heal", "ConfigWindow_Param_UseAbility": "Auto-use abilities", "ConfigWindow_Param_NoNewHostiles": "Don't attack new mobs by aoe", "ConfigWindow_Params_NoNewHostilesDesc": "Never use any AOE action when this action may attack the mobs that not is a hostile target.", diff --git a/RotationSolver/UI/ImGuiHelper.cs b/RotationSolver/UI/ImGuiHelper.cs index a6030acfe..ab74e077e 100644 --- a/RotationSolver/UI/ImGuiHelper.cs +++ b/RotationSolver/UI/ImGuiHelper.cs @@ -3,12 +3,15 @@ using Dalamud.Utility; using ECommons.DalamudServices; using FFXIVClientStructs.FFXIV.Client.Game; +using FFXIVClientStructs.Havok; +using Newtonsoft.Json.Linq; using RotationSolver.Basic.Configuration; using RotationSolver.Commands; using RotationSolver.Helpers; using RotationSolver.Localization; using RotationSolver.Updaters; using System.ComponentModel; +using System.Xml.Linq; namespace RotationSolver.UI; @@ -148,7 +151,7 @@ public static void UndoValue(string name, ref T value1, T default1, ref T val } } - static bool UndoValue(string name) + private static bool UndoValue(string name) { ImGui.SameLine(); Spacing(); @@ -549,20 +552,20 @@ public unsafe static void Display(this ICustomRotation rotation, ICustomRotation ImGui.SameLine(); ImGui.Text(rotation.GameVersion); - if (rotation.Configs.Any()) - { - ImGui.SameLine(); - Spacing(); - if (IconButton(FontAwesomeIcon.Undo, $"#{rotation.GetHashCode()}Undo", - LocalizationManager.RightLang.ConfigWindow_Rotation_ResetToDefault)) - { - if (Service.Config.RotationsConfigurations.TryGetValue(rotation.ClassJob.RowId, out var jobDict) - && jobDict.ContainsKey(rotation.GetType().FullName)) - { - jobDict.Remove(rotation.GetType().FullName); - } - } - } + //if (rotation.Configs.Any()) + //{ + // ImGui.SameLine(); + // Spacing(); + // if (IconButton(FontAwesomeIcon.Undo, $"#{rotation.GetHashCode()}Undo", + // LocalizationManager.RightLang.ConfigWindow_Rotation_ResetToDefault)) + // { + // if (Service.Config.RotationsConfigurations.TryGetValue(rotation.ClassJob.RowId, out var jobDict) + // && jobDict.ContainsKey(rotation.GetType().FullName)) + // { + // jobDict.Remove(rotation.GetType().FullName); + // } + // } + //} var link = rotation.GetType().GetCustomAttribute(); if(link != null) @@ -783,7 +786,8 @@ static void Draw(this RotationConfigCombo config, IRotationConfigSet set, bool c { var val = set.GetCombo(config.Name); ImGui.SetNextItemWidth(ImGui.CalcTextSize(config.Items[val]).X + 50); - if (ImGui.BeginCombo($"{config.DisplayName}##{config.GetHashCode()}_{config.Name}", config.Items[val])) + var name = $"{config.DisplayName}##{config.GetHashCode()}_{config.Name}"; + if (ImGui.BeginCombo(name, config.Items[val])) { for (int comboIndex = 0; comboIndex < config.Items.Length; comboIndex++) { @@ -807,6 +811,12 @@ static void Draw(this RotationConfigCombo config, IRotationConfigSet set, bool c } HoveredString(LocalizationManager.RightLang.ConfigWindow_Rotation_KeyName + ": " + config.Name); + var @default = int.TryParse(config.DefaultValue, out var f) ? f : 0; + if (val != @default) + { + UndoValue(name, ref val, @default); + } + if (canAddButton) { ImGui.SameLine(); @@ -818,14 +828,12 @@ static void Draw(this RotationConfigCombo config, IRotationConfigSet set, bool c static void Draw(this RotationConfigBoolean config, IRotationConfigSet set, bool canAddButton) { bool val = set.GetBool(config.Name); - if (ImGui.Checkbox($"{config.DisplayName}##{config.GetHashCode()}_{config.DisplayName}", ref val)) + + RotationConfigWindow.DrawCheckBox($"{config.DisplayName}##{config.GetHashCode()}_{config.DisplayName}", ref val, bool.TryParse(config.DefaultValue, out var f) ? f : false, LocalizationManager.RightLang.ConfigWindow_Rotation_KeyName + ": " + config.Name, () => { set.SetValue(config.Name, val.ToString()); - Service.Config.Save(); - } - HoveredString(LocalizationManager.RightLang.ConfigWindow_Rotation_KeyName + ": " + config.Name); + }); - //显示可以设置的案件 if (canAddButton) { ImGui.SameLine(); @@ -837,12 +845,10 @@ static void Draw(this RotationConfigBoolean config, IRotationConfigSet set, bool static void Draw(this RotationConfigFloat config, IRotationConfigSet set, bool canAddButton) { float val = set.GetFloat(config.Name); - ImGui.SetNextItemWidth(100); - if (ImGui.DragFloat($"{config.DisplayName}##{config.GetHashCode()}_{config.Name}", ref val, config.Speed, config.Min, config.Max)) + RotationConfigWindow.DrawFloatNumber($"{config.DisplayName}##{config.GetHashCode()}_{config.Name}", ref val, float.TryParse(config.DefaultValue, out var f) ? f : 0, config.Speed, config.Min, config.Max, otherThing: () => { set.SetValue(config.Name, val.ToString()); - Service.Config.Save(); - } + }); } static void Draw(this RotationConfigString config, IRotationConfigSet set, bool canAddButton) @@ -858,12 +864,10 @@ static void Draw(this RotationConfigString config, IRotationConfigSet set, bool static void Draw(this RotationConfigInt config, IRotationConfigSet set, bool canAddButton) { int val = set.GetInt(config.Name); - ImGui.SetNextItemWidth(100); - if (ImGui.DragInt($"{config.DisplayName}##{config.GetHashCode()}_{config.Name}", ref val, config.Speed, config.Min, config.Max)) + RotationConfigWindow.DrawIntNumber($"{config.DisplayName}##{config.GetHashCode()}_{config.Name}", ref val, int.TryParse(config.DefaultValue, out var f) ? f : 0, config.Speed, config.Min, config.Max, otherThing: () => { set.SetValue(config.Name, val.ToString()); - Service.Config.Save(); - } + }); } #endregion diff --git a/RotationSolver/UI/RotationConfigWindow_Major.cs b/RotationSolver/UI/RotationConfigWindow_Major.cs index ef8a122b4..d533b0d66 100644 --- a/RotationSolver/UI/RotationConfigWindow_Major.cs +++ b/RotationSolver/UI/RotationConfigWindow_Major.cs @@ -138,11 +138,12 @@ private static void DrawRangedFloat(string name, ref float minValue, ref float m } } - private static void DrawRangedInt(string name, ref int minValue, ref int maxValue, int defaultMin, int defaultMax, float speed = 0.01f, int min = 0, int max = 3, string description = "") + private static void DrawRangedInt(string name, ref int minValue, ref int maxValue, int defaultMin, int defaultMax, float speed = 0.01f, int min = 0, int max = 3, string description = "", Action otherThing = null) { ImGui.SetNextItemWidth(100); if (ImGui.DragIntRange2(name, ref minValue, ref maxValue, speed, min, max)) { + otherThing?.Invoke(); Service.Config.Save(); } @@ -150,17 +151,17 @@ private static void DrawRangedInt(string name, ref int minValue, ref int maxValu if (minValue != defaultMin || maxValue != defaultMax) { - ImGuiHelper.UndoValue(name, ref minValue, defaultMin, ref maxValue, defaultMax); + ImGuiHelper.UndoValue(name, ref minValue, defaultMin, ref maxValue, defaultMax, otherThing); } } - private static void DrawFloatNumber(string name, ref float value, float @default, float speed = 0.002f, float min = 0, float max = 1, string description = "", Action otherThing = null) + public static void DrawFloatNumber(string name, ref float value, float @default, float speed = 0.002f, float min = 0, float max = 1, string description = "", Action otherThing = null) { ImGui.SetNextItemWidth(100); if (ImGui.DragFloat(name, ref value, speed, min, max)) { - Service.Config.Save(); otherThing?.Invoke(); + Service.Config.Save(); } ImGuiHelper.HoveredString(description); @@ -171,7 +172,7 @@ private static void DrawFloatNumber(string name, ref float value, float @default } } - private static void DrawIntNumber(string name, ref int value, int @default, float speed = 0.2f, int min = 0, int max = 1, string description = "", Action otherThing = null) + public static void DrawIntNumber(string name, ref int value, int @default, float speed = 0.2f, int min = 0, int max = 1, string description = "", Action otherThing = null) { ImGui.SetNextItemWidth(100); if (ImGui.DragInt(name, ref value, speed, min, max)) @@ -204,7 +205,7 @@ private static void DrawColor3(string name, ref Vector3 value, Vector3 @default, } } - private static void DrawCombo(string name, ref int value, Func toString, T[] choices = null, string description = "") where T : struct, Enum + public static void DrawCombo(string name, ref int value, int @default, Func toString, T[] choices = null, string description = "") where T : struct, Enum { choices ??= Enum.GetValues(); @@ -222,6 +223,11 @@ private static void DrawCombo(string name, ref int value, Func toS ImGui.EndCombo(); } ImGuiHelper.HoveredString(description); + + if (value != @default) + { + ImGuiHelper.UndoValue(name, ref value, @default); + } } private static void DrawInputText(string name, ref string value, uint maxLength, string description = "") diff --git a/RotationSolver/UI/RotationConfigWindow_Param.cs b/RotationSolver/UI/RotationConfigWindow_Param.cs index 4d63dcc76..be44cd536 100644 --- a/RotationSolver/UI/RotationConfigWindow_Param.cs +++ b/RotationSolver/UI/RotationConfigWindow_Param.cs @@ -141,7 +141,7 @@ private void DrawParamAdvanced() ImGui.Indent(); DrawCombo(LocalizationManager.RightLang.ConfigWindow_Param_PoslockModifier, - ref Service.Config.PoslockModifier, EnumTranslations.ToName, + ref Service.Config.PoslockModifier, Service.Default.PoslockModifier, EnumTranslations.ToName, ConfigurationHelper.Keys, LocalizationManager.RightLang.ConfigWindow_Param_PoslockDescription);