From 9735526488230055c318f2b311150b8653718f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E6=B0=B4?= <1123993881@qq.com> Date: Thu, 17 Aug 2023 21:48:50 +0800 Subject: [PATCH] fix: fixed for major ui. --- RotationSolver.Basic/DataCenter.cs | 1 - .../ActionSequencer/ConditionHelper.cs | 4 +- .../ActionSequencer/ConditionSet.cs | 13 +- .../ActionSequencer/RotationCondition.cs | 2 +- RotationSolver/Localization/Localization.json | 27 ++-- RotationSolver/Localization/Strings.cs | 11 +- RotationSolver/UI/ControlWindow.cs | 10 +- RotationSolver/UI/CooldownWindow.cs | 7 +- RotationSolver/UI/ImGuiHelper.cs | 127 +++++++++++++++++- RotationSolver/UI/RotationConfigWindow.cs | 42 +++--- .../UI/RotationConfigWindow_Config.cs | 4 +- .../UI/SearchableConfigs/Searchable.cs | 102 +------------- .../Updaters/ActionSequencerUpdater.cs | 70 +++++----- 13 files changed, 221 insertions(+), 199 deletions(-) diff --git a/RotationSolver.Basic/DataCenter.cs b/RotationSolver.Basic/DataCenter.cs index 826fab98c..50c9dd685 100644 --- a/RotationSolver.Basic/DataCenter.cs +++ b/RotationSolver.Basic/DataCenter.cs @@ -325,7 +325,6 @@ public static float DPSTaken var time = recs.Last().ReceiveTime - recs.First().ReceiveTime + TimeSpan.FromMilliseconds(2.5f); return damages / (float)time.TotalSeconds; - } catch { diff --git a/RotationSolver/ActionSequencer/ConditionHelper.cs b/RotationSolver/ActionSequencer/ConditionHelper.cs index 51014dc25..331923e38 100644 --- a/RotationSolver/ActionSequencer/ConditionHelper.cs +++ b/RotationSolver/ActionSequencer/ConditionHelper.cs @@ -76,9 +76,7 @@ public static bool DrawCheckBox(string name, ref int value, string desc = "") internal static void SearchItemsReflection(string popId, string name, ref string searchTxt, T[] actions, Action selectAction) where T : MemberInfo { - ImGui.SetNextItemWidth(Math.Max(80 * ImGuiHelpers.GlobalScale, ImGui.CalcTextSize(name).X)); - - if (ImGui.Selectable(name + "##" + popId)) + if (ImGuiHelper.SelectableButton(name + "##" + popId)) { if (!ImGui.IsPopupOpen(popId)) ImGui.OpenPopup(popId); } diff --git a/RotationSolver/ActionSequencer/ConditionSet.cs b/RotationSolver/ActionSequencer/ConditionSet.cs index 36ddb9682..4a155dfac 100644 --- a/RotationSolver/ActionSequencer/ConditionSet.cs +++ b/RotationSolver/ActionSequencer/ConditionSet.cs @@ -8,6 +8,7 @@ using System.Drawing; using System.Security.Policy; using System.Windows.Forms; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar; namespace RotationSolver.ActionSequencer; @@ -26,10 +27,12 @@ public void Draw(ICustomRotation rotation) ImGui.SameLine(); - if(ImGui.Selectable((IsAnd ? "&&" : " | | ") + $"##Rule{GetHashCode()}")) + var index = IsAnd ? 0 : 1; + ImGuiHelper.SelectableCombo($"##Rule{GetHashCode()}", new string[] { - IsAnd = !IsAnd; - } + "&&" , " | | ", + }, ref index); + IsAnd = index == 0; ImGui.Spacing(); @@ -55,14 +58,14 @@ void Down() var key = $"Condition Pop Up: {condition.GetHashCode()}"; - Searchable.DrawHotKeysPopup(key, string.Empty, + ImGuiHelper.DrawHotKeysPopup(key, string.Empty, (LocalizationManager.RightLang.ConfigWindow_List_Remove, Delete, new string[] { "Delete" }), (LocalizationManager.RightLang.ConfigWindow_Actions_MoveUp, Up, new string[] { "↑" }), (LocalizationManager.RightLang.ConfigWindow_Actions_MoveDown, Down, new string[] { "↓" })); DrawCondition(condition.IsTrue(rotation)); - Searchable.ExecuteHotKeysPopup(key, string.Empty, string.Empty, true, + ImGuiHelper.ExecuteHotKeysPopup(key, string.Empty, string.Empty, true, (Delete, new VirtualKey[] { VirtualKey.DELETE }), (Up, new VirtualKey[] { VirtualKey.UP }), (Down, new VirtualKey[] { VirtualKey.DOWN })); diff --git a/RotationSolver/ActionSequencer/RotationCondition.cs b/RotationSolver/ActionSequencer/RotationCondition.cs index 821994233..531d29047 100644 --- a/RotationSolver/ActionSequencer/RotationCondition.cs +++ b/RotationSolver/ActionSequencer/RotationCondition.cs @@ -170,7 +170,7 @@ public void Draw(ICustomRotation rotation) nameof(CustomRotation.IsLastAction), nameof(CustomRotation.IsLastAbility), }; - var index = Array.IndexOf(names, MethodName); + var index = Math.Max(0, Array.IndexOf(names, MethodName)); ImGuiHelper.SelectableCombo($"##Last{GetHashCode()}", names, ref index); MethodName = names[index]; diff --git a/RotationSolver/Localization/Localization.json b/RotationSolver/Localization/Localization.json index 11430eb49..034272337 100644 --- a/RotationSolver/Localization/Localization.json +++ b/RotationSolver/Localization/Localization.json @@ -131,7 +131,7 @@ "ConfigWindow_Param_HealthTankRatio": "Heal tank first if its HP%% is lower than this.", "ConfigWindow_Param_DistanceForMoving": "Use gapcloser as a damage ability if the distance to your target is less then this.", "ConfigWindow_Param_HealWhenNothingTodoBelow": "Healing the members with GCD if there is nothing to do in combat and their min HP%% is lower than this.", - "ConfigWindow_Param_HealthForDyingTank": "Set the HP%% for tank to use invincibility", + "ConfigWindow_Param_HealthForDyingTank": "Set the HP%% for tank to use invulnerability", "ConfigWindow_Param_MeleeRangeOffset": "Melee Range action using offset", "ConfigWindow_Param_RightNowTargetToHostileType": "Engage settings", "ConfigWindow_Param_TargetToHostileType1": "All targets can attack", @@ -168,7 +168,6 @@ "ConfigWindow_Control_ShowItemsCooldown": "Show Items' Cooldown", "ConfigWindow_Control_ShowGCDCooldown": "Show GCD' Cooldown", "ConfigWindow_Control_UseOriginalCooldown": "Show Original Cooldown", - "ConfigWindow_Control_CooldownActionOneLine": "The count of cooldown actions in one line.", "ConfigWindow_Control_CooldownFontSize": "Change the cooldown font size.", "ConfigWindow_Control_UnlockBackgroundColor": "Unlocked Control Window's Background", "ConfigWindow_Control_LockBackgroundColor": "Locked Control Window's Background", @@ -177,8 +176,6 @@ "ConfigWindow_Control_ControlWindow0GCDSize": "0GCD icon size", "ConfigWindow_Control_CooldownWindowIconSize": "Cooldown icon size", "ConfigWindow_Control_ControlWindowNextSizeRatio": "Next Action Size Ratio", - "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_ClickToUse": "Click to use it!", "ConfigWindow_Rotation_BetaRotation": "Beta Rotation!", "ConfigWindow_Rotation_DownloadRotations": "Auto Download Rotations", "ConfigWindow_Rotation_AutoUpdateRotations": "Auto Update Rotations", @@ -195,19 +192,14 @@ "ConfigWindow_List_HostileCastingAreaDesc": "If the target is casting the action like this, it'll defense area.", "ConfigWindow_List_NoHostile": "No Hostile", "ConfigWindow_List_NoHostileDesc": "Add a name of target that never be the hostile for you.", - "ActionSequencer_DragdropDescription": "Drag&drop to move,Ctrl+Alt+RightClick to delete.", - "ActionSequencer_SearchBar": "Search Bar", - "ActionSequencer_MustUse": "MustUse", - "ActionSequencer_MustUseDesc": "Skip AOE and Buff.", - "ActionSequencer_Empty": "UseUp", - "ActionSequencer_EmptyDesc": "UseUp or Skip Combo", "ActionSequencer_Can": "Can", "ActionSequencer_Cannot": "Cannot", "ActionSequencer_Is": "Is", "ActionSequencer_Isnot": "Isnot", - "ActionSequencer_Have": "Have", - "ActionSequencer_HaveNot": "Have not", + "ActionSequencer_Has": "Has", + "ActionSequencer_HasNot": "Has not", "ActionSequencer_TimeOffset": "Time Offset", + "ActionSequencer_AOECount": "AOE Count", "ActionSequencer_Charges": "Charges", "ActionSequencer_ConditionSet": "ConditionSet", "ActionSequencer_ActionCondition": "ActionCondition", @@ -216,8 +208,10 @@ "ActionSequencer_ActionTarget": "{0}'s target", "ActionSequencer_Target": "Target", "ActionSequencer_Player": "Player", - "ActionSequencer_StatusSelf": "StatusSelf", - "ActionSequencer_StatusSelfDesc": "StatusSelf", + "ActionSequencer_Original": "Original", + "ActionSequencer_Adjusted": "Adjusted", + "ActionSequencer_StatusSelf": "From Self", + "ActionSequencer_StatusAll": "From All", "Action_Friendly": "Support", "Action_Ability": "0GCD", "Action_Attack": "Attack", @@ -256,7 +250,7 @@ "ActionConditionType_IsCoolDown": "IsCoolDown", "ActionConditionType_CurrentCharges": "CurrentCharges", "ActionConditionType_MaxCharges": "MaxCharges", - "TargetConditionType_HaveStatus": "Have Status", + "TargetConditionType_HasStatus": "Has Status", "TargetConditionType_IsDying": "Is Dying", "TargetConditionType_IsBoss": "Is Boss", "TargetConditionType_Distance": "Distance", @@ -420,7 +414,8 @@ "ConfigWindow_About_Macros": "Macros", "ConfigWindow_About_Links": "Links", "ConfigWindow_About_Compatibility": "Compatibility", - "ConfigWindow_About_Compatibility_Description": "literally, Rotation Solver helps you to choose the target and then click the action. So any plugin that changes these will affect its decision.\n\nHere is a list of known incompatible plugins:", + "ConfigWindow_About_Compatibility_Description": "Literally, Rotation Solver helps you to choose the target and then click the action. So any plugin that changes these will affect its decision.\n\nHere is a list of known incompatible plugins:", + "ConfigWindow_About_Compatibility_Others": "Please don't relogin without closing the game. It may occur crash.", "ConfigWindow_About_Compatibility_Mistake": "Can't properly execute the behavior that RS is going to do.", "ConfigWindow_About_Compatibility_Mislead": "Misleading RS to make the right decision.", "ConfigWindow_About_Compatibility_Crash": "Cause the game to crash.", diff --git a/RotationSolver/Localization/Strings.cs b/RotationSolver/Localization/Strings.cs index 3bbb34e88..4dd446738 100644 --- a/RotationSolver/Localization/Strings.cs +++ b/RotationSolver/Localization/Strings.cs @@ -206,7 +206,7 @@ internal partial class Strings public string ConfigWindow_Param_HealWhenNothingTodoBelow { get; set; } = "Healing the members with GCD if there is nothing to do in combat and their min HP%% is lower than this."; - public string ConfigWindow_Param_HealthForDyingTank { get; set; } = "Set the HP%% for tank to use invincibility"; + public string ConfigWindow_Param_HealthForDyingTank { get; set; } = "Set the HP%% for tank to use invulnerability"; public string ConfigWindow_Param_MeleeRangeOffset { get; set; } = "Melee Range action using offset"; public string ConfigWindow_Param_RightNowTargetToHostileType { get; set; } = "Engage settings"; @@ -258,7 +258,6 @@ internal partial class Strings public string ConfigWindow_Control_ControlWindow0GCDSize { get; set; } = "0GCD icon size"; public string ConfigWindow_Control_CooldownWindowIconSize { get; set; } = "Cooldown icon size"; public string ConfigWindow_Control_ControlWindowNextSizeRatio { get; set; } = "Next Action Size Ratio"; - public string ConfigWindow_Control_ClickToUse { get; set; } = "Click to use it!"; public string ConfigWindow_Rotation_BetaRotation { get; set; } = "Beta Rotation!"; public string ConfigWindow_Rotation_DownloadRotations { get; set; } = "Auto Download Rotations"; @@ -289,10 +288,11 @@ internal partial class Strings #endregion #region ScriptWindow + public string ActionSequencer_Load { get; set; } = "Load From folder."; public string ActionSequencer_Can { get; set; } = "Can"; - public string ActionSequencer_Cannot { get; set; } = "Cannot"; + public string ActionSequencer_Cannot { get; set; } = "Can Not"; public string ActionSequencer_Is { get; set; } = "Is"; - public string ActionSequencer_Isnot { get; set; } = "Isnot"; + public string ActionSequencer_Isnot { get; set; } = "Is Not"; public string ActionSequencer_Has { get; set; } = "Has"; public string ActionSequencer_HasNot { get; set; } = "Has not"; public string ActionSequencer_TimeOffset { get; set; } = "Time Offset"; @@ -616,7 +616,8 @@ internal partial class Strings public string ConfigWindow_About_Macros { get; set; } = "Macros"; public string ConfigWindow_About_Links { get; set; } = "Links"; public string ConfigWindow_About_Compatibility { get; set; } = "Compatibility"; - public string ConfigWindow_About_Compatibility_Description { get; set; } = "literally, Rotation Solver helps you to choose the target and then click the action. So any plugin that changes these will affect its decision.\n\nHere is a list of known incompatible plugins:"; + public string ConfigWindow_About_Compatibility_Description { get; set; } = "Literally, Rotation Solver helps you to choose the target and then click the action. So any plugin that changes these will affect its decision.\n\nHere is a list of known incompatible plugins:"; + public string ConfigWindow_About_Compatibility_Others { get; set; } = "Please don't relogin without closing the game. It may occur crash."; public string ConfigWindow_About_Compatibility_Mistake { get; set; } = "Can't properly execute the behavior that RS is going to do."; public string ConfigWindow_About_Compatibility_Mislead { get; set; } = "Misleading RS to make the right decision."; diff --git a/RotationSolver/UI/ControlWindow.cs b/RotationSolver/UI/ControlWindow.cs index 1ec42dfa2..047ea008d 100644 --- a/RotationSolver/UI/ControlWindow.cs +++ b/RotationSolver/UI/ControlWindow.cs @@ -320,7 +320,7 @@ static void DrawIAction(nint handle, string id, float width, SpecialCommandType { Svc.Commands.ProcessCommand(command.GetCommandStr()); } - ImGuiHelper.DrawActionOverlay(cursor, width, IconSet.GetTexture(0u, out var text) && text.ImGuiHandle == handle ? 0 : 1); + ImGuiHelper.DrawActionOverlay(cursor, width, IconSet.GetTexture(0u, out var text) && text.ImGuiHandle == handle ? -1 : 1); ImguiTooltips.HoveredTooltip(help); } @@ -340,7 +340,9 @@ internal static (Vector2, Vector2) DrawIAction(IAction action, float width, floa if (!action.GetTexture(out var texture, isAdjust)) return (default, default); var cursor = ImGui.GetCursorPos(); - if (ImGuiHelper.NoPaddingNoColorImageButton(texture.ImGuiHandle, Vector2.One * width, action.Name)) + + var desc = action?.Name ?? string.Empty; + if (ImGuiHelper.NoPaddingNoColorImageButton(texture.ImGuiHandle, Vector2.One * width, desc)) { if (!DataCenter.State) { @@ -364,13 +366,14 @@ internal static (Vector2, Vector2) DrawIAction(IAction action, float width, floa } var size = ImGui.GetItemRectSize(); ImGuiHelper.DrawActionOverlay(cursor, width, action == null ? -1 : percent); - ImguiTooltips.HoveredTooltip(action.Name); + ImguiTooltips.HoveredTooltip(desc); return (cursor, size); } static unsafe void DrawNextAction(float gcd, float ability, float width) { + ImGui.BeginGroup(); var str = "Next Action"; ImGui.SetCursorPosX(ImGui.GetCursorPosX() + width / 2 - ImGui.CalcTextSize(str).X / 2); ImGui.TextColored(ImGuiColors.DalamudYellow, str); @@ -384,5 +387,6 @@ static unsafe void DrawNextAction(float gcd, float ability, float width) ImGui.SameLine(); DrawIAction(next, ability, -1); + ImGui.EndGroup(); } } diff --git a/RotationSolver/UI/CooldownWindow.cs b/RotationSolver/UI/CooldownWindow.cs index 98c100960..abbf3cb26 100644 --- a/RotationSolver/UI/CooldownWindow.cs +++ b/RotationSolver/UI/CooldownWindow.cs @@ -1,12 +1,10 @@ -using Dalamud.Interface.Windowing; -using RotationSolver.Basic.Configuration; +using RotationSolver.Basic.Configuration; using RotationSolver.Localization; using RotationSolver.Updaters; -using System.Drawing; namespace RotationSolver.UI; -internal class CooldownWindow : Window +internal class CooldownWindow : CtrlWindow { public CooldownWindow() :base(nameof(CooldownWindow)) @@ -63,7 +61,6 @@ private static void DrawActionCooldown(IAction act, float width) var pair = ControlWindow.DrawIAction(act, width, r, false); var pos = pair.Item1; var size = pair.Item2; - ImguiTooltips.HoveredTooltip(act.Name + "\n" + LocalizationManager.RightLang.ConfigWindow_Control_ClickToUse); if (!act.EnoughLevel) { diff --git a/RotationSolver/UI/ImGuiHelper.cs b/RotationSolver/UI/ImGuiHelper.cs index be40c29a0..bfc9ba252 100644 --- a/RotationSolver/UI/ImGuiHelper.cs +++ b/RotationSolver/UI/ImGuiHelper.cs @@ -1,4 +1,6 @@ -using ECommons.DalamudServices; +using Dalamud.Game.ClientState.Keys; +using ECommons.DalamudServices; +using ECommons.ImGuiMethods; using ImGuiScene; using RotationSolver.Basic.Configuration; using RotationSolver.Commands; @@ -103,12 +105,12 @@ public unsafe static ImFontPtr GetFont(float size) return font; } - public static void SelectableCombo(string popUp, string[] items, ref int index) + public static unsafe void SelectableCombo(string popUp, string[] items, ref int index) { var count = items.Length; var name = items[index % count] + "##" + popUp; - ImGui.SetNextItemWidth(ImGui.CalcTextSize(name).X); - if (ImGui.Selectable(name)) + + if (SelectableButton(name)) { if(count < 3) { @@ -120,6 +122,11 @@ public static void SelectableCombo(string popUp, string[] items, ref int index) } } + if (ImGui.IsItemHovered()) + { + ImGui.SetMouseCursor(ImGuiMouseCursor.Hand); + } + if (ImGui.BeginPopup(popUp)) { for (int i = 0; i < count; i++) @@ -133,6 +140,16 @@ public static void SelectableCombo(string popUp, string[] items, ref int index) } } + public static unsafe bool SelectableButton(string name) + { + ImGui.PushStyleColor(ImGuiCol.ButtonActive, ImGui.ColorConvertFloat4ToU32(*ImGui.GetStyleColorVec4(ImGuiCol.HeaderActive))); + ImGui.PushStyleColor(ImGuiCol.ButtonHovered, ImGui.ColorConvertFloat4ToU32(*ImGui.GetStyleColorVec4(ImGuiCol.HeaderHovered))); + ImGui.PushStyleColor(ImGuiCol.Button, 0); + var result = ImGui.Button(name); + ImGui.PopStyleColor(3); + return result; + } + internal static void DrawItemMiddle(Action drawAction, float wholeWidth, float width, bool leftAlign = true) { if (drawAction == null) return; @@ -271,4 +288,106 @@ internal static void DrawActionOverlay(Vector2 cursor, float width, float percen } #endregion + #region PopUp + public static void DrawHotKeysPopup(string key, string command, params (string name, Action action, string[] keys)[] pairs) + { + if (ImGui.BeginPopup(key)) + { + if (ImGui.BeginTable(key, 2, ImGuiTableFlags.BordersOuter)) + { + foreach (var (name, action, keys) in pairs) + { + if (action == null) continue; + DrawHotKeys(name, action, keys); + } + if (!string.IsNullOrEmpty(command)) + { + DrawHotKeys($"Execute \"{command}\"", () => ExecuteCommand(command), "Alt"); + + DrawHotKeys($"Copy \"{command}\"", () => CopyCommand(command), "Ctrl"); + } + ImGui.EndTable(); + } + + ImGui.EndPopup(); + } + } + public static void PrepareGroup(string key, string command, Action reset) + { + DrawHotKeysPopup(key, command, ("Reset to Default Value.", reset, new string[] { "Backspace" })); + } + public static void ReactPopup(string key, string command, Action reset, bool showHand = true) + { + ExecuteHotKeysPopup(key, command, string.Empty, showHand, (reset, new VirtualKey[] { VirtualKey.BACK })); + } + + public static void ExecuteHotKeysPopup(string key, string command, string tooltip, bool showHand, params (Action action, VirtualKey[] keys)[] pairs) + { + if (!ImGui.IsItemHovered()) return; + if (!string.IsNullOrEmpty(tooltip)) ImguiTooltips.ShowTooltip(tooltip); + + if (showHand) ImGui.SetMouseCursor(ImGuiMouseCursor.Hand); + + if (ImGui.IsMouseClicked(ImGuiMouseButton.Right)) + { + if (!ImGui.IsPopupOpen(key)) + { + ImGui.OpenPopup(key); + } + } + + foreach (var (action, keys) in pairs) + { + if (action == null) continue; + ExecuteHotKeys(action, keys); + } + if (!string.IsNullOrEmpty(command)) + { + ExecuteHotKeys(() => ExecuteCommand(command), VirtualKey.MENU); + ExecuteHotKeys(() => CopyCommand(command), VirtualKey.CONTROL); + } + } + + private static void ExecuteCommand(string command) + { + Svc.Commands.ProcessCommand(command); + } + + private static void CopyCommand(string command) + { + ImGui.SetClipboardText(command); + Notify.Success($"\"{command}\" copied to clipboard."); + } + + private static readonly SortedList _lastChecked = new(); + private static void ExecuteHotKeys(Action action, params VirtualKey[] keys) + { + if (action == null) return; + var name = string.Join(' ', keys); + + if (!_lastChecked.TryGetValue(name, out var last)) last = false; + var now = keys.All(k => Svc.KeyState[k]); + _lastChecked[name] = now; + + if (!last && now) action(); + } + + private static void DrawHotKeys(string name, Action action, params string[] keys) + { + if (action == null) return; + + ImGui.TableNextRow(); + ImGui.TableNextColumn(); + if (ImGui.Selectable(name)) + { + action(); + ImGui.CloseCurrentPopup(); + } + + ImGui.TableNextColumn(); + ImGui.TextDisabled(string.Join(' ', keys)); + } + + + #endregion } diff --git a/RotationSolver/UI/RotationConfigWindow.cs b/RotationSolver/UI/RotationConfigWindow.cs index adf8d0fc6..bc51ea832 100644 --- a/RotationSolver/UI/RotationConfigWindow.cs +++ b/RotationSolver/UI/RotationConfigWindow.cs @@ -62,6 +62,7 @@ public override void PostDraw() public override void OnClose() { Service.Config.Save(); + ActionSequencerUpdater.SaveFiles(); base.OnClose(); } @@ -510,6 +511,8 @@ private static void DrawAboutMacros() private static void DrawAboutCompatibility() { + ImGui.TextWrapped(LocalizationManager.RightLang.ConfigWindow_About_Compatibility_Others); + ImGui.TextWrapped(LocalizationManager.RightLang.ConfigWindow_About_Compatibility_Description); ImGui.Spacing(); @@ -594,6 +597,11 @@ private static void DrawAboutLinks() { Util.OpenLink("https://crowdin.com/project/rotationsolver"); } + + if (ImGuiEx.IconButton(FontAwesomeIcon.Folder, "##OpenFolder")) + { + Process.Start("explorer.exe", Svc.PluginInterface.ConfigDirectory.FullName); + } } #endregion @@ -790,14 +798,14 @@ private static void DrawRotationConfiguration() string command = ToCommandStr(OtherCommandType.Rotations,config.Name, config.DefaultValue); void Reset() => set.SetValue(config.Name, config.DefaultValue); - Searchable.PrepareGroup(key, command, Reset); + ImGuiHelper.PrepareGroup(key, command, Reset); if (config is RotationConfigCombo c) { var val = set.GetCombo(c.Name); ImGui.SetNextItemWidth(ImGui.CalcTextSize(c.Items[val]).X + 50 * _scale); var openCombo = ImGui.BeginCombo(name, c.Items[val]); - Searchable.ReactPopup(key, command, Reset); + ImGuiHelper.ReactPopup(key, command, Reset); if (openCombo) { for (int comboIndex = 0; comboIndex < c.Items.Length; comboIndex++) @@ -818,7 +826,7 @@ private static void DrawRotationConfiguration() { set.SetValue(config.Name, val.ToString()); } - Searchable.ReactPopup(key, command, Reset); + ImGuiHelper.ReactPopup(key, command, Reset); } else if (config is RotationConfigFloat f) { @@ -828,7 +836,7 @@ private static void DrawRotationConfiguration() { set.SetValue(config.Name, val.ToString()); } - Searchable.ReactPopup(key, command, Reset); + ImGuiHelper.ReactPopup(key, command, Reset); } else if (config is RotationConfigString s) { @@ -839,7 +847,7 @@ private static void DrawRotationConfiguration() { set.SetValue(config.Name, val.ToString()); } - Searchable.ReactPopup(key, command, Reset); + ImGuiHelper.ReactPopup(key, command, Reset); continue; } else if (config is RotationConfigInt i) @@ -850,13 +858,13 @@ private static void DrawRotationConfiguration() { set.SetValue(config.Name, val.ToString()); } - Searchable.ReactPopup(key, command, Reset); + ImGuiHelper.ReactPopup(key, command, Reset); } else continue; ImGui.SameLine(); ImGui.TextWrapped(config.DisplayName); - Searchable.ReactPopup(key, command, Reset, false); + ImGuiHelper.ReactPopup(key, command, Reset, false); } } @@ -969,8 +977,8 @@ private static unsafe void DrawActions() string key = $"Action Macro Usage {item.Name} {item.ID}"; var cmd = ToCommandStr(OtherCommandType.DoActions, $"{item}-{5}"); - Searchable.DrawHotKeysPopup(key, cmd); - Searchable.ExecuteHotKeysPopup(key, cmd, item.Name, false); + ImGuiHelper.DrawHotKeysPopup(key, cmd); + ImGuiHelper.ExecuteHotKeysPopup(key, cmd, item.Name, false); } }); } @@ -1047,8 +1055,8 @@ private static unsafe void DrawActions() const string key = "Action Enable Popup"; var cmd = ToCommandStr(OtherCommandType.ToggleActions, _activeAction.ToString()); - Searchable.DrawHotKeysPopup(key, cmd); - Searchable.ExecuteHotKeysPopup(key, cmd, string.Empty, false); + ImGuiHelper.DrawHotKeysPopup(key, cmd); + ImGuiHelper.ExecuteHotKeysPopup(key, cmd, string.Empty, false); enable = _activeAction.IsInCooldown; if (ImGui.Checkbox($"{LocalizationManager.RightLang.ConfigWindow_Actions_ShowOnCDWindow}##{_activeAction.Name}InCooldown", ref enable)) @@ -1446,7 +1454,7 @@ private static void DrawStatusList(string name, HashSet statuses, Status[] var key = "Status" + status.RowId.ToString(); - Searchable.DrawHotKeysPopup(key, string.Empty, (LocalizationManager.RightLang.ConfigWindow_List_Remove, Delete, new string[] { "Delete" })); + ImGuiHelper.DrawHotKeysPopup(key, string.Empty, (LocalizationManager.RightLang.ConfigWindow_List_Remove, Delete, new string[] { "Delete" })); if (IconSet.GetTexture(status.Icon, out var texture, notLoadId)) { @@ -1456,7 +1464,7 @@ private static void DrawStatusList(string name, HashSet statuses, Status[] } ImGuiHelper.NoPaddingNoColorImageButton(texture.ImGuiHandle, new Vector2(24, 32) * _scale, "Status" + status.RowId.ToString()); - Searchable.ExecuteHotKeysPopup(key, string.Empty, $"{status.Name} ({status.RowId})", false, + ImGuiHelper.ExecuteHotKeysPopup(key, string.Empty, $"{status.Name} ({status.RowId})", false, (Delete, new Dalamud.Game.ClientState.Keys.VirtualKey[] { Dalamud.Game.ClientState.Keys.VirtualKey.DELETE })); } } @@ -1600,11 +1608,11 @@ private static void DrawActionsList(string name, HashSet actions) var key = "Action" + action.RowId.ToString(); - Searchable.DrawHotKeysPopup(key, string.Empty, (LocalizationManager.RightLang.ConfigWindow_List_Remove, Reset, new string[] { "Delete" })); + ImGuiHelper.DrawHotKeysPopup(key, string.Empty, (LocalizationManager.RightLang.ConfigWindow_List_Remove, Reset, new string[] { "Delete" })); ImGui.Selectable($"{action.Name} ({action.RowId})"); - Searchable.ExecuteHotKeysPopup(key, string.Empty, string.Empty, false, (Reset, new Dalamud.Game.ClientState.Keys.VirtualKey[] { Dalamud.Game.ClientState.Keys.VirtualKey.DELETE })); + ImGuiHelper.ExecuteHotKeysPopup(key, string.Empty, string.Empty, false, (Reset, new Dalamud.Game.ClientState.Keys.VirtualKey[] { Dalamud.Game.ClientState.Keys.VirtualKey.DELETE })); } if (removeId != 0) @@ -1730,7 +1738,7 @@ private static void DrawListTerritories() var key = "Beneficial Positions" + i.ToString(); - Searchable.DrawHotKeysPopup(key, string.Empty, (LocalizationManager.RightLang.ConfigWindow_List_Remove, Reset, new string[] { "Delete" })); + ImGuiHelper.DrawHotKeysPopup(key, string.Empty, (LocalizationManager.RightLang.ConfigWindow_List_Remove, Reset, new string[] { "Delete" })); ImGui.Selectable(pts[i].ToString()); @@ -1739,7 +1747,7 @@ private static void DrawListTerritories() HoveredPosition = pts[i]; } - Searchable.ExecuteHotKeysPopup(key, string.Empty, string.Empty, false, (Reset, new Dalamud.Game.ClientState.Keys.VirtualKey[] { Dalamud.Game.ClientState.Keys.VirtualKey.DELETE })); + ImGuiHelper.ExecuteHotKeysPopup(key, string.Empty, string.Empty, false, (Reset, new Dalamud.Game.ClientState.Keys.VirtualKey[] { Dalamud.Game.ClientState.Keys.VirtualKey.DELETE })); } if (removeIndex > -1) { diff --git a/RotationSolver/UI/RotationConfigWindow_Config.cs b/RotationSolver/UI/RotationConfigWindow_Config.cs index 9e935ecef..9d1b135ff 100644 --- a/RotationSolver/UI/RotationConfigWindow_Config.cs +++ b/RotationSolver/UI/RotationConfigWindow_Config.cs @@ -666,7 +666,7 @@ void Down() var key = $"Targeting Type Pop Up: {i}"; - Searchable.DrawHotKeysPopup(key, string.Empty, + ImGuiHelper.DrawHotKeysPopup(key, string.Empty, (LocalizationManager.RightLang.ConfigWindow_List_Remove, Delete, new string[] { "Delete" }), (LocalizationManager.RightLang.ConfigWindow_Actions_MoveUp, Up, new string[] { "↑" }), (LocalizationManager.RightLang.ConfigWindow_Actions_MoveDown, Down, new string[] { "↓" })); @@ -680,7 +680,7 @@ void Down() Service.Config.GlobalConfig.TargetingTypes[i] = (TargetingType)targingType; } - Searchable.ExecuteHotKeysPopup(key, string.Empty, string.Empty, true, + ImGuiHelper.ExecuteHotKeysPopup(key, string.Empty, string.Empty, true, (Delete, new VirtualKey[] { VirtualKey.DELETE }), (Up, new VirtualKey[] { VirtualKey.UP }), (Down, new VirtualKey[] { VirtualKey.DOWN })); diff --git a/RotationSolver/UI/SearchableConfigs/Searchable.cs b/RotationSolver/UI/SearchableConfigs/Searchable.cs index 1e35bc767..b742389a3 100644 --- a/RotationSolver/UI/SearchableConfigs/Searchable.cs +++ b/RotationSolver/UI/SearchableConfigs/Searchable.cs @@ -53,7 +53,7 @@ public void Draw(Job job, bool mustDraw = false) DrawMain(job); - PrepareGroup(Popup_Key, Command, () => ResetToDefault(job)); + ImGuiHelper.PrepareGroup(Popup_Key, Command, () => ResetToDefault(job)); } protected abstract void DrawMain(Job job); @@ -84,108 +84,10 @@ protected void ShowTooltip(Job job, bool showHand = true) }); } - ReactPopup(Popup_Key, Command, () => ResetToDefault(job), showHand); + ImGuiHelper.ReactPopup(Popup_Key, Command, () => ResetToDefault(job), showHand); } - public static void PrepareGroup(string key, string command, Action reset) - { - DrawHotKeysPopup(key, command, ("Reset to Default Value.", reset, new string[] { "Backspace" })); - } - public static void ReactPopup(string key, string command, Action reset, bool showHand = true) - { - ExecuteHotKeysPopup(key, command, string.Empty, showHand, (reset, new VirtualKey[] { VirtualKey.BACK })); - } - public static void DrawHotKeysPopup(string key, string command, params (string name, Action action, string[] keys)[] pairs) - { - if (ImGui.BeginPopup(key)) - { - if (ImGui.BeginTable(key, 2, ImGuiTableFlags.BordersOuter)) - { - foreach (var (name, action, keys) in pairs) - { - if (action == null) continue; - DrawHotKeys(name, action, keys); - } - if (!string.IsNullOrEmpty(command)) - { - DrawHotKeys($"Execute \"{command}\"", () => ExecuteCommand(command), "Alt"); - - DrawHotKeys($"Copy \"{command}\"", () => CopyCommand(command), "Ctrl"); - } - ImGui.EndTable(); - } - - ImGui.EndPopup(); - } - } - public static void ExecuteHotKeysPopup(string key, string command, string tooltip, bool showHand, params (Action action, VirtualKey[] keys)[] pairs) - { - if (!ImGui.IsItemHovered()) return; - if (!string.IsNullOrEmpty(tooltip)) ImguiTooltips.ShowTooltip(tooltip); - - if (showHand) ImGui.SetMouseCursor(ImGuiMouseCursor.Hand); - - if (ImGui.IsMouseClicked(ImGuiMouseButton.Right)) - { - if (!ImGui.IsPopupOpen(key)) - { - ImGui.OpenPopup(key); - } - } - - foreach (var (action, keys) in pairs) - { - if (action == null) continue; - ExecuteHotKeys(action, keys); - } - if (!string.IsNullOrEmpty(command)) - { - ExecuteHotKeys(() => ExecuteCommand(command), VirtualKey.MENU); - ExecuteHotKeys(() => CopyCommand(command), VirtualKey.CONTROL); - } - } - - private static void ExecuteCommand(string command) - { - Svc.Commands.ProcessCommand(command); - } - - private static void CopyCommand(string command) - { - ImGui.SetClipboardText(command); - Notify.Success($"\"{command}\" copied to clipboard."); - } - - - private static void ExecuteHotKeys(Action action, params VirtualKey[] keys) - { - if (action == null) return; - var name = string.Join(' ', keys); - - if (!_lastChecked.TryGetValue(name, out var last)) last = false; - var now = keys.All(k => Svc.KeyState[k]); - _lastChecked[name] = now; - - if (!last && now) action(); - } - - private static void DrawHotKeys(string name, Action action, params string[] keys) - { - if (action == null) return; - - ImGui.TableNextRow(); - ImGui.TableNextColumn(); - if (ImGui.Selectable(name)) - { - action(); - ImGui.CloseCurrentPopup(); - } - - ImGui.TableNextColumn(); - ImGui.TextDisabled(string.Join(' ', keys)); - } - private static readonly SortedList _lastChecked = new(); protected static void DrawJobIcon() diff --git a/RotationSolver/Updaters/ActionSequencerUpdater.cs b/RotationSolver/Updaters/ActionSequencerUpdater.cs index 59e7c209c..dfd447126 100644 --- a/RotationSolver/Updaters/ActionSequencerUpdater.cs +++ b/RotationSolver/Updaters/ActionSequencerUpdater.cs @@ -1,8 +1,12 @@ -using ECommons.ImGuiMethods; +using Dalamud.Interface.Colors; +using ECommons.DalamudServices; +using ECommons.ImGuiMethods; using RotationSolver.ActionSequencer; using RotationSolver.Basic.Configuration; +using RotationSolver.Localization; using RotationSolver.UI; using System.Diagnostics; +using System.Windows.Forms; namespace RotationSolver.Updaters; @@ -90,6 +94,7 @@ private static void AddNew() private static void Delete(string name) { _conditionSet = _conditionSet.Where(c => c.Name != name); + File.Delete(_actionSequencerFolder + $"\\{name}.json"); } public static void DrawHeader(float width) @@ -105,51 +110,41 @@ public static void DrawHeader(float width) ImGui.SameLine(); } - var index = Service.Config.GetValue(PluginConfigInt.ActionSequencerIndex); - var combos = ConditionSetsName; - if (combos != null && combos.Length > index) - { - ImGui.SetNextItemWidth(ImGui.CalcTextSize(combos[index]).X + width); - } - else - { - ImGui.SetNextItemWidth(width); - } + ImGui.SetNextItemWidth(width); - if(ImGui.Combo("##MajorConditionCombo", ref index, combos, combos.Length)) + if(ImGui.BeginCombo("##MajorConditionCombo", "")) { - Service.Config.SetValue(PluginConfigInt.ActionSequencerIndex, index); - } - - if (hasSet) - { - ImGui.SameLine(); - if (ImGuiEx.IconButton(FontAwesomeIcon.Ban, "##DeleteTimelineConditionSet")) + for (int i = 0; i < combos.Length; i++) { - Delete(set.Name); - } + void DeleteFile() + { + Delete(combos[i]); + } - ImGui.SameLine(); - } + var key = "Condition Set At " + i.ToString(); - ImGui.SameLine(); + ImGuiHelper.DrawHotKeysPopup(key, string.Empty, (LocalizationManager.RightLang.ConfigWindow_List_Remove, DeleteFile, new string[] { "Delete" })); - if (ImGuiEx.IconButton(FontAwesomeIcon.Plus, "##AddNewTimelineConditionSet")) - { - AddNew(); - } - ImGui.SameLine(); - if (ImGuiEx.IconButton(FontAwesomeIcon.Folder, "##OpenDefinationFolder")) - { - Process.Start("explorer.exe", _actionSequencerFolder); - } + if (ImGui.Selectable(combos[i])) + { + Service.Config.SetValue(PluginConfigInt.ActionSequencerIndex, i); + } - ImGui.SameLine(); - if (ImGuiEx.IconButton(FontAwesomeIcon.Save, "##SaveTheConditions")) - { - SaveFiles(); + ImGuiHelper.ExecuteHotKeysPopup(key, string.Empty, string.Empty, false, + (DeleteFile, new Dalamud.Game.ClientState.Keys.VirtualKey[] { Dalamud.Game.ClientState.Keys.VirtualKey.DELETE })); + } + + ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.HealerGreen); + ImGui.PushFont(UiBuilder.IconFont); + if (ImGui.Selectable(FontAwesomeIcon.Plus.ToIconString())) + { + AddNew(); + } + ImGui.PopFont(); + ImGui.PopStyleColor(); + ImGui.EndCombo(); } ImGui.SameLine(); @@ -157,5 +152,6 @@ public static void DrawHeader(float width) { LoadFiles(); } + ImguiTooltips.HoveredTooltip(LocalizationManager.RightLang.ActionSequencer_Load); } }