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>
This commit is contained in:
@@ -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 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<EntityPrototype>(material.StackEntity);
|
||||
|
||||
if (proto.TryGetComponent<PhysicalCompositionComponent>(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<EntityPrototype>(material.StackEntity);
|
||||
|
||||
if (!proto.TryGetComponent<PhysicalCompositionComponent>(out var composition))
|
||||
return DEFAULT_SHEET_VOLUME;
|
||||
|
||||
return composition.MaterialComposition.FirstOrDefault(kvp => kvp.Key == material.ID).Value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
20
Resources/Locale/en-US/materials/units.ftl
Normal file
20
Resources/Locale/en-US/materials/units.ftl
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user