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

Commit

Permalink
fix: add reset for each jobs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Apr 5, 2023
1 parent 85e1aaf commit 99255fe
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public string GetDisplayString(string name)
#endregion



public IEnumerator<IRotationConfig> GetEnumerator() => Configs.GetEnumerator();


Expand Down
10 changes: 7 additions & 3 deletions RotationSolver.Basic/Helpers/ConfigurationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static float GetHealAreaSpell(this ClassJobID job)
=> Service.Config.HealthAreaSpells.TryGetValue(job, out var value) ? value : Service.Config.HealthAreaSpell;

public static float GetHealingOfTimeSubtractArea(this ClassJobID job)
=> Service.Config.HealingOfTimeSubtractAreas.TryGetValue(job, out var value) ? value : 0.2f;
=> Service.Config.HealingOfTimeSubtractAreas.TryGetValue(job, out var value) ? value : HealingOfTimeSubtractAreasDefault;

public static float GetHealSingleAbility(this ClassJobID job)
=> Service.Config.HealthSingleAbilities.TryGetValue(job, out var value) ? value : Service.Config.HealthSingleAbility;
Expand All @@ -50,8 +50,12 @@ public static float GetHealSingleSpell(this ClassJobID job)
=> Service.Config.HealthSingleSpells.TryGetValue(job, out var value) ? value : Service.Config.HealthSingleSpell;

public static float GetHealingOfTimeSubtractSingle(this ClassJobID job)
=> Service.Config.HealingOfTimeSubtractSingles.TryGetValue(job, out var value) ? value : 0.2f;
=> Service.Config.HealingOfTimeSubtractSingles.TryGetValue(job, out var value) ? value : HealingOfTimeSubtractSinglesDefault;

public static float GetHealthForDyingTank(this ClassJobID job)
=> Service.Config.HealthForDyingTanks.TryGetValue(job, out var value) ? value : 0.15f;
=> Service.Config.HealthForDyingTanks.TryGetValue(job, out var value) ? value : HealthForDyingTanksDefault;

public const float HealingOfTimeSubtractAreasDefault = 0.2f;
public const float HealingOfTimeSubtractSinglesDefault = 0.2f;
public const float HealthForDyingTanksDefault = 0.15f;
}
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Rotations/CustomRotation_BasicInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private protected CustomRotation()

protected virtual IRotationConfigSet CreateConfiguration()
{
return new RotationConfigSet(JobIDs[0], RotationName);
return new RotationConfigSet(JobIDs[0], GetType().FullName);
}


Expand Down
3 changes: 2 additions & 1 deletion RotationSolver/Localization/Localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@
"ConfigWindow_Control_ResetButtonOrKeyCommand": "Right click to reset the gamepad button or key board key.\nHold Left Ctrl and middle click to clear the key setting.",
"ConfigWindow_Control_NeedToEnable": " (Need to enable)",
"ConfigWindow_Control_ClickToUse": "Click to use it!",
"ConfigWindow_Rotation_BetaRotation": "Beta Rotation",
"ConfigWindow_Rotation_BetaRotation": "Beta Rotation!",
"ConfigWindow_Rotation_ResetToDefault": "Click to reset value!",
"Timeline_DragdropDescription": "Drag&drop to move,Ctrl+Alt+RightClick to delete.",
"Timeline_SearchBar": "Search Bar",
"Timeline_MustUse": "MustUse",
Expand Down
4 changes: 2 additions & 2 deletions RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ internal partial class Strings
public string ConfigWindow_Control_ResetButtonOrKeyCommand { get; set; } = "Right click to reset the gamepad button or key board key.\nHold Left Ctrl and middle click to clear the key setting.";
public string ConfigWindow_Control_NeedToEnable { get; set; } = " (Need to enable)";
public string ConfigWindow_Control_ClickToUse { get; set; } = "Click to use it!";
public string ConfigWindow_Rotation_BetaRotation { get; set; } = "Beta Rotation";

public string ConfigWindow_Rotation_BetaRotation { get; set; } = "Beta Rotation!";
public string ConfigWindow_Rotation_ResetToDefault { get; set; } = "Click to reset value!";
#endregion

#region ScriptWindow
Expand Down
15 changes: 8 additions & 7 deletions RotationSolver/UI/ControlWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ static void DrawCommandAction(IAction gcd, IAction ability, SpecialCommandType c
ImGui.EndGroup();
}

static void HighLight(Vector2 pt, Vector2 size, float thickness = 2f)
{
var offset = ImGui.GetStyle().ItemSpacing / 2;
ImGui.GetWindowDrawList().AddRect(pt - offset, pt + size + offset,
ImGui.ColorConvertFloat4ToU32(ImGuiColors.DalamudGrey), 5, ImDrawFlags.RoundCornersAll, thickness);
}

static void DrawCommandAction(IAction ability, SpecialCommandType command, Vector4 color)
{
DrawCommandAction(GetTexture(ability), command, color);
Expand Down Expand Up @@ -268,13 +275,7 @@ static void DrawCommandAction(uint iconId, StateCommandType command, Vector4 col
}
}

static readonly uint highLight = ImGui.ColorConvertFloat4ToU32(ImGuiColors.DalamudGrey);
static void HighLight(Vector2 pt, Vector2 size)
{
var offset = ImGui.GetStyle().ItemSpacing / 2;
ImGui.GetWindowDrawList().AddRect(pt - offset, pt + size + offset,
highLight, 5, ImDrawFlags.RoundCornersAll, 2);
}



static string GetHelp(SpecialCommandType command)
Expand Down
42 changes: 36 additions & 6 deletions RotationSolver/UI/ImGuiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,17 @@ public static bool IconButton(FontAwesomeIcon icon, string name)
var result = ImGui.Button($"{icon.ToIconString()}##{name}");
ImGui.PopFont();
return result;
}

//ImGuiComponents.IconButton(icon)
public static Vector2 IconButtonSize(FontAwesomeIcon icon, string name)
{
ImGui.PushFont(UiBuilder.IconFont);
var result = ImGui.CalcTextSize($"{icon.ToIconString()}##{name}");
ImGui.PopFont();
return result;
}


public static void HoveredString(string text, Action selected = null)
{
if (ImGui.IsItemHovered())
Expand All @@ -119,9 +126,10 @@ public static bool HoveredStringReset(string text)
{
if (ImGui.IsItemHovered())
{
if (string.IsNullOrEmpty(text)) text = string.Empty;
text += "\n \n" + LocalizationManager.RightLang.ConfigWindow_Param_ResetToDefault;
ImGui.SetTooltip(text);
text = string.IsNullOrEmpty(text)? LocalizationManager.RightLang.ConfigWindow_Param_ResetToDefault
: text + "\n \n" + LocalizationManager.RightLang.ConfigWindow_Param_ResetToDefault;

ImGui.SetTooltip(text);

return ImGui.IsMouseDown(ImGuiMouseButton.Right)
&& ImGui.IsKeyPressed(ImGuiKey.LeftShift)
Expand Down Expand Up @@ -518,7 +526,7 @@ public unsafe static void Display(this ICustomRotation rotation, ICustomRotation
{
RotationConfigWindow.DrawRotationRole(rotation);

rotation.Configs.Draw(canAddButton);
rotation.DrawConfig(canAddButton);
});

#region IAction
Expand Down Expand Up @@ -617,20 +625,42 @@ public static void DisplayEvent(this ActionEventInfo info)
}

#region Rotation Config Display
static void Draw(this IRotationConfigSet set, bool canAddButton)
static void DrawConfig(this ICustomRotation rotation, bool canAddButton)
{
var set = rotation.Configs;
if (!set.Any()) return;

ImGui.BeginGroup();
foreach (var config in set.Configs)
{
if (config is RotationConfigCombo c) c.Draw(set, canAddButton);
else if (config is RotationConfigBoolean b) b.Draw(set, canAddButton);
else if (config is RotationConfigFloat f) f.Draw(set, canAddButton);
else if (config is RotationConfigString s) s.Draw(set, canAddButton);
}
ImGui.EndGroup();
ImGui.SameLine();

var str = $"#{set.GetHashCode()}Undo";
var hight = ImGui.GetItemRectSize().Y - IconButtonSize(FontAwesomeIcon.Undo, str).Y;
var pos = ImGui.GetCursorPos();

ImGui.SetCursorPos(pos + new Vector2(10, hight / 2));
if(IconButton(FontAwesomeIcon.Undo, str))
{
if(Service.Config.RotationsConfigurations.TryGetValue(rotation.Job.RowId, out var jobDict)
&& jobDict.ContainsKey(rotation.GetType().FullName))
{
jobDict.Remove(rotation.GetType().FullName);
}
}
HoveredString(LocalizationManager.RightLang.ConfigWindow_Rotation_ResetToDefault);
}

static void Draw(this RotationConfigCombo config, IRotationConfigSet set, bool canAddButton)
{
var val = set.GetCombo(config.Name);
ImGui.SetNextItemWidth(ImGui.CalcTextSize(config.DisplayName).X );
if (ImGui.BeginCombo($"{config.DisplayName}##{config.GetHashCode()}_{config.Name}", config.Items[val]))
{
for (int comboIndex = 0; comboIndex < config.Items.Length; comboIndex++)
Expand Down
2 changes: 0 additions & 2 deletions RotationSolver/UI/RotationConfigWindow_Major.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
namespace RotationSolver.UI;
internal partial class RotationConfigWindow : Window
{
const float DRAG_NUMBER_WIDTH = 100;

public RotationConfigWindow()
: base(nameof(RotationConfigWindow), 0, false)
{
Expand Down
6 changes: 5 additions & 1 deletion RotationSolver/UI/RotationConfigWindow_Param.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ internal static void DrawCheckBox(string name, ref bool value, bool @default, st
{
value = @default;
Service.Config.Save();
otherThing?.Invoke();
}
}

Expand Down Expand Up @@ -544,17 +545,19 @@ private static void DrawRangedInt(string name, ref int minValue, ref int maxValu
}
}

private static void DrawFloatNumber(string name, ref float value, float @default, float speed = 0.002f, float min = 0, float max = 1, string description = "")
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)
{
ImGui.SetNextItemWidth(100);
if (ImGui.DragFloat(name, ref value, speed, min, max))
{
Service.Config.Save();
otherThing?.Invoke();
}
if (ImGuiHelper.HoveredStringReset(description) && value != @default)
{
value = @default;
Service.Config.Save();
otherThing?.Invoke();
}
}

Expand All @@ -570,6 +573,7 @@ private static void DrawIntNumber(string name, ref int value, int @default, floa
{
value = @default;
Service.Config.Save();
otherThing?.Invoke();
}
}

Expand Down
30 changes: 18 additions & 12 deletions RotationSolver/UI/RotationConfigWindow_Rotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,46 +94,52 @@ private static void DrawSpecialRoleSettings(JobRole role, ClassJobID job)
{
DrawDragFloat(job, LocalizationManager.RightLang.ConfigWindow_Param_HealthForDyingTank,
() => ConfigurationHelper.GetHealthForDyingTank(job),
(value) => Service.Config.HealthForDyingTanks[job] = value);
(value) => Service.Config.HealthForDyingTanks[job] = value,
ConfigurationHelper.HealthForDyingTanksDefault);
}
}

private static void DrawHealerSettings(ClassJobID job)
{
DrawDragFloat(job, LocalizationManager.RightLang.ConfigWindow_Param_HealthAreaAbility,
() => ConfigurationHelper.GetHealAreaAbility(job),
(value) => Service.Config.HealthAreaAbilities[job] = value);
(value) => Service.Config.HealthAreaAbilities[job] = value,
Service.Config.HealthAreaAbility);

DrawDragFloat(job, LocalizationManager.RightLang.ConfigWindow_Param_HealthAreaSpell,
() => ConfigurationHelper.GetHealAreaSpell(job),
(value) => Service.Config.HealthAreaSpells[job] = value);
(value) => Service.Config.HealthAreaSpells[job] = value,
Service.Config.HealthAreaSpell);

DrawDragFloat(job, LocalizationManager.RightLang.ConfigWindow_Param_HealingOfTimeSubtractArea,
() => ConfigurationHelper.GetHealingOfTimeSubtractArea(job),
(value) => Service.Config.HealingOfTimeSubtractAreas[job] = value);
(value) => Service.Config.HealingOfTimeSubtractAreas[job] = value,
ConfigurationHelper.HealingOfTimeSubtractAreasDefault);

DrawDragFloat(job, LocalizationManager.RightLang.ConfigWindow_Param_HealthSingleAbility,
() => ConfigurationHelper.GetHealSingleAbility(job),
(value) => Service.Config.HealthSingleAbilities[job] = value);
(value) => Service.Config.HealthSingleAbilities[job] = value,
Service.Config.HealthSingleAbility);

DrawDragFloat(job, LocalizationManager.RightLang.ConfigWindow_Param_HealthSingleSpell,
() => ConfigurationHelper.GetHealSingleSpell(job),
(value) => Service.Config.HealthSingleSpells[job] = value);
(value) => Service.Config.HealthSingleSpells[job] = value,
Service.Config.HealthSingleSpell);

DrawDragFloat(job, LocalizationManager.RightLang.ConfigWindow_Param_HealingOfTimeSubtractSingle,
() => ConfigurationHelper.GetHealingOfTimeSubtractSingle(job),
(value) => Service.Config.HealingOfTimeSubtractSingles[job] = value);
(value) => Service.Config.HealingOfTimeSubtractSingles[job] = value,
ConfigurationHelper.HealingOfTimeSubtractSinglesDefault);
}

private static void DrawDragFloat(ClassJobID job, string desc, Func<float> getValue, Action<float> setValue)
private static void DrawDragFloat(ClassJobID job, string desc, Func<float> getValue, Action<float> setValue, float @default)
{
const float speed = 0.005f;

if (getValue == null || setValue == null) return;

var value = getValue();
ImGui.SetNextItemWidth(DRAG_NUMBER_WIDTH);
if (ImGui.DragFloat($"{desc}##{job}{desc}", ref value, speed, 0, 1))
var last = value;
DrawFloatNumber($"{desc}##{job}{desc}", ref value, @default, speed: 0.005f, description: desc);
if(last != value)
{
setValue(value);
Service.Config.Save();
Expand Down

0 comments on commit 99255fe

Please sign in to comment.