forked from liza/ARDiscard
Improve search window
This commit is contained in:
parent
ac9de53c7f
commit
262e146a69
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using AutoRetainerAPI;
|
||||
using ClickLib.Clicks;
|
||||
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)> _discarding = new();
|
||||
private List<(uint ItemId, string Name)>? _allItems = null;
|
||||
private bool _resetKeyboardFocus = true;
|
||||
|
||||
public ConfigWindow(DalamudPluginInterface pluginInterface, Configuration configuration, DataManager dataManager)
|
||||
: base("Auto Discard###AutoDiscardConfig")
|
||||
@ -37,8 +39,8 @@ public class ConfigWindow : Window
|
||||
MaximumSize = new Vector2(9999, 9999),
|
||||
};
|
||||
|
||||
_discarding = _configuration.DiscardingItems
|
||||
.Select(x => (x, dataManager.GetExcelSheet<Item>()?.GetRow(x)?.Name?.ToString() ?? x.ToString())).ToList();
|
||||
_discarding.AddRange(_configuration.DiscardingItems
|
||||
.Select(x => (x, dataManager.GetExcelSheet<Item>()?.GetRow(x)?.Name?.ToString() ?? x.ToString())).ToList());
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
@ -55,7 +57,33 @@ public class ConfigWindow : Window
|
||||
{
|
||||
ImGui.Text("Search");
|
||||
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();
|
||||
|
||||
ImGui.Separator();
|
||||
@ -79,8 +107,7 @@ public class ConfigWindow : Window
|
||||
_discarding.Remove((id, name));
|
||||
}
|
||||
|
||||
_configuration.DiscardingItems = _discarding.Select(x => x.ItemId).ToList();
|
||||
_pluginInterface.SavePluginConfig(_configuration);
|
||||
Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -105,8 +132,7 @@ public class ConfigWindow : Window
|
||||
foreach (var tr in toRemove)
|
||||
_discarding.Remove(tr);
|
||||
|
||||
_configuration.DiscardingItems = _discarding.Select(x => x.ItemId).ToList();
|
||||
_pluginInterface.SavePluginConfig(_configuration);
|
||||
Save();
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,14 +145,28 @@ public class ConfigWindow : Window
|
||||
_searchResults = new();
|
||||
else
|
||||
{
|
||||
_searchResults = _dataManager.GetExcelSheet<Item>()
|
||||
.Where(x => x.RowId != 0)
|
||||
.Where(x => !x.IsUnique && !x.IsUntradable)
|
||||
.Where(x => x.ItemUICategory?.Value?.Name?.ToString() != "Currency")
|
||||
.Where(x => !string.IsNullOrEmpty(x.Name) &&
|
||||
x.Name.ToString().Contains(_itemName, StringComparison.CurrentCultureIgnoreCase))
|
||||
.Select(x => (x.RowId, x.Name.ToString()))
|
||||
if (_allItems == null)
|
||||
{
|
||||
_allItems = _dataManager.GetExcelSheet<Item>()!
|
||||
.Where(x => x.RowId != 0)
|
||||
.Where(x => !x.IsUnique && !x.IsUntradable)
|
||||
.Where(x => x.ItemUICategory?.Value?.Name?.ToString() != "Currency" &&
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
_configuration.DiscardingItems = _discarding.Select(x => x.ItemId).ToList();
|
||||
_pluginInterface.SavePluginConfig(_configuration);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user