Option to delay uplink item purchase (#20214)
* Time delay for certain uplink stock. * Remove glitchy timer and add refresh button.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Content.Client.Actions;
|
||||
using Content.Client.GameTicking.Managers;
|
||||
using Content.Client.Message;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Store;
|
||||
@@ -10,6 +12,7 @@ using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Client.Store.Ui;
|
||||
|
||||
@@ -18,12 +21,16 @@ public sealed partial class StoreMenu : DefaultWindow
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystem = default!;
|
||||
private readonly ClientGameTicker _gameTicker;
|
||||
|
||||
private StoreWithdrawWindow? _withdrawWindow;
|
||||
|
||||
public event Action<BaseButton.ButtonEventArgs, ListingData>? OnListingButtonPressed;
|
||||
public event Action<BaseButton.ButtonEventArgs, string>? OnCategoryButtonPressed;
|
||||
public event Action<BaseButton.ButtonEventArgs, string, int>? OnWithdrawAttempt;
|
||||
public event Action<BaseButton.ButtonEventArgs>? OnRefreshButtonPressed;
|
||||
|
||||
public Dictionary<string, FixedPoint2> Balance = new();
|
||||
public string CurrentCategory = string.Empty;
|
||||
@@ -33,7 +40,10 @@ public sealed partial class StoreMenu : DefaultWindow
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_gameTicker = _entitySystem.GetEntitySystem<ClientGameTicker>();
|
||||
|
||||
WithdrawButton.OnButtonDown += OnWithdrawButtonDown;
|
||||
RefreshButton.OnButtonDown += OnRefreshButtonDown;
|
||||
if (Window != null)
|
||||
Window.Title = name;
|
||||
}
|
||||
@@ -68,6 +78,7 @@ public sealed partial class StoreMenu : DefaultWindow
|
||||
{
|
||||
var sorted = listings.OrderBy(l => l.Priority).ThenBy(l => l.Cost.Values.Sum());
|
||||
|
||||
|
||||
// should probably chunk these out instead. to-do if this clogs the internet tubes.
|
||||
// maybe read clients prototypes instead?
|
||||
ClearListings();
|
||||
@@ -82,6 +93,12 @@ public sealed partial class StoreMenu : DefaultWindow
|
||||
TraitorFooter.Visible = visible;
|
||||
}
|
||||
|
||||
|
||||
private void OnRefreshButtonDown(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
OnRefreshButtonPressed?.Invoke(args);
|
||||
}
|
||||
|
||||
private void OnWithdrawButtonDown(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
// check if window is already open
|
||||
@@ -135,14 +152,38 @@ public sealed partial class StoreMenu : DefaultWindow
|
||||
texture = spriteSys.Frame0(action.Icon);
|
||||
}
|
||||
}
|
||||
var listingInStock = ListingInStock(listing);
|
||||
if (listingInStock != GetListingPriceString(listing))
|
||||
{
|
||||
listingName += " (Out of stock)";
|
||||
canBuy = false;
|
||||
}
|
||||
|
||||
var newListing = new StoreListingControl(listingName, listingDesc, GetListingPriceString(listing), canBuy, texture);
|
||||
var newListing = new StoreListingControl(listingName, listingDesc, listingInStock, canBuy, texture);
|
||||
newListing.StoreItemBuyButton.OnButtonDown += args
|
||||
=> OnListingButtonPressed?.Invoke(args, listing);
|
||||
|
||||
StoreListingsContainer.AddChild(newListing);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return time until available or the cost.
|
||||
/// </summary>
|
||||
/// <param name="listing"></param>
|
||||
/// <returns></returns>
|
||||
public string ListingInStock(ListingData listing)
|
||||
{
|
||||
var stationTime = _gameTiming.CurTime.Subtract(_gameTicker.RoundStartTimeSpan);
|
||||
|
||||
TimeSpan restockTimeSpan = TimeSpan.FromMinutes(listing.RestockTime);
|
||||
if (restockTimeSpan > stationTime)
|
||||
{
|
||||
var timeLeftToBuy = stationTime - restockTimeSpan;
|
||||
return timeLeftToBuy.Duration().ToString(@"mm\:ss");
|
||||
}
|
||||
|
||||
return GetListingPriceString(listing);
|
||||
}
|
||||
public bool CanBuyListing(Dictionary<string, FixedPoint2> currency, Dictionary<string, FixedPoint2> price)
|
||||
{
|
||||
foreach (var type in price)
|
||||
@@ -159,7 +200,6 @@ public sealed partial class StoreMenu : DefaultWindow
|
||||
public string GetListingPriceString(ListingData listing)
|
||||
{
|
||||
var text = string.Empty;
|
||||
|
||||
if (listing.Cost.Count < 1)
|
||||
text = Loc.GetString("store-currency-free");
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user