]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
show non-sheet material units in lathe (#19896)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Fri, 8 Sep 2023 02:11:10 +0000 (03:11 +0100)
committerGitHub <noreply@github.com>
Fri, 8 Sep 2023 02:11:10 +0000 (22:11 -0400)
* 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
Content.Shared/Materials/MaterialPrototype.cs
Resources/Locale/en-US/lathe/ui/lathe-menu.ftl
Resources/Locale/en-US/materials/materials.ftl
Resources/Locale/en-US/materials/units.ftl [new file with mode: 0644]
Resources/Prototypes/Entities/Objects/Misc/space_cash.yml
Resources/Prototypes/Reagents/Materials/materials.yml
Resources/Prototypes/Reagents/Materials/metals.yml

index 77ab0090769c588878cd0d016cdabd2b08be9666..1fd7c78ea40cc4fbbc599f57b3c5e62bed7a626d 100644 (file)
@@ -26,6 +26,11 @@ public sealed partial class LatheMenu : DefaultWindow
     public event Action<string, int>? OnEjectPressed;
     public List<string> Recipes = new();
 
+    /// <summary>
+    /// Default volume for a sheet if the material's entity prototype has no material composition.
+    /// </summary>
+    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 name = Loc.GetString(material.Name);
-            var mat = Loc.GetString("lathe-menu-material-display",
-                ("material", name), ("amount", volume / 100));
-            var volumePerSheet = 0;
-            var maxEjectableSheets = 0;
-
-            if (material.StackEntity != null)
-            {
-                var proto = _prototypeManager.Index<EntityPrototype>(material.StackEntity);
+            var sheetVolume = SheetVolume(material);
+            var sheets = (float) volume / sheetVolume;
+            var maxEjectableSheets = (int) MathF.Floor(sheets);
 
-                if (proto.TryGetComponent<PhysicalCompositionComponent>(out var composition))
-                {
-                    volumePerSheet = composition.MaterialComposition.FirstOrDefault(kvp => kvp.Key == materialId).Value;
-                    maxEjectableSheets = (int) MathF.Floor((float) volume / volumePerSheet);
-                }
-            }
+            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", amountText));
 
-            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);
-
-                sb.Append(Loc.GetString("lathe-menu-tooltip-display",
-                    ("amount", MathF.Round(adjustedAmount / 100f, 2)),
-                    ("material", Loc.GetString(proto.Name))));
+                var sheetVolume = SheetVolume(proto);
+
+                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<EntityPrototype>(material.StackEntity);
+
+        if (!proto.TryGetComponent<PhysicalCompositionComponent>(out var composition))
+            return DEFAULT_SHEET_VOLUME;
+
+        return composition.MaterialComposition.FirstOrDefault(kvp => kvp.Key == material.ID).Value;
+    }
 }
index d78fa9452afefdb514625a1a95c79ef5826a3cb2..7eb4dfd9a435760e4b992a39aa174993e4a87c4b 100644 (file)
@@ -33,7 +33,15 @@ namespace Content.Shared.Materials
         public string? StackEntity;
 
         [DataField("name")]
-        public string Name = "";
+        public string Name = string.Empty;
+
+        /// <summary>
+        /// 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.
+        /// </summary>
+        [DataField("unit")]
+        public string Unit = "materials-unit-sheet";
 
         [DataField("color")]
         public Color Color { get; private set; } = Color.Gray;
index d255346d080bcafdb121df23f85d58844eb0a164..914bb64b4ff74f3aa097681cdbac7630fc6eeb60 100644 (file)
@@ -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
index 41052e572729e0e5ffd1f7d80422878962cf551f..12bfcf5e12eb745ef7059d3fcd5ea48ef0a95744 100644 (file)
@@ -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 (file)
index 0000000..9915444
--- /dev/null
@@ -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
index e2305c98d3d42f8dd05a14e25f41de6e79e5943c..5925d3a8482b84f63503479168590e496cfddbb1 100644 (file)
@@ -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
index 1c4b00b906845132253c214232918671522e9249..66033508062e3926e976eadc917b0ac752c08fa8 100644 (file)
@@ -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.
index c4425115710c4464b7993a9108941b0f0f90ef8b..affeb9427eee0aa72ecddf36dd0293794f87904a 100644 (file)
@@ -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