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 update.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 17, 2023
1 parent aebb871 commit 07fc813
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 174 deletions.
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Attributes/RotationDescAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace RotationSolver.Basic.Attributes;

/// <summary>
/// The description about the rotation.
/// The description about the macro. If it tag at the rotation class, it means Burst. Others means the macro that this method belongs to.
/// </summary>
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
public class RotationDescAttribute : Attribute
Expand Down
44 changes: 5 additions & 39 deletions RotationSolver/ActionSequencer/ActionCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,58 +73,24 @@ public bool IsTrue(ICustomRotation combo)
{
HeaderSize = 12,
};
private float size => 32 * ImGuiHelpers.GlobalScale;
private int count = 15;
public void Draw(ICustomRotation combo)
public void Draw(ICustomRotation rotation)
{
ConditionHelper.CheckBaseAction(combo, ID, ref _action);
ConditionHelper.CheckBaseAction(rotation, ID, ref _action);

var name = _action?.Name ?? string.Empty;

var popUpKey = "Action Condition Pop Up" + GetHashCode().ToString();

if (_actionsList != null && ImGui.BeginPopup(popUpKey))
{
_actionsList.ClearCollapsingHeader();

foreach (var pair in RotationUpdater.GroupActions(combo.AllBaseActions))
{
_actionsList.AddCollapsingHeader(() => pair.Key, () =>
{
var index = 0;
foreach (var item in pair.OrderBy(t => t.ID))
{
if (!item.GetTexture(out var icon)) continue;

if (index++ % count != 0)
{
ImGui.SameLine();
}

ImGui.BeginGroup();
var cursor = ImGui.GetCursorPos();
if (RotationConfigWindow.NoPaddingNoColorImageButton(icon.ImGuiHandle, Vector2.One * size, GetHashCode().ToString()))
{
ID = (ActionID)item.ID;
ImGui.CloseCurrentPopup();
}
RotationConfigWindow.DrawActionOverlay(cursor, size, 1);
ImGui.EndGroup();
}
});
}
_actionsList.Draw();
ImGui.EndPopup();
}
ConditionHelper.ActionSelectorPopUp(popUpKey, _actionsList, rotation, item => ID = (ActionID)item.ID);

if (_action?.GetTexture(out var icon) ?? false || IconSet.GetTexture(4, out icon))
{
var cursor = ImGui.GetCursorPos();
if (RotationConfigWindow.NoPaddingNoColorImageButton(icon.ImGuiHandle, Vector2.One * size, GetHashCode().ToString()))
if (RotationConfigWindow.NoPaddingNoColorImageButton(icon.ImGuiHandle, Vector2.One * ConditionHelper.IconSize, GetHashCode().ToString()))
{
if(!ImGui.IsPopupOpen(popUpKey)) ImGui.OpenPopup(popUpKey);
}
RotationConfigWindow.DrawActionOverlay(cursor, size, 1);
RotationConfigWindow.DrawActionOverlay(cursor, ConditionHelper.IconSize, 1);
}

ImGui.SameLine();
Expand Down
78 changes: 77 additions & 1 deletion RotationSolver/ActionSequencer/ConditionHelper.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using ECommons.GameHelpers;
using RotationSolver.Localization;
using RotationSolver.UI;
using RotationSolver.Updaters;

namespace RotationSolver.ActionSequencer;

public class ConditionHelper
internal class ConditionHelper
{
public static bool CheckBaseAction(ICustomRotation rotation, ActionID id, ref BaseAction action)
{
Expand Down Expand Up @@ -74,4 +76,78 @@ public static bool DrawCheckBox(string name, ref int value, string desc = "")

return result;
}

internal static void SearchItemsReflection<T>(string popId, string name, ref string searchTxt, T[] actions, Action<T> selectAction) where T : MemberInfo
{
ImGui.SetNextItemWidth(Math.Max(80 * ImGuiHelpers.GlobalScale, ImGui.CalcTextSize(name).X));

if (ImGui.Selectable(name + "##" + popId))
{
if (!ImGui.IsPopupOpen(popId)) ImGui.OpenPopup(popId);
}

if (ImGui.BeginPopup(popId))
{
ImGui.SetNextItemWidth(200 * ImGuiHelpers.GlobalScale);
ImGui.InputTextWithHint("##Searching the member", LocalizationManager.RightLang.ConfigWindow_Actions_MemberName, ref searchTxt, 128);

ImGui.Spacing();

if (ImGui.BeginChild("Rotation Solver Find Member", new Vector2(-1, 400 * ImGuiHelpers.GlobalScale)))
{
var searchingKey = searchTxt;
foreach (var member in actions.OrderBy(s => s.GetMemberName().Split(' ').Min(c => RotationConfigWindow.StringComparer.Distance(c, searchingKey))))
{
if (ImGui.Selectable(member.GetMemberName()))
{
selectAction?.Invoke(member);
ImGui.CloseCurrentPopup();
}
}
ImGui.EndChild();
}

ImGui.EndPopup();
}
}

public static float IconSize => 32 * ImGuiHelpers.GlobalScale;
private int count = 15;
public static void ActionSelectorPopUp(string popUpId, CollapsingHeaderGroup group, ICustomRotation rotation, Action<IAction> action)
{
if (group != null && ImGui.BeginPopup(popUpId))
{
group.ClearCollapsingHeader();

foreach (var pair in RotationUpdater.GroupActions(rotation.AllBaseActions))
{
group.AddCollapsingHeader(() => pair.Key, () =>
{
var index = 0;
foreach (var item in pair.OrderBy(t => t.ID))
{
if (!item.GetTexture(out var icon)) continue;

if (index++ % count != 0)
{
ImGui.SameLine();
}

ImGui.BeginGroup();
var cursor = ImGui.GetCursorPos();
if (RotationConfigWindow.NoPaddingNoColorImageButton(icon.ImGuiHandle, Vector2.One * IconSize, group.GetHashCode().ToString()))
{
action?.Invoke(item);
ImGui.CloseCurrentPopup();
}
RotationConfigWindow.DrawActionOverlay(cursor, IconSize, 1);
ImGui.EndGroup();
}
});
}
group.Draw();
ImGui.EndPopup();
}

}
}
30 changes: 22 additions & 8 deletions RotationSolver/ActionSequencer/RotationCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public bool IsTrue(ICustomRotation rotation)
}

string searchTxt = string.Empty;

private readonly CollapsingHeaderGroup _actionsList = new()
{
HeaderSize = 12,
};
public void Draw(ICustomRotation rotation)
{
UpdateInfo(rotation);
Expand All @@ -106,7 +111,7 @@ public void Draw(ICustomRotation rotation)
{
case ComboConditionType.Bool:
ImGui.SameLine();
ImGuiHelper.SearchItemsReflection($"##Comparation{GetHashCode()}", _prop?.GetMemberName(), ref searchTxt, rotation.AllBools, i =>
ConditionHelper.SearchItemsReflection($"##Comparation{GetHashCode()}", _prop?.GetMemberName(), ref searchTxt, rotation.AllBools, i =>
{
_prop = i;
PropertyName = i.Name;
Expand All @@ -123,7 +128,7 @@ public void Draw(ICustomRotation rotation)

case ComboConditionType.Byte:
ImGui.SameLine();
ImGuiHelper.SearchItemsReflection($"##ByteChoice{GetHashCode()}", _prop?.GetMemberName(), ref searchTxt, rotation.AllBytes, i =>
ConditionHelper.SearchItemsReflection($"##ByteChoice{GetHashCode()}", _prop?.GetMemberName(), ref searchTxt, rotation.AllBytes, i =>
{
_prop = i;
PropertyName = i.Name;
Expand All @@ -142,13 +147,12 @@ public void Draw(ICustomRotation rotation)
break;
case ComboConditionType.Float:
ImGui.SameLine();
ImGuiHelper.SearchItemsReflection($"##FloatChoice{GetHashCode()}", _prop?.GetMemberName(), ref searchTxt, rotation.AllFloats, i =>
ConditionHelper.SearchItemsReflection($"##FloatChoice{GetHashCode()}", _prop?.GetMemberName(), ref searchTxt, rotation.AllFloats, i =>
{
_prop = i;
PropertyName = i.Name;
});


ImGui.SameLine();
ImGui.SetNextItemWidth(50);
ImGui.Combo($"##Comparation{GetHashCode()}", ref Condition, new string[] { ">", "<", "=" }, 3);
Expand Down Expand Up @@ -190,12 +194,22 @@ public void Draw(ICustomRotation rotation)
}, 2);

ImGui.SameLine();

var name = _action?.Name ?? string.Empty;
ImGuiHelper.SearchCombo($"##ActionChoice{GetHashCode()}", name, ref searchTxt, rotation.AllBaseActions, i =>

var popUpKey = "Rotation Condition Pop Up" + GetHashCode().ToString();

ConditionHelper.ActionSelectorPopUp(popUpKey, _actionsList, rotation, item => ID = (ActionID)item.ID);

if (_action?.GetTexture(out var icon) ?? false || IconSet.GetTexture(4, out icon))
{
_action = (BaseAction)i;
ID = (ActionID)_action.ID;
});
var cursor = ImGui.GetCursorPos();
if (RotationConfigWindow.NoPaddingNoColorImageButton(icon.ImGuiHandle, Vector2.One * ConditionHelper.IconSize, GetHashCode().ToString()))
{
if (!ImGui.IsPopupOpen(popUpKey)) ImGui.OpenPopup(popUpKey);
}
RotationConfigWindow.DrawActionOverlay(cursor, ConditionHelper.IconSize, 1);
}

ImGui.SameLine();
ImGui.SetNextItemWidth(50);
Expand Down
55 changes: 4 additions & 51 deletions RotationSolver/ActionSequencer/TargetCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ public bool IsTrue(ICustomRotation rotation)
{
HeaderSize = 12,
};
private float size => 32 * ImGuiHelpers.GlobalScale;
private int count = 15;

public void Draw(ICustomRotation rotation)
{
ConditionHelper.CheckBaseAction(rotation, ID, ref _action);
Expand All @@ -131,63 +130,17 @@ public void Draw(ICustomRotation rotation)

var popUpKey = "Target Condition Pop Up" + GetHashCode().ToString();

if (_actionsList != null && ImGui.BeginPopup(popUpKey))
{
_actionsList.ClearCollapsingHeader();

if (ImGui.Selectable(LocalizationManager.RightLang.ActionSequencer_Target))
{
_action = null;
ID = ActionID.None;
IsTarget = true;
}

if (ImGui.Selectable(LocalizationManager.RightLang.ActionSequencer_Player))
{
_action = null;
ID = ActionID.None;
IsTarget = false;
}

foreach (var pair in RotationUpdater.GroupActions(rotation.AllBaseActions))
{
_actionsList.AddCollapsingHeader(() => pair.Key, () =>
{
var index = 0;
foreach (var item in pair.OrderBy(t => t.ID))
{
if (!item.GetTexture(out var icon)) continue;

if (index++ % count != 0)
{
ImGui.SameLine();
}

ImGui.BeginGroup();
var cursor = ImGui.GetCursorPos();
if (RotationConfigWindow.NoPaddingNoColorImageButton(icon.ImGuiHandle, Vector2.One * size, GetHashCode().ToString()))
{
ID = (ActionID)item.ID;
ImGui.CloseCurrentPopup();
}
RotationConfigWindow.DrawActionOverlay(cursor, size, 1);
ImGui.EndGroup();
}
});
}
_actionsList.Draw();
ImGui.EndPopup();
}
ConditionHelper.ActionSelectorPopUp(popUpKey, _actionsList, rotation, item => ID = (ActionID)item.ID);

if (_action != null ? ( _action.GetTexture(out var icon) || IconSet.GetTexture(4, out icon))
: IconSet.GetTexture(IsTarget ? 16u : 18u, out icon))
{
var cursor = ImGui.GetCursorPos();
if (RotationConfigWindow.NoPaddingNoColorImageButton(icon.ImGuiHandle, Vector2.One * size, GetHashCode().ToString()))
if (RotationConfigWindow.NoPaddingNoColorImageButton(icon.ImGuiHandle, Vector2.One * ConditionHelper.IconSize, GetHashCode().ToString()))
{
if (!ImGui.IsPopupOpen(popUpKey)) ImGui.OpenPopup(popUpKey);
}
RotationConfigWindow.DrawActionOverlay(cursor, size, 1);
RotationConfigWindow.DrawActionOverlay(cursor, ConditionHelper.IconSize, 1);

var description = _action != null ? string.Format(LocalizationManager.RightLang.ActionSequencer_ActionTarget, _action.Name)
: IsTarget
Expand Down
1 change: 1 addition & 0 deletions RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ internal partial class Strings
public string ConfigWindow_List_Actions { get; set; } = "Actions";
public string ConfigWindow_List_Territories { get; set; } = "Territories";
public string ConfigWindow_List_StatusNameOrId { get; set; } = "Status name or id";
public string ConfigWindow_Actions_MemberName { get; set; } = "Member Name";
public string ConfigWindow_List_AddStatus { get; set; } = "Add Status";
public string ConfigWindow_List_Remove { get; set; } = "Remove";

Expand Down
Loading

0 comments on commit 07fc813

Please sign in to comment.