diff --git a/.editorconfig b/.editorconfig index 872a068c7c..58d0d332bb 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,7 +9,7 @@ indent_style = space tab_width = 4 # New line preferences -#end_of_line = crlf +end_of_line = crlf:suggestion insert_final_newline = true trim_trailing_whitespace = true @@ -104,6 +104,7 @@ csharp_preferred_modifier_order = public, private, protected, internal, new, abs # 'using' directive preferences csharp_using_directive_placement = outside_namespace:silent +csharp_style_namespace_declarations = file_scoped:suggestion #### C# Formatting Rules #### diff --git a/Content.Client/HealthAnalyzer/UI/HealthAnalyzerWindow.xaml.cs b/Content.Client/HealthAnalyzer/UI/HealthAnalyzerWindow.xaml.cs index 1d8d415bab..0cb3ad144d 100644 --- a/Content.Client/HealthAnalyzer/UI/HealthAnalyzerWindow.xaml.cs +++ b/Content.Client/HealthAnalyzer/UI/HealthAnalyzerWindow.xaml.cs @@ -1,5 +1,6 @@ using System.Linq; using System.Numerics; +using Content.Shared.Atmos; using Content.Client.UserInterface.Controls; using Content.Shared.Damage; using Content.Shared.Damage.Prototypes; @@ -79,7 +80,7 @@ namespace Content.Client.HealthAnalyzer.UI ); Temperature.Text = Loc.GetString("health-analyzer-window-entity-temperature-text", - ("temperature", float.IsNaN(msg.Temperature) ? "N/A" : $"{msg.Temperature - 273f:F1} °C ({msg.Temperature:F1} °K)") + ("temperature", float.IsNaN(msg.Temperature) ? "N/A" : $"{msg.Temperature - Atmospherics.T0C:F1} °C ({msg.Temperature:F1} K)") ); BloodLevel.Text = Loc.GetString("health-analyzer-window-entity-blood-level-text", diff --git a/Content.Client/Store/Ui/StoreBoundUserInterface.cs b/Content.Client/Store/Ui/StoreBoundUserInterface.cs index f87b92bc61..88ad0e3de8 100644 --- a/Content.Client/Store/Ui/StoreBoundUserInterface.cs +++ b/Content.Client/Store/Ui/StoreBoundUserInterface.cs @@ -17,7 +17,7 @@ public sealed class StoreBoundUserInterface : BoundUserInterface private string _windowName = Loc.GetString("store-ui-default-title"); [ViewVariables] - private string _search = ""; + private string _search = string.Empty; [ViewVariables] private HashSet _listings = new(); @@ -41,7 +41,7 @@ public sealed class StoreBoundUserInterface : BoundUserInterface _menu.OnCategoryButtonPressed += (_, category) => { _menu.CurrentCategory = category; - SendMessage(new StoreRequestUpdateInterfaceMessage()); + _menu?.UpdateListing(); }; _menu.OnWithdrawAttempt += (_, type, amount) => @@ -49,11 +49,6 @@ public sealed class StoreBoundUserInterface : BoundUserInterface SendMessage(new StoreRequestWithdrawMessage(type, amount)); }; - _menu.OnRefreshButtonPressed += (_) => - { - SendMessage(new StoreRequestUpdateInterfaceMessage()); - }; - _menu.SearchTextUpdated += (_, search) => { _search = search.Trim().ToLowerInvariant(); diff --git a/Content.Client/Store/Ui/StoreListingControl.xaml b/Content.Client/Store/Ui/StoreListingControl.xaml index aefeec17cc..12b4d7b5b3 100644 --- a/Content.Client/Store/Ui/StoreListingControl.xaml +++ b/Content.Client/Store/Ui/StoreListingControl.xaml @@ -15,6 +15,7 @@ Margin="0,0,4,0" MinSize="48 48" Stretch="KeepAspectCentered" /> + diff --git a/Content.Client/Store/Ui/StoreListingControl.xaml.cs b/Content.Client/Store/Ui/StoreListingControl.xaml.cs index bb600588e0..030f07dc7c 100644 --- a/Content.Client/Store/Ui/StoreListingControl.xaml.cs +++ b/Content.Client/Store/Ui/StoreListingControl.xaml.cs @@ -1,25 +1,91 @@ +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.Graphics; +using Robust.Shared.Prototypes; +using Robust.Shared.Timing; namespace Content.Client.Store.Ui; [GenerateTypedNameReferences] public sealed partial class StoreListingControl : Control { - public StoreListingControl(string itemName, string itemDescription, - string price, bool canBuy, Texture? texture = null) + [Dependency] private readonly IPrototypeManager _prototype = default!; + [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); - StoreItemName.Text = itemName; - StoreItemDescription.SetMessage(itemDescription); + _ticker = _entity.System(); - StoreItemBuyButton.Text = price; - StoreItemBuyButton.Disabled = !canBuy; + _data = data; + _hasBalance = hasBalance; + _price = price; + + 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; + + 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(); + } } diff --git a/Content.Client/Store/Ui/StoreMenu.xaml b/Content.Client/Store/Ui/StoreMenu.xaml index fc4cbe444f..843c9dc029 100644 --- a/Content.Client/Store/Ui/StoreMenu.xaml +++ b/Content.Client/Store/Ui/StoreMenu.xaml @@ -12,11 +12,6 @@ HorizontalAlignment="Left" Access="Public" HorizontalExpand="True" /> -