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

Commit

Permalink
fix: add territory list.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 13, 2023
1 parent 1294709 commit fdb570b
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 22 deletions.
6 changes: 5 additions & 1 deletion Resources/NoHostileNames.json
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
{}
{
"0": [
""
]
}
3 changes: 2 additions & 1 deletion RotationSolver.Basic/Data/IconSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/// <summary>
/// Get Texture from path.
Expand Down
14 changes: 13 additions & 1 deletion RotationSolver/Localization/Localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
18 changes: 18 additions & 0 deletions RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

}
150 changes: 131 additions & 19 deletions RotationSolver/UI/RotationConfigWindowNew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -108,6 +109,8 @@ private void DrawSideBar()
{
ImGui.SetNextItemWidth(wholeWidth);
SearchingBox();

ImGui.Spacing();
}
else
{
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -1208,16 +1211,15 @@ 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
{
_allTerritories ??= Service.GetSheet<TerritoryType>()
.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;
}
Expand Down Expand Up @@ -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))
{
Expand All @@ -1300,7 +1303,6 @@ private static void DrawActionsStatuses()
}

static string _statusSearching = string.Empty;

private static void DrawStatusList(string name, HashSet<uint> statuses, Status[] allStatus)
{
uint removeId = 0;
Expand All @@ -1319,11 +1321,11 @@ private static void DrawStatusList(string name, HashSet<uint> 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<Status>().GetRow(a))
Expand All @@ -1339,13 +1341,13 @@ private static void DrawStatusList(string name, HashSet<uint> 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)
{
Expand All @@ -1368,11 +1370,11 @@ private static void DrawStatusList(string name, HashSet<uint> 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;
Expand Down Expand Up @@ -1414,7 +1416,7 @@ private static void DrawStatusList(string name, HashSet<uint> 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))
{
Expand Down Expand Up @@ -1446,7 +1448,7 @@ private static void DrawActionsList(string name, HashSet<uint> 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);
}
Expand All @@ -1468,7 +1470,7 @@ private static void DrawActionsList(string name, HashSet<uint> actions)
{
if (ImGui.BeginTable(key, 2, ImGuiTableFlags.BordersOuter))
{
Searchable.DrawHotKeys("Remove", Reset, "Delete");
Searchable.DrawHotKeys(LocalizationManager.RightLang.ConfigWindow_List_Remove, Reset, "Delete");
ImGui.EndTable();
}

Expand All @@ -1490,11 +1492,11 @@ private static void DrawActionsList(string name, HashSet<uint> 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)))
Expand Down Expand Up @@ -1522,6 +1524,116 @@ private static void DrawActionsList(string name, HashSet<uint> 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<TerritoryType>().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<string>();
}

//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()
Expand Down

0 comments on commit fdb570b

Please sign in to comment.