Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: add more reset value.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Jul 17, 2023
1 parent bc4a603 commit a7938dc
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 36 deletions.
1 change: 1 addition & 0 deletions RotationSolver/Localization/Localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
62 changes: 33 additions & 29 deletions RotationSolver/UI/ImGuiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -148,7 +151,7 @@ public static void UndoValue<T>(string name, ref T value1, T default1, ref T val
}
}

static bool UndoValue(string name)
private static bool UndoValue(string name)
{
ImGui.SameLine();
Spacing();
Expand Down Expand Up @@ -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<SourceCodeAttribute>();
if(link != null)
Expand Down Expand Up @@ -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++)
{
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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)
Expand All @@ -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

Expand Down
18 changes: 12 additions & 6 deletions RotationSolver/UI/RotationConfigWindow_Major.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,29 +138,30 @@ 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();
}

ImGuiHelper.HoveredString(description);

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);
Expand All @@ -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))
Expand Down Expand Up @@ -204,7 +205,7 @@ private static void DrawColor3(string name, ref Vector3 value, Vector3 @default,
}
}

private static void DrawCombo<T>(string name, ref int value, Func<T, string> toString, T[] choices = null, string description = "") where T : struct, Enum
public static void DrawCombo<T>(string name, ref int value, int @default, Func<T, string> toString, T[] choices = null, string description = "") where T : struct, Enum
{
choices ??= Enum.GetValues<T>();

Expand All @@ -222,6 +223,11 @@ private static void DrawCombo<T>(string name, ref int value, Func<T, string> 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 = "")
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/UI/RotationConfigWindow_Param.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit a7938dc

Please sign in to comment.