Files
OldThink/Content.Client/Store/Ui/StoreBoundUserInterface.cs

79 lines
2.0 KiB
C#
Raw Normal View History

2022-08-17 00:34:25 -04:00
using Content.Shared.Store;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using System.Linq;
namespace Content.Client.Store.Ui;
[UsedImplicitly]
public sealed class StoreBoundUserInterface : BoundUserInterface
{
2023-07-08 09:02:17 -07:00
[ViewVariables]
2022-08-17 00:34:25 -04:00
private StoreMenu? _menu;
2023-07-08 09:02:17 -07:00
[ViewVariables]
2022-08-17 00:34:25 -04:00
private string _windowName = Loc.GetString("store-ui-default-title");
2023-07-08 09:02:17 -07:00
public StoreBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
2022-08-17 00:34:25 -04:00
{
}
protected override void Open()
{
_menu = new StoreMenu(_windowName);
_menu.OpenCentered();
_menu.OnClose += Close;
_menu.OnListingButtonPressed += (_, listing) =>
{
SendMessage(new StoreBuyListingMessage(listing));
2022-08-17 00:34:25 -04:00
};
_menu.OnCategoryButtonPressed += (_, category) =>
{
_menu.CurrentCategory = category;
SendMessage(new StoreRequestUpdateInterfaceMessage());
2022-08-17 00:34:25 -04:00
};
_menu.OnWithdrawAttempt += (_, type, amount) =>
{
SendMessage(new StoreRequestWithdrawMessage(type, amount));
2022-08-17 00:34:25 -04:00
};
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (_menu == null)
return;
switch (state)
{
case StoreUpdateState msg:
_menu.UpdateBalance(msg.Balance);
_menu.PopulateStoreCategoryButtons(msg.Listings);
_menu.UpdateListing(msg.Listings.ToList());
_menu.SetFooterVisibility(msg.ShowFooter);
2022-08-17 00:34:25 -04:00
break;
case StoreInitializeState msg:
_windowName = msg.Name;
if (_menu != null && _menu.Window != null)
{
2022-08-17 00:34:25 -04:00
_menu.Window.Title = msg.Name;
}
2022-08-17 00:34:25 -04:00
break;
}
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_menu?.Close();
_menu?.Dispose();
}
}