Localize preset labels on chem dispenser (#24617)

This commit is contained in:
Errant
2024-01-28 23:31:16 +01:00
committed by GitHub
parent 96ffc31b66
commit 556545e324
3 changed files with 37 additions and 25 deletions

View File

@@ -7,12 +7,17 @@ namespace Content.Server.Labels.Components
public sealed partial class LabelComponent : Component
{
/// <summary>
/// The actual text in the label
/// Current text on the label. If set before map init, during map init this string will be localized.
/// This permits localized preset labels with fallback to the text written on the label.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("currentLabel")]
public string? CurrentLabel { get; set; }
/// <summary>
/// The original name of the entity
/// Used for reverting the modified entity name when the label is removed
/// </summary>
[DataField("originalName")]
public string? OriginalName { get; set; }
}

View File

@@ -27,6 +27,7 @@ namespace Content.Server.Labels
base.Initialize();
SubscribeLocalEvent<LabelComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<LabelComponent, MapInitEvent>(OnLabelCompMapInit);
SubscribeLocalEvent<PaperLabelComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<PaperLabelComponent, ComponentRemove>(OnComponentRemove);
SubscribeLocalEvent<PaperLabelComponent, EntInsertedIntoContainerMessage>(OnContainerModified);
@@ -34,6 +35,12 @@ namespace Content.Server.Labels
SubscribeLocalEvent<PaperLabelComponent, ExaminedEvent>(OnExamined);
}
private void OnLabelCompMapInit(EntityUid uid, LabelComponent component, MapInitEvent args)
{
if (!string.IsNullOrEmpty(component.CurrentLabel))
component.CurrentLabel = Loc.GetString(component.CurrentLabel);
}
/// <summary>
/// Apply or remove a label on an entity.
/// </summary>

View File

@@ -58,7 +58,7 @@
noSpawn: true
components:
- type: Label
currentLabel: carbon
currentLabel: reagent-name-carbon
- type: SolutionContainerManager
solutions:
beaker:
@@ -73,7 +73,7 @@
noSpawn: true
components:
- type: Label
currentLabel: iodine
currentLabel: reagent-name-iodine
- type: SolutionContainerManager
solutions:
beaker:
@@ -88,7 +88,7 @@
noSpawn: true
components:
- type: Label
currentLabel: fluorine
currentLabel: reagent-name-fluorine
- type: SolutionContainerManager
solutions:
beaker:
@@ -103,7 +103,7 @@
noSpawn: true
components:
- type: Label
currentLabel: chlorine
currentLabel: reagent-name-chlorine
- type: SolutionContainerManager
solutions:
beaker:
@@ -118,7 +118,7 @@
noSpawn: true
components:
- type: Label
currentLabel: aluminium
currentLabel: reagent-name-aluminium
- type: SolutionContainerManager
solutions:
beaker:
@@ -133,7 +133,7 @@
noSpawn: true
components:
- type: Label
currentLabel: phosphorus
currentLabel: reagent-name-phosphorus
- type: SolutionContainerManager
solutions:
beaker:
@@ -148,7 +148,7 @@
noSpawn: true
components:
- type: Label
currentLabel: sulfur
currentLabel: reagent-name-sulfur
- type: SolutionContainerManager
solutions:
beaker:
@@ -163,7 +163,7 @@
noSpawn: true
components:
- type: Label
currentLabel: silicon
currentLabel: reagent-name-silicon
- type: SolutionContainerManager
solutions:
beaker:
@@ -178,7 +178,7 @@
noSpawn: true
components:
- type: Label
currentLabel: hydrogen
currentLabel: reagent-name-hydrogen
- type: SolutionContainerManager
solutions:
beaker:
@@ -193,7 +193,7 @@
noSpawn: true
components:
- type: Label
currentLabel: lithium
currentLabel: reagent-name-lithium
- type: SolutionContainerManager
solutions:
beaker:
@@ -208,7 +208,7 @@
noSpawn: true
components:
- type: Label
currentLabel: sodium
currentLabel: reagent-name-sodium
- type: SolutionContainerManager
solutions:
beaker:
@@ -223,7 +223,7 @@
noSpawn: true
components:
- type: Label
currentLabel: potassium
currentLabel: reagent-name-potassium
- type: SolutionContainerManager
solutions:
beaker:
@@ -238,7 +238,7 @@
noSpawn: true
components:
- type: Label
currentLabel: radium
currentLabel: reagent-name-radium
- type: SolutionContainerManager
solutions:
beaker:
@@ -253,7 +253,7 @@
noSpawn: true
components:
- type: Label
currentLabel: iron
currentLabel: reagent-name-iron
- type: SolutionContainerManager
solutions:
beaker:
@@ -268,7 +268,7 @@
noSpawn: true
components:
- type: Label
currentLabel: copper
currentLabel: reagent-name-copper
- type: SolutionContainerManager
solutions:
beaker:
@@ -283,7 +283,7 @@
noSpawn: true
components:
- type: Label
currentLabel: gold
currentLabel: reagent-name-gold
- type: SolutionContainerManager
solutions:
beaker:
@@ -298,7 +298,7 @@
noSpawn: true
components:
- type: Label
currentLabel: mercury
currentLabel: reagent-name-mercury
- type: SolutionContainerManager
solutions:
beaker:
@@ -313,7 +313,7 @@
noSpawn: true
components:
- type: Label
currentLabel: silver
currentLabel: reagent-name-silver
- type: SolutionContainerManager
solutions:
beaker:
@@ -328,7 +328,7 @@
noSpawn: true
components:
- type: Label
currentLabel: ethanol
currentLabel: reagent-name-ethanol
- type: SolutionContainerManager
solutions:
beaker:
@@ -343,7 +343,7 @@
noSpawn: true
components:
- type: Label
currentLabel: sugar
currentLabel: reagent-name-sugar
- type: SolutionContainerManager
solutions:
beaker:
@@ -358,7 +358,7 @@
noSpawn: true
components:
- type: Label
currentLabel: nitrogen
currentLabel: reagent-name-nitrogen
- type: SolutionContainerManager
solutions:
beaker:
@@ -373,7 +373,7 @@
noSpawn: true
components:
- type: Label
currentLabel: oxygen
currentLabel: reagent-name-oxygen
- type: SolutionContainerManager
solutions:
beaker:
@@ -388,7 +388,7 @@
noSpawn: true
components:
- type: Label
currentLabel: Plant-B-Gone
currentLabel: reagent-name-plant-b-gone
- type: SolutionContainerManager
solutions:
beaker:
@@ -403,7 +403,7 @@
noSpawn: true
components:
- type: Label
currentLabel: welding fuel
currentLabel: reagent-name-welding-fuel
- type: SolutionContainerManager
solutions:
beaker: