CatStation/Content.Client/Store/Ui/StoreListingControl.xaml.cs
KeTuFaisPiKiNut e1d8263bb7
Changeling Store Identity Count Condition (#45049)
* i wanna explode

* Revert "i wanna explode"

This reverts commit 595dc4ea49aa81d9ca19fccc52279cf7ef52c13d.

* fix

* Update Content.Client/Store/Ui/StoreListingControl.xaml.cs

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>

* Update Content.Server/Store/Conditions/BuyerBodyCountCondition.cs

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>

* Update Content.Shared/Store/ListingCondition.cs

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>

* Update Content.Shared/Store/ListingPrototype.cs

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>

* frog

* wewlad

* cut mah life into pieces, this is my last resort

* ewjqiorwerte

* Apply suggestion from @ScarKy0

* works

* Apply suggestion from @ScarKy0

* init

* small cleanup

* Revert "init"

This reverts commit db5d86aa6d662463972539462bccb61ba441624b.

---------

Co-authored-by: nomdéraisonnablementlong <you@example.com>
Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>
Co-authored-by: ScarKy0 <scarky0@onet.eu>
2026-08-18 19:01:04 +00:00

101 lines
3 KiB
C#

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.Prototypes;
using Robust.Shared.Timing;
namespace Content.Client.Store.Ui;
[GenerateTypedNameReferences]
public sealed partial class StoreListingControl : Control
{
[Dependency] private IPrototypeManager _prototype = default!;
[Dependency] private IEntityManager _entity = default!;
[Dependency] private IGameTiming _timing = default!;
private readonly ClientGameTicker _ticker;
private readonly ListingDataWithCostModifiers _data;
private readonly bool _hasBalance;
private readonly string _price;
private readonly string _discount;
public StoreListingControl(ListingDataWithCostModifiers data, string price, string discount, bool hasBalance, Texture? texture = null)
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);
_ticker = _entity.System<ClientGameTicker>();
_data = data;
_hasBalance = hasBalance;
_price = price;
_discount = discount;
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;
if (_data.Locked)
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 if (_data.Locked)
{
StoreItemBuyButton.Text = Loc.GetString("store-listing-locked");
}
else
{
DiscountSubText.Text = _discount;
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();
}
}