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

Commit

Permalink
fix: action sequencer ui.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 17, 2023
1 parent 0ca796e commit 33e9a31
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 95 deletions.
11 changes: 6 additions & 5 deletions RotationSolver.Basic/Data/CanUseOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ public enum CanUseOption : byte
/// </summary>
IgnoreCastCheck = 1 << 3,

/// <summary>
/// The combination of <see cref="MustUse"/> and <see cref="EmptyOrSkipCombo"/>
/// </summary>
MustUseEmpty = MustUse | EmptyOrSkipCombo,

/// <summary>
/// On the last ability in one GCD.
/// </summary>
Expand All @@ -48,4 +43,10 @@ public enum CanUseOption : byte
/// Ignore clipping check for 0GCDs.
/// </summary>
IgnoreClippingCheck = 1 << 5,

/// <summary>
/// The combination of <see cref="MustUse"/> and <see cref="EmptyOrSkipCombo"/>
/// </summary>
[JsonIgnore]
MustUseEmpty = MustUse | EmptyOrSkipCombo,
}
47 changes: 34 additions & 13 deletions RotationSolver/ActionSequencer/ActionCondition.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using RotationSolver.Localization;
using Dalamud.Utility;
using RotationSolver.Localization;
using RotationSolver.UI;
using RotationSolver.Updaters;

namespace RotationSolver.ActionSequencer;

Expand Down Expand Up @@ -43,10 +43,7 @@ public bool IsTrue(ICustomRotation combo)
break;

case ActionConditionType.CanUse:
var option = CanUseOption.IgnoreTarget;
if (Param1 > 0) option |= CanUseOption.MustUse;
if (Param2 > 0) option |= CanUseOption.EmptyOrSkipCombo;
result = _action.CanUse(out _, option);
result = _action.CanUse(out _, (CanUseOption)Param1, (byte)Param2);
break;

case ActionConditionType.EnoughLevel:
Expand Down Expand Up @@ -129,11 +126,9 @@ public void Draw(ICustomRotation rotation)
break;
}
ImGui.SameLine();
ImGuiHelper.SetNextWidthWithName(combos[condition]);
if (ImGui.Combo($"##Comparation{GetHashCode()}", ref condition, combos, combos.Length))
{
Condition = condition > 0;
}

ImGuiHelper.SelectableCombo($"##Comparation{GetHashCode()}", combos, ref condition);
Condition = condition > 0;


switch (ActionConditionType)
Expand All @@ -156,9 +151,35 @@ public void Draw(ICustomRotation rotation)
break;

case ActionConditionType.CanUse:
var popUpId = "Can Use Id" + GetHashCode().ToString();
var option = (CanUseOption)Param1;

if (ImGui.Selectable($"{option}##CanUse{GetHashCode()}"))
{
if (!ImGui.IsPopupOpen(popUpId)) ImGui.OpenPopup(popUpId);
}

ConditionHelper.DrawCheckBox($"{LocalizationManager.RightLang.ActionSequencer_MustUse}##MustUse{GetHashCode()}", ref Param1, LocalizationManager.RightLang.ActionSequencer_MustUseDesc);
ConditionHelper.DrawCheckBox($"{LocalizationManager.RightLang.ActionSequencer_Empty}##MustUse{GetHashCode()}", ref Param2, LocalizationManager.RightLang.ActionSequencer_EmptyDesc);
if (ImGui.BeginPopup(popUpId))
{
var showedValues = Enum.GetValues<CanUseOption>().Where(i => i.GetAttribute<JsonIgnoreAttribute>() == null);

foreach (var value in showedValues)
{
var b = option.HasFlag(value);
if(ImGui.Checkbox(value.ToString(), ref b))
{
option ^= value;
Param1 = (int)option;
}
}

ImGui.EndPopup();
}

if (ConditionHelper.DrawDragInt($"{LocalizationManager.RightLang.ActionSequencer_AOECount}##AOECount{GetHashCode()}", ref Param2))
{
Param2 = Math.Max(0, Param2);
}
break;

case ActionConditionType.CurrentCharges:
Expand Down
14 changes: 5 additions & 9 deletions RotationSolver/ActionSequencer/ConditionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,12 @@ public static void CheckMemberInfo<T>(ICustomRotation rotation, string name, ref

public static void DrawByteEnum<T>(string name, ref T value, Func<T, string> function) where T : struct, Enum
{
var type = (int)(byte)(object)value;
var names = Enum.GetValues<T>().Select(function).ToArray();
//ImGui.SetNextItemWidth(100);
ImGui.SetNextItemWidth(Math.Max(80, ImGui.CalcTextSize(name).X + 30));
var values = Enum.GetValues<T>();
var index = Array.IndexOf(values, value);
var names = values.Select(function).ToArray();

if (ImGui.Combo(name, ref type, names, names.Length))
{
value = (T)(object)(byte)type;
}
ImGuiHelper.SelectableCombo(name, names, ref index);
value = values[index];
}

public static bool DrawDragFloat(string name, ref float value)
Expand Down Expand Up @@ -151,6 +148,5 @@ public static void ActionSelectorPopUp(string popUpId, CollapsingHeaderGroup gro
group.Draw();
ImGui.EndPopup();
}

}
}
2 changes: 1 addition & 1 deletion RotationSolver/ActionSequencer/ConditionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void Draw(ICustomRotation rotation)

ImGui.SameLine();

if(ImGui.Button((IsAnd ? "&&" : "||") + $"##Rule{GetHashCode()}"))
if(ImGui.Selectable((IsAnd ? "&&" : " | | ") + $"##Rule{GetHashCode()}"))
{
IsAnd = !IsAnd;
}
Expand Down
48 changes: 20 additions & 28 deletions RotationSolver/ActionSequencer/RotationCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ public void Draw(ICustomRotation rotation)
_prop = i;
PropertyName = i.Name;
});

ImGui.SameLine();
ImGui.SetNextItemWidth(80);
ImGui.Combo($"##IsOrNot{GetHashCode()}", ref Condition, new string[]

ImGuiHelper.SelectableCombo($"##IsOrNot{GetHashCode()}", new string[]
{
LocalizationManager.RightLang.ActionSequencer_Is,
LocalizationManager.RightLang.ActionSequencer_Isnot,
}, 2);
}, ref Condition);

break;

case ComboConditionType.Byte:
Expand All @@ -134,10 +134,9 @@ public void Draw(ICustomRotation rotation)
PropertyName = i.Name;
});


ImGui.SameLine();
ImGui.SetNextItemWidth(50);
ImGui.Combo($"##Comparation{GetHashCode()}", ref Condition, new string[] { ">", "<", "=" }, 3);

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

ImGui.SameLine();
ImGui.SetNextItemWidth(50);
Expand All @@ -154,8 +153,7 @@ public void Draw(ICustomRotation rotation)
});

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

ImGui.SameLine();
ImGui.SetNextItemWidth(50);
Expand All @@ -167,31 +165,23 @@ public void Draw(ICustomRotation rotation)
case ComboConditionType.Last:
ImGui.SameLine();

ImGui.SetNextItemWidth(Math.Max(80, ImGui.CalcTextSize(MethodName).X + 30));
if (ImGui.BeginCombo($"##Last{GetHashCode()}", MethodName))
{
foreach(var methodName in new string[]
var names = new string[]
{
nameof(CustomRotation.IsLastGCD),
nameof(CustomRotation.IsLastAction),
nameof(CustomRotation.IsLastAbility),
})
{
if (ImGui.Selectable(methodName))
{
MethodName = methodName;
}
}
ImGui.EndCombo();
}
};
var index = Array.IndexOf(names, MethodName);
ImGuiHelper.SelectableCombo($"##Last{GetHashCode()}", names, ref index);
MethodName = names[index];

ImGui.SameLine();
ImGui.SetNextItemWidth(80);
ImGui.Combo($"##IsNot{GetHashCode()}", ref Condition, new string[]

ImGuiHelper.SelectableCombo($"##IsNot{GetHashCode()}", new string[]
{
LocalizationManager.RightLang.ActionSequencer_Is,
LocalizationManager.RightLang.ActionSequencer_Isnot,
}, 2);
}, ref Condition);

ImGui.SameLine();

Expand All @@ -212,9 +202,11 @@ public void Draw(ICustomRotation rotation)
}

ImGui.SameLine();
ImGui.SetNextItemWidth(50);
ImGui.Combo($"##Adjust{GetHashCode()}", ref Param1, new string[] { "Original", "Adjusted" }, 2);

ImGuiHelper.SelectableCombo($"##Adjust{GetHashCode()}", new string[]
{
LocalizationManager.RightLang.ActionSequencer_Original,
LocalizationManager.RightLang.ActionSequencer_Adjusted,
}, ref Param1);
break;
}
}
Expand Down
49 changes: 27 additions & 22 deletions RotationSolver/ActionSequencer/TargetCondition.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
using ECommons.DalamudServices;
using ECommons.GameHelpers;
using ECommons.Reflection;
using Lumina.Excel.GeneratedSheets;
using RotationSolver.Localization;
using RotationSolver.TextureItems;
using RotationSolver.UI;
using RotationSolver.Updaters;
using System.Xml.Linq;
using static System.Net.Mime.MediaTypeNames;

namespace RotationSolver.ActionSequencer;

Expand Down Expand Up @@ -174,8 +169,8 @@ public void Draw(ICustomRotation rotation)
case TargetConditionType.HasStatus:
combos = new string[]
{
LocalizationManager.RightLang.ActionSequencer_Have,
LocalizationManager.RightLang.ActionSequencer_HaveNot,
LocalizationManager.RightLang.ActionSequencer_Has,
LocalizationManager.RightLang.ActionSequencer_HasNot,
};
break;
case TargetConditionType.IsDying:
Expand All @@ -197,11 +192,8 @@ public void Draw(ICustomRotation rotation)

ImGui.SameLine();

ImGuiHelper.SetNextWidthWithName(combos[condition]);
if (ImGui.Combo($"##Comparation{GetHashCode()}", ref condition, combos, combos.Length))
{
Condition = condition > 0;
}
ImGuiHelper.SelectableCombo($"##Comparation{GetHashCode()}", combos, ref condition);
Condition = condition > 0;

var popupId = "Status Finding Popup" + GetHashCode().ToString();

Expand Down Expand Up @@ -232,8 +224,13 @@ void DrawStatusIcon()

ImGui.SameLine();

ImGui.Checkbox($"{LocalizationManager.RightLang.ActionSequencer_StatusSelf}##Self{GetHashCode()}", ref FromSelf);
ImguiTooltips.HoveredTooltip(LocalizationManager.RightLang.ActionSequencer_StatusSelfDesc);
var check = FromSelf ? 1 : 0;
ImGuiHelper.SelectableCombo($"From Self {GetHashCode()}", new string[]
{
LocalizationManager.RightLang.ActionSequencer_StatusAll,
LocalizationManager.RightLang.ActionSequencer_StatusSelf,
}, ref check);
FromSelf = check != 0;
break;

case TargetConditionType.StatusEnd:
Expand All @@ -242,9 +239,13 @@ void DrawStatusIcon()

ImGui.SameLine();

ImGui.Checkbox($"{LocalizationManager.RightLang.ActionSequencer_StatusSelf}##Self{GetHashCode()}", ref FromSelf);

ImguiTooltips.HoveredTooltip(LocalizationManager.RightLang.ActionSequencer_StatusSelfDesc);
check = FromSelf ? 1 : 0;
ImGuiHelper.SelectableCombo($"From Self {GetHashCode()}", new string[]
{
LocalizationManager.RightLang.ActionSequencer_StatusAll,
LocalizationManager.RightLang.ActionSequencer_StatusSelf,
}, ref check);
FromSelf = check != 0;

ConditionHelper.DrawDragFloat($"s##Seconds{GetHashCode()}", ref DistanceOrTime);
break;
Expand All @@ -256,9 +257,13 @@ void DrawStatusIcon()

ImGui.SameLine();

ImGui.Checkbox($"{LocalizationManager.RightLang.ActionSequencer_StatusSelf}##Self{GetHashCode()}", ref FromSelf);

ImguiTooltips.HoveredTooltip(LocalizationManager.RightLang.ActionSequencer_StatusSelfDesc);
check = FromSelf ? 1 : 0;
ImGuiHelper.SelectableCombo($"From Self {GetHashCode()}", new string[]
{
LocalizationManager.RightLang.ActionSequencer_StatusAll,
LocalizationManager.RightLang.ActionSequencer_StatusSelf,
}, ref check);
FromSelf = check != 0;

ConditionHelper.DrawDragInt($"GCD##GCD{GetHashCode()}", ref GCD);
ConditionHelper.DrawDragFloat($"{LocalizationManager.RightLang.ActionSequencer_TimeOffset}##Ability{GetHashCode()}", ref DistanceOrTime);
Expand All @@ -274,13 +279,13 @@ void DrawStatusIcon()
case TargetConditionType.CastingAction:
ImGui.SameLine();
ImGuiHelper.SetNextWidthWithName(CastingActionName);
ImGui.InputText($"Ability name##CastingActionName{GetHashCode()}", ref CastingActionName, 100);
ImGui.InputText($"Ability name##CastingActionName{GetHashCode()}", ref CastingActionName, 128);
break;

case TargetConditionType.CastingActionTimeUntil:
ImGui.SameLine();
ImGui.SetNextItemWidth(Math.Max(150 * ImGuiHelpers.GlobalScale, ImGui.CalcTextSize(DistanceOrTime.ToString()).X));
ImGui.InputFloat($"Seconds##CastingActionTimeUntil{GetHashCode()}", ref DistanceOrTime, .1f);
ImGui.InputFloat($"s##CastingActionTimeUntil{GetHashCode()}", ref DistanceOrTime, .1f);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/Localization/EnumTranslations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static class EnumTranslations
{
internal static string ToName(this TargetConditionType type) => type switch
{
TargetConditionType.HasStatus => LocalizationManager.RightLang.TargetConditionType_HaveStatus,
TargetConditionType.HasStatus => LocalizationManager.RightLang.TargetConditionType_HasStatus,
TargetConditionType.IsDying => LocalizationManager.RightLang.TargetConditionType_IsDying,
TargetConditionType.IsBoss => LocalizationManager.RightLang.TargetConditionType_IsBoss,
TargetConditionType.Distance => LocalizationManager.RightLang.TargetConditionType_Distance,
Expand Down
21 changes: 9 additions & 12 deletions RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,20 +291,15 @@ internal partial class Strings
#endregion

#region ScriptWindow
public string ActionSequencer_DragdropDescription { get; set; } = "Drag&drop to move,Ctrl+Alt+RightClick to delete.";
public string ActionSequencer_SearchBar { get; set; } = "Search Bar";
public string ActionSequencer_MustUse { get; set; } = "MustUse";
public string ActionSequencer_MustUseDesc { get; set; } = "Skip AOE and Buff.";
public string ActionSequencer_Empty { get; set; } = "UseUp";
public string ActionSequencer_EmptyDesc { get; set; } = "UseUp or Skip Combo";

public string ActionSequencer_Can { get; set; } = "Can";
public string ActionSequencer_Cannot { get; set; } = "Cannot";
public string ActionSequencer_Is { get; set; } = "Is";
public string ActionSequencer_Isnot { get; set; } = "Isnot";
public string ActionSequencer_Have { get; set; } = "Have";
public string ActionSequencer_HaveNot { get; set; } = "Have not";
public string ActionSequencer_Has { get; set; } = "Has";
public string ActionSequencer_HasNot { get; set; } = "Has not";
public string ActionSequencer_TimeOffset { get; set; } = "Time Offset";

public string ActionSequencer_AOECount { get; set; } = "AOE Count";
public string ActionSequencer_Charges { get; set; } = "Charges";
public string ActionSequencer_ConditionSet { get; set; } = "ConditionSet";
public string ActionSequencer_ActionCondition { get; set; } = "ActionCondition";
Expand All @@ -313,8 +308,10 @@ internal partial class Strings
public string ActionSequencer_ActionTarget { get; set; } = "{0}'s target";
public string ActionSequencer_Target { get; set; } = "Target";
public string ActionSequencer_Player { get; set; } = "Player";
public string ActionSequencer_StatusSelf { get; set; } = "StatusSelf";
public string ActionSequencer_StatusSelfDesc { get; set; } = "StatusSelf";
public string ActionSequencer_Original { get; set; } = "Original";
public string ActionSequencer_Adjusted { get; set; } = "Adjusted";
public string ActionSequencer_StatusSelf { get; set; } = "From Self";
public string ActionSequencer_StatusAll { get; set; } = "From All";
#endregion

#region Actions
Expand Down Expand Up @@ -372,7 +369,7 @@ internal partial class Strings
#endregion

#region TargetConditionType
public string TargetConditionType_HaveStatus { get; set; } = "Have Status";
public string TargetConditionType_HasStatus { get; set; } = "Has Status";
public string TargetConditionType_IsDying { get; set; } = "Is Dying";
public string TargetConditionType_IsBoss { get; set; } = "Is Boss";
public string TargetConditionType_Distance { get; set; } = "Distance";
Expand Down
Loading

0 comments on commit 33e9a31

Please sign in to comment.