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

Commit

Permalink
fix: fixed search result.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 13, 2023
1 parent fdb570b commit f29a52e
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 53 deletions.
8 changes: 6 additions & 2 deletions RotationSolver/Localization/ConfigTranslation.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ECommons.Configuration;
using RotationSolver.Basic.Configuration;
using RotationSolver.Basic.Configuration;

namespace RotationSolver.Localization;

Expand All @@ -18,6 +17,9 @@ internal static class ConfigTranslation

public static string ToName(this PluginConfigInt config) => config switch
{
PluginConfigInt.PoslockModifier => LocalizationManager.RightLang.ConfigWindow_Param_PoslockModifier,


// UI
PluginConfigInt.KeyBoardNoiseMin => LocalizationManager.RightLang.ConfigWindow_Param_KeyBoardNoiseTimes,
PluginConfigInt.LessMPNoRaise => LocalizationManager.RightLang.ConfigWindow_Param_LessMPNoRaise,
Expand Down Expand Up @@ -189,6 +191,8 @@ internal static class ConfigTranslation

public static string ToDescription(this PluginConfigInt config) => config switch
{
PluginConfigInt.PoslockModifier => LocalizationManager.RightLang.ConfigWindow_Param_PoslockDescription,

PluginConfigInt.MoveTargetAngle => LocalizationManager.RightLang.ConfigWindow_Param_MoveAreaActionFarthestDesc,
_ => string.Empty,
};
Expand Down
20 changes: 10 additions & 10 deletions RotationSolver/UI/RotationConfigWindowNew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1330,8 +1330,8 @@ private static void DrawStatusList(string name, HashSet<uint> statuses, Status[]

foreach (var status in statuses.Select(a => Service.GetSheet<Status>().GetRow(a))
.Where(a => a != null)
.OrderBy(s => StringComparer.Distance(s.Name, _statusSearching)
+ StringComparer.Distance(s.RowId.ToString(), _statusSearching)))
.OrderBy(s => Math.Min( StringComparer.Distance(s.Name, _statusSearching)
, StringComparer.Distance(s.RowId.ToString(), _statusSearching))))
{
void Reset() => removeId = status.RowId;

Expand Down Expand Up @@ -1379,8 +1379,8 @@ private static void DrawStatusList(string name, HashSet<uint> statuses, Status[]
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, _statusSearching)
+ StringComparer.Distance(s.RowId.ToString(), _statusSearching)))
foreach (var status in allStatus.OrderBy(s => Math.Min(StringComparer.Distance(s.Name, _statusSearching)
, StringComparer.Distance(s.RowId.ToString(), _statusSearching))))
{
if (IconSet.GetTexture(status.Icon, out var texture, notLoadId))
{
Expand Down Expand Up @@ -1459,8 +1459,8 @@ private static void DrawActionsList(string name, HashSet<uint> actions)
{
foreach (var action in actions.Select(a => Service.GetSheet<GAction>().GetRow(a))
.Where(a => a != null)
.OrderBy(s => StringComparer.Distance(s.Name, _actionSearching)
+ StringComparer.Distance(s.RowId.ToString(), _actionSearching)))
.OrderBy(s => Math.Min( StringComparer.Distance(s.Name, _actionSearching)
, StringComparer.Distance(s.RowId.ToString(), _actionSearching))))
{
void Reset() => removeId = action.RowId;

Expand Down Expand Up @@ -1498,8 +1498,8 @@ private static void DrawActionsList(string name, HashSet<uint> actions)

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)))
foreach (var action in AllActions.OrderBy(s => Math.Min( StringComparer.Distance(s.Name, _actionSearching)
, StringComparer.Distance(s.RowId.ToString(), _actionSearching))))
{
ImGui.Selectable($"{action.Name} ({action.RowId})");
{
Expand Down Expand Up @@ -1542,8 +1542,8 @@ private static void DrawListTerritories()

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)))
foreach (var territory in AllTerritories.OrderBy(s => Math.Min( 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))
Expand Down
103 changes: 97 additions & 6 deletions RotationSolver/UI/RotationConfigWindowNew_Config.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using F23.StringSimilarity;
using RotationSolver.Basic.Configuration;
using RotationSolver.Localization;
using RotationSolver.UI.SearchableConfigs;
using RotationSolver.UI.SearchableSettings;

Expand All @@ -24,7 +25,8 @@ private void SearchingBox()
var enumerator = GetType().GetRuntimeFields()
.Where(f => f.FieldType == typeof(ISearchable[]) && f.IsInitOnly)
.SelectMany(f => (ISearchable[])f.GetValue(this))
.OrderBy(i => StringComparer.Distance(i.SearchingKey, _searchText))
.SelectMany(GetChildren)
.OrderBy(i => i.SearchingKeys.Split(' ').Min(k => StringComparer.Distance(k, _searchText)))
.Select(GetParent).GetEnumerator();

int index = 0;
Expand All @@ -40,6 +42,16 @@ private void SearchingBox()
}
}

private static IEnumerable<ISearchable> GetChildren(ISearchable searchable)
{
var myself = new ISearchable[] { searchable };
if (searchable is CheckBoxSearch c && c.Children != null)
{
return c.Children.SelectMany(GetChildren).Union(myself);
}
else return myself;
}

private static ISearchable GetParent(ISearchable searchable)
{
if (searchable == null) return null;
Expand Down Expand Up @@ -337,10 +349,26 @@ private static void DrawTarget()
private static readonly ISearchable[] _extraSearchable = new ISearchable[]
{
new CheckBoxSearchPlugin(PluginConfigBool.SayOutStateChanged),
new CheckBoxSearchPlugin(PluginConfigBool.PoslockCasting, new ISearchable[]
{

new CheckBoxSearchPlugin(PluginConfigBool.PoslockCasting,
new DragIntSearchPlugin( PluginConfigInt.PoslockModifier, "SHIFT", "CTRL", "ALT", "Left Mouse", "Middle Mouse", "Right Mouse"),
new CheckBoxSearchPlugin(PluginConfigBool.PosPassageOfArms)
{
Action = ActionID.PassageOfArms
},
new CheckBoxSearchPlugin(PluginConfigBool.PosTenChiJin)
{
Action = ActionID.TenChiJin
},
new CheckBoxSearchPlugin(PluginConfigBool.PosFlameThrower)
{
Action = ActionID.FlameThrower
},
new CheckBoxSearchPlugin(PluginConfigBool.PosImprovisation)
{
Action = ActionID.Improvisation
}),

new CheckBoxSearchPlugin(PluginConfigBool.ShowHealthRatio, new ISearchable[]
{
new DragFloatSearchPlugin(PluginConfigFloat.HealthRatioBoss, 0.02f),
Expand All @@ -362,11 +390,74 @@ private static void DrawTarget()
new CheckBoxSearchPlugin(PluginConfigBool.AutoCloseChestWindow),
}),
};
private static void DrawExtra()

private static readonly CollapsingHeaderGroup _extraHeader = new(new()
{
{ () => "Extra", () =>
{
foreach (var searchable in _extraSearchable)
{
searchable?.Draw(Job);
}
}
},

{ () => LocalizationManager.RightLang.ConfigWindow_EventItem, DrawEventTab },
});

private static void DrawEventTab()
{
foreach (var searchable in _extraSearchable)
if (ImGui.Button(LocalizationManager.RightLang.ConfigWindow_Events_AddEvent))
{
searchable?.Draw(Job);
Service.Config.Events.Add(new ActionEventInfo());
Service.Config.Save();
}
ImGui.SameLine();
ImGuiHelper.Spacing();

ImGui.TextWrapped(LocalizationManager.RightLang.ConfigWindow_Events_Description);

ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(0f, 5f));

ImGui.Text(LocalizationManager.RightLang.ConfigWindow_Events_DutyStart);
ImGui.SameLine();
ImGuiHelper.Spacing();
Service.Config.DutyStart.DisplayMacro();

ImGui.Text(LocalizationManager.RightLang.ConfigWindow_Events_DutyEnd);
ImGui.SameLine();
ImGuiHelper.Spacing();
Service.Config.DutyEnd.DisplayMacro();

if (ImGui.BeginChild("Events List", new Vector2(0f, -1f), true))
{
ActionEventInfo remove = null;
foreach (var eve in Service.Config.Events)
{
eve.DisplayEvent();

ImGui.SameLine();
ImGuiHelper.Spacing();

if (ImGui.Button($"{LocalizationManager.RightLang.ConfigWindow_Events_RemoveEvent}##RemoveEvent{eve.GetHashCode()}"))
{
remove = eve;
}
ImGui.Separator();
}
if (remove != null)
{
Service.Config.Events.Remove(remove);
Service.Config.Save();
}

ImGui.EndChild();
}
ImGui.PopStyleVar();
}

private static void DrawExtra()
{
_extraHeader?.Draw();
}
}
42 changes: 21 additions & 21 deletions RotationSolver/UI/RotationConfigWindow_Param.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,37 +129,37 @@ private void DrawParamAdvanced()

ImGui.Separator();

DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_PoslockCasting,
ref Service.Config.PoslockCasting, Service.Default.PoslockCasting);
//DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_PoslockCasting,
//ref Service.Config.PoslockCasting, Service.Default.PoslockCasting);

if (Service.Config.PoslockCasting)
{
ImGui.Indent();
//if (Service.Config.PoslockCasting)
//{
// ImGui.Indent();

DrawCombo(LocalizationManager.RightLang.ConfigWindow_Param_PoslockModifier,
ref Service.Config.PoslockModifier, Service.Default.PoslockModifier, EnumTranslations.ToName,
ConfigurationHelper.Keys,
LocalizationManager.RightLang.ConfigWindow_Param_PoslockDescription);
// DrawCombo(LocalizationManager.RightLang.ConfigWindow_Param_PoslockModifier,
// ref Service.Config.PoslockModifier, Service.Default.PoslockModifier, EnumTranslations.ToName,
// ConfigurationHelper.Keys,
// LocalizationManager.RightLang.ConfigWindow_Param_PoslockDescription);

DrawIconCheckBox(ActionID.PassageOfArms, ref Service.Config.PosPassageOfArms);
// DrawIconCheckBox(ActionID.PassageOfArms, ref Service.Config.PosPassageOfArms);

ImGui.SameLine();
ImGuiHelper.Spacing();
// ImGui.SameLine();
// ImGuiHelper.Spacing();

DrawIconCheckBox(ActionID.TenChiJin, ref Service.Config.PosTenChiJin);
// DrawIconCheckBox(ActionID.TenChiJin, ref Service.Config.PosTenChiJin);

ImGui.SameLine();
ImGuiHelper.Spacing();
// ImGui.SameLine();
// ImGuiHelper.Spacing();

DrawIconCheckBox(ActionID.FlameThrower, ref Service.Config.PosFlameThrower);
// DrawIconCheckBox(ActionID.FlameThrower, ref Service.Config.PosFlameThrower);

ImGui.SameLine();
ImGuiHelper.Spacing();
// ImGui.SameLine();
// ImGuiHelper.Spacing();

DrawIconCheckBox(ActionID.Improvisation, ref Service.Config.PosImprovisation);
// DrawIconCheckBox(ActionID.Improvisation, ref Service.Config.PosImprovisation);

ImGui.Unindent();
}
// ImGui.Unindent();
//}

//DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_UseStopCasting,
// ref Service.Config.UseStopCasting, Service.Default.UseStopCasting);
Expand Down
18 changes: 11 additions & 7 deletions RotationSolver/UI/SearchableConfigs/CheckBoxSearch.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using ECommons.ExcelServices;
using ImGuiScene;
using RotationSolver.Basic.Configuration;
using RotationSolver.Localization;
using RotationSolver.UI.SearchableConfigs;
using static FFXIVClientStructs.FFXIV.Client.UI.AddonAOZNotebook;
using System.Drawing;
using ImGuiScene;

namespace RotationSolver.UI.SearchableSettings;

Expand All @@ -15,7 +13,7 @@ internal class CheckBoxSearchPlugin : CheckBoxSearch

public override string Name => _config.ToName();

public override string Description => _config.ToDescription();
public override string Description => Action == ActionID.NoMercy ? _config.ToDescription() : Action.ToString();

public override LinkDescription[] Tooltips => _config.ToAction();

Expand Down Expand Up @@ -82,15 +80,13 @@ protected override void DrawMain(Job job)
ImGui.BeginGroup();
var cursor = ImGui.GetCursorPos();
var size = ImGuiHelpers.GlobalScale * 32;
if (RotationConfigWindowNew.NoPaddingNoColorImageButton(texture.ImGuiHandle, Vector2.One * size))
if (RotationConfigWindowNew.NoPaddingNoColorImageButton(texture.ImGuiHandle, Vector2.One * size, ID))
{
SetValue(job, !enable);
}
if (ImGui.IsItemHovered()) ShowTooltip(job);
RotationConfigWindowNew.DrawActionOverlay(cursor, size, enable ? 1 : 0);
ImGui.EndGroup();

ImGui.SameLine();
if (ImGui.IsItemHovered()) ShowTooltip(job);
}
else if (hasChild)
Expand All @@ -105,8 +101,16 @@ protected override void DrawMain(Job job)
{
ImGui.SetCursorPosX(x);
ImGui.BeginGroup();
var lastIs = false;
foreach (var child in Children)
{
var thisIs = child is CheckBoxSearch c && c.Action != ActionID.None && IconSet.GetTexture(c.Action, out texture);
if (lastIs && thisIs)
{
ImGui.SameLine();
}
lastIs = thisIs;

child.Draw(job);
}
ImGui.EndGroup();
Expand Down
30 changes: 27 additions & 3 deletions RotationSolver/UI/SearchableConfigs/DragIntSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public DragIntSearchPlugin(PluginConfigInt config, float speed)
_config = config;
}

public DragIntSearchPlugin(PluginConfigInt config, params string[] names)
:base(names)
{
_config = config;
}

public override void ResetToDefault(Job job)
{
Service.ConfigNew.SetValue(_config, Service.ConfigNew.GetDefault(_config));
Expand All @@ -84,21 +90,39 @@ internal abstract class DragIntSearch : Searchable
public int Min { get; }
public int Max { get; }
public float Speed { get; }
public string[] Names { get; }
public DragIntSearch(int min, int max, float speed)
{
Min = min; Max = max;
Speed = speed;
}
public DragIntSearch(params string[] names)
{
Names = names;
}
protected abstract int GetValue(Job job);
protected abstract void SetValue(Job job, int value);
protected override void DrawMain(Job job)
{
var value = GetValue(job);
ImGui.SetNextItemWidth(Scale * DRAG_WIDTH);
if(ImGui.DragInt($"##Config_{ID}", ref value, Speed, Min, Max))

if(Names != null && Names.Length > 0)
{
SetValue(job, value);
ImGui.SetNextItemWidth(Math.Max(ImGui.CalcTextSize(Names[value]).X + 30, DRAG_WIDTH) * Scale);
if (ImGui.Combo($"##Config_{ID}", ref value, Names, Names.Length))
{
SetValue(job, value);
}
}
else
{
ImGui.SetNextItemWidth(Scale * DRAG_WIDTH);
if (ImGui.DragInt($"##Config_{ID}", ref value, Speed, Min, Max))
{
SetValue(job, value);
}
}

if (ImGui.IsItemHovered()) ShowTooltip(job);

if (IsJob) DrawJobIcon();
Expand Down
Loading

0 comments on commit f29a52e

Please sign in to comment.