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

Commit

Permalink
fix: added status list.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 13, 2023
1 parent 20d59b4 commit 5780189
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 30 deletions.
3 changes: 1 addition & 2 deletions Resources/InvincibleStatus.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[
151,
198,
469,
3012
469
]
4 changes: 2 additions & 2 deletions RotationSolver.Basic/Data/IconSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/// <summary>
/// Get Texture from path.
Expand Down
109 changes: 85 additions & 24 deletions RotationSolver/UI/RotationConfigWindowNew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -112,6 +116,7 @@ private void DrawSideBar()
{
if (ImGui.BeginPopup("Searching Popup"))
{
ImGui.SetNextItemWidth(200 * _scale);
SearchingBox();
if (ImGui.IsKeyDown(ImGuiKey.Enter))
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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(() =>
{
Expand Down Expand Up @@ -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<Status>()
.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<Status>()
.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;
}
Expand Down Expand Up @@ -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<uint> 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<Status>().GetRow(statusId);
if (status == null) continue;

var key = "Status" + statusId;

if (ImGui.BeginPopup(key))
{
if (ImGui.BeginTable(key, 2, ImGuiTableFlags.BordersOuter))
Expand All @@ -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())
{
Expand All @@ -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()
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions RotationSolver/UI/RotationConfigWindowNew_Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISearchable>();
private void SearchingBox()
Expand All @@ -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;
Expand Down

0 comments on commit 5780189

Please sign in to comment.