uplink and store freshening (#26444)
* uplink and store freshening * more * im gonna POOOOOOGGGGGGG * we love it
This commit is contained in:
@@ -17,7 +17,7 @@ public sealed class StoreBoundUserInterface : BoundUserInterface
|
|||||||
private string _windowName = Loc.GetString("store-ui-default-title");
|
private string _windowName = Loc.GetString("store-ui-default-title");
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
private string _search = "";
|
private string _search = string.Empty;
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
private HashSet<ListingData> _listings = new();
|
private HashSet<ListingData> _listings = new();
|
||||||
@@ -41,7 +41,7 @@ public sealed class StoreBoundUserInterface : BoundUserInterface
|
|||||||
_menu.OnCategoryButtonPressed += (_, category) =>
|
_menu.OnCategoryButtonPressed += (_, category) =>
|
||||||
{
|
{
|
||||||
_menu.CurrentCategory = category;
|
_menu.CurrentCategory = category;
|
||||||
SendMessage(new StoreRequestUpdateInterfaceMessage());
|
_menu?.UpdateListing();
|
||||||
};
|
};
|
||||||
|
|
||||||
_menu.OnWithdrawAttempt += (_, type, amount) =>
|
_menu.OnWithdrawAttempt += (_, type, amount) =>
|
||||||
@@ -49,11 +49,6 @@ public sealed class StoreBoundUserInterface : BoundUserInterface
|
|||||||
SendMessage(new StoreRequestWithdrawMessage(type, amount));
|
SendMessage(new StoreRequestWithdrawMessage(type, amount));
|
||||||
};
|
};
|
||||||
|
|
||||||
_menu.OnRefreshButtonPressed += (_) =>
|
|
||||||
{
|
|
||||||
SendMessage(new StoreRequestUpdateInterfaceMessage());
|
|
||||||
};
|
|
||||||
|
|
||||||
_menu.SearchTextUpdated += (_, search) =>
|
_menu.SearchTextUpdated += (_, search) =>
|
||||||
{
|
{
|
||||||
_search = search.Trim().ToLowerInvariant();
|
_search = search.Trim().ToLowerInvariant();
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
Margin="0,0,4,0"
|
Margin="0,0,4,0"
|
||||||
MinSize="48 48"
|
MinSize="48 48"
|
||||||
Stretch="KeepAspectCentered" />
|
Stretch="KeepAspectCentered" />
|
||||||
|
<Control MinWidth="5"/>
|
||||||
<RichTextLabel Name="StoreItemDescription" />
|
<RichTextLabel Name="StoreItemDescription" />
|
||||||
</BoxContainer>
|
</BoxContainer>
|
||||||
</BoxContainer>
|
</BoxContainer>
|
||||||
|
|||||||
@@ -1,25 +1,91 @@
|
|||||||
|
using Content.Client.GameTicking.Managers;
|
||||||
|
using Content.Shared.Store;
|
||||||
using Robust.Client.AutoGenerated;
|
using Robust.Client.AutoGenerated;
|
||||||
using Robust.Client.Graphics;
|
using Robust.Client.Graphics;
|
||||||
using Robust.Client.UserInterface;
|
using Robust.Client.UserInterface;
|
||||||
using Robust.Client.UserInterface.XAML;
|
using Robust.Client.UserInterface.XAML;
|
||||||
using Robust.Shared.Graphics;
|
using Robust.Shared.Prototypes;
|
||||||
|
using Robust.Shared.Timing;
|
||||||
|
|
||||||
namespace Content.Client.Store.Ui;
|
namespace Content.Client.Store.Ui;
|
||||||
|
|
||||||
[GenerateTypedNameReferences]
|
[GenerateTypedNameReferences]
|
||||||
public sealed partial class StoreListingControl : Control
|
public sealed partial class StoreListingControl : Control
|
||||||
{
|
{
|
||||||
public StoreListingControl(string itemName, string itemDescription,
|
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
||||||
string price, bool canBuy, Texture? texture = null)
|
[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);
|
RobustXamlLoader.Load(this);
|
||||||
|
|
||||||
StoreItemName.Text = itemName;
|
_ticker = _entity.System<ClientGameTicker>();
|
||||||
StoreItemDescription.SetMessage(itemDescription);
|
|
||||||
|
|
||||||
StoreItemBuyButton.Text = price;
|
_data = data;
|
||||||
StoreItemBuyButton.Disabled = !canBuy;
|
_hasBalance = hasBalance;
|
||||||
|
_price = price;
|
||||||
|
|
||||||
|
StoreItemName.Text = ListingLocalisationHelpers.GetLocalisedNameOrEntityName(_data, _prototype);
|
||||||
|
StoreItemDescription.SetMessage(ListingLocalisationHelpers.GetLocalisedDescriptionOrEntityDescription(_data, _prototype));
|
||||||
|
|
||||||
|
UpdateBuyButtonText();
|
||||||
|
StoreItemBuyButton.Disabled = !CanBuy();
|
||||||
|
|
||||||
StoreItemTexture.Texture = texture;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,11 +12,6 @@
|
|||||||
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,6 +1,5 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
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;
|
||||||
@@ -11,7 +10,6 @@ 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;
|
||||||
|
|
||||||
@@ -20,9 +18,6 @@ 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;
|
||||||
|
|
||||||
@@ -30,21 +25,19 @@ public sealed partial class StoreMenu : DefaultWindow
|
|||||||
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 event Action<BaseButton.ButtonEventArgs>? OnRefundAttempt;
|
public event Action<BaseButton.ButtonEventArgs>? OnRefundAttempt;
|
||||||
|
|
||||||
public Dictionary<string, FixedPoint2> Balance = new();
|
public Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> Balance = new();
|
||||||
public string CurrentCategory = string.Empty;
|
public string CurrentCategory = string.Empty;
|
||||||
|
|
||||||
|
private List<ListingData> _cachedListings = new();
|
||||||
|
|
||||||
public StoreMenu(string name)
|
public StoreMenu(string name)
|
||||||
{
|
{
|
||||||
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;
|
|
||||||
RefundButton.OnButtonDown += OnRefundButtonDown;
|
RefundButton.OnButtonDown += OnRefundButtonDown;
|
||||||
SearchBar.OnTextChanged += _ => SearchTextUpdated?.Invoke(this, SearchBar.Text);
|
SearchBar.OnTextChanged += _ => SearchTextUpdated?.Invoke(this, SearchBar.Text);
|
||||||
|
|
||||||
@@ -52,12 +45,12 @@ public sealed partial class StoreMenu : DefaultWindow
|
|||||||
Window.Title = name;
|
Window.Title = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateBalance(Dictionary<string, FixedPoint2> balance)
|
public void UpdateBalance(Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> balance)
|
||||||
{
|
{
|
||||||
Balance = balance;
|
Balance = balance;
|
||||||
|
|
||||||
var currency = balance.ToDictionary(type =>
|
var currency = balance.ToDictionary(type =>
|
||||||
(type.Key, type.Value), type => _prototypeManager.Index<CurrencyPrototype>(type.Key));
|
(type.Key, type.Value), type => _prototypeManager.Index(type.Key));
|
||||||
|
|
||||||
var balanceStr = string.Empty;
|
var balanceStr = string.Empty;
|
||||||
foreach (var ((_, amount), proto) in currency)
|
foreach (var ((_, amount), proto) in currency)
|
||||||
@@ -80,7 +73,13 @@ public sealed partial class StoreMenu : DefaultWindow
|
|||||||
|
|
||||||
public void UpdateListing(List<ListingData> listings)
|
public void UpdateListing(List<ListingData> listings)
|
||||||
{
|
{
|
||||||
var sorted = listings.OrderBy(l => l.Priority).ThenBy(l => l.Cost.Values.Sum());
|
_cachedListings = listings;
|
||||||
|
UpdateListing();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateListing()
|
||||||
|
{
|
||||||
|
var sorted = _cachedListings.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?
|
||||||
@@ -96,12 +95,6 @@ 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
|
||||||
@@ -129,10 +122,8 @@ public sealed partial class StoreMenu : DefaultWindow
|
|||||||
if (!listing.Categories.Contains(CurrentCategory))
|
if (!listing.Categories.Contains(CurrentCategory))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var listingName = ListingLocalisationHelpers.GetLocalisedNameOrEntityName(listing, _prototypeManager);
|
|
||||||
var listingDesc = ListingLocalisationHelpers.GetLocalisedDescriptionOrEntityDescription(listing, _prototypeManager);
|
|
||||||
var listingPrice = listing.Cost;
|
var listingPrice = listing.Cost;
|
||||||
var canBuy = CanBuyListing(Balance, listingPrice);
|
var hasBalance = HasListingPrice(Balance, listingPrice);
|
||||||
|
|
||||||
var spriteSys = _entityManager.EntitySysManager.GetEntitySystem<SpriteSystem>();
|
var spriteSys = _entityManager.EntitySysManager.GetEntitySystem<SpriteSystem>();
|
||||||
|
|
||||||
@@ -154,39 +145,15 @@ 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, listingInStock, canBuy, texture);
|
var newListing = new StoreListingControl(listing, GetListingPriceString(listing), hasBalance, texture);
|
||||||
newListing.StoreItemBuyButton.OnButtonDown += args
|
newListing.StoreItemBuyButton.OnButtonDown += args
|
||||||
=> OnListingButtonPressed?.Invoke(args, listing);
|
=> OnListingButtonPressed?.Invoke(args, listing);
|
||||||
|
|
||||||
StoreListingsContainer.AddChild(newListing);
|
StoreListingsContainer.AddChild(newListing);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public bool HasListingPrice(Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> currency, Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> price)
|
||||||
/// 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)
|
foreach (var type in price)
|
||||||
{
|
{
|
||||||
@@ -208,7 +175,7 @@ public sealed partial class StoreMenu : DefaultWindow
|
|||||||
{
|
{
|
||||||
foreach (var (type, amount) in listing.Cost)
|
foreach (var (type, amount) in listing.Cost)
|
||||||
{
|
{
|
||||||
var currency = _prototypeManager.Index<CurrencyPrototype>(type);
|
var currency = _prototypeManager.Index(type);
|
||||||
text += Loc.GetString("store-ui-price-display", ("amount", amount),
|
text += Loc.GetString("store-ui-price-display", ("amount", amount),
|
||||||
("currency", Loc.GetString(currency.DisplayName, ("amount", amount))));
|
("currency", Loc.GetString(currency.DisplayName, ("amount", amount))));
|
||||||
}
|
}
|
||||||
@@ -229,7 +196,7 @@ public sealed partial class StoreMenu : DefaultWindow
|
|||||||
{
|
{
|
||||||
foreach (var cat in listing.Categories)
|
foreach (var cat in listing.Categories)
|
||||||
{
|
{
|
||||||
var proto = _prototypeManager.Index<StoreCategoryPrototype>(cat);
|
var proto = _prototypeManager.Index(cat);
|
||||||
if (!allCategories.Contains(proto))
|
if (!allCategories.Contains(proto))
|
||||||
allCategories.Add(proto);
|
allCategories.Add(proto);
|
||||||
}
|
}
|
||||||
@@ -248,12 +215,17 @@ public sealed partial class StoreMenu : DefaultWindow
|
|||||||
if (allCategories.Count < 1)
|
if (allCategories.Count < 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var group = new ButtonGroup();
|
||||||
foreach (var proto in allCategories)
|
foreach (var proto in allCategories)
|
||||||
{
|
{
|
||||||
var catButton = new StoreCategoryButton
|
var catButton = new StoreCategoryButton
|
||||||
{
|
{
|
||||||
Text = Loc.GetString(proto.Name),
|
Text = Loc.GetString(proto.Name),
|
||||||
Id = proto.ID
|
Id = proto.ID,
|
||||||
|
Pressed = proto.ID == CurrentCategory,
|
||||||
|
Group = group,
|
||||||
|
ToggleMode = true,
|
||||||
|
StyleClasses = { "OpenBoth" }
|
||||||
};
|
};
|
||||||
|
|
||||||
catButton.OnPressed += args => OnCategoryButtonPressed?.Invoke(args, catButton.Id);
|
catButton.OnPressed += args => OnCategoryButtonPressed?.Invoke(args, catButton.Id);
|
||||||
@@ -269,7 +241,7 @@ public sealed partial class StoreMenu : DefaultWindow
|
|||||||
|
|
||||||
public void UpdateRefund(bool allowRefund)
|
public void UpdateRefund(bool allowRefund)
|
||||||
{
|
{
|
||||||
RefundButton.Disabled = !allowRefund;
|
RefundButton.Visible = allowRefund;
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed class StoreCategoryButton : Button
|
private sealed class StoreCategoryButton : Button
|
||||||
|
|||||||
@@ -28,12 +28,12 @@ public sealed partial class StoreWithdrawWindow : DefaultWindow
|
|||||||
IoCManager.InjectDependencies(this);
|
IoCManager.InjectDependencies(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CreateCurrencyButtons(Dictionary<string, FixedPoint2> balance)
|
public void CreateCurrencyButtons(Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> balance)
|
||||||
{
|
{
|
||||||
_validCurrencies.Clear();
|
_validCurrencies.Clear();
|
||||||
foreach (var currency in balance)
|
foreach (var currency in balance)
|
||||||
{
|
{
|
||||||
if (!_prototypeManager.TryIndex<CurrencyPrototype>(currency.Key, out var proto))
|
if (!_prototypeManager.TryIndex(currency.Key, out var proto))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
_validCurrencies.Add(currency.Value, proto);
|
_validCurrencies.Add(currency.Value, proto);
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ using Content.Server.PDA.Ringer;
|
|||||||
using Content.Server.Stack;
|
using Content.Server.Stack;
|
||||||
using Content.Server.Store.Components;
|
using Content.Server.Store.Components;
|
||||||
using Content.Shared.Actions;
|
using Content.Shared.Actions;
|
||||||
using Content.Shared.Administration.Logs;
|
|
||||||
using Content.Shared.Database;
|
using Content.Shared.Database;
|
||||||
using Content.Shared.FixedPoint;
|
using Content.Shared.FixedPoint;
|
||||||
using Content.Shared.Hands.EntitySystems;
|
using Content.Shared.Hands.EntitySystems;
|
||||||
@@ -99,13 +98,13 @@ public sealed partial class StoreSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
//dictionary for all currencies, including 0 values for currencies on the whitelist
|
//dictionary for all currencies, including 0 values for currencies on the whitelist
|
||||||
Dictionary<string, FixedPoint2> allCurrency = new();
|
Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> allCurrency = new();
|
||||||
foreach (var supported in component.CurrencyWhitelist)
|
foreach (var supported in component.CurrencyWhitelist)
|
||||||
{
|
{
|
||||||
allCurrency.Add(supported, FixedPoint2.Zero);
|
allCurrency.Add(supported, FixedPoint2.Zero);
|
||||||
|
|
||||||
if (component.Balance.ContainsKey(supported))
|
if (component.Balance.TryGetValue(supported, out var value))
|
||||||
allCurrency[supported] = component.Balance[supported];
|
allCurrency[supported] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: if multiple users are supposed to be able to interact with a single BUI & see different
|
// TODO: if multiple users are supposed to be able to interact with a single BUI & see different
|
||||||
|
|||||||
@@ -11,15 +11,14 @@ public static class ListingLocalisationHelpers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static string GetLocalisedNameOrEntityName(ListingData listingData, IPrototypeManager prototypeManager)
|
public static string GetLocalisedNameOrEntityName(ListingData listingData, IPrototypeManager prototypeManager)
|
||||||
{
|
{
|
||||||
bool wasLocalised = Loc.TryGetString(listingData.Name, out string? listingName);
|
var name = string.Empty;
|
||||||
|
|
||||||
if (!wasLocalised && listingData.ProductEntity != null)
|
if (listingData.Name != null)
|
||||||
{
|
name = Loc.GetString(listingData.Name);
|
||||||
var proto = prototypeManager.Index<EntityPrototype>(listingData.ProductEntity);
|
else if (listingData.ProductEntity != null)
|
||||||
listingName = proto.Name;
|
name = prototypeManager.Index(listingData.ProductEntity.Value).Name;
|
||||||
}
|
|
||||||
|
|
||||||
return listingName ?? listingData.Name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -29,14 +28,13 @@ public static class ListingLocalisationHelpers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static string GetLocalisedDescriptionOrEntityDescription(ListingData listingData, IPrototypeManager prototypeManager)
|
public static string GetLocalisedDescriptionOrEntityDescription(ListingData listingData, IPrototypeManager prototypeManager)
|
||||||
{
|
{
|
||||||
bool wasLocalised = Loc.TryGetString(listingData.Description, out string? listingDesc);
|
var desc = string.Empty;
|
||||||
|
|
||||||
if (!wasLocalised && listingData.ProductEntity != null)
|
if (listingData.Description != null)
|
||||||
{
|
desc = Loc.GetString(listingData.Description);
|
||||||
var proto = prototypeManager.Index<EntityPrototype>(listingData.ProductEntity);
|
else if (listingData.ProductEntity != null)
|
||||||
listingDesc = proto.Description;
|
desc = prototypeManager.Index(listingData.ProductEntity.Value).Description;
|
||||||
}
|
|
||||||
|
|
||||||
return listingDesc ?? listingData.Description;
|
return desc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,6 @@ using System.Linq;
|
|||||||
using Content.Shared.FixedPoint;
|
using Content.Shared.FixedPoint;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.Serialization.TypeSerializers.Implementations;
|
|
||||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
|
||||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
|
|
||||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Shared.Store;
|
namespace Content.Shared.Store;
|
||||||
@@ -26,57 +22,57 @@ public partial class ListingData : IEquatable<ListingData>, ICloneable
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The name of the listing. If empty, uses the entity's name (if present)
|
/// The name of the listing. If empty, uses the entity's name (if present)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("name")]
|
[DataField]
|
||||||
public string Name = string.Empty;
|
public string? Name;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The description of the listing. If empty, uses the entity's description (if present)
|
/// The description of the listing. If empty, uses the entity's description (if present)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("description")]
|
[DataField]
|
||||||
public string Description = string.Empty;
|
public string? Description;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The categories that this listing applies to. Used for filtering a listing for a store.
|
/// The categories that this listing applies to. Used for filtering a listing for a store.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("categories", required: true, customTypeSerializer: typeof(PrototypeIdListSerializer<StoreCategoryPrototype>))]
|
[DataField]
|
||||||
public List<string> Categories = new();
|
public List<ProtoId<StoreCategoryPrototype>> Categories = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The cost of the listing. String represents the currency type while the FixedPoint2 represents the amount of that currency.
|
/// The cost of the listing. String represents the currency type while the FixedPoint2 represents the amount of that currency.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("cost", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<FixedPoint2, CurrencyPrototype>))]
|
[DataField]
|
||||||
public Dictionary<string, FixedPoint2> Cost = new();
|
public Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> Cost = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specific customizeable conditions that determine whether or not the listing can be purchased.
|
/// Specific customizable conditions that determine whether or not the listing can be purchased.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
[DataField("conditions", serverOnly: true)]
|
[DataField(serverOnly: true)]
|
||||||
public List<ListingCondition>? Conditions;
|
public List<ListingCondition>? Conditions;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The icon for the listing. If null, uses the icon for the entity or action.
|
/// The icon for the listing. If null, uses the icon for the entity or action.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("icon")]
|
[DataField]
|
||||||
public SpriteSpecifier? Icon;
|
public SpriteSpecifier? Icon;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The priority for what order the listings will show up in on the menu.
|
/// The priority for what order the listings will show up in on the menu.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("priority")]
|
[DataField]
|
||||||
public int Priority = 0;
|
public int Priority;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The entity that is given when the listing is purchased.
|
/// The entity that is given when the listing is purchased.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("productEntity", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
[DataField]
|
||||||
public string? ProductEntity;
|
public EntProtoId? ProductEntity;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The action that is given when the listing is purchased.
|
/// The action that is given when the listing is purchased.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("productAction", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
[DataField]
|
||||||
public string? ProductAction;
|
public EntProtoId? ProductAction;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The listing ID of the related upgrade listing. Can be used to link a <see cref="ProductAction"/> to an
|
/// The listing ID of the related upgrade listing. Can be used to link a <see cref="ProductAction"/> to an
|
||||||
@@ -95,7 +91,7 @@ public partial class ListingData : IEquatable<ListingData>, ICloneable
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The event that is broadcast when the listing is purchased.
|
/// The event that is broadcast when the listing is purchased.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("productEvent")]
|
[DataField]
|
||||||
public object? ProductEvent;
|
public object? ProductEvent;
|
||||||
|
|
||||||
[DataField]
|
[DataField]
|
||||||
@@ -104,13 +100,14 @@ public partial class ListingData : IEquatable<ListingData>, ICloneable
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// used internally for tracking how many times an item was purchased.
|
/// used internally for tracking how many times an item was purchased.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int PurchaseAmount = 0;
|
[DataField]
|
||||||
|
public int PurchaseAmount;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used to delay purchase of some items.
|
/// Used to delay purchase of some items.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("restockTime")]
|
[DataField]
|
||||||
public int RestockTime;
|
public TimeSpan RestockTime = TimeSpan.Zero;
|
||||||
|
|
||||||
public bool Equals(ListingData? listing)
|
public bool Equals(ListingData? listing)
|
||||||
{
|
{
|
||||||
@@ -173,14 +170,10 @@ public partial class ListingData : IEquatable<ListingData>, ICloneable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//<inheritdoc>
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines a set item listing that is available in a store
|
/// Defines a set item listing that is available in a store
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Prototype("listing")]
|
[Prototype("listing")]
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
[DataDefinition]
|
[DataDefinition]
|
||||||
public sealed partial class ListingPrototype : ListingData, IPrototype
|
public sealed partial class ListingPrototype : ListingData, IPrototype;
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Content.Shared.FixedPoint;
|
using Content.Shared.FixedPoint;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Shared.Store;
|
namespace Content.Shared.Store;
|
||||||
@@ -14,13 +15,13 @@ public sealed class StoreUpdateState : BoundUserInterfaceState
|
|||||||
{
|
{
|
||||||
public readonly HashSet<ListingData> Listings;
|
public readonly HashSet<ListingData> Listings;
|
||||||
|
|
||||||
public readonly Dictionary<string, FixedPoint2> Balance;
|
public readonly Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> Balance;
|
||||||
|
|
||||||
public readonly bool ShowFooter;
|
public readonly bool ShowFooter;
|
||||||
|
|
||||||
public readonly bool AllowRefund;
|
public readonly bool AllowRefund;
|
||||||
|
|
||||||
public StoreUpdateState(HashSet<ListingData> listings, Dictionary<string, FixedPoint2> balance, bool showFooter, bool allowRefund)
|
public StoreUpdateState(HashSet<ListingData> listings, Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> balance, bool showFooter, bool allowRefund)
|
||||||
{
|
{
|
||||||
Listings = listings;
|
Listings = listings;
|
||||||
Balance = balance;
|
Balance = balance;
|
||||||
@@ -46,9 +47,7 @@ public sealed class StoreInitializeState : BoundUserInterfaceState
|
|||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class StoreRequestUpdateInterfaceMessage : BoundUserInterfaceMessage
|
public sealed class StoreRequestUpdateInterfaceMessage : BoundUserInterfaceMessage
|
||||||
{
|
{
|
||||||
public StoreRequestUpdateInterfaceMessage()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
|
|||||||
@@ -6,5 +6,5 @@ store-ui-traitor-flavor = Copyright (C) NT -30643
|
|||||||
store-ui-traitor-warning = Operatives must lock their uplinks after use to avoid detection.
|
store-ui-traitor-warning = Operatives must lock their uplinks after use to avoid detection.
|
||||||
|
|
||||||
store-withdraw-button-ui = Withdraw {$currency}
|
store-withdraw-button-ui = Withdraw {$currency}
|
||||||
|
store-ui-button-out-of-stock = {""} (Out of Stock)
|
||||||
store-not-account-owner = This {$store} is not bound to you!
|
store-not-account-owner = This {$store} is not bound to you!
|
||||||
|
|||||||
@@ -100,7 +100,7 @@
|
|||||||
blacklist:
|
blacklist:
|
||||||
tags:
|
tags:
|
||||||
- NukeOpsUplink
|
- NukeOpsUplink
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkEshield
|
id: UplinkEshield
|
||||||
name: uplink-eshield-name
|
name: uplink-eshield-name
|
||||||
@@ -314,7 +314,7 @@
|
|||||||
Telecrystal: 11
|
Telecrystal: 11
|
||||||
categories:
|
categories:
|
||||||
- UplinkExplosives
|
- UplinkExplosives
|
||||||
restockTime: 30
|
restockTime: 1800
|
||||||
conditions:
|
conditions:
|
||||||
- !type:StoreWhitelistCondition
|
- !type:StoreWhitelistCondition
|
||||||
blacklist:
|
blacklist:
|
||||||
@@ -478,7 +478,7 @@
|
|||||||
Telecrystal: 6
|
Telecrystal: 6
|
||||||
categories:
|
categories:
|
||||||
- UplinkChemicals
|
- UplinkChemicals
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkHypoDart
|
id: UplinkHypoDart
|
||||||
name: uplink-hypodart-name
|
name: uplink-hypodart-name
|
||||||
@@ -500,7 +500,7 @@
|
|||||||
Telecrystal: 4
|
Telecrystal: 4
|
||||||
categories:
|
categories:
|
||||||
- UplinkChemicals
|
- UplinkChemicals
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkZombieBundle
|
id: UplinkZombieBundle
|
||||||
name: uplink-zombie-bundle-name
|
name: uplink-zombie-bundle-name
|
||||||
@@ -570,7 +570,7 @@
|
|||||||
Telecrystal: 12
|
Telecrystal: 12
|
||||||
categories:
|
categories:
|
||||||
- UplinkChemicals
|
- UplinkChemicals
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkCigarettes
|
id: UplinkCigarettes
|
||||||
name: uplink-cigarettes-name
|
name: uplink-cigarettes-name
|
||||||
@@ -601,7 +601,7 @@
|
|||||||
- SurplusBundle
|
- SurplusBundle
|
||||||
|
|
||||||
# Deception
|
# Deception
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkAgentIDCard
|
id: UplinkAgentIDCard
|
||||||
name: uplink-agent-id-card-name
|
name: uplink-agent-id-card-name
|
||||||
@@ -611,7 +611,7 @@
|
|||||||
Telecrystal: 3
|
Telecrystal: 3
|
||||||
categories:
|
categories:
|
||||||
- UplinkDeception
|
- UplinkDeception
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkStealthBox
|
id: UplinkStealthBox
|
||||||
name: uplink-stealth-box-name
|
name: uplink-stealth-box-name
|
||||||
@@ -639,11 +639,11 @@
|
|||||||
description: uplink-binary-translator-key-desc
|
description: uplink-binary-translator-key-desc
|
||||||
icon: { sprite: /Textures/Objects/Devices/encryption_keys.rsi, state: rd_label }
|
icon: { sprite: /Textures/Objects/Devices/encryption_keys.rsi, state: rd_label }
|
||||||
productEntity: EncryptionKeyBinary
|
productEntity: EncryptionKeyBinary
|
||||||
cost:
|
cost:
|
||||||
Telecrystal: 1
|
Telecrystal: 1
|
||||||
categories:
|
categories:
|
||||||
- UplinkDeception
|
- UplinkDeception
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkCyberpen
|
id: UplinkCyberpen
|
||||||
name: uplink-cyberpen-name
|
name: uplink-cyberpen-name
|
||||||
@@ -663,7 +663,7 @@
|
|||||||
Telecrystal: 1
|
Telecrystal: 1
|
||||||
categories:
|
categories:
|
||||||
- UplinkDeception
|
- UplinkDeception
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkUltrabrightLantern
|
id: UplinkUltrabrightLantern
|
||||||
name: uplink-ultrabright-lantern-name
|
name: uplink-ultrabright-lantern-name
|
||||||
@@ -726,7 +726,7 @@
|
|||||||
Telecrystal: 8
|
Telecrystal: 8
|
||||||
categories:
|
categories:
|
||||||
- UplinkDisruption
|
- UplinkDisruption
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkRadioJammer
|
id: UplinkRadioJammer
|
||||||
name: uplink-radio-jammer-name
|
name: uplink-radio-jammer-name
|
||||||
@@ -766,7 +766,7 @@
|
|||||||
Telecrystal: 3
|
Telecrystal: 3
|
||||||
categories:
|
categories:
|
||||||
- UplinkDisruption
|
- UplinkDisruption
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkToolbox
|
id: UplinkToolbox
|
||||||
name: uplink-toolbox-name
|
name: uplink-toolbox-name
|
||||||
@@ -1120,7 +1120,7 @@
|
|||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- NukeOpsUplink
|
- NukeOpsUplink
|
||||||
|
|
||||||
- type: listing
|
- type: listing
|
||||||
id: UplinkUplinkImplanter # uplink uplink real
|
id: UplinkUplinkImplanter # uplink uplink real
|
||||||
name: uplink-uplink-implanter-name
|
name: uplink-uplink-implanter-name
|
||||||
|
|||||||
Reference in New Issue
Block a user