diff --git a/Content.Client/Store/Ui/StoreBoundUserInterface.cs b/Content.Client/Store/Ui/StoreBoundUserInterface.cs index f87b92bc615ef9..88ad0e3de8b5b9 100644 --- a/Content.Client/Store/Ui/StoreBoundUserInterface.cs +++ b/Content.Client/Store/Ui/StoreBoundUserInterface.cs @@ -17,7 +17,7 @@ public sealed class StoreBoundUserInterface : BoundUserInterface private string _windowName = Loc.GetString("store-ui-default-title"); [ViewVariables] - private string _search = ""; + private string _search = string.Empty; [ViewVariables] private HashSet _listings = new(); @@ -41,7 +41,7 @@ protected override void Open() _menu.OnCategoryButtonPressed += (_, category) => { _menu.CurrentCategory = category; - SendMessage(new StoreRequestUpdateInterfaceMessage()); + _menu?.UpdateListing(); }; _menu.OnWithdrawAttempt += (_, type, amount) => @@ -49,11 +49,6 @@ protected override void Open() SendMessage(new StoreRequestWithdrawMessage(type, amount)); }; - _menu.OnRefreshButtonPressed += (_) => - { - SendMessage(new StoreRequestUpdateInterfaceMessage()); - }; - _menu.SearchTextUpdated += (_, search) => { _search = search.Trim().ToLowerInvariant(); diff --git a/Content.Client/Store/Ui/StoreListingControl.xaml b/Content.Client/Store/Ui/StoreListingControl.xaml index aefeec17cc8e4e..12b4d7b5b3002c 100644 --- a/Content.Client/Store/Ui/StoreListingControl.xaml +++ b/Content.Client/Store/Ui/StoreListingControl.xaml @@ -15,6 +15,7 @@ Margin="0,0,4,0" MinSize="48 48" Stretch="KeepAspectCentered" /> + diff --git a/Content.Client/Store/Ui/StoreListingControl.xaml.cs b/Content.Client/Store/Ui/StoreListingControl.xaml.cs index bb600588e042be..030f07dc7ca95c 100644 --- a/Content.Client/Store/Ui/StoreListingControl.xaml.cs +++ b/Content.Client/Store/Ui/StoreListingControl.xaml.cs @@ -1,25 +1,91 @@ +using Content.Client.GameTicking.Managers; +using Content.Shared.Store; using Robust.Client.AutoGenerated; using Robust.Client.Graphics; using Robust.Client.UserInterface; using Robust.Client.UserInterface.XAML; -using Robust.Shared.Graphics; +using Robust.Shared.Prototypes; +using Robust.Shared.Timing; namespace Content.Client.Store.Ui; [GenerateTypedNameReferences] public sealed partial class StoreListingControl : Control { - public StoreListingControl(string itemName, string itemDescription, - string price, bool canBuy, Texture? texture = null) + [Dependency] private readonly IPrototypeManager _prototype = default!; + [Dependency] private readonly IEntityManager _entity = default!; + [Dependency] private readonly IGameTiming _timing = default!; + private readonly ClientGameTicker _ticker; + + private readonly ListingData _data; + + private readonly bool _hasBalance; + private readonly string _price; + public StoreListingControl(ListingData data, string price, bool hasBalance, Texture? texture = null) { + IoCManager.InjectDependencies(this); RobustXamlLoader.Load(this); - StoreItemName.Text = itemName; - StoreItemDescription.SetMessage(itemDescription); + _ticker = _entity.System(); + + _data = data; + _hasBalance = hasBalance; + _price = price; - StoreItemBuyButton.Text = price; - StoreItemBuyButton.Disabled = !canBuy; + StoreItemName.Text = ListingLocalisationHelpers.GetLocalisedNameOrEntityName(_data, _prototype); + StoreItemDescription.SetMessage(ListingLocalisationHelpers.GetLocalisedDescriptionOrEntityDescription(_data, _prototype)); + + UpdateBuyButtonText(); + StoreItemBuyButton.Disabled = !CanBuy(); StoreItemTexture.Texture = texture; } + + private bool CanBuy() + { + if (!_hasBalance) + return false; + + var stationTime = _timing.CurTime.Subtract(_ticker.RoundStartTimeSpan); + if (_data.RestockTime > stationTime) + return false; + + return true; + } + + private void UpdateBuyButtonText() + { + var stationTime = _timing.CurTime.Subtract(_ticker.RoundStartTimeSpan); + if (_data.RestockTime > stationTime) + { + var timeLeftToBuy = stationTime - _data.RestockTime; + StoreItemBuyButton.Text = timeLeftToBuy.Duration().ToString(@"mm\:ss"); + } + else + { + StoreItemBuyButton.Text = _price; + } + } + + private void UpdateName() + { + var name = ListingLocalisationHelpers.GetLocalisedNameOrEntityName(_data, _prototype); + + var stationTime = _timing.CurTime.Subtract(_ticker.RoundStartTimeSpan); + if (_data.RestockTime > stationTime) + { + name += Loc.GetString("store-ui-button-out-of-stock"); + } + + StoreItemName.Text = name; + } + + protected override void FrameUpdate(FrameEventArgs args) + { + base.FrameUpdate(args); + + UpdateBuyButtonText(); + UpdateName(); + StoreItemBuyButton.Disabled = !CanBuy(); + } } diff --git a/Content.Client/Store/Ui/StoreMenu.xaml b/Content.Client/Store/Ui/StoreMenu.xaml index fc4cbe444fc573..843c9dc0296a5c 100644 --- a/Content.Client/Store/Ui/StoreMenu.xaml +++ b/Content.Client/Store/Ui/StoreMenu.xaml @@ -12,11 +12,6 @@ HorizontalAlignment="Left" Access="Public" HorizontalExpand="True" /> -