]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Option to delay uplink item purchase (#20214)
authorRepo <47093363+Titian3@users.noreply.github.com>
Tue, 19 Sep 2023 23:51:15 +0000 (11:51 +1200)
committerGitHub <noreply@github.com>
Tue, 19 Sep 2023 23:51:15 +0000 (16:51 -0700)
* Time delay for certain uplink stock.

* Remove glitchy timer and add refresh button.

Content.Client/Store/Ui/StoreBoundUserInterface.cs
Content.Client/Store/Ui/StoreMenu.xaml
Content.Client/Store/Ui/StoreMenu.xaml.cs
Content.Shared/Store/ListingPrototype.cs
Resources/Prototypes/Catalog/uplink_catalog.yml

index 0860abb9faba17fecb449439df9640e5fe9e5aad..6774ef35a021fb1b947a0e5dcb47a95fa33f9793 100644 (file)
@@ -2,6 +2,9 @@ using Content.Shared.Store;
 using JetBrains.Annotations;
 using Robust.Client.GameObjects;
 using System.Linq;
+using System.Threading;
+using Serilog;
+using Timer = Robust.Shared.Timing.Timer;
 
 namespace Content.Client.Store.Ui;
 
@@ -40,6 +43,11 @@ public sealed class StoreBoundUserInterface : BoundUserInterface
         {
             SendMessage(new StoreRequestWithdrawMessage(type, amount));
         };
+
+        _menu.OnRefreshButtonPressed += (_) =>
+        {
+            SendMessage(new StoreRequestUpdateInterfaceMessage());
+        };
     }
     protected override void UpdateState(BoundUserInterfaceState state)
     {
@@ -53,6 +61,7 @@ public sealed class StoreBoundUserInterface : BoundUserInterface
             case StoreUpdateState msg:
                 _menu.UpdateBalance(msg.Balance);
                 _menu.PopulateStoreCategoryButtons(msg.Listings);
+
                 _menu.UpdateListing(msg.Listings.ToList());
                 _menu.SetFooterVisibility(msg.ShowFooter);
                 break;
@@ -71,7 +80,6 @@ public sealed class StoreBoundUserInterface : BoundUserInterface
         base.Dispose(disposing);
         if (!disposing)
             return;
-
         _menu?.Close();
         _menu?.Dispose();
     }
index 824c153671b7461ee3bcad9daaf6310e560a5bfb..a454e3e2b7f4feaa70996ed795e5bdad6166d823 100644 (file)
                     HorizontalAlignment="Left"
                     Access="Public"
                     HorizontalExpand="True" />
+                <Button
+                    Name="RefreshButton"
+                    MinWidth="64"
+                    HorizontalAlignment="Right"
+                    Text="Refresh" />
                 <Button
                     Name="WithdrawButton"
                     MinWidth="64"
index c59c3a1062a13da9e61823806bf43bac86da40c5..d938dbfe542c64642ef9f81ce109765b0142c82e 100644 (file)
@@ -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
index e695c30e5cd80cbc602fd096a74c0ac5a243145e..0adcbd46374cc8e42e96793b51b159f80e95ef27 100644 (file)
@@ -84,6 +84,12 @@ public partial class ListingData : IEquatable<ListingData>, ICloneable
     /// </summary>
     public int PurchaseAmount = 0;
 
+    /// <summary>
+    /// Used to delay purchase of some items.
+    /// </summary>
+    [DataField("restockTime")]
+    public int RestockTime;
+
     public bool Equals(ListingData? listing)
     {
         if (listing == null)
@@ -136,6 +142,7 @@ public partial class ListingData : IEquatable<ListingData>, ICloneable
             ProductAction = ProductAction,
             ProductEvent = ProductEvent,
             PurchaseAmount = PurchaseAmount,
+            RestockTime = RestockTime,
         };
     }
 }
index 62ba6594bfede0c2fd583b659e281dfee36266cd..8faf8bdfa76093b62099b6f62b96bf2ea3fa4c44 100644 (file)
     Telecrystal: 11
   categories:
     - UplinkExplosives
+  restockTime: 10
 
 # Ammo