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 event Action<string, int>? OnEjectPressed;
|
||||||
public List<string> Recipes = new();
|
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)
|
public LatheMenu(LatheBoundUserInterface owner)
|
||||||
{
|
{
|
||||||
RobustXamlLoader.Load(this);
|
RobustXamlLoader.Load(this);
|
||||||
@@ -71,24 +76,16 @@ public sealed partial class LatheMenu : DefaultWindow
|
|||||||
if (!_prototypeManager.TryIndex(materialId, out MaterialPrototype? material))
|
if (!_prototypeManager.TryIndex(materialId, out MaterialPrototype? material))
|
||||||
continue;
|
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 name = Loc.GetString(material.Name);
|
||||||
var mat = Loc.GetString("lathe-menu-material-display",
|
var mat = Loc.GetString("lathe-menu-material-display", ("material", name), ("amount", amountText));
|
||||||
("material", name), ("amount", volume / 100));
|
|
||||||
var volumePerSheet = 0;
|
|
||||||
var maxEjectableSheets = 0;
|
|
||||||
|
|
||||||
if (material.StackEntity != null)
|
var row = new LatheMaterialEjector(materialId, OnEjectPressed, sheetVolume, maxEjectableSheets)
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
Icon = { Texture = _spriteSystem.Frame0(material.Icon) },
|
Icon = { Texture = _spriteSystem.Frame0(material.Icon) },
|
||||||
ProductName = { Text = mat }
|
ProductName = { Text = mat }
|
||||||
@@ -151,10 +148,14 @@ public sealed partial class LatheMenu : DefaultWindow
|
|||||||
sb.Append('\n');
|
sb.Append('\n');
|
||||||
|
|
||||||
var adjustedAmount = SharedLatheSystem.AdjustMaterial(amount, prototype.ApplyMaterialDiscount, component.MaterialUseMultiplier);
|
var adjustedAmount = SharedLatheSystem.AdjustMaterial(amount, prototype.ApplyMaterialDiscount, component.MaterialUseMultiplier);
|
||||||
|
var sheetVolume = SheetVolume(proto);
|
||||||
|
|
||||||
sb.Append(Loc.GetString("lathe-menu-tooltip-display",
|
var unit = Loc.GetString(proto.Unit);
|
||||||
("amount", MathF.Round(adjustedAmount / 100f, 2)),
|
// rounded in locale not here
|
||||||
("material", Loc.GetString(proto.Name))));
|
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
|
var icon = prototype.Icon == null
|
||||||
@@ -201,4 +202,17 @@ public sealed partial class LatheMenu : DefaultWindow
|
|||||||
: _spriteSystem.Frame0(recipe.Icon);
|
: _spriteSystem.Frame0(recipe.Icon);
|
||||||
NameLabel.Text = $"{recipe.Name}";
|
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;
|
public string? StackEntity;
|
||||||
|
|
||||||
[DataField("name")]
|
[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")]
|
[DataField("color")]
|
||||||
public Color Color { get; private set; } = Color.Gray;
|
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-designs = Search designs
|
||||||
lathe-menu-search-filter = Filter
|
lathe-menu-search-filter = Filter
|
||||||
lathe-menu-amount = Amount:
|
lathe-menu-amount = Amount:
|
||||||
lathe-menu-material-display = {$material} ({ $amount ->
|
lathe-menu-material-display = {$material} ({$amount})
|
||||||
[1] {NATURALFIXED($amount, 2)} sheet
|
lathe-menu-tooltip-display = {$amount} of {$material}
|
||||||
*[other] {NATURALFIXED($amount, 2)} sheets
|
lathe-menu-material-amount = { $amount ->
|
||||||
})
|
[1] {NATURALFIXED($amount, 2)} {$unit}
|
||||||
lathe-menu-tooltip-display = { $amount ->
|
*[other] {NATURALFIXED($amount, 2)} {MAKEPLURAL($unit)}
|
||||||
[1] {NATURALFIXED($amount, 2)} sheet
|
}
|
||||||
*[other] {NATURALFIXED($amount, 2)} sheets
|
|
||||||
} of {$material}
|
|
||||||
lathe-menu-no-materials-message = No materials loaded.
|
lathe-menu-no-materials-message = No materials loaded.
|
||||||
lathe-menu-fabricating-message = Fabricating...
|
lathe-menu-fabricating-message = Fabricating...
|
||||||
lathe-menu-materials-title = Materials
|
lathe-menu-materials-title = Materials
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ materials-plasteel = plasteel
|
|||||||
|
|
||||||
# Other
|
# Other
|
||||||
materials-biomass = biomass
|
materials-biomass = biomass
|
||||||
|
materials-cardboard = cardboard
|
||||||
materials-cloth = cloth
|
materials-cloth = cloth
|
||||||
materials-durathread = durathread
|
materials-durathread = durathread
|
||||||
materials-plasma = plasma
|
materials-plasma = plasma
|
||||||
@@ -20,6 +21,7 @@ materials-wood = wood
|
|||||||
materials-uranium = uranium
|
materials-uranium = uranium
|
||||||
materials-bananium = bananium
|
materials-bananium = bananium
|
||||||
materials-meat = meat
|
materials-meat = meat
|
||||||
|
materials-web = silk
|
||||||
|
|
||||||
# Material Reclaimer
|
# Material Reclaimer
|
||||||
material-reclaimer-upgrade-process-rate = process rate
|
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
|
- type: material
|
||||||
id: Credit
|
id: Credit
|
||||||
name: speso
|
name: speso
|
||||||
|
unit: materials-unit-bill
|
||||||
stackEntity: SpaceCash
|
stackEntity: SpaceCash
|
||||||
icon: { sprite: /Textures/Objects/Economy/cash.rsi, state: cash }
|
icon: { sprite: /Textures/Objects/Economy/cash.rsi, state: cash }
|
||||||
price: 1
|
price: 1
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
id: Biomass
|
id: Biomass
|
||||||
stackEntity: MaterialBiomass1
|
stackEntity: MaterialBiomass1
|
||||||
name: materials-biomass
|
name: materials-biomass
|
||||||
|
unit: materials-unit-piece
|
||||||
icon: { sprite: /Textures/Objects/Misc/monkeycube.rsi, state: cube }
|
icon: { sprite: /Textures/Objects/Misc/monkeycube.rsi, state: cube }
|
||||||
color: "#8A9A5B"
|
color: "#8A9A5B"
|
||||||
price: 0.1
|
price: 0.1
|
||||||
@@ -18,6 +19,7 @@
|
|||||||
id: Cloth
|
id: Cloth
|
||||||
stackEntity: MaterialCloth1
|
stackEntity: MaterialCloth1
|
||||||
name: materials-cloth
|
name: materials-cloth
|
||||||
|
unit: materials-unit-roll
|
||||||
icon: { sprite: /Textures/Objects/Materials/materials.rsi, state: cloth }
|
icon: { sprite: /Textures/Objects/Materials/materials.rsi, state: cloth }
|
||||||
color: "#e7e7de"
|
color: "#e7e7de"
|
||||||
price: 0.05
|
price: 0.05
|
||||||
@@ -26,6 +28,8 @@
|
|||||||
id: Durathread
|
id: Durathread
|
||||||
stackEntity: MaterialDurathread1
|
stackEntity: MaterialDurathread1
|
||||||
name: materials-durathread
|
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 }
|
icon: { sprite: /Textures/Objects/Materials/materials.rsi, state: durathread }
|
||||||
color: "#8291a1"
|
color: "#8291a1"
|
||||||
price: 0.15 # 1-1 mix of plastic and cloth.
|
price: 0.15 # 1-1 mix of plastic and cloth.
|
||||||
@@ -50,6 +54,7 @@
|
|||||||
id: Wood
|
id: Wood
|
||||||
stackEntity: MaterialWoodPlank1
|
stackEntity: MaterialWoodPlank1
|
||||||
name: materials-wood
|
name: materials-wood
|
||||||
|
unit: materials-unit-plank
|
||||||
icon: { sprite: Objects/Materials/materials.rsi, state: wood }
|
icon: { sprite: Objects/Materials/materials.rsi, state: wood }
|
||||||
color: "#966F33"
|
color: "#966F33"
|
||||||
price: 0.05
|
price: 0.05
|
||||||
@@ -66,6 +71,7 @@
|
|||||||
id: Bananium
|
id: Bananium
|
||||||
stackEntity: MaterialBananium1
|
stackEntity: MaterialBananium1
|
||||||
name: materials-bananium
|
name: materials-bananium
|
||||||
|
unit: materials-unit-bunch
|
||||||
icon: { sprite: Objects/Materials/materials.rsi, state: bananium }
|
icon: { sprite: Objects/Materials/materials.rsi, state: bananium }
|
||||||
color: "#32a852"
|
color: "#32a852"
|
||||||
price: 0.2
|
price: 0.2
|
||||||
@@ -73,6 +79,7 @@
|
|||||||
- type: material
|
- type: material
|
||||||
id: Meaterial # you can't take this pun from me
|
id: Meaterial # you can't take this pun from me
|
||||||
name: materials-meat
|
name: materials-meat
|
||||||
|
unit: materials-unit-slab
|
||||||
icon: { sprite: Objects/Materials/Sheets/meaterial.rsi, state: meat }
|
icon: { sprite: Objects/Materials/Sheets/meaterial.rsi, state: meat }
|
||||||
color: "#c53648"
|
color: "#c53648"
|
||||||
price: 0.05
|
price: 0.05
|
||||||
@@ -80,6 +87,7 @@
|
|||||||
- type: material
|
- type: material
|
||||||
id: WebSilk
|
id: WebSilk
|
||||||
name: materials-web
|
name: materials-web
|
||||||
|
unit: materials-unit-web
|
||||||
icon: { sprite: Objects/Materials/silk.rsi, state: icon }
|
icon: { sprite: Objects/Materials/silk.rsi, state: icon }
|
||||||
color: "#eeeeee" #eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
color: "#eeeeee" #eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
||||||
price: 0 # Maybe better for it to be priceless, knowing how greedy cargo is.
|
price: 0 # Maybe better for it to be priceless, knowing how greedy cargo is.
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
id: Gold
|
id: Gold
|
||||||
stackEntity: IngotGold1
|
stackEntity: IngotGold1
|
||||||
name: materials-gold
|
name: materials-gold
|
||||||
|
unit: materials-unit-bar
|
||||||
icon: { sprite: Objects/Materials/ingots.rsi, state: gold }
|
icon: { sprite: Objects/Materials/ingots.rsi, state: gold }
|
||||||
color: "#FFD700"
|
color: "#FFD700"
|
||||||
price: 0.2
|
price: 0.2
|
||||||
@@ -17,6 +18,7 @@
|
|||||||
id: Silver
|
id: Silver
|
||||||
stackEntity: IngotSilver1
|
stackEntity: IngotSilver1
|
||||||
name: materials-silver
|
name: materials-silver
|
||||||
|
unit: materials-unit-bar
|
||||||
icon: { sprite: Objects/Materials/ingots.rsi, state: silver }
|
icon: { sprite: Objects/Materials/ingots.rsi, state: silver }
|
||||||
color: "#C0C0C0"
|
color: "#C0C0C0"
|
||||||
price: 0.15
|
price: 0.15
|
||||||
|
|||||||
Reference in New Issue
Block a user