<DefaultWindow xmlns="https://spacestation14.io">
<BoxContainer Orientation="Vertical">
- <LineEdit Name="SearchBar" PlaceHolder="{Loc 'vending-machine-component-search-filter'}" HorizontalExpand="True" Margin ="0 4"/>
+ <LineEdit Name="SearchBar" PlaceHolder="{Loc 'vending-machine-component-search-filter'}" HorizontalExpand="True" Margin ="0 4" Access="Public"/>
<ItemList Name="VendingContents"
SizeFlagsStretchRatio="8"
VerticalExpand="True">
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
-using Robust.Shared.Graphics;
using Robust.Shared.Prototypes;
namespace Content.Client.VendingMachines.UI
VendingContents.OnItemSelected += args =>
{
- SearchBar.Text = string.Empty;
OnItemSelected?.Invoke(args);
};
}
/// Populates the list of available items on the vending machine interface
/// and sets icons based on their prototypes
/// </summary>
- public void Populate(List<VendingMachineInventoryEntry> inventory, string? filter = null)
+ public void Populate(List<VendingMachineInventoryEntry> inventory, out List<int> filteredInventory, string? filter = null)
{
+ filteredInventory = new();
+
if (inventory.Count == 0)
{
VendingContents.Clear();
vendingItem.Text = $"{itemName} [{entry.Amount}]";
vendingItem.Icon = icon;
+ filteredInventory.Add(i);
}
SetSizeAfterUpdate(longestEntry.Length, inventory.Count);
using Content.Client.VendingMachines.UI;
using Content.Shared.VendingMachines;
-using Robust.Client.GameObjects;
using Robust.Client.UserInterface.Controls;
using System.Linq;
[ViewVariables]
private List<VendingMachineInventoryEntry> _cachedInventory = new();
+ [ViewVariables]
+ private List<int> _cachedFilteredIndex = new();
+
public VendingMachineBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
_menu.OnItemSelected += OnItemSelected;
_menu.OnSearchChanged += OnSearchChanged;
- _menu.Populate(_cachedInventory);
+ _menu.Populate(_cachedInventory, out _cachedFilteredIndex);
_menu.OpenCentered();
}
_cachedInventory = newState.Inventory;
- _menu?.Populate(_cachedInventory);
+ _menu?.Populate(_cachedInventory, out _cachedFilteredIndex, _menu.SearchBar.Text);
}
private void OnItemSelected(ItemList.ItemListSelectedEventArgs args)
if (_cachedInventory.Count == 0)
return;
- var selectedItem = _cachedInventory.ElementAtOrDefault(args.ItemIndex);
+ var selectedItem = _cachedInventory.ElementAtOrDefault(_cachedFilteredIndex.ElementAtOrDefault(args.ItemIndex));
if (selectedItem == null)
return;
private void OnSearchChanged(string? filter)
{
- _menu?.Populate(_cachedInventory, filter);
+ _menu?.Populate(_cachedInventory, out _cachedFilteredIndex, filter);
}
}
}