2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.VendingMachines;
|
2022-08-31 14:12:09 +02:00
|
|
|
using System.Linq;
|
2024-01-28 17:32:55 +07:00
|
|
|
using Content.Client._White.Economy.Ui;
|
2019-08-14 10:49:28 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.VendingMachines
|
2019-08-14 10:49:28 +02:00
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class VendingMachineBoundUserInterface : BoundUserInterface
|
2019-08-14 10:49:28 +02:00
|
|
|
{
|
2022-08-31 14:12:09 +02:00
|
|
|
[ViewVariables]
|
2023-10-02 16:50:02 +09:00
|
|
|
private VendingMenu? _menu; // WD EDIT
|
2019-08-14 10:49:28 +02:00
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
[ViewVariables]
|
2022-08-31 14:12:09 +02:00
|
|
|
private List<VendingMachineInventoryEntry> _cachedInventory = new();
|
2019-08-14 10:49:28 +02:00
|
|
|
|
2023-10-25 09:01:16 -04:00
|
|
|
[ViewVariables]
|
|
|
|
|
private List<int> _cachedFilteredIndex = new();
|
|
|
|
|
|
2024-12-14 17:50:46 +03:00
|
|
|
private VendingMachineComponent component = new(); // WD edit
|
2023-07-08 09:02:17 -07:00
|
|
|
public VendingMachineBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
2019-08-14 10:49:28 +02:00
|
|
|
{
|
|
|
|
|
}
|
2024-12-14 17:50:46 +03:00
|
|
|
|
2019-08-14 10:49:28 +02:00
|
|
|
protected override void Open()
|
|
|
|
|
{
|
|
|
|
|
base.Open();
|
|
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
var vendingMachineSys = EntMan.System<VendingMachineSystem>();
|
2019-08-14 10:49:28 +02:00
|
|
|
|
2023-10-02 16:50:02 +09:00
|
|
|
// WD EDIT START
|
2024-12-14 02:06:20 +03:00
|
|
|
component = EntMan.GetComponent<VendingMachineComponent>(Owner);
|
2023-10-02 16:50:02 +09:00
|
|
|
_cachedInventory = vendingMachineSys.GetAllInventory(Owner, component);
|
2019-08-14 10:49:28 +02:00
|
|
|
|
2023-10-02 16:50:02 +09:00
|
|
|
_menu = new VendingMenu { Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName };
|
2019-08-14 10:49:28 +02:00
|
|
|
|
|
|
|
|
_menu.OnClose += Close;
|
2022-08-31 14:12:09 +02:00
|
|
|
_menu.OnItemSelected += OnItemSelected;
|
2023-10-02 16:50:02 +09:00
|
|
|
_menu.OnWithdraw += SendMessage;
|
2024-12-14 02:06:20 +03:00
|
|
|
_menu.SearchBar.OnTextChanged += UpdateFilter;
|
2023-10-02 16:50:02 +09:00
|
|
|
// WD EDIT END
|
2022-08-31 14:12:09 +02:00
|
|
|
|
2023-10-02 16:50:02 +09:00
|
|
|
_menu.Populate(_cachedInventory, component.PriceMultiplier, component.Credits);
|
2022-08-31 14:12:09 +02:00
|
|
|
|
2024-02-01 05:49:48 -07:00
|
|
|
_menu.OpenCenteredLeft();
|
2019-08-14 10:49:28 +02:00
|
|
|
}
|
|
|
|
|
|
2024-12-14 02:06:20 +03:00
|
|
|
// WD EDIT START
|
|
|
|
|
private void UpdateFilter(Robust.Client.UserInterface.Controls.LineEdit.LineEditEventArgs obj)
|
|
|
|
|
{
|
|
|
|
|
if (_menu != null)
|
|
|
|
|
{
|
|
|
|
|
_menu.filter = obj.Text;
|
|
|
|
|
_menu.Populate(_cachedInventory, component.PriceMultiplier, component.Credits);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// WD EDIT END
|
|
|
|
|
|
2022-08-31 14:12:09 +02:00
|
|
|
protected override void UpdateState(BoundUserInterfaceState state)
|
2019-08-14 10:49:28 +02:00
|
|
|
{
|
2022-08-31 14:12:09 +02:00
|
|
|
base.UpdateState(state);
|
|
|
|
|
|
|
|
|
|
if (state is not VendingMachineInterfaceState newState)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_cachedInventory = newState.Inventory;
|
|
|
|
|
|
2023-10-02 16:50:02 +09:00
|
|
|
_menu?.Populate(_cachedInventory, newState.PriceMultiplier, newState.Credits);
|
2019-08-14 10:49:28 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-02 16:50:02 +09:00
|
|
|
// WD EDIT START
|
|
|
|
|
private void OnItemSelected(int index)
|
2019-08-14 10:49:28 +02:00
|
|
|
{
|
2022-10-04 14:24:19 +11:00
|
|
|
if (_cachedInventory.Count == 0)
|
2022-08-31 14:12:09 +02:00
|
|
|
return;
|
|
|
|
|
|
2023-10-02 16:50:02 +09:00
|
|
|
var selectedItem = _cachedInventory.ElementAtOrDefault(index);
|
2022-08-31 14:12:09 +02:00
|
|
|
|
|
|
|
|
if (selectedItem == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
SendMessage(new VendingMachineEjectMessage(selectedItem.Type, selectedItem.ID));
|
2019-08-14 10:49:28 +02:00
|
|
|
}
|
2023-10-02 16:50:02 +09:00
|
|
|
// WD EDIT END
|
2019-08-14 10:49:28 +02:00
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(disposing);
|
2020-10-06 10:16:42 +02:00
|
|
|
if (!disposing)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-08-31 14:12:09 +02:00
|
|
|
if (_menu == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_menu.OnItemSelected -= OnItemSelected;
|
|
|
|
|
_menu.OnClose -= Close;
|
|
|
|
|
_menu.Dispose();
|
2019-08-14 10:49:28 +02:00
|
|
|
}
|
2023-09-20 12:40:41 -07:00
|
|
|
|
|
|
|
|
private void OnSearchChanged(string? filter)
|
|
|
|
|
{
|
2024-12-14 02:06:20 +03:00
|
|
|
//_menu?.filter = (filter ?? "");
|
2023-09-20 12:40:41 -07:00
|
|
|
}
|
2019-08-14 10:49:28 +02:00
|
|
|
}
|
|
|
|
|
}
|