Make vending machine use EntityPrototypeView (#30064)

* Make vendor machines use EntityPrototypeView

* Update

* 1

* Kill me

* For the love of god!!!
This commit is contained in:
Winkarst
2024-08-22 17:40:39 +03:00
committed by GitHub
parent 5139ecdbd2
commit 588661465a
5 changed files with 109 additions and 98 deletions

View File

@@ -1,6 +1,9 @@
using Content.Client.UserInterface.Controls;
using Content.Client.VendingMachines.UI;
using Content.Shared.VendingMachines;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Input;
using System.Linq;
using Robust.Client.UserInterface;
@@ -14,9 +17,6 @@ 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)
{
}
@@ -34,9 +34,10 @@ namespace Content.Client.VendingMachines
_menu.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
_menu.OnItemSelected += OnItemSelected;
_menu.OnSearchChanged += OnSearchChanged;
_menu.Populate(_cachedInventory, out _cachedFilteredIndex);
_menu.Populate(_cachedInventory);
_menu.OpenCenteredLeft();
}
protected override void UpdateState(BoundUserInterfaceState state)
@@ -48,15 +49,21 @@ namespace Content.Client.VendingMachines
_cachedInventory = newState.Inventory;
_menu?.Populate(_cachedInventory, out _cachedFilteredIndex, _menu.SearchBar.Text);
_menu?.Populate(_cachedInventory);
}
private void OnItemSelected(ItemList.ItemListSelectedEventArgs args)
private void OnItemSelected(GUIBoundKeyEventArgs args, ListData data)
{
if (args.Function != EngineKeyFunctions.UIClick)
return;
if (data is not VendorItemsListData { ItemIndex: var itemIndex })
return;
if (_cachedInventory.Count == 0)
return;
var selectedItem = _cachedInventory.ElementAtOrDefault(_cachedFilteredIndex.ElementAtOrDefault(args.ItemIndex));
var selectedItem = _cachedInventory.ElementAtOrDefault(itemIndex);
if (selectedItem == null)
return;
@@ -77,10 +84,5 @@ namespace Content.Client.VendingMachines
_menu.OnClose -= Close;
_menu.Dispose();
}
private void OnSearchChanged(string? filter)
{
_menu?.Populate(_cachedInventory, out _cachedFilteredIndex, filter);
}
}
}