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

Commit

Permalink
fix: changed the unit showing.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Nov 7, 2023
1 parent 3f6ac78 commit 8a5be95
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 63 deletions.
15 changes: 9 additions & 6 deletions RotationSolver/UI/ConditionDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using RotationSolver.Basic.Configuration.Conditions;
using RotationSolver.Localization;
using RotationSolver.Updaters;
using System.Reflection.Emit;
using Action = System.Action;

namespace RotationSolver.UI;
Expand Down Expand Up @@ -102,9 +101,11 @@ public static void DrawByteEnum<T>(string name, ref T value, Func<T, string> fun
public static bool DrawDragFloat(ConfigUnitType type, string name, ref float value)
{
ImGui.SameLine();
ImGui.SetNextItemWidth(Math.Max(50 * ImGuiHelpers.GlobalScale, ImGui.CalcTextSize(value.ToString()).X));
var result = ImGui.DragFloat(name, ref value);
type.Draw();
var show = type == ConfigUnitType.Percent ? $"{value:F1}{type.ToSymbol()}" : $"{value:F2}{type.ToSymbol()}";

ImGui.SetNextItemWidth(Math.Max(50 * ImGuiHelpers.GlobalScale, ImGui.CalcTextSize(show).X));
var result = ImGui.DragFloat(name, ref value, 0.1f, 0, 0, show);
ImguiTooltips.HoveredTooltip(type.ToDesc());
return result;
}

Expand Down Expand Up @@ -248,12 +249,14 @@ private static void DrawDelay(this DelayCondition condition)
const float MIN = 0, MAX = 60;

ImGui.SetNextItemWidth(80 * ImGuiHelpers.GlobalScale);
if (ImGui.DragFloatRange2($"##Random Delay {condition.GetHashCode()}", ref condition.DelayMin, ref condition.DelayMax, 0.1f, MIN, MAX))
if (ImGui.DragFloatRange2($"##Random Delay {condition.GetHashCode()}", ref condition.DelayMin, ref condition.DelayMax, 0.1f, MIN, MAX,
$"{condition.DelayMin:F1}{ConfigUnitType.Seconds.ToSymbol()}", $"{condition.DelayMax:F1}{ConfigUnitType.Seconds.ToSymbol()}"))
{
condition.DelayMin = Math.Max(Math.Min(condition.DelayMin, condition.DelayMax), MIN);
condition.DelayMax = Math.Min(Math.Max(condition.DelayMin, condition.DelayMax), MAX);
}
ImguiTooltips.HoveredTooltip(LocalizationManager.RightLang.ActionSequencer_Delay_Description);
ImguiTooltips.HoveredTooltip(LocalizationManager.RightLang.ActionSequencer_Delay_Description +
"\n" + ConfigUnitType.Seconds.ToDesc());
}

private static void DrawBefore(this ICondition condition)
Expand Down
46 changes: 19 additions & 27 deletions RotationSolver/UI/ImGuiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,32 +417,24 @@ public static bool IsInRect(Vector2 leftTop, Vector2 size)
return true;
}

public static void Draw(this ConfigUnitType unit)
{
if (unit == ConfigUnitType.None) return;

var unitName = unit switch
{
ConfigUnitType.Seconds => "(s)",
ConfigUnitType.Degree => "(°)",
ConfigUnitType.Pixels => "(p)",
ConfigUnitType.Yalms => "(y)",
ConfigUnitType.Percent => "(%%)",
_ => string.Empty,
};

ImGui.SameLine();
ImGui.TextColored(ImGuiColors.DalamudViolet, unitName);

var desc = unit switch
{
ConfigUnitType.Seconds => LocalizationManager.RightLang.ConfigUnitType_Seconds,
ConfigUnitType.Degree => LocalizationManager.RightLang.ConfigUnitType_Degree,
ConfigUnitType.Pixels => LocalizationManager.RightLang.ConfigUnitType_Pixels,
ConfigUnitType.Yalms => LocalizationManager.RightLang.ConfigUnitType_Yalms,
ConfigUnitType.Percent => LocalizationManager.RightLang.ConfigUnitType_Ratio,
_ => string.Empty,
};
ImguiTooltips.HoveredTooltip(desc);
}
public static string ToSymbol(this ConfigUnitType unit) => unit switch
{
ConfigUnitType.Seconds => " s",
ConfigUnitType.Degree => " °",
ConfigUnitType.Pixels => " p",
ConfigUnitType.Yalms => " y",
ConfigUnitType.Percent => " %%",
_ => string.Empty,
};

public static string ToDesc(this ConfigUnitType unit) => unit switch
{
ConfigUnitType.Seconds => LocalizationManager.RightLang.ConfigUnitType_Seconds,
ConfigUnitType.Degree => LocalizationManager.RightLang.ConfigUnitType_Degree,
ConfigUnitType.Pixels => LocalizationManager.RightLang.ConfigUnitType_Pixels,
ConfigUnitType.Yalms => LocalizationManager.RightLang.ConfigUnitType_Yalms,
ConfigUnitType.Percent => LocalizationManager.RightLang.ConfigUnitType_Ratio,
_ => string.Empty,
};
}
8 changes: 4 additions & 4 deletions RotationSolver/UI/RotationConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1166,21 +1166,21 @@ private static void DrawRotationConfiguration()
ImGui.SetNextItemWidth(Scale * Searchable.DRAG_WIDTH);
if (f.UnitType == ConfigUnitType.Percent)
{
var v = (int)val * 100;
if (ImGui.SliderInt(name, ref v, (int)(f.Min * 100), (int)(f.Max * 100)))
var v = val * 100;
if (ImGui.SliderFloat(name, ref v,f.Min * 100,f.Max * 100, $"{v:F1}{f.UnitType.ToSymbol()}"))
{
set.SetValue(config.Name, (v / 100f).ToString());
}
}
else
{
if (ImGui.DragFloat(name, ref val, f.Speed, f.Min, f.Max))
if (ImGui.DragFloat(name, ref val, f.Speed, f.Min, f.Max, $"{val:F2}{f.UnitType.ToSymbol()}"))
{
set.SetValue(config.Name, val.ToString());
}
}
ImguiTooltips.HoveredTooltip(f.UnitType.ToDesc());

f.UnitType.Draw();
ImGuiHelper.ReactPopup(key, command, Reset);
}
else if (config is RotationConfigString s)
Expand Down
52 changes: 36 additions & 16 deletions RotationSolver/UI/SearchableConfigs/DragFloatRangeSearch.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Dalamud.Utility;
using ECommons.Configuration;
using ECommons.ExcelServices;
using RotationSolver.Basic.Configuration;
using RotationSolver.Localization;
Expand All @@ -13,8 +12,21 @@ internal class DragFloatRangeSearchJob : DragFloatRangeSearch

public override string Name => _configMin.ToName();

public override string Description => _configMin.ToDescription();

public override string Description
{
get
{
var baseDesc = _configMin.ToDescription();
if (!string.IsNullOrEmpty(baseDesc))
{
return baseDesc + "\n" + Unit.ToDesc();
}
else
{
return Unit.ToDesc();
}
}
}
public override LinkDescription[] Tooltips => _configMin.ToAction();

protected override bool IsJob => true;
Expand Down Expand Up @@ -62,7 +74,21 @@ internal class DragFloatRangeSearchPlugin : DragFloatRangeSearch

public override string Name => _configMin.ToName();

public override string Description => _configMin.ToDescription();
public override string Description
{
get
{
var baseDesc = _configMin.ToDescription();
if (!string.IsNullOrEmpty(baseDesc))
{
return baseDesc + "\n" + Unit.ToDesc();
}
else
{
return Unit.ToDesc();
}
}
}

public override LinkDescription[] Tooltips => _configMin.ToAction();

Expand Down Expand Up @@ -130,33 +156,27 @@ protected override void DrawMain(Job job)

if (Unit == ConfigUnitType.Percent)
{
var vm = (int)minValue * 100;
var vM = (int)maxValue * 100;
if (ImGui.DragIntRange2($"##Config_{ID}{GetHashCode()}", ref vm, ref vM, Speed, (int)(Min * 100), (int)(Max * 100)))
var vm = minValue * 100;
var vM = maxValue * 100;
if (ImGui.DragFloatRange2($"##Config_{ID}{GetHashCode()}", ref vm, ref vM, Speed, Min * 100, Max * 100,
$"{vm:F1}{Unit.ToSymbol()}", $"{vM:F1}{Unit.ToSymbol()}"))
{
SetMinValue(job, Math.Min(vm / 100f, vM / 100f));
SetMaxValue(job, Math.Max(vm / 100f, vM / 100f));
}
}
else
{
if (ImGui.DragFloatRange2($"##Config_{ID}{GetHashCode()}", ref minValue, ref maxValue, Speed, Min, Max))
if (ImGui.DragFloatRange2($"##Config_{ID}{GetHashCode()}", ref minValue, ref maxValue, Speed, Min, Max,
$"{minValue:F2}{Unit.ToSymbol()}", $"{maxValue:F2}{Unit.ToSymbol()}"))
{
SetMinValue(job, Math.Min(minValue, maxValue));
SetMaxValue(job, Math.Max(minValue, maxValue));
}
}

if (ImGui.DragFloatRange2($"##Config_{ID}{GetHashCode()}", ref minValue, ref maxValue, Speed, Min, Max))
{
SetMinValue(job, Math.Min(minValue, maxValue));
SetMaxValue(job, Math.Max(minValue, maxValue));
}

if (ImGui.IsItemHovered()) ShowTooltip(job);

Unit.Draw();

if (IsJob) DrawJobIcon();
ImGui.SameLine();
if (Color != 0) ImGui.PushStyleColor(ImGuiCol.Text, Color);
Expand Down
42 changes: 33 additions & 9 deletions RotationSolver/UI/SearchableConfigs/DragFloatSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,21 @@ internal class DragFloatSearchJob : DragFloatSearch

public override string Name => _config.ToName();

public override string Description => _config.ToDescription();

public override string Description
{
get
{
var baseDesc = _config.ToDescription();
if (!string.IsNullOrEmpty(baseDesc))
{
return baseDesc + "\n" + Unit.ToDesc();
}
else
{
return Unit.ToDesc();
}
}
}
public override LinkDescription[] Tooltips => _config.ToAction();

public override string Command => _config.ToCommand();
Expand Down Expand Up @@ -53,7 +66,21 @@ internal class DragFloatSearchPlugin : DragFloatSearch

public override string Name => _config.ToName();

public override string Description => _config.ToDescription();
public override string Description
{
get
{
var baseDesc = _config.ToDescription();
if (!string.IsNullOrEmpty(baseDesc))
{
return baseDesc + "\n" + Unit.ToDesc();
}
else
{
return Unit.ToDesc();
}
}
}

public override LinkDescription[] Tooltips => _config.ToAction();

Expand Down Expand Up @@ -90,7 +117,6 @@ internal abstract class DragFloatSearch : Searchable
public float Max { get; init; }
public float Speed { get; init; }
public ConfigUnitType Unit { get; init; }

public DragFloatSearch(float min, float max, float speed, ConfigUnitType unit)
{
Min = min; Max = max;
Expand All @@ -103,26 +129,24 @@ protected override void DrawMain(Job job)
{
var value = GetValue(job);
ImGui.SetNextItemWidth(Scale * DRAG_WIDTH);
var v = value * 100f;
if (Unit == ConfigUnitType.Percent)
{
var v = (int)value * 100;
if (ImGui.SliderInt($"##Config_{ID}{GetHashCode()}", ref v, (int)(Min * 100), (int)(Max * 100)))
if (ImGui.SliderFloat($"##Config_{ID}{GetHashCode()}", ref v, Min * 100, Max * 100, $"{v:F1}{Unit.ToSymbol()}"))
{
SetValue(job, v / 100f);
}
}
else
{
if (ImGui.DragFloat($"##Config_{ID}{GetHashCode()}", ref value, Speed, Min, Max))
if (ImGui.DragFloat($"##Config_{ID}{GetHashCode()}", ref value, Speed, Min, Max, $"{value:F2}{Unit.ToSymbol()}"))
{
SetValue(job, value);
}
}

if (ImGui.IsItemHovered()) ShowTooltip(job);

Unit.Draw();

if (IsJob) DrawJobIcon();

ImGui.SameLine();
Expand Down
7 changes: 6 additions & 1 deletion RotationSolver/Updaters/ActionUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ internal static void UpdateNextAction()
}
return false;
});
WrongAction = actions.ElementAt(_wrongRandom.Next(actions.Count()));

var count = actions.Count();
if (count > 0)
{
WrongAction = actions.ElementAt(_wrongRandom.Next(count));
}
}

NextAction = newAction;
Expand Down

0 comments on commit 8a5be95

Please sign in to comment.