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

Commit

Permalink
fix: seperate files.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 9, 2023
1 parent 8355742 commit 36f8236
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 103 deletions.
104 changes: 1 addition & 103 deletions RotationSolver/UI/RotationConfigWindowNew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace RotationSolver.UI;

public class RotationConfigWindowNew : Window
public partial class RotationConfigWindowNew : Window
{
private static float _scale => ImGuiHelpers.GlobalScale;
internal static Job Job => RotationUpdater.RightNowRotation?.Jobs[0] ?? Job.ADV;
Expand Down Expand Up @@ -173,46 +173,6 @@ private void DrawSideBar()
}
}

private string _searchText = string.Empty;
private ISearchable[] _searchResults = Array.Empty<ISearchable>();
private void SearchingBox()
{
if(ImGui.InputTextWithHint("##Rotation Solver Search Box", "Searching is not available", ref _searchText, 128, ImGuiInputTextFlags.AutoSelectAll))
{
if(!string.IsNullOrEmpty(_searchText))
{
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))
.Select(GetParent).GetEnumerator();

int index = 0;
while (enumerator.MoveNext() && index < MAX_RESULT_LENGTH)
{
_searchResults[index++] = enumerator.Current;
}
}
else
{
_searchResults = Array.Empty<ISearchable>();
}
}
}

private static ISearchable GetParent(ISearchable searchable)
{
return searchable;
if(searchable == null) return null;
if (searchable.Parent == null) return searchable;
return GetParent(searchable.Parent);
}

private void DrawHeader(float wholeWidth)
{
var size = MathF.Max(MathF.Min(wholeWidth, _scale * 120), _scale * MIN_COLUMN_WIDTH);
Expand Down Expand Up @@ -918,68 +878,6 @@ private static void DrawIDs()
_idsHeader?.Draw();
}


private static readonly ISearchable[] _basicSearchable = new ISearchable[]
{
new DragFloatSearchPlugin(PluginConfigFloat.ActionAhead, 0, 0.5f, 0.002f),
new DragFloatSearchPlugin(PluginConfigFloat.MinLastAbilityAdvanced, 0, 0.4f, 0.002f),
};
private static void DrawBasic()
{
foreach (var searchable in _basicSearchable)
{
searchable?.Draw(Job);
}
}

private static readonly ISearchable[] _uiSearchable = new ISearchable[]
{
new DragFloatSearchPlugin(PluginConfigFloat.ActionAhead, 0, 0.5f, 0.002f),
};
private static void DrawUI()
{
foreach (var searchable in _uiSearchable)
{
searchable?.Draw(Job);
}
}

private static readonly ISearchable[] _autoSearchable = new ISearchable[]
{
new DragFloatSearchPlugin(PluginConfigFloat.ActionAhead, 0, 0.5f, 0.002f),
};
private static void DrawAuto()
{
foreach (var searchable in _autoSearchable)
{
searchable?.Draw(Job);
}
}

private static readonly ISearchable[] _targetSearchable = new ISearchable[]
{
new DragFloatSearchPlugin(PluginConfigFloat.ActionAhead, 0, 0.5f, 0.002f),
};
private static void DrawTarget()
{
foreach (var searchable in _targetSearchable)
{
searchable?.Draw(Job);
}
}

private static readonly ISearchable[] _extraSearchable = new ISearchable[]
{
new DragFloatSearchPlugin(PluginConfigFloat.ActionAhead, 0, 0.5f, 0.002f),
};
private static void DrawExtra()
{
foreach (var searchable in _extraSearchable)
{
searchable?.Draw(Job);
}
}

private static readonly CollapsingHeaderGroup _debugHeader = new(new()
{

Expand Down
111 changes: 111 additions & 0 deletions RotationSolver/UI/RotationConfigWindowNew_Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using F23.StringSimilarity;
using RotationSolver.Basic.Configuration;
using RotationSolver.UI.SearchableConfigs;
using RotationSolver.UI.SearchableSettings;

namespace RotationSolver.UI;

public partial class RotationConfigWindowNew
{
private string _searchText = string.Empty;
private ISearchable[] _searchResults = Array.Empty<ISearchable>();
private void SearchingBox()
{
if (ImGui.InputTextWithHint("##Rotation Solver Search Box", "Searching is not available", ref _searchText, 128, ImGuiInputTextFlags.AutoSelectAll))
{
if (!string.IsNullOrEmpty(_searchText))
{
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))
.Select(GetParent).GetEnumerator();

int index = 0;
while (enumerator.MoveNext() && index < MAX_RESULT_LENGTH)
{
_searchResults[index++] = enumerator.Current;
}
}
else
{
_searchResults = Array.Empty<ISearchable>();
}
}
}

private static ISearchable GetParent(ISearchable searchable)
{
if (searchable == null) return null;
if (searchable.Parent == null) return searchable;
return GetParent(searchable.Parent);
}



private static readonly ISearchable[] _basicSearchable = new ISearchable[]
{
new DragFloatSearchPlugin(PluginConfigFloat.ActionAhead, 0, 0.5f, 0.002f),
new DragFloatSearchPlugin(PluginConfigFloat.MinLastAbilityAdvanced, 0, 0.4f, 0.002f),
};
private static void DrawBasic()
{
foreach (var searchable in _basicSearchable)
{
searchable?.Draw(Job);
}
}

private static readonly ISearchable[] _uiSearchable = new ISearchable[]
{
new DragFloatSearchPlugin(PluginConfigFloat.ActionAhead, 0, 0.5f, 0.002f),
};
private static void DrawUI()
{
foreach (var searchable in _uiSearchable)
{
searchable?.Draw(Job);
}
}

private static readonly ISearchable[] _autoSearchable = new ISearchable[]
{
new DragFloatSearchPlugin(PluginConfigFloat.ActionAhead, 0, 0.5f, 0.002f),
};
private static void DrawAuto()
{
foreach (var searchable in _autoSearchable)
{
searchable?.Draw(Job);
}
}

private static readonly ISearchable[] _targetSearchable = new ISearchable[]
{
new DragFloatSearchPlugin(PluginConfigFloat.ActionAhead, 0, 0.5f, 0.002f),
};
private static void DrawTarget()
{
foreach (var searchable in _targetSearchable)
{
searchable?.Draw(Job);
}
}

private static readonly ISearchable[] _extraSearchable = new ISearchable[]
{
new DragFloatSearchPlugin(PluginConfigFloat.ActionAhead, 0, 0.5f, 0.002f),
};
private static void DrawExtra()
{
foreach (var searchable in _extraSearchable)
{
searchable?.Draw(Job);
}
}
}

0 comments on commit 36f8236

Please sign in to comment.