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:
@@ -2,6 +2,9 @@ using Content.Shared.Store;
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using Serilog;
|
||||||
|
using Timer = Robust.Shared.Timing.Timer;
|
||||||
|
|
||||||
namespace Content.Client.Store.Ui;
|
namespace Content.Client.Store.Ui;
|
||||||
|
|
||||||
@@ -40,6 +43,11 @@ public sealed class StoreBoundUserInterface : BoundUserInterface
|
|||||||
{
|
{
|
||||||
SendMessage(new StoreRequestWithdrawMessage(type, amount));
|
SendMessage(new StoreRequestWithdrawMessage(type, amount));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_menu.OnRefreshButtonPressed += (_) =>
|
||||||
|
{
|
||||||
|
SendMessage(new StoreRequestUpdateInterfaceMessage());
|
||||||
|
};
|
||||||
}
|
}
|
||||||
protected override void UpdateState(BoundUserInterfaceState state)
|
protected override void UpdateState(BoundUserInterfaceState state)
|
||||||
{
|
{
|
||||||
@@ -53,6 +61,7 @@ public sealed class StoreBoundUserInterface : BoundUserInterface
|
|||||||
case StoreUpdateState msg:
|
case StoreUpdateState msg:
|
||||||
_menu.UpdateBalance(msg.Balance);
|
_menu.UpdateBalance(msg.Balance);
|
||||||
_menu.PopulateStoreCategoryButtons(msg.Listings);
|
_menu.PopulateStoreCategoryButtons(msg.Listings);
|
||||||
|
|
||||||
_menu.UpdateListing(msg.Listings.ToList());
|
_menu.UpdateListing(msg.Listings.ToList());
|
||||||
_menu.SetFooterVisibility(msg.ShowFooter);
|
_menu.SetFooterVisibility(msg.ShowFooter);
|
||||||
break;
|
break;
|
||||||
@@ -71,7 +80,6 @@ public sealed class StoreBoundUserInterface : BoundUserInterface
|
|||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
if (!disposing)
|
if (!disposing)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_menu?.Close();
|
_menu?.Close();
|
||||||
_menu?.Dispose();
|
_menu?.Dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,11 @@
|
|||||||
HorizontalAlignment="Left"
|
HorizontalAlignment="Left"
|
||||||
Access="Public"
|
Access="Public"
|
||||||
HorizontalExpand="True" />
|
HorizontalExpand="True" />
|
||||||
|
<Button
|
||||||
|
Name="RefreshButton"
|
||||||
|
MinWidth="64"
|
||||||
|
HorizontalAlignment="Right"
|
||||||
|
Text="Refresh" />
|
||||||
<Button
|
<Button
|
||||||
Name="WithdrawButton"
|
Name="WithdrawButton"
|
||||||
MinWidth="64"
|
MinWidth="64"
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using Content.Client.Actions;
|
using Content.Client.Actions;
|
||||||
|
using Content.Client.GameTicking.Managers;
|
||||||
using Content.Client.Message;
|
using Content.Client.Message;
|
||||||
using Content.Shared.FixedPoint;
|
using Content.Shared.FixedPoint;
|
||||||
using Content.Shared.Store;
|
using Content.Shared.Store;
|
||||||
@@ -10,6 +12,7 @@ using Robust.Client.UserInterface.Controls;
|
|||||||
using Robust.Client.UserInterface.CustomControls;
|
using Robust.Client.UserInterface.CustomControls;
|
||||||
using Robust.Client.UserInterface.XAML;
|
using Robust.Client.UserInterface.XAML;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
|
using Robust.Shared.Timing;
|
||||||
|
|
||||||
namespace Content.Client.Store.Ui;
|
namespace Content.Client.Store.Ui;
|
||||||
|
|
||||||
@@ -18,12 +21,16 @@ public sealed partial class StoreMenu : DefaultWindow
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||||
[Dependency] private readonly IPrototypeManager _prototypeManager = 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;
|
private StoreWithdrawWindow? _withdrawWindow;
|
||||||
|
|
||||||
public event Action<BaseButton.ButtonEventArgs, ListingData>? OnListingButtonPressed;
|
public event Action<BaseButton.ButtonEventArgs, ListingData>? OnListingButtonPressed;
|
||||||
public event Action<BaseButton.ButtonEventArgs, string>? OnCategoryButtonPressed;
|
public event Action<BaseButton.ButtonEventArgs, string>? OnCategoryButtonPressed;
|
||||||
public event Action<BaseButton.ButtonEventArgs, string, int>? OnWithdrawAttempt;
|
public event Action<BaseButton.ButtonEventArgs, string, int>? OnWithdrawAttempt;
|
||||||
|
public event Action<BaseButton.ButtonEventArgs>? OnRefreshButtonPressed;
|
||||||
|
|
||||||
public Dictionary<string, FixedPoint2> Balance = new();
|
public Dictionary<string, FixedPoint2> Balance = new();
|
||||||
public string CurrentCategory = string.Empty;
|
public string CurrentCategory = string.Empty;
|
||||||
@@ -33,7 +40,10 @@ public sealed partial class StoreMenu : DefaultWindow
|
|||||||
RobustXamlLoader.Load(this);
|
RobustXamlLoader.Load(this);
|
||||||
IoCManager.InjectDependencies(this);
|
IoCManager.InjectDependencies(this);
|
||||||
|
|
||||||
|
_gameTicker = _entitySystem.GetEntitySystem<ClientGameTicker>();
|
||||||
|
|
||||||
WithdrawButton.OnButtonDown += OnWithdrawButtonDown;
|
WithdrawButton.OnButtonDown += OnWithdrawButtonDown;
|
||||||
|
RefreshButton.OnButtonDown += OnRefreshButtonDown;
|
||||||
if (Window != null)
|
if (Window != null)
|
||||||
Window.Title = name;
|
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());
|
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.
|
// should probably chunk these out instead. to-do if this clogs the internet tubes.
|
||||||
// maybe read clients prototypes instead?
|
// maybe read clients prototypes instead?
|
||||||
ClearListings();
|
ClearListings();
|
||||||
@@ -82,6 +93,12 @@ public sealed partial class StoreMenu : DefaultWindow
|
|||||||
TraitorFooter.Visible = visible;
|
TraitorFooter.Visible = visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void OnRefreshButtonDown(BaseButton.ButtonEventArgs args)
|
||||||
|
{
|
||||||
|
OnRefreshButtonPressed?.Invoke(args);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnWithdrawButtonDown(BaseButton.ButtonEventArgs args)
|
private void OnWithdrawButtonDown(BaseButton.ButtonEventArgs args)
|
||||||
{
|
{
|
||||||
// check if window is already open
|
// check if window is already open
|
||||||
@@ -135,14 +152,38 @@ public sealed partial class StoreMenu : DefaultWindow
|
|||||||
texture = spriteSys.Frame0(action.Icon);
|
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
|
newListing.StoreItemBuyButton.OnButtonDown += args
|
||||||
=> OnListingButtonPressed?.Invoke(args, listing);
|
=> OnListingButtonPressed?.Invoke(args, listing);
|
||||||
|
|
||||||
StoreListingsContainer.AddChild(newListing);
|
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)
|
public bool CanBuyListing(Dictionary<string, FixedPoint2> currency, Dictionary<string, FixedPoint2> price)
|
||||||
{
|
{
|
||||||
foreach (var type in price)
|
foreach (var type in price)
|
||||||
@@ -159,7 +200,6 @@ public sealed partial class StoreMenu : DefaultWindow
|
|||||||
public string GetListingPriceString(ListingData listing)
|
public string GetListingPriceString(ListingData listing)
|
||||||
{
|
{
|
||||||
var text = string.Empty;
|
var text = string.Empty;
|
||||||
|
|
||||||
if (listing.Cost.Count < 1)
|
if (listing.Cost.Count < 1)
|
||||||
text = Loc.GetString("store-currency-free");
|
text = Loc.GetString("store-currency-free");
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -84,6 +84,12 @@ public partial class ListingData : IEquatable<ListingData>, ICloneable
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int PurchaseAmount = 0;
|
public int PurchaseAmount = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used to delay purchase of some items.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("restockTime")]
|
||||||
|
public int RestockTime;
|
||||||
|
|
||||||
public bool Equals(ListingData? listing)
|
public bool Equals(ListingData? listing)
|
||||||
{
|
{
|
||||||
if (listing == null)
|
if (listing == null)
|
||||||
@@ -136,6 +142,7 @@ public partial class ListingData : IEquatable<ListingData>, ICloneable
|
|||||||
ProductAction = ProductAction,
|
ProductAction = ProductAction,
|
||||||
ProductEvent = ProductEvent,
|
ProductEvent = ProductEvent,
|
||||||
PurchaseAmount = PurchaseAmount,
|
PurchaseAmount = PurchaseAmount,
|
||||||
|
RestockTime = RestockTime,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -248,6 +248,7 @@
|
|||||||
Telecrystal: 11
|
Telecrystal: 11
|
||||||
categories:
|
categories:
|
||||||
- UplinkExplosives
|
- UplinkExplosives
|
||||||
|
restockTime: 10
|
||||||
|
|
||||||
# Ammo
|
# Ammo
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user