'Add venture' filter now adds the first venture when pressing enter

This commit is contained in:
Liza 2023-11-04 01:47:20 +01:00
parent cfc41a5a61
commit ba40a916b3
Signed by: liza
GPG Key ID: 7199F8D727D55F67
2 changed files with 24 additions and 9 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework> <TargetFramework>net7.0-windows</TargetFramework>
<Version>2.7</Version> <Version>2.8</Version>
<LangVersion>11.0</LangVersion> <LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

View File

@ -280,7 +280,9 @@ internal sealed class ConfigWindow : Window
if (ImGui.BeginCombo($"##VentureSelection{list.Id}", "Add Venture...", ImGuiComboFlags.HeightLarge)) if (ImGui.BeginCombo($"##VentureSelection{list.Id}", "Add Venture...", ImGuiComboFlags.HeightLarge))
{ {
ImGuiEx.SetNextItemFullWidth(); ImGuiEx.SetNextItemFullWidth();
ImGui.InputTextWithHint("", "Filter...", ref _searchString, 256, ImGuiInputTextFlags.AutoSelectAll);
bool addFirst = ImGui.InputTextWithHint("", "Filter...", ref _searchString, 256,
ImGuiInputTextFlags.AutoSelectAll | ImGuiInputTextFlags.EnterReturnsTrue);
int quantity; int quantity;
string itemName; string itemName;
@ -296,15 +298,19 @@ internal sealed class ConfigWindow : Window
itemName = _searchString.ToLower(); itemName = _searchString.ToLower();
} }
foreach (var ventures in _gameCache.Ventures foreach (var filtered in _gameCache.Ventures
.Where(x => x.Name.ToLower().Contains(itemName)) .Where(x => x.Name.ToLower().Contains(itemName))
.OrderBy(x => x.Level) .OrderBy(x => x.Level)
.ThenBy(x => x.Name) .ThenBy(x => x.Name)
.ThenBy(x => x.ItemId) .ThenBy(x => x.ItemId)
.GroupBy(x => x.ItemId)) .GroupBy(x => x.ItemId)
.Select(x => new
{ {
var venture = ventures.First(); Venture = x.First(),
IDalamudTextureWrap? icon = _iconCache.GetIcon(venture.IconId); CategoryNames = x.Select(y => y.CategoryName)
}))
{
IDalamudTextureWrap? icon = _iconCache.GetIcon(filtered.Venture.IconId);
if (icon != null) if (icon != null)
{ {
ImGui.Image(icon.ImGuiHandle, new Vector2(23, 23)); ImGui.Image(icon.ImGuiHandle, new Vector2(23, 23));
@ -312,14 +318,23 @@ internal sealed class ConfigWindow : Window
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + 3); ImGui.SetCursorPosY(ImGui.GetCursorPosY() + 3);
} }
if (ImGui.Selectable( bool addThis = ImGui.Selectable(
$"{venture.Name} ({string.Join(" ", ventures.Select(x => x.CategoryName))})##SelectVenture{venture.RowId}")) $"{filtered.Venture.Name} ({string.Join(" ", filtered.CategoryNames)})##SelectVenture{filtered.Venture.RowId}");
if (addThis || addFirst)
{ {
list.Items.Add(new Configuration.QueuedItem list.Items.Add(new Configuration.QueuedItem
{ {
ItemId = venture.ItemId, ItemId = filtered.Venture.ItemId,
RemainingQuantity = quantity, RemainingQuantity = quantity,
}); });
if (addFirst)
{
addFirst = false;
ImGui.CloseCurrentPopup();
}
Save(); Save();
} }
} }