fix searching on vending machines (#21233)

This commit is contained in:
Nemanja
2023-10-25 09:01:16 -04:00
committed by GitHub
parent 88a29450d9
commit 0253270a9a
3 changed files with 12 additions and 9 deletions

View File

@@ -1,6 +1,5 @@
using Content.Client.VendingMachines.UI;
using Content.Shared.VendingMachines;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.Controls;
using System.Linq;
@@ -14,6 +13,9 @@ namespace Content.Client.VendingMachines
[ViewVariables]
private List<VendingMachineInventoryEntry> _cachedInventory = new();
[ViewVariables]
private List<int> _cachedFilteredIndex = new();
public VendingMachineBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
@@ -32,7 +34,7 @@ namespace Content.Client.VendingMachines
_menu.OnItemSelected += OnItemSelected;
_menu.OnSearchChanged += OnSearchChanged;
_menu.Populate(_cachedInventory);
_menu.Populate(_cachedInventory, out _cachedFilteredIndex);
_menu.OpenCentered();
}
@@ -46,7 +48,7 @@ namespace Content.Client.VendingMachines
_cachedInventory = newState.Inventory;
_menu?.Populate(_cachedInventory);
_menu?.Populate(_cachedInventory, out _cachedFilteredIndex, _menu.SearchBar.Text);
}
private void OnItemSelected(ItemList.ItemListSelectedEventArgs args)
@@ -54,7 +56,7 @@ namespace Content.Client.VendingMachines
if (_cachedInventory.Count == 0)
return;
var selectedItem = _cachedInventory.ElementAtOrDefault(args.ItemIndex);
var selectedItem = _cachedInventory.ElementAtOrDefault(_cachedFilteredIndex.ElementAtOrDefault(args.ItemIndex));
if (selectedItem == null)
return;
@@ -78,7 +80,7 @@ namespace Content.Client.VendingMachines
private void OnSearchChanged(string? filter)
{
_menu?.Populate(_cachedInventory, filter);
_menu?.Populate(_cachedInventory, out _cachedFilteredIndex, filter);
}
}
}