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

Commit

Permalink
fix: add unit for rotation config and conditions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Nov 7, 2023
1 parent 1902edb commit 031a1aa
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 155 deletions.
42 changes: 21 additions & 21 deletions RotationSolver.Basic/Configuration/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,17 @@ public enum JobConfigInt : byte

public enum JobConfigFloat : byte
{
[Default(0.55f), Unit(ConfigUnitType.Ratio)] HealthAreaAbilityHot,
[Default(0.55f), Unit(ConfigUnitType.Ratio)] HealthAreaSpellHot,
[Default(0.75f), Unit(ConfigUnitType.Ratio)] HealthAreaAbility,
[Default(0.65f), Unit(ConfigUnitType.Ratio)] HealthAreaSpell,
[Default(0.6f), Unit(ConfigUnitType.Ratio)] HealthSingleAbilityHot,
[Default(0.45f), Unit(ConfigUnitType.Ratio)] HealthSingleSpellHot,
[Default(0.7f), Unit(ConfigUnitType.Ratio)] HealthSingleAbility,
[Default(0.55f), Unit(ConfigUnitType.Ratio)] HealthSingleSpell,

[Default(0.15f), Unit(ConfigUnitType.Ratio)] HealthForDyingTanks,
[Default(1f), Unit(ConfigUnitType.Ratio)] HealthForAutoDefense,
[Default(0.55f), Unit(ConfigUnitType.Percent)] HealthAreaAbilityHot,
[Default(0.55f), Unit(ConfigUnitType.Percent)] HealthAreaSpellHot,
[Default(0.75f), Unit(ConfigUnitType.Percent)] HealthAreaAbility,
[Default(0.65f), Unit(ConfigUnitType.Percent)] HealthAreaSpell,
[Default(0.6f), Unit(ConfigUnitType.Percent)] HealthSingleAbilityHot,
[Default(0.45f), Unit(ConfigUnitType.Percent)] HealthSingleSpellHot,
[Default(0.7f), Unit(ConfigUnitType.Percent)] HealthSingleAbility,
[Default(0.55f), Unit(ConfigUnitType.Percent)] HealthSingleSpell,

[Default(0.15f), Unit(ConfigUnitType.Percent)] HealthForDyingTanks,
[Default(1f), Unit(ConfigUnitType.Percent)] HealthForAutoDefense,
}
#endregion

Expand Down Expand Up @@ -380,16 +380,16 @@ public enum PluginConfigFloat : byte
[Default(45f, 0f, 90f), Unit(ConfigUnitType.Degree)] AngleOfVisionCone,


[Default(0.25f, 0f, 0.5f), Unit(ConfigUnitType.Ratio)] HealthDifference,
[Default(0.25f, 0f, 0.5f), Unit(ConfigUnitType.Percent)] HealthDifference,
[Default(1f, 0f, 5f), Unit(ConfigUnitType.Yalms)] MeleeRangeOffset,
[Default(0.1f, 0f, 0.4f), Unit(ConfigUnitType.Seconds)] MinLastAbilityAdvanced,
[Default(0.8f, 0f, 1f), Unit(ConfigUnitType.Ratio)] HealWhenNothingTodoBelow,
[Default(0.8f, 0f, 1f), Unit(ConfigUnitType.Percent)] HealWhenNothingTodoBelow,
[Default(0.6f, 0f, 1f), Unit(ConfigUnitType.Pixels)] TargetIconSize,

[Default(0f, 0f, 1f), Unit(ConfigUnitType.Ratio)] MistakeRatio,
[Default(0f, 0f, 1f), Unit(ConfigUnitType.Percent)] MistakeRatio,

[Default(0.4f, 0f, 1f), Unit(ConfigUnitType.Ratio)] HealthTankRatio,
[Default(0.4f, 0f, 1f), Unit(ConfigUnitType.Ratio)] HealthHealerRatio,
[Default(0.4f, 0f, 1f), Unit(ConfigUnitType.Percent)] HealthTankRatio,
[Default(0.4f, 0f, 1f), Unit(ConfigUnitType.Percent)] HealthHealerRatio,

[Default(3f, 1f, 20f), Unit(ConfigUnitType.Seconds)] SpecialDuration,

Expand Down Expand Up @@ -442,20 +442,20 @@ public enum PluginConfigFloat : byte
[Default(40f, 0f, 80f), Unit(ConfigUnitType.Pixels)] ControlWindowGCDSize,
[Default(30f, 0f, 80f), Unit(ConfigUnitType.Pixels)] ControlWindow0GCDSize,
[Default(30f, 0f, 80f), Unit(ConfigUnitType.Pixels)] CooldownWindowIconSize,
[Default(1.5f, 0f, 10f), Unit(ConfigUnitType.Ratio)] ControlWindowNextSizeRatio,
[Default(1.5f, 0f, 10f), Unit(ConfigUnitType.Percent)] ControlWindowNextSizeRatio,
[Default(8f), Unit(ConfigUnitType.Pixels)] ControlProgressHeight,
[Default(1.2f, 0f, 30f), Unit(ConfigUnitType.Yalms)] DistanceForMoving,
[Default(0.2f, 0.01f, 0.5f), Unit(ConfigUnitType.Seconds)] MaxPing,

[Default(8f, 0f, 30f), Unit(ConfigUnitType.Seconds)] AutoHealTimeToKill,
[Default(0.5f, 0f, 10f), Unit(ConfigUnitType.Pixels)] HostileIconHeight,
[Default(1f, 0.1f, 10f), Unit(ConfigUnitType.Ratio)] HostileIconSize,
[Default(1f, 0.1f, 10f), Unit(ConfigUnitType.Percent)] HostileIconSize,

[Default(1f, 0f, 3f), Unit(ConfigUnitType.Pixels)] StateIconHeight,
[Default(1f, 0.2f, 10f), Unit(ConfigUnitType.Ratio)] StateIconSize,
[Default(1f, 0.2f, 10f), Unit(ConfigUnitType.Percent)] StateIconSize,

[Default(0.02f, 0f, 1f), Unit(ConfigUnitType.Seconds)] MinUpdatingTime,
[Default(0.15f), Unit(ConfigUnitType.Ratio)] HealthForGuard,
[Default(0.15f), Unit(ConfigUnitType.Percent)] HealthForGuard,
}

public enum PluginConfigVector4 : byte
Expand Down Expand Up @@ -494,7 +494,7 @@ public enum ConfigUnitType : byte
Seconds,
Degree,
Yalms,
Ratio,
Percent,
Pixels,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@ internal class RotationConfigFloat : RotationConfigBase
{
public float Min, Max, Speed;

public RotationConfigFloat(string name, float value, string displayName, float min, float max, float speed) : base(name, value.ToString(), displayName)
public ConfigUnitType UnitType { get; set; }


[Obsolete("Please use the one with unit type!", true)]
public RotationConfigFloat(string name, float value, string displayName, float min, float max, float speed)
:this(name, value, displayName, min, max, speed, ConfigUnitType.None)
{

}

public RotationConfigFloat(string name, float value, string displayName, float min, float max, float speed, ConfigUnitType unitType) : base(name, value.ToString(), displayName)
{
Min = min;
Max = max;
Speed = speed;
UnitType = unitType;
}

public override bool DoCommand(IRotationConfigSet set, string str)
Expand Down
132 changes: 34 additions & 98 deletions RotationSolver/UI/ConditionDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
using ECommons.DalamudServices;
using ECommons.ImGuiMethods;
using Lumina.Excel.GeneratedSheets;
using RotationSolver.Basic.Configuration;
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 @@ -77,22 +79,6 @@ internal static void DrawCondition(bool? tag)
}
}

public static void CheckMemberInfo<T>(ICustomRotation rotation, ref string name, ref T value) where T : MemberInfo
{
if (!string.IsNullOrEmpty(name) && (value == null || value.Name != name))
{
var memberName = name;
if (typeof(T).IsAssignableFrom(typeof(PropertyInfo)))
{
value = (T)rotation.GetType().GetAllMethods(RuntimeReflectionExtensions.GetRuntimeProperties).FirstOrDefault(m => m.Name == memberName);
}
else if (typeof(T).IsAssignableFrom(typeof(MethodInfo)))
{
value = (T)rotation.GetType().GetAllMethods(RuntimeReflectionExtensions.GetRuntimeMethods).FirstOrDefault(m => m.Name == memberName);
}
}
}

private static IEnumerable<MemberInfo> GetAllMethods(this Type type, Func<Type, IEnumerable<MemberInfo>> getFunc)
{
if (type == null || getFunc == null) return Array.Empty<MemberInfo>();
Expand All @@ -113,36 +99,27 @@ public static void DrawByteEnum<T>(string name, ref T value, Func<T, string> fun
}
}

public static bool DrawDragFloat(string name, ref float value)
public static bool DrawDragFloat(ConfigUnitType type, string name, ref float value)
{
ImGui.SameLine();
ImGui.SetNextItemWidth(50);
return ImGui.DragFloat(name, ref value);
ImGui.SetNextItemWidth(Math.Max(50 * ImGuiHelpers.GlobalScale, ImGui.CalcTextSize(value.ToString()).X));
var result = ImGui.DragFloat(name, ref value);
type.Draw();
return result;
}

public static bool DrawDragInt(string name, ref int value)
{
ImGui.SameLine();
ImGui.SetNextItemWidth(50);
ImGui.SetNextItemWidth(Math.Max(50 * ImGuiHelpers.GlobalScale, ImGui.CalcTextSize(value.ToString()).X));
return ImGui.DragInt(name, ref value);
}

public static bool DrawCheckBox(string name, ref int value, string desc = "")
public static bool DrawCondition(ICondition condition, ref int index)
{
ImGui.SameLine();

var @bool = value != 0;

var result = false;
if (ImGui.Checkbox(name, ref @bool))
{
value = @bool ? 1 : 0;
result = true;
}

ImguiTooltips.HoveredTooltip(desc);

return result;
return ImGuiHelper.SelectableCombo($"##Comparation{condition.GetHashCode()}", new string[] { ">", "<", "=" }, ref index);
}

internal static void SearchItemsReflection<T>(string popId, string name, ref string searchTxt, T[] actions, Action<T> selectAction) where T : MemberInfo
Expand Down Expand Up @@ -427,7 +404,7 @@ private static void DrawAfter(this ActionCondition actionCondition, ICustomRotat
{
case ActionConditionType.Elapsed:
case ActionConditionType.Remain:
DrawDragFloat($"s##Seconds{actionCondition.GetHashCode()}", ref actionCondition.Time);
DrawDragFloat(ConfigUnitType.Seconds, $"##Seconds{actionCondition.GetHashCode()}", ref actionCondition.Time);
break;

case ActionConditionType.ElapsedGCD:
Expand Down Expand Up @@ -477,7 +454,7 @@ private static void DrawAfter(this ActionCondition actionCondition, ICustomRotat

case ActionConditionType.CurrentCharges:
case ActionConditionType.MaxCharges:
ImGuiHelper.SelectableCombo($"##Comparation{actionCondition.GetHashCode()}", new string[] { ">", "<", "=" }, ref actionCondition.Param2);
DrawCondition(actionCondition, ref actionCondition.Param2);

ImGui.SameLine();

Expand Down Expand Up @@ -629,14 +606,9 @@ private static void DrawAfter(this RotationCondition rotationCondition, ICustomR
rotationCondition.PropertyName = i.Name;
});

ImGui.SameLine();
DrawCondition(rotationCondition, ref rotationCondition.Condition);

ImGuiHelper.SelectableCombo($"##Comparation{rotationCondition.GetHashCode()}", new string[] { ">", "<", "=" }, ref rotationCondition.Condition);

ImGui.SameLine();
ImGui.SetNextItemWidth(50);

ImGui.DragInt($"##Value{rotationCondition.GetHashCode()}", ref rotationCondition.Param1);
DrawDragInt($"##Value{rotationCondition.GetHashCode()}", ref rotationCondition.Param1);

break;
case ComboConditionType.Float:
Expand All @@ -647,14 +619,9 @@ private static void DrawAfter(this RotationCondition rotationCondition, ICustomR
rotationCondition.PropertyName = i.Name;
});

ImGui.SameLine();
ImGuiHelper.SelectableCombo($"##Comparation{rotationCondition.GetHashCode()}", new string[] { ">", "<", "=" }, ref rotationCondition.Condition);

ImGui.SameLine();
ImGui.SetNextItemWidth(50);

ImGui.DragFloat($"##Value{rotationCondition.GetHashCode()}", ref rotationCondition.Param2);
DrawCondition(rotationCondition, ref rotationCondition.Condition);

DrawDragFloat(ConfigUnitType.None, $"##Value{rotationCondition.GetHashCode()}", ref rotationCondition.Param2);
break;

case ComboConditionType.Last:
Expand Down Expand Up @@ -826,11 +793,9 @@ void DrawStatusIcon()
targetCondition.FromSelf = check != 0;
}

ImGui.SameLine();

ImGuiHelper.SelectableCombo($"##Comparation{targetCondition.GetHashCode()}", new string[] { ">", "<", "=" }, ref targetCondition.Param2);
DrawCondition(targetCondition, ref targetCondition.Param2);

DrawDragFloat($"s##Seconds{targetCondition.GetHashCode()}", ref targetCondition.DistanceOrTime);
DrawDragFloat(ConfigUnitType.Seconds, $"s##Seconds{targetCondition.GetHashCode()}", ref targetCondition.DistanceOrTime);
break;


Expand All @@ -851,15 +816,13 @@ void DrawStatusIcon()
}

DrawDragInt($"GCD##GCD{targetCondition.GetHashCode()}", ref targetCondition.GCD);
DrawDragFloat($"{LocalizationManager.RightLang.ActionSequencer_TimeOffset}##Ability{targetCondition.GetHashCode()}", ref targetCondition.DistanceOrTime);
DrawDragFloat(ConfigUnitType.Seconds, $"{LocalizationManager.RightLang.ActionSequencer_TimeOffset}##Ability{targetCondition.GetHashCode()}", ref targetCondition.DistanceOrTime);
break;

case TargetConditionType.Distance:
ImGui.SameLine();

ImGuiHelper.SelectableCombo($"##Comparation{targetCondition.GetHashCode()}", new string[] { ">", "<", "=" }, ref targetCondition.Param2);
DrawCondition(targetCondition, ref targetCondition.Param2);

if (DrawDragFloat($"yalm##yalm{targetCondition.GetHashCode()}", ref targetCondition.DistanceOrTime))
if (DrawDragFloat(ConfigUnitType.Yalms, $"##yalm{targetCondition.GetHashCode()}", ref targetCondition.DistanceOrTime))
{
targetCondition.DistanceOrTime = Math.Max(0, targetCondition.DistanceOrTime);
}
Expand All @@ -872,44 +835,27 @@ void DrawStatusIcon()
break;

case TargetConditionType.CastingActionTime:
ImGui.SameLine();

ImGuiHelper.SelectableCombo($"##Comparation{targetCondition.GetHashCode()}", new string[] { ">", "<", "=" }, ref targetCondition.Param2);

ImGui.SameLine();
ImGui.SetNextItemWidth(Math.Max(150 * ImGuiHelpers.GlobalScale, ImGui.CalcTextSize(targetCondition.DistanceOrTime.ToString()).X));
ImGui.DragFloat($"s##CastingActionTimeUntil{targetCondition.GetHashCode()}", ref targetCondition.DistanceOrTime, .1f);
DrawCondition(targetCondition, ref targetCondition.Param2);
DrawDragFloat(ConfigUnitType.Seconds, $"##CastingActionTimeUntil{targetCondition.GetHashCode()}", ref targetCondition.DistanceOrTime);
break;

case TargetConditionType.HPRatio:
ImGui.SameLine();

ImGuiHelper.SelectableCombo($"##Comparation{targetCondition.GetHashCode()}", new string[] { ">", "<", "=" }, ref targetCondition.Param2);
DrawCondition(targetCondition, ref targetCondition.Param2);

ImGui.SameLine();
ImGui.SetNextItemWidth(Math.Max(150 * ImGuiHelpers.GlobalScale, ImGui.CalcTextSize(targetCondition.DistanceOrTime.ToString()).X));
ImGui.DragFloat($"##HPRatio{targetCondition.GetHashCode()}", ref targetCondition.DistanceOrTime, .1f);
DrawDragFloat( ConfigUnitType.Percent,$"##HPRatio{targetCondition.GetHashCode()}", ref targetCondition.DistanceOrTime);
break;

case TargetConditionType.MP:
case TargetConditionType.HP:
ImGui.SameLine();

ImGuiHelper.SelectableCombo($"##Comparation{targetCondition.GetHashCode()}", new string[] { ">", "<", "=" }, ref targetCondition.Param2);
DrawCondition(targetCondition, ref targetCondition.Param2);

ImGui.SameLine();
ImGui.SetNextItemWidth(Math.Max(150 * ImGuiHelpers.GlobalScale, ImGui.CalcTextSize(targetCondition.GCD.ToString()).X));
ImGui.DragInt($"##HPorMP{targetCondition.GetHashCode()}", ref targetCondition.GCD, .1f);
DrawDragInt($"##HPorMP{targetCondition.GetHashCode()}", ref targetCondition.GCD);
break;

case TargetConditionType.TimeToKill:
ImGui.SameLine();

ImGuiHelper.SelectableCombo($"##Comparation{targetCondition.GetHashCode()}", new string[] { ">", "<", "=" }, ref targetCondition.Param2);
DrawCondition(targetCondition, ref targetCondition.Param2);

ImGui.SameLine();
ImGui.SetNextItemWidth(Math.Max(150 * ImGuiHelpers.GlobalScale, ImGui.CalcTextSize(targetCondition.DistanceOrTime.ToString()).X));
ImGui.DragFloat($"##TimeToKill{targetCondition.GetHashCode()}", ref targetCondition.DistanceOrTime, .1f);
DrawDragFloat(ConfigUnitType.Seconds, $"##TimeToKill{targetCondition.GetHashCode()}", ref targetCondition.DistanceOrTime);
break;

case TargetConditionType.TargetName:
Expand All @@ -922,16 +868,12 @@ void DrawStatusIcon()
ImGui.SameLine();

ImGui.Text("P1:");
ImGui.SameLine();
ImGui.SetNextItemWidth(40 * ImGuiHelpers.GlobalScale);
ImGui.DragInt($"##Param1{targetCondition.GetHashCode()}", ref targetCondition.GCD, .1f);
DrawDragInt($"##Param1{targetCondition.GetHashCode()}", ref targetCondition.GCD);

ImGui.SameLine();

ImGui.Text("P2:");
ImGui.SameLine();
ImGui.SetNextItemWidth(40 * ImGuiHelpers.GlobalScale);
ImGui.DragInt($"##Param2{targetCondition.GetHashCode()}", ref targetCondition.Param2, .1f);
DrawDragInt($"##Param2{targetCondition.GetHashCode()}", ref targetCondition.Param2);

ImGui.SameLine();

Expand Down Expand Up @@ -1046,23 +988,17 @@ private static void DrawAfter(this TerritoryCondition territoryCondition, ICusto
ImGui.SameLine();

ImGui.Text("Pos:");
ImGui.SameLine();
ImGui.SetNextItemWidth(40 * ImGuiHelpers.GlobalScale);
ImGui.DragInt($"##Position{territoryCondition.GetHashCode()}", ref territoryCondition.Position, .1f);
DrawDragInt($"##Position{territoryCondition.GetHashCode()}", ref territoryCondition.Position);

ImGui.SameLine();

ImGui.Text("P1:");
ImGui.SameLine();
ImGui.SetNextItemWidth(40 * ImGuiHelpers.GlobalScale);
ImGui.DragInt($"##Param1{territoryCondition.GetHashCode()}", ref territoryCondition.Param1, .1f);
DrawDragInt($"##Param1{territoryCondition.GetHashCode()}", ref territoryCondition.Param1);

ImGui.SameLine();

ImGui.Text("P2:");
ImGui.SameLine();
ImGui.SetNextItemWidth(40 * ImGuiHelpers.GlobalScale);
ImGui.DragInt($"##Param2{territoryCondition.GetHashCode()}", ref territoryCondition.Param2, .1f);
DrawDragInt($"##Param2{territoryCondition.GetHashCode()}", ref territoryCondition.Param2);

ImGui.SameLine();

Expand Down
Loading

0 comments on commit 031a1aa

Please sign in to comment.