From 57801899b294378e04d912e7630254a4d547d093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E6=B0=B4?= <1123993881@qq.com> Date: Sun, 13 Aug 2023 16:58:00 +0800 Subject: [PATCH] fix: added status list. --- Resources/InvincibleStatus.json | 3 +- RotationSolver.Basic/Data/IconSet.cs | 4 +- RotationSolver/UI/RotationConfigWindowNew.cs | 109 ++++++++++++++---- .../UI/RotationConfigWindowNew_Config.cs | 5 +- 4 files changed, 91 insertions(+), 30 deletions(-) diff --git a/Resources/InvincibleStatus.json b/Resources/InvincibleStatus.json index b095d6bd8..b85d5d62f 100644 --- a/Resources/InvincibleStatus.json +++ b/Resources/InvincibleStatus.json @@ -1,6 +1,5 @@ [ 151, 198, - 469, - 3012 + 469 ] \ No newline at end of file diff --git a/RotationSolver.Basic/Data/IconSet.cs b/RotationSolver.Basic/Data/IconSet.cs index 533983443..0bcee7afd 100644 --- a/RotationSolver.Basic/Data/IconSet.cs +++ b/RotationSolver.Basic/Data/IconSet.cs @@ -126,9 +126,9 @@ public static TextureWrap GetTexture(uint id) => ThreadLoadImageHandler.TryGetIconTextureWrap(id, false, out var texture) ? texture : ThreadLoadImageHandler.TryGetIconTextureWrap(0, false, out texture) ? texture : null; - public static bool GetTexture(uint id, out TextureWrap texture) + public static bool GetTexture(uint id, out TextureWrap texture, uint @default = 0) => ThreadLoadImageHandler.TryGetIconTextureWrap(id, false, out texture) - || ThreadLoadImageHandler.TryGetIconTextureWrap(0, false, out texture); + || ThreadLoadImageHandler.TryGetIconTextureWrap(@default, false, out texture); /// /// Get Texture from path. diff --git a/RotationSolver/UI/RotationConfigWindowNew.cs b/RotationSolver/UI/RotationConfigWindowNew.cs index 77219f3be..162fc2826 100644 --- a/RotationSolver/UI/RotationConfigWindowNew.cs +++ b/RotationSolver/UI/RotationConfigWindowNew.cs @@ -6,10 +6,13 @@ using ECommons.ExcelServices; using ECommons.GameHelpers; using ECommons.ImGuiMethods; +using F23.StringSimilarity; +using ImGuiNET; using ImGuiScene; using Lumina.Excel.GeneratedSheets; using RotationSolver.ActionSequencer; using RotationSolver.Basic.Configuration; +using RotationSolver.Basic.Data; using RotationSolver.Data; using RotationSolver.Helpers; using RotationSolver.Localization; @@ -18,6 +21,7 @@ using RotationSolver.UI.SearchableSettings; using RotationSolver.Updaters; using System.Diagnostics; +using System.Windows.Forms; using GAction = Lumina.Excel.GeneratedSheets.Action; namespace RotationSolver.UI; @@ -87,7 +91,7 @@ public override void Draw() private void DrawSideBar() { - if (BeginChild("Rotation Solver Side bar")) + if (BeginChild("Rotation Solver Side bar", -Vector2.One, false, ImGuiWindowFlags.NoScrollbar)) { var wholeWidth = ImGui.GetWindowSize().X; @@ -112,6 +116,7 @@ private void DrawSideBar() { if (ImGui.BeginPopup("Searching Popup")) { + ImGui.SetNextItemWidth(200 * _scale); SearchingBox(); if (ImGui.IsKeyDown(ImGuiKey.Enter)) { @@ -141,7 +146,7 @@ private void DrawSideBar() DrawItemMiddle(() => { var cursor = ImGui.GetCursorPos(); - if (NoPaddingNoColorImageButton(icon.ImGuiHandle, Vector2.One * iconSize)) + if (NoPaddingNoColorImageButton(icon.ImGuiHandle, Vector2.One * iconSize, item.ToString())) { _activeTab = item; } @@ -172,7 +177,7 @@ private void DrawSideBar() var result = false; DrawItemMiddle(() => { - ImGui.SetCursorPosY(ImGui.GetWindowSize().Y - size.Y); + ImGui.SetCursorPosY(ImGui.GetWindowSize().Y + ImGui.GetScrollY() - size.Y); result = NoPaddingNoColorImageButton(texture.ImGuiHandle, size); }, wholeWidth, size.X); @@ -209,13 +214,13 @@ private void DrawHeader(float wholeWidth) var size = MathF.Max(MathF.Min(wholeWidth, _scale * 120), _scale * MIN_COLUMN_WIDTH); int realFrame = FRAME_COUNT; - if (Service.ConfigNew.GetValue(Basic.Configuration.PluginConfigBool.DrawIconAnimation)) + if (Service.ConfigNew.GetValue(PluginConfigBool.DrawIconAnimation)) { var frame = Environment.TickCount / 34; //30 realFrame = frame % FRAME_COUNT; if (realFrame == 0) realFrame = FRAME_COUNT; } - if (GetLocalImage(realFrame.ToString("0000"), out var logo) && IconSet.GetTexture(0, out var overlay)) + if (GetLocalImage(realFrame.ToString("0000"), out var logo) && IconSet.GetTexture((uint)0, out var overlay)) { DrawItemMiddle(() => { @@ -1217,28 +1222,26 @@ internal static TerritoryTypeTexture[] AllTerritories } } - private static StatusTexture[] _allDispelStatus = null; - internal static StatusTexture[] AllDispelStatus + private static Status[] _allDispelStatus = null; + internal static Status[] AllDispelStatus { get { _allDispelStatus ??= Service.GetSheet() .Where(s => s.CanDispel) - .Select(s => new StatusTexture(s)) .ToArray(); return _allDispelStatus; } } - private static StatusTexture[] _allInvStatus = null; - internal static StatusTexture[] AllInvStatus + private static Status[] _allInvStatus = null; + internal static Status[] AllInvStatus { get { _allInvStatus ??= Service.GetSheet() .Where(s => !s.CanDispel && !s.LockMovement && !s.IsGaze && !s.IsFcBuff && s.HitEffect.Row == 16 && s.ClassJobCategory.Row == 1 && s.StatusCategory == 1 && !string.IsNullOrEmpty(s.Name.ToString()) && s.Icon != 0) - .Select(s => new StatusTexture(s)) .ToArray(); return _allInvStatus; } @@ -1283,31 +1286,51 @@ private static void DrawIDsStatus() ImGui.TableNextRow(); ImGui.TableNextColumn(); - DrawInvincibility(); + DrawStatusList(nameof(OtherConfiguration.InvincibleStatus), OtherConfiguration.InvincibleStatus, AllInvStatus); ImGui.TableNextColumn(); - DrawDangerousStatus(); + DrawStatusList(nameof(OtherConfiguration.DangerousStatus), OtherConfiguration.DangerousStatus, AllDispelStatus); ImGui.EndTable(); } } - private static void DrawInvincibility() + static string _statusSearching = string.Empty; + + private static void DrawStatusList(string name, HashSet statuses, Status[] allStatus) { uint removeId = 0; + uint notLoadId = 10100; + var popupId = "Rotation Solver Popup" + name; - if(BeginChild("Rotation Solver InvincibleStatus")) + if (BeginChild("Rotation Solver Child" + name)) { var count = Math.Max(1, (int)MathF.Floor(ImGui.GetWindowWidth() / (24 * _scale + ImGui.GetStyle().ItemSpacing.X))); - var index = 0; - foreach (var statusId in OtherConfiguration.InvincibleStatus) + + if (IconSet.GetTexture(16220, out var text)) + { + if (index++ % count != 0) + { + ImGui.SameLine(); + } + if (NoPaddingNoColorImageButton(text.ImGuiHandle, new Vector2(24, 32) * _scale)) + { + if (!ImGui.IsPopupOpen(popupId)) ImGui.OpenPopup(popupId); + } + ImguiTooltips.HoveredTooltip("Add Status"); + } + + foreach (var statusId in statuses) { void Reset() => removeId = statusId; var status = Service.GetSheet().GetRow(statusId); + if (status == null) continue; + var key = "Status" + statusId; + if (ImGui.BeginPopup(key)) { if (ImGui.BeginTable(key, 2, ImGuiTableFlags.BordersOuter)) @@ -1324,7 +1347,7 @@ private static void DrawInvincibility() { ImGui.SameLine(); } - NoPaddingNoColorImageButton(texture.ImGuiHandle, new Vector2(24, 32) * _scale, "Status"); + NoPaddingNoColorImageButton(texture.ImGuiHandle, new Vector2(24, 32) * _scale, "Status" + statusId.ToString()); if (ImGui.IsItemHovered()) { @@ -1337,20 +1360,52 @@ private static void DrawInvincibility() } } } + + + if (ImGui.BeginPopup(popupId)) + { + ImGui.SetNextItemWidth(200 * _scale); + ImGui.InputTextWithHint("##Searching the status", "Status name or id", ref _statusSearching, 128); + + ImGui.Spacing(); + + if(ImGui.BeginChild("Rotation Solver Add Status", new Vector2(-1, 400))) + { + count = Math.Max(1, (int)MathF.Floor(ImGui.GetWindowWidth() / (24 * _scale + ImGui.GetStyle().ItemSpacing.X))); + index = 0; + + foreach (var status in allStatus.OrderBy(s => StringComparer.Distance($"{s.Name}{s.RowId}", _statusSearching))) + { + if (IconSet.GetTexture(status.Icon, out var texture, notLoadId)) + { + if (index++ % count != 0) + { + ImGui.SameLine(); + } + if (NoPaddingNoColorImageButton(texture.ImGuiHandle, new Vector2(24, 32) * _scale, "Adding" + status.RowId.ToString())) + { + statuses.Add(status.RowId); + OtherConfiguration.SaveInvincibleStatus(); + ImGui.CloseCurrentPopup(); + } + ImguiTooltips.HoveredTooltip($"{status.Name} ({status.RowId})"); + } + } + ImGui.EndChild(); + } + + ImGui.EndPopup(); + } + ImGui.EndChild(); } if (removeId != 0) { - OtherConfiguration.InvincibleStatus.Remove(removeId); + statuses.Remove(removeId); OtherConfiguration.SaveInvincibleStatus(); } } - private static void DrawDangerousStatus() - { - - } - #endregion private static readonly CollapsingHeaderGroup _debugHeader = new(new() @@ -1503,6 +1558,12 @@ private static bool BeginChild(string str_id, Vector2 size) return ImGui.BeginChild(str_id, size); } + private static bool BeginChild(string str_id, Vector2 size, bool border, ImGuiWindowFlags flags) + { + if (IsFailed()) return false; + return ImGui.BeginChild(str_id, size, border, flags); + } + private static bool IsFailed() { var style = ImGui.GetStyle(); diff --git a/RotationSolver/UI/RotationConfigWindowNew_Config.cs b/RotationSolver/UI/RotationConfigWindowNew_Config.cs index 05c073457..a1369be90 100644 --- a/RotationSolver/UI/RotationConfigWindowNew_Config.cs +++ b/RotationSolver/UI/RotationConfigWindowNew_Config.cs @@ -7,6 +7,8 @@ namespace RotationSolver.UI; public partial class RotationConfigWindowNew { + private static readonly Levenshtein StringComparer = new (); + private string _searchText = string.Empty; private ISearchable[] _searchResults = Array.Empty(); private void SearchingBox() @@ -18,12 +20,11 @@ private void SearchingBox() const int MAX_RESULT_LENGTH = 20; _searchResults = new ISearchable[MAX_RESULT_LENGTH]; - var l = new Levenshtein(); var enumerator = GetType().GetRuntimeFields() .Where(f => f.FieldType == typeof(ISearchable[]) && f.IsInitOnly) .SelectMany(f => (ISearchable[])f.GetValue(this)) - .OrderBy(i => l.Distance(i.SearchingKey, _searchText)) + .OrderBy(i => StringComparer.Distance(i.SearchingKey, _searchText)) .Select(GetParent).GetEnumerator(); int index = 0;