From fdb570b9a43b9c8d3132cb2869cafe6947328544 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 20:25:34 +0800 Subject: [PATCH] fix: add territory list. --- Resources/NoHostileNames.json | 6 +- RotationSolver.Basic/Data/IconSet.cs | 3 +- RotationSolver/Localization/Localization.json | 14 +- RotationSolver/Localization/Strings.cs | 18 +++ RotationSolver/UI/RotationConfigWindowNew.cs | 150 +++++++++++++++--- 5 files changed, 169 insertions(+), 22 deletions(-) diff --git a/Resources/NoHostileNames.json b/Resources/NoHostileNames.json index 9e26dfeeb..cc3ca2316 100644 --- a/Resources/NoHostileNames.json +++ b/Resources/NoHostileNames.json @@ -1 +1,5 @@ -{} \ No newline at end of file +{ + "0": [ + "" + ] +} \ No newline at end of file diff --git a/RotationSolver.Basic/Data/IconSet.cs b/RotationSolver.Basic/Data/IconSet.cs index 0bcee7afd..9adaf098a 100644 --- a/RotationSolver.Basic/Data/IconSet.cs +++ b/RotationSolver.Basic/Data/IconSet.cs @@ -128,7 +128,8 @@ public static TextureWrap GetTexture(uint id) public static bool GetTexture(uint id, out TextureWrap texture, uint @default = 0) => ThreadLoadImageHandler.TryGetIconTextureWrap(id, false, out texture) - || ThreadLoadImageHandler.TryGetIconTextureWrap(@default, false, out texture); + || ThreadLoadImageHandler.TryGetIconTextureWrap(@default, false, out texture) + || ThreadLoadImageHandler.TryGetIconTextureWrap(0, false, out texture); /// /// Get Texture from path. diff --git a/RotationSolver/Localization/Localization.json b/RotationSolver/Localization/Localization.json index d66618877..b7d66d292 100644 --- a/RotationSolver/Localization/Localization.json +++ b/RotationSolver/Localization/Localization.json @@ -450,5 +450,17 @@ "ConfigWindow_Rotations_UserName": "User Name", "ConfigWindow_Rotations_Repository": "Repository", "ConfigWindow_Rotations_FileName": "File Name", - "ConfigWindow_Rotations_Library": "The folder contains rotation libs or the download url about rotation lib." + "ConfigWindow_Rotations_Library": "The folder contains rotation libs or the download url about rotation lib.", + "ConfigWindow_List_Statuses": "Statuses", + "ConfigWindow_List_Actions": "Actions", + "ConfigWindow_List_Territories": "Territories", + "ConfigWindow_List_StatusNameOrId": "Status name or id", + "ConfigWindow_List_AddStatus": "Add Status", + "ConfigWindow_List_Remove": "Remove", + "ConfigWindow_List_ActionNameOrId": "Action name or id", + "ConfigWindow_List_AddAction": "Add Action", + "ConfigWindow_List_TerritoryEverywhere": "Everywhere", + "ConfigWindow_List_AddTerritory": "Territory name or id", + "ConfigWindow_List_BeneficialLocations": "Beneficial locations", + "ConfigWindow_List_NoHostilesName": "The name of object that you don't want to attack" } \ No newline at end of file diff --git a/RotationSolver/Localization/Strings.cs b/RotationSolver/Localization/Strings.cs index 8d054333b..65fddc241 100644 --- a/RotationSolver/Localization/Strings.cs +++ b/RotationSolver/Localization/Strings.cs @@ -656,4 +656,22 @@ internal partial class Strings public string ConfigWindow_Rotations_FileName { get; set; } = "File Name"; public string ConfigWindow_Rotations_Library { get; set; } = "The folder contains rotation libs or the download url about rotation lib."; + + public string ConfigWindow_List_Statuses { get; set; } = "Statuses"; + 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_List_AddStatus { get; set; } = "Add Status"; + public string ConfigWindow_List_Remove { get; set; } = "Remove"; + + public string ConfigWindow_List_ActionNameOrId { get; set; } = "Action name or id"; + public string ConfigWindow_List_AddAction { get; set; } = "Add Action"; + + public string ConfigWindow_List_TerritoryEverywhere { get; set; } = "Everywhere"; + + public string ConfigWindow_List_AddTerritory{ get; set; } = "Territory name or id"; + + public string ConfigWindow_List_BeneficialLocations { get; set; } = "Beneficial locations"; + public string ConfigWindow_List_NoHostilesName { get; set; } = "The name of object that you don't want to attack"; + } diff --git a/RotationSolver/UI/RotationConfigWindowNew.cs b/RotationSolver/UI/RotationConfigWindowNew.cs index 382ce2f95..05d71e5c4 100644 --- a/RotationSolver/UI/RotationConfigWindowNew.cs +++ b/RotationSolver/UI/RotationConfigWindowNew.cs @@ -21,6 +21,7 @@ using RotationSolver.UI.SearchableSettings; using RotationSolver.Updaters; using System; +using System.Collections.Generic; using System.Diagnostics; using System.Windows.Forms; using GAction = Lumina.Excel.GeneratedSheets.Action; @@ -108,6 +109,8 @@ private void DrawSideBar() { ImGui.SetNextItemWidth(wholeWidth); SearchingBox(); + + ImGui.Spacing(); } else { @@ -1090,7 +1093,7 @@ private static void DrawRotationsLoaded() if (lastRole == role && lastRole != JobRole.None) ImGui.SameLine(); lastRole = role; - if(IconSet.GetTexture(IconSet.GetJobIcon(jobs.First(), IconType.Framed), out var texture)) + if(IconSet.GetTexture(IconSet.GetJobIcon(jobs.First(), IconType.Framed), out var texture, 62574)) ImGui.Image(texture.ImGuiHandle, Vector2.One * 30 * _scale); ImGuiHelper.HoveredString(string.Join('\n', jobs)); @@ -1208,8 +1211,8 @@ private static void DrawRotationsLibraries() #region Ids private static uint _territoryId = 0; - private static TerritoryTypeTexture[] _allTerritories = null; - internal static TerritoryTypeTexture[] AllTerritories + private static TerritoryType[] _allTerritories = null; + internal static TerritoryType[] AllTerritories { get { @@ -1217,7 +1220,6 @@ internal static TerritoryTypeTexture[] AllTerritories .Where(t => t != null && t.ContentFinderCondition?.Value?.ContentType?.Value?.RowId != 0) .OrderBy(t => t.ContentFinderCondition?.Value?.ContentType?.Value?.RowId) - .Select(t => new TerritoryTypeTexture(t)) .ToArray(); return _allTerritories; } @@ -1268,13 +1270,14 @@ private static void DrawList() } private static readonly CollapsingHeaderGroup _idsHeader = new(new() { - { () => "Statuses", DrawActionsStatuses}, - { () => "Actions", DrawListActions}, + { () => LocalizationManager.RightLang.ConfigWindow_List_Statuses, DrawActionsStatuses}, + { () => LocalizationManager.RightLang.ConfigWindow_List_Actions, DrawListActions}, + { () => LocalizationManager.RightLang.ConfigWindow_List_Territories, DrawListTerritories}, }); private static void DrawActionsStatuses() { ImGui.SetNextItemWidth(ImGui.GetWindowWidth() - ImGui.GetStyle().WindowPadding.X * 2); - ImGui.InputTextWithHint("##Searching the action", "Status name or id", ref _statusSearching, 128); + ImGui.InputTextWithHint("##Searching the action", LocalizationManager.RightLang.ConfigWindow_List_StatusNameOrId, ref _statusSearching, 128); if (ImGui.BeginTable("Rotation Solver List Statuses", 2, ImGuiTableFlags.Borders | ImGuiTableFlags.Resizable | ImGuiTableFlags.SizingStretchSame)) { @@ -1300,7 +1303,6 @@ private static void DrawActionsStatuses() } static string _statusSearching = string.Empty; - private static void DrawStatusList(string name, HashSet statuses, Status[] allStatus) { uint removeId = 0; @@ -1319,11 +1321,11 @@ private static void DrawStatusList(string name, HashSet statuses, Status[] { ImGui.SameLine(); } - if (NoPaddingNoColorImageButton(text.ImGuiHandle, new Vector2(24, 32) * _scale)) + if (NoPaddingNoColorImageButton(text.ImGuiHandle, new Vector2(24, 32) * _scale, name)) { if (!ImGui.IsPopupOpen(popupId)) ImGui.OpenPopup(popupId); } - ImguiTooltips.HoveredTooltip("Add Status"); + ImguiTooltips.HoveredTooltip(LocalizationManager.RightLang.ConfigWindow_List_AddStatus); } foreach (var status in statuses.Select(a => Service.GetSheet().GetRow(a)) @@ -1339,13 +1341,13 @@ private static void DrawStatusList(string name, HashSet statuses, Status[] { if (ImGui.BeginTable(key, 2, ImGuiTableFlags.BordersOuter)) { - Searchable.DrawHotKeys("Remove", Reset, "Delete"); + Searchable.DrawHotKeys(LocalizationManager.RightLang.ConfigWindow_List_Remove, Reset, "Delete"); ImGui.EndTable(); } ImGui.EndPopup(); } - if (IconSet.GetTexture(status.Icon, out var texture)) + if (IconSet.GetTexture(status.Icon, out var texture, notLoadId)) { if (index++ % count != 0) { @@ -1368,11 +1370,11 @@ private static void DrawStatusList(string name, HashSet statuses, Status[] if (ImGui.BeginPopup(popupId)) { ImGui.SetNextItemWidth(200 * _scale); - ImGui.InputTextWithHint("##Searching the status", "Status name or id", ref _statusSearching, 128); + ImGui.InputTextWithHint("##Searching the status", LocalizationManager.RightLang.ConfigWindow_List_StatusNameOrId, ref _statusSearching, 128); ImGui.Spacing(); - if(ImGui.BeginChild("Rotation Solver Add Status", new Vector2(-1, 400))) + if(ImGui.BeginChild("Rotation Solver Add Status", new Vector2(-1, 400 * _scale))) { count = Math.Max(1, (int)MathF.Floor(ImGui.GetWindowWidth() / (24 * _scale + ImGui.GetStyle().ItemSpacing.X))); index = 0; @@ -1414,7 +1416,7 @@ private static void DrawStatusList(string name, HashSet statuses, Status[] private static void DrawListActions() { ImGui.SetNextItemWidth(ImGui.GetWindowWidth() - ImGui.GetStyle().WindowPadding.X * 2); - ImGui.InputTextWithHint("##Searching the action", "Action name or id", ref _actionSearching, 128); + ImGui.InputTextWithHint("##Searching the action", LocalizationManager.RightLang.ConfigWindow_List_ActionNameOrId, ref _actionSearching, 128); if (ImGui.BeginTable("Rotation Solver List Actions", 2, ImGuiTableFlags.Borders | ImGuiTableFlags.Resizable | ImGuiTableFlags.SizingStretchSame)) { @@ -1446,7 +1448,7 @@ private static void DrawActionsList(string name, HashSet actions) var popupId = "Rotation Solver Popup" + name; - if (ImGui.Button("Add Action")) + if (ImGui.Button(LocalizationManager.RightLang.ConfigWindow_List_AddAction + "##" + name)) { if (!ImGui.IsPopupOpen(popupId)) ImGui.OpenPopup(popupId); } @@ -1468,7 +1470,7 @@ private static void DrawActionsList(string name, HashSet actions) { if (ImGui.BeginTable(key, 2, ImGuiTableFlags.BordersOuter)) { - Searchable.DrawHotKeys("Remove", Reset, "Delete"); + Searchable.DrawHotKeys(LocalizationManager.RightLang.ConfigWindow_List_Remove, Reset, "Delete"); ImGui.EndTable(); } @@ -1490,11 +1492,11 @@ private static void DrawActionsList(string name, HashSet actions) if (ImGui.BeginPopup(popupId)) { ImGui.SetNextItemWidth(200 * _scale); - ImGui.InputTextWithHint("##Searching the action pop up", "Action name or id", ref _actionSearching, 128); + ImGui.InputTextWithHint("##Searching the action pop up", LocalizationManager.RightLang.ConfigWindow_List_ActionNameOrId, ref _actionSearching, 128); ImGui.Spacing(); - if (ImGui.BeginChild("Rotation Solver Add action", new Vector2(-1, 400))) + if (ImGui.BeginChild("Rotation Solver Add action", new Vector2(-1, 400 * _scale))) { foreach (var action in AllActions.OrderBy(s => StringComparer.Distance(s.Name, _actionSearching) + StringComparer.Distance(s.RowId.ToString(), _actionSearching))) @@ -1522,6 +1524,116 @@ private static void DrawActionsList(string name, HashSet actions) OtherConfiguration.Save(); } } + + private static string _territorySearching = string.Empty; + private static void DrawListTerritories() + { + var popupId = "Rotation Solver Choice about Territories"; + + if(ImGui.BeginPopup(popupId)) + { + if (ImGui.Selectable(LocalizationManager.RightLang.ConfigWindow_List_TerritoryEverywhere)) + { + _territoryId = 0; + } + + ImGui.SetNextItemWidth(300 * _scale); + ImGui.InputTextWithHint("##Searching the action", LocalizationManager.RightLang.ConfigWindow_List_AddTerritory, ref _territorySearching, 128); + + if (ImGui.BeginChild("Rotation Solver Territory Choice", new Vector2(-1, 400 * _scale))) + { + foreach (var territory in AllTerritories.OrderBy(s => StringComparer.Distance(s.Name, _territorySearching) + + StringComparer.Distance(s.RowId.ToString(), _territorySearching))) + { + var icon = territory?.ContentFinderCondition?.Value?.ContentType?.Value?.Icon ?? 0; + if (IconSet.GetTexture(icon, out var texture)) + { + if (NoPaddingNoColorImageButton(texture.ImGuiHandle, Vector2.One * 28 * _scale, territory.RowId.ToString())) + { + _territoryId = territory.RowId; + ImGui.CloseCurrentPopup(); + } + ImGui.SameLine(); + } + + if (ImGui.Selectable($"{territory.PlaceName?.Value?.Name} ({territory.RowId})")) + { + _territoryId = territory.RowId; + ImGui.CloseCurrentPopup(); + } + } + + ImGui.EndChild(); + } + ImGui.EndPopup(); + } + + ImGui.PushFont(ImGuiHelper.GetFont(16)); + ImGui.SetNextItemWidth(ImGui.GetWindowWidth() - ImGui.GetStyle().WindowPadding.X * 2); + if(ImGui.Selectable(Service.GetSheet().GetRow(_territoryId)?.PlaceName?.Value?.Name.ToString() ?? LocalizationManager.RightLang.ConfigWindow_List_TerritoryEverywhere + "##Territory Choice")) + { + if (!ImGui.IsPopupOpen(popupId)) ImGui.OpenPopup(popupId); + } + ImGui.PopFont(); + + if (ImGui.BeginTable("Rotation Solver List Territories", 2, ImGuiTableFlags.Borders | ImGuiTableFlags.Resizable | ImGuiTableFlags.SizingStretchSame)) + { + ImGui.TableSetupScrollFreeze(0, 1); + ImGui.TableNextRow(ImGuiTableRowFlags.Headers); + + ImGui.TableNextColumn(); + ImGui.TableHeader(LocalizationManager.RightLang.ConfigWindow_List_NoHostile); + + ImGui.TableNextColumn(); + ImGui.TableHeader(LocalizationManager.RightLang.ConfigWindow_List_BeneficialLocations); + + ImGui.TableNextRow(); + + ImGui.TableNextColumn(); + + var width = ImGui.GetColumnWidth() - ImGuiEx.CalcIconSize(FontAwesomeIcon.Ban).X - ImGui.GetStyle().ItemSpacing.X - 10 * _scale; + + if(!OtherConfiguration.NoHostileNames.TryGetValue(_territoryId, out var libs)) + { + OtherConfiguration.NoHostileNames[_territoryId] = libs = Array.Empty(); + } + + //Add one. + if (!libs.Any(string.IsNullOrEmpty)) + { + OtherConfiguration.NoHostileNames[_territoryId] = libs.Append(string.Empty).ToArray(); + } + + int removeIndex = -1; + for (int i = 0; i < libs.Length; i++) + { + ImGui.SetNextItemWidth(width); + if(ImGui.InputTextWithHint($"##Rotation Solver Territory Name {i}", LocalizationManager.RightLang.ConfigWindow_List_NoHostilesName, ref libs[i], 1024)) + { + OtherConfiguration.NoHostileNames[_territoryId] = libs; + OtherConfiguration.SaveNoHostileNames(); + } + ImGui.SameLine(); + + if (ImGuiHelper.IconButton(FontAwesomeIcon.Ban, $"##Rotation Solver Remove Territory Name {i}")) + { + removeIndex = i; + } + } + if (removeIndex > -1) + { + var list = libs.ToList(); + list.RemoveAt(removeIndex); + OtherConfiguration.NoHostileNames[_territoryId] = list.ToArray(); + OtherConfiguration.SaveNoHostileNames(); + } + ImGui.TableNextColumn(); + + ImGui.TextColored(ImGuiColors.ParsedBlue, "To be continued.."); + + ImGui.EndTable(); + } + } #endregion private static readonly CollapsingHeaderGroup _debugHeader = new(new()