From db2a4478b0981d9d2ec32e608b1706fb0213bc96 Mon Sep 17 00:00:00 2001 From: deltanedas <39013340+deltanedas@users.noreply.github.com> Date: Fri, 8 Sep 2023 03:11:10 +0100 Subject: [PATCH] show non-sheet material units in lathe (#19896) * locale for material units * use material units in lathe ui * give units to non-sheet materials * :trollface: * use volume properly * :trollface: * review --------- Co-authored-by: deltanedas <@deltanedas:kde.org> --- Content.Client/Lathe/UI/LatheMenu.xaml.cs | 52 ++++++++++++------- Content.Shared/Materials/MaterialPrototype.cs | 10 +++- .../Locale/en-US/lathe/ui/lathe-menu.ftl | 14 +++-- .../Locale/en-US/materials/materials.ftl | 2 + Resources/Locale/en-US/materials/units.ftl | 20 +++++++ .../Entities/Objects/Misc/space_cash.yml | 1 + .../Reagents/Materials/materials.yml | 8 +++ .../Prototypes/Reagents/Materials/metals.yml | 2 + 8 files changed, 81 insertions(+), 28 deletions(-) create mode 100644 Resources/Locale/en-US/materials/units.ftl diff --git a/Content.Client/Lathe/UI/LatheMenu.xaml.cs b/Content.Client/Lathe/UI/LatheMenu.xaml.cs index 77ab009076..1fd7c78ea4 100644 --- a/Content.Client/Lathe/UI/LatheMenu.xaml.cs +++ b/Content.Client/Lathe/UI/LatheMenu.xaml.cs @@ -26,6 +26,11 @@ public sealed partial class LatheMenu : DefaultWindow public event Action? OnEjectPressed; public List Recipes = new(); + /// + /// Default volume for a sheet if the material's entity prototype has no material composition. + /// + private const int DEFAULT_SHEET_VOLUME = 100; + public LatheMenu(LatheBoundUserInterface owner) { RobustXamlLoader.Load(this); @@ -71,24 +76,16 @@ public sealed partial class LatheMenu : DefaultWindow if (!_prototypeManager.TryIndex(materialId, out MaterialPrototype? material)) continue; + var sheetVolume = SheetVolume(material); + var sheets = (float) volume / sheetVolume; + var maxEjectableSheets = (int) MathF.Floor(sheets); + + var unit = Loc.GetString(material.Unit); + var amountText = Loc.GetString("lathe-menu-material-amount", ("amount", sheets), ("unit", unit)); var name = Loc.GetString(material.Name); - var mat = Loc.GetString("lathe-menu-material-display", - ("material", name), ("amount", volume / 100)); - var volumePerSheet = 0; - var maxEjectableSheets = 0; + var mat = Loc.GetString("lathe-menu-material-display", ("material", name), ("amount", amountText)); - if (material.StackEntity != null) - { - var proto = _prototypeManager.Index(material.StackEntity); - - if (proto.TryGetComponent(out var composition)) - { - volumePerSheet = composition.MaterialComposition.FirstOrDefault(kvp => kvp.Key == materialId).Value; - maxEjectableSheets = (int) MathF.Floor((float) volume / volumePerSheet); - } - } - - var row = new LatheMaterialEjector(materialId, OnEjectPressed, volumePerSheet, maxEjectableSheets) + var row = new LatheMaterialEjector(materialId, OnEjectPressed, sheetVolume, maxEjectableSheets) { Icon = { Texture = _spriteSystem.Frame0(material.Icon) }, ProductName = { Text = mat } @@ -151,10 +148,14 @@ public sealed partial class LatheMenu : DefaultWindow sb.Append('\n'); var adjustedAmount = SharedLatheSystem.AdjustMaterial(amount, prototype.ApplyMaterialDiscount, component.MaterialUseMultiplier); + var sheetVolume = SheetVolume(proto); - sb.Append(Loc.GetString("lathe-menu-tooltip-display", - ("amount", MathF.Round(adjustedAmount / 100f, 2)), - ("material", Loc.GetString(proto.Name)))); + var unit = Loc.GetString(proto.Unit); + // rounded in locale not here + var sheets = adjustedAmount / (float) sheetVolume; + var amountText = Loc.GetString("lathe-menu-material-amount", ("amount", sheets), ("unit", unit)); + var name = Loc.GetString(proto.Name); + sb.Append(Loc.GetString("lathe-menu-tooltip-display", ("material", name), ("amount", amountText))); } var icon = prototype.Icon == null @@ -201,4 +202,17 @@ public sealed partial class LatheMenu : DefaultWindow : _spriteSystem.Frame0(recipe.Icon); NameLabel.Text = $"{recipe.Name}"; } + + private int SheetVolume(MaterialPrototype material) + { + if (material.StackEntity == null) + return DEFAULT_SHEET_VOLUME; + + var proto = _prototypeManager.Index(material.StackEntity); + + if (!proto.TryGetComponent(out var composition)) + return DEFAULT_SHEET_VOLUME; + + return composition.MaterialComposition.FirstOrDefault(kvp => kvp.Key == material.ID).Value; + } } diff --git a/Content.Shared/Materials/MaterialPrototype.cs b/Content.Shared/Materials/MaterialPrototype.cs index d78fa9452a..7eb4dfd9a4 100644 --- a/Content.Shared/Materials/MaterialPrototype.cs +++ b/Content.Shared/Materials/MaterialPrototype.cs @@ -33,7 +33,15 @@ namespace Content.Shared.Materials public string? StackEntity; [DataField("name")] - public string Name = ""; + public string Name = string.Empty; + + /// + /// Locale id for the unit of this material. + /// Lathe recipe tooltips and material storage display use this to let you change a material to sound nicer. + /// For example, 5 bars of gold is better than 5 sheets of gold. + /// + [DataField("unit")] + public string Unit = "materials-unit-sheet"; [DataField("color")] public Color Color { get; private set; } = Color.Gray; diff --git a/Resources/Locale/en-US/lathe/ui/lathe-menu.ftl b/Resources/Locale/en-US/lathe/ui/lathe-menu.ftl index d255346d08..914bb64b4f 100644 --- a/Resources/Locale/en-US/lathe/ui/lathe-menu.ftl +++ b/Resources/Locale/en-US/lathe/ui/lathe-menu.ftl @@ -5,14 +5,12 @@ lathe-menu-sync = Sync lathe-menu-search-designs = Search designs lathe-menu-search-filter = Filter lathe-menu-amount = Amount: -lathe-menu-material-display = {$material} ({ $amount -> - [1] {NATURALFIXED($amount, 2)} sheet - *[other] {NATURALFIXED($amount, 2)} sheets - }) -lathe-menu-tooltip-display = { $amount -> - [1] {NATURALFIXED($amount, 2)} sheet - *[other] {NATURALFIXED($amount, 2)} sheets - } of {$material} +lathe-menu-material-display = {$material} ({$amount}) +lathe-menu-tooltip-display = {$amount} of {$material} +lathe-menu-material-amount = { $amount -> + [1] {NATURALFIXED($amount, 2)} {$unit} + *[other] {NATURALFIXED($amount, 2)} {MAKEPLURAL($unit)} +} lathe-menu-no-materials-message = No materials loaded. lathe-menu-fabricating-message = Fabricating... lathe-menu-materials-title = Materials diff --git a/Resources/Locale/en-US/materials/materials.ftl b/Resources/Locale/en-US/materials/materials.ftl index 41052e5727..12bfcf5e12 100644 --- a/Resources/Locale/en-US/materials/materials.ftl +++ b/Resources/Locale/en-US/materials/materials.ftl @@ -12,6 +12,7 @@ materials-plasteel = plasteel # Other materials-biomass = biomass +materials-cardboard = cardboard materials-cloth = cloth materials-durathread = durathread materials-plasma = plasma @@ -20,6 +21,7 @@ materials-wood = wood materials-uranium = uranium materials-bananium = bananium materials-meat = meat +materials-web = silk # Material Reclaimer material-reclaimer-upgrade-process-rate = process rate diff --git a/Resources/Locale/en-US/materials/units.ftl b/Resources/Locale/en-US/materials/units.ftl new file mode 100644 index 0000000000..9915444bdc --- /dev/null +++ b/Resources/Locale/en-US/materials/units.ftl @@ -0,0 +1,20 @@ +# sheets of steel +materials-unit-sheet = sheet +# bars of gold +materials-unit-bar = bar +# planks of wood +materials-unit-plank = plank +# rolls of cloth +materials-unit-roll = roll +# pieces of biomass +materials-unit-piece = piece +# bunches of bananium +materials-unit-bunch = bunch +# slabs of meat +materials-unit-slab = slab +# webs of silk +materials-unit-web = web + +# bills of spesos... not very good but they are not (yet?) used for crafting anything +# also the lathe/atm would need bigger denominations to output... +materials-unit-bill = bill diff --git a/Resources/Prototypes/Entities/Objects/Misc/space_cash.yml b/Resources/Prototypes/Entities/Objects/Misc/space_cash.yml index e2305c98d3..5925d3a848 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/space_cash.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/space_cash.yml @@ -43,6 +43,7 @@ - type: material id: Credit name: speso + unit: materials-unit-bill stackEntity: SpaceCash icon: { sprite: /Textures/Objects/Economy/cash.rsi, state: cash } price: 1 diff --git a/Resources/Prototypes/Reagents/Materials/materials.yml b/Resources/Prototypes/Reagents/Materials/materials.yml index 1c4b00b906..6603350806 100644 --- a/Resources/Prototypes/Reagents/Materials/materials.yml +++ b/Resources/Prototypes/Reagents/Materials/materials.yml @@ -2,6 +2,7 @@ id: Biomass stackEntity: MaterialBiomass1 name: materials-biomass + unit: materials-unit-piece icon: { sprite: /Textures/Objects/Misc/monkeycube.rsi, state: cube } color: "#8A9A5B" price: 0.1 @@ -18,6 +19,7 @@ id: Cloth stackEntity: MaterialCloth1 name: materials-cloth + unit: materials-unit-roll icon: { sprite: /Textures/Objects/Materials/materials.rsi, state: cloth } color: "#e7e7de" price: 0.05 @@ -26,6 +28,8 @@ id: Durathread stackEntity: MaterialDurathread1 name: materials-durathread + # not exactly a sheet but its sprite suggests it cant be rolled like cloth + unit: materials-unit-sheet icon: { sprite: /Textures/Objects/Materials/materials.rsi, state: durathread } color: "#8291a1" price: 0.15 # 1-1 mix of plastic and cloth. @@ -50,6 +54,7 @@ id: Wood stackEntity: MaterialWoodPlank1 name: materials-wood + unit: materials-unit-plank icon: { sprite: Objects/Materials/materials.rsi, state: wood } color: "#966F33" price: 0.05 @@ -66,6 +71,7 @@ id: Bananium stackEntity: MaterialBananium1 name: materials-bananium + unit: materials-unit-bunch icon: { sprite: Objects/Materials/materials.rsi, state: bananium } color: "#32a852" price: 0.2 @@ -73,6 +79,7 @@ - type: material id: Meaterial # you can't take this pun from me name: materials-meat + unit: materials-unit-slab icon: { sprite: Objects/Materials/Sheets/meaterial.rsi, state: meat } color: "#c53648" price: 0.05 @@ -80,6 +87,7 @@ - type: material id: WebSilk name: materials-web + unit: materials-unit-web icon: { sprite: Objects/Materials/silk.rsi, state: icon } color: "#eeeeee" #eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee price: 0 # Maybe better for it to be priceless, knowing how greedy cargo is. diff --git a/Resources/Prototypes/Reagents/Materials/metals.yml b/Resources/Prototypes/Reagents/Materials/metals.yml index c442511571..affeb9427e 100644 --- a/Resources/Prototypes/Reagents/Materials/metals.yml +++ b/Resources/Prototypes/Reagents/Materials/metals.yml @@ -9,6 +9,7 @@ id: Gold stackEntity: IngotGold1 name: materials-gold + unit: materials-unit-bar icon: { sprite: Objects/Materials/ingots.rsi, state: gold } color: "#FFD700" price: 0.2 @@ -17,6 +18,7 @@ id: Silver stackEntity: IngotSilver1 name: materials-silver + unit: materials-unit-bar icon: { sprite: Objects/Materials/ingots.rsi, state: silver } color: "#C0C0C0" price: 0.15