Improve search window
This commit is contained in:
parent
ac9de53c7f
commit
262e146a69
@ -1,7 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using AutoRetainerAPI;
|
using AutoRetainerAPI;
|
||||||
using ClickLib.Clicks;
|
using ClickLib.Clicks;
|
||||||
using Dalamud.Data;
|
using Dalamud.Data;
|
||||||
|
@ -20,6 +20,8 @@ public class ConfigWindow : Window
|
|||||||
|
|
||||||
private List<(uint ItemId, string Name)> _searchResults = new();
|
private List<(uint ItemId, string Name)> _searchResults = new();
|
||||||
private List<(uint ItemId, string Name)> _discarding = new();
|
private List<(uint ItemId, string Name)> _discarding = new();
|
||||||
|
private List<(uint ItemId, string Name)>? _allItems = null;
|
||||||
|
private bool _resetKeyboardFocus = true;
|
||||||
|
|
||||||
public ConfigWindow(DalamudPluginInterface pluginInterface, Configuration configuration, DataManager dataManager)
|
public ConfigWindow(DalamudPluginInterface pluginInterface, Configuration configuration, DataManager dataManager)
|
||||||
: base("Auto Discard###AutoDiscardConfig")
|
: base("Auto Discard###AutoDiscardConfig")
|
||||||
@ -37,8 +39,8 @@ public class ConfigWindow : Window
|
|||||||
MaximumSize = new Vector2(9999, 9999),
|
MaximumSize = new Vector2(9999, 9999),
|
||||||
};
|
};
|
||||||
|
|
||||||
_discarding = _configuration.DiscardingItems
|
_discarding.AddRange(_configuration.DiscardingItems
|
||||||
.Select(x => (x, dataManager.GetExcelSheet<Item>()?.GetRow(x)?.Name?.ToString() ?? x.ToString())).ToList();
|
.Select(x => (x, dataManager.GetExcelSheet<Item>()?.GetRow(x)?.Name?.ToString() ?? x.ToString())).ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
@ -55,7 +57,33 @@ public class ConfigWindow : Window
|
|||||||
{
|
{
|
||||||
ImGui.Text("Search");
|
ImGui.Text("Search");
|
||||||
ImGui.SetNextItemWidth(ws.X / 2 - 20);
|
ImGui.SetNextItemWidth(ws.X / 2 - 20);
|
||||||
if (ImGui.InputText("", ref _itemName, 256))
|
if (_resetKeyboardFocus)
|
||||||
|
{
|
||||||
|
ImGui.SetKeyboardFocusHere();
|
||||||
|
_resetKeyboardFocus = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
string previousName = _itemName;
|
||||||
|
if (ImGui.InputText("", ref _itemName, 256, ImGuiInputTextFlags.EnterReturnsTrue))
|
||||||
|
{
|
||||||
|
_resetKeyboardFocus = true;
|
||||||
|
if (_searchResults.Count > 0)
|
||||||
|
{
|
||||||
|
var itemToAdd = _searchResults.FirstOrDefault();
|
||||||
|
if (_discarding.All(x => x.ItemId != itemToAdd.ItemId))
|
||||||
|
{
|
||||||
|
_discarding.Add(itemToAdd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_discarding.Remove(itemToAdd);
|
||||||
|
}
|
||||||
|
|
||||||
|
Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (previousName != _itemName)
|
||||||
UpdateResults();
|
UpdateResults();
|
||||||
|
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
@ -79,8 +107,7 @@ public class ConfigWindow : Window
|
|||||||
_discarding.Remove((id, name));
|
_discarding.Remove((id, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
_configuration.DiscardingItems = _discarding.Select(x => x.ItemId).ToList();
|
Save();
|
||||||
_pluginInterface.SavePluginConfig(_configuration);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,8 +132,7 @@ public class ConfigWindow : Window
|
|||||||
foreach (var tr in toRemove)
|
foreach (var tr in toRemove)
|
||||||
_discarding.Remove(tr);
|
_discarding.Remove(tr);
|
||||||
|
|
||||||
_configuration.DiscardingItems = _discarding.Select(x => x.ItemId).ToList();
|
Save();
|
||||||
_pluginInterface.SavePluginConfig(_configuration);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,14 +145,28 @@ public class ConfigWindow : Window
|
|||||||
_searchResults = new();
|
_searchResults = new();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_searchResults = _dataManager.GetExcelSheet<Item>()
|
if (_allItems == null)
|
||||||
.Where(x => x.RowId != 0)
|
{
|
||||||
.Where(x => !x.IsUnique && !x.IsUntradable)
|
_allItems = _dataManager.GetExcelSheet<Item>()!
|
||||||
.Where(x => x.ItemUICategory?.Value?.Name?.ToString() != "Currency")
|
.Where(x => x.RowId != 0)
|
||||||
.Where(x => !string.IsNullOrEmpty(x.Name) &&
|
.Where(x => !x.IsUnique && !x.IsUntradable)
|
||||||
x.Name.ToString().Contains(_itemName, StringComparison.CurrentCultureIgnoreCase))
|
.Where(x => x.ItemUICategory?.Value?.Name?.ToString() != "Currency" &&
|
||||||
.Select(x => (x.RowId, x.Name.ToString()))
|
x.ItemUICategory?.Value?.Name?.ToString() != "Crystal")
|
||||||
|
.Where(x => !string.IsNullOrEmpty(x.Name.ToString()))
|
||||||
|
.Select(x => (x.RowId, x.Name.ToString()))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
_searchResults = _allItems.Where(x => x.Name.Contains(_itemName, StringComparison.CurrentCultureIgnoreCase)
|
||||||
|
|| (uint.TryParse(_itemName, out uint itemId) && x.ItemId == itemId))
|
||||||
|
.OrderBy(x => _itemName.EqualsIgnoreCase(x.Name) ? string.Empty : x.Name)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Save()
|
||||||
|
{
|
||||||
|
_configuration.DiscardingItems = _discarding.Select(x => x.ItemId).ToList();
|
||||||
|
_pluginInterface.SavePluginConfig(_configuration);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user