From f0f9512b491fefa2416f661e8f6b20fab215fa2f Mon Sep 17 00:00:00 2001 From: NeLepus Date: Thu, 16 Jan 2025 03:03:08 +0700 Subject: [PATCH] Label Rendering For Vending Machines and Item Preferences Menus (#1538) # Description This PR removes label duplicates from item names in order to make actual labels work properly and make them visible in vending machines' menus as well as loadout preferences. As we can see in Fig 1, the aluminium jug is not only labelled as "aluminium 10u" but contains "(aluminium 10u)" in the item name, which drives chemists homicidal when it comes to labelling the jugs. This issue also appears with other labelled items such as pill canisters in item preferences (see Fig 2), which led to a row of nameless pill canisters being present in our server's menu. My solution is to fetch the item's LabelComponent in the menu so this redundancy is no more needed. See Fig 3 for an example. The VendingMachineMenu.xaml.cs code fetches and localizes the text from the LabelComponent from the prototype the same way it fetches sprites, and in the LoadoutPreferenceSelector.xaml.cs the task is pretty straightforward since the item is spawned in the Nullspace anyway. --- - [x] Added label rendering for VendingMachineMenu.xaml.cs - [x] Stripped reagent jugs' names off their fake labels - [x] Added label rendering for LoadoutPreferenceSelector.xaml.cs - [x] Stripped pill canisters' names off their fake labels - [x] Reformatted pills *that do not have explicit descriptions* to match "pill (label)" format ---

Media

Fig 1, the issue with ChemVend's reagent jugs: ![Fig 1](https://github.com/user-attachments/assets/05983f8d-1bc6-4352-b13c-194a6ea172e9) Fig 2, the issue with pill canisters: ![Fig 2](https://github.com/user-attachments/assets/5afec42f-ef55-4b9d-af2f-2cef6174225d) Fig 3, demonstration of the solution: ![Fig 3](https://github.com/user-attachments/assets/bbc2d1b3-e773-4654-a32a-ab5d7205e0e9)

--- # Changelog :cl: NeLepus - add: Added label rendering for vending machines & item preferences - tweak: Formatted pill without descriptions to follow "pill (label)" - remove: Fake label duplicates in reagent jugs and pill canisters --- .../UI/LoadoutPreferenceSelector.xaml.cs | 10 ++++ .../UI/VendingMachineMenu.xaml.cs | 15 +++++ .../Objects/Specific/Medical/healing.yml | 55 +++++++++---------- .../Objects/Specific/chemical-containers.yml | 24 -------- .../Objects/Specific/Medical/pills.yml | 4 +- 5 files changed, 51 insertions(+), 57 deletions(-) diff --git a/Content.Client/Lobby/UI/LoadoutPreferenceSelector.xaml.cs b/Content.Client/Lobby/UI/LoadoutPreferenceSelector.xaml.cs index eb472e7d959..cd73bf65b85 100644 --- a/Content.Client/Lobby/UI/LoadoutPreferenceSelector.xaml.cs +++ b/Content.Client/Lobby/UI/LoadoutPreferenceSelector.xaml.cs @@ -9,6 +9,7 @@ using Content.Shared.Clothing.Loadouts.Prototypes; using Content.Shared.Clothing.Loadouts.Systems; using Content.Shared.Customization.Systems; +using Content.Shared.Labels.Components; using Content.Shared.Paint; using Content.Shared.Preferences; using Content.Shared.Roles; @@ -140,6 +141,15 @@ public LoadoutPreferenceSelector(LoadoutPrototype loadout, JobPrototype highJob, Loc.GetString($"loadout-name-{loadout.ID}") == $"loadout-name-{loadout.ID}" ? entityManager.GetComponent(dummyLoadoutItem).EntityName : Loc.GetString($"loadout-name-{loadout.ID}"); + + // Display the item's label if it's present + if (entityManager.TryGetComponent(dummyLoadoutItem, out LabelComponent? labelComponent)) + { + var itemLabel = labelComponent.CurrentLabel; + if (!string.IsNullOrEmpty(itemLabel)) + loadoutName += $" ({Loc.GetString(itemLabel)})"; + } + var loadoutDesc = !Loc.TryGetString($"loadout-description-{loadout.ID}", out var description) ? entityManager.GetComponent(dummyLoadoutItem).EntityDescription diff --git a/Content.Client/VendingMachines/UI/VendingMachineMenu.xaml.cs b/Content.Client/VendingMachines/UI/VendingMachineMenu.xaml.cs index 8b53290f7fb..450b2d75c6f 100644 --- a/Content.Client/VendingMachines/UI/VendingMachineMenu.xaml.cs +++ b/Content.Client/VendingMachines/UI/VendingMachineMenu.xaml.cs @@ -8,6 +8,10 @@ using Robust.Client.UserInterface.XAML; using Robust.Shared.Prototypes; using FancyWindow = Content.Client.UserInterface.Controls.FancyWindow; +using Content.Shared.Labels.Components; +using Content.Shared.Prototypes; +using System.Reflection.Emit; +using Content.Client.Labels; namespace Content.Client.VendingMachines.UI { @@ -73,11 +77,21 @@ public void Populate(List inventory, out List vendingItem.Icon = null; var itemName = entry.ID; + Texture? icon = null; if (_prototypeManager.TryIndex(entry.ID, out var prototype)) { itemName = prototype.Name; icon = spriteSystem.GetPrototypeIcon(prototype).Default; + + const string labelCompName = "Label"; + if (prototype.Components.TryGetValue(labelCompName, out var labelCompData) + && labelCompData.Component is LabelComponent labelComponent) + { + var itemLabel = labelComponent.CurrentLabel; + if (!string.IsNullOrEmpty(itemLabel)) + itemName += $" ({Loc.GetString(itemLabel)})"; + } } // search filter @@ -93,6 +107,7 @@ public void Populate(List inventory, out List longestEntry = itemName; vendingItem.Text = $"{itemName} [{entry.Amount}]"; + vendingItem.Icon = icon; filteredInventory.Add(i); } diff --git a/Resources/Prototypes/Entities/Objects/Specific/Medical/healing.yml b/Resources/Prototypes/Entities/Objects/Specific/Medical/healing.yml index e852b217cba..6e59fc95ecb 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/Medical/healing.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/Medical/healing.yml @@ -347,7 +347,7 @@ # Pills - type: entity - name: pill (dexalin 10u) + suffix: Dexalin 10u parent: Pill id: PillDexalin components: @@ -367,7 +367,6 @@ - type: entity - name: pill canister (dexalin 10u) parent: PillCanister id: PillCanisterDexalin suffix: Dexalin, 7 @@ -380,7 +379,7 @@ amount: 7 - type: entity - name: pill (dylovene 10u) + suffix: Dylovene 10u parent: Pill id: PillDylovene components: @@ -399,7 +398,6 @@ Quantity: 10 - type: entity - name: pill canister (dylovene 10u) parent: PillCanister id: PillCanisterDylovene suffix: Dylovene, 5 @@ -412,7 +410,7 @@ amount: 5 - type: entity - name: pill (hyronalin 10u) + suffix: Hyronalin 10u parent: Pill id: PillHyronalin components: @@ -431,7 +429,6 @@ Quantity: 10 - type: entity - name: pill canister (hyronalin 10u) parent: PillCanister id: PillCanisterHyronalin suffix: Hyronalin, 5 @@ -444,7 +441,6 @@ amount: 5 - type: entity - name: pill suffix: Potassium iodide 10u parent: Pill id: PillPotassiumIodide @@ -464,10 +460,9 @@ Quantity: 10 - type: entity - name: pill canister parent: PillCanister id: PillCanisterPotassiumIodide - suffix: Potassium iodide 10u, 5 + suffix: Potassium iodide, 5 components: - type: Label currentLabel: potassium iodide 10u @@ -477,7 +472,6 @@ amount: 5 - type: entity - name: pill suffix: Iron 10u parent: Pill id: PillIron @@ -497,7 +491,7 @@ Quantity: 10 - type: entity - name: pill (copper 10u) + suffix: Copper 10u parent: Pill id: PillCopper components: @@ -516,7 +510,6 @@ Quantity: 10 - type: entity - name: pill canister (iron 10u) parent: PillCanister id: PillCanisterIron suffix: Iron, 5 @@ -529,7 +522,6 @@ amount: 5 - type: entity - name: pill canister (copper 10u) parent: PillCanister id: PillCanisterCopper suffix: Copper, 5 @@ -542,7 +534,7 @@ amount: 5 - type: entity - name: pill (kelotane 10u) + suffix: Kelotane 10u parent: Pill id: PillKelotane components: @@ -561,7 +553,6 @@ Quantity: 10 - type: entity - name: pill canister (kelotane 10u) parent: PillCanister id: PillCanisterKelotane suffix: Kelotane, 5 @@ -574,7 +565,7 @@ amount: 5 - type: entity - name: pill (dermaline 10u) + suffix: Dermaline 10u parent: Pill id: PillDermaline components: @@ -593,7 +584,6 @@ Quantity: 10 - type: entity - name: pill canister (dermaline 10u) parent: PillCanister id: PillCanisterDermaline suffix: Dermaline, 5 @@ -606,10 +596,12 @@ amount: 5 - type: entity - name: space drugs + suffix: Space drugs 15u parent: Pill id: PillSpaceDrugs components: + - type: Label + currentLabel: space drugs 15u - type: SolutionContainerManager solutions: food: @@ -619,7 +611,6 @@ Quantity: 15 - type: entity - name: pill canister (LSD 15u) parent: PillCanister id: PillCanisterSpaceDrugs suffix: Space Drugs, 5 @@ -632,10 +623,12 @@ amount: 5 - type: entity - name: pax + suffix: Pax 10u parent: Pill id: PillPax components: + - type: Label + currentLabel: pax 10u - type: SolutionContainerManager solutions: food: @@ -645,7 +638,6 @@ Quantity: 10 - type: entity - name: pill canister (Pax 10u) parent: PillCanister id: PillCanisterPax suffix: Pax, 5 @@ -659,7 +651,7 @@ - type: entity - name: pill (tricordrazine 10u) + suffix: Tricordrazine 10u parent: Pill id: PillTricordrazine components: @@ -678,7 +670,6 @@ Quantity: 10 - type: entity - name: pill canister (tricordrazine 10u) parent: PillCanister id: PillCanisterTricordrazine suffix: Tricordrazine, 5 @@ -691,7 +682,7 @@ amount: 5 - type: entity - name: pill (bicaridine 10u) + suffix: Bicaridine 10u parent: Pill id: PillBicaridine components: @@ -710,7 +701,6 @@ Quantity: 10 - type: entity - name: pill canister (bicaridine 10u) parent: PillCanister id: PillCanisterBicaridine suffix: Bicaridine, 5 @@ -723,7 +713,7 @@ amount: 5 - type: entity - name: pill (charcoal 10u) + suffix: Charcoal 10u parent: Pill id: PillCharcoal components: @@ -742,7 +732,6 @@ Quantity: 10 - type: entity - name: pill canister (charcoal 10u) parent: PillCanister id: PillCanisterCharcoal suffix: Charcoal, 3 @@ -755,10 +744,12 @@ amount: 3 - type: entity - name: romerol pill + suffix: Romerol 10u parent: Pill id: PillRomerol components: + - type: Label + currentLabel: romerol 10u - type: SolutionContainerManager solutions: food: @@ -768,10 +759,12 @@ Quantity: 10 - type: entity - name: ambuzol pill + suffix: Ambuzol 10u parent: Pill id: PillAmbuzol components: + - type: Label + currentLabel: ambuzol 10u - type: SolutionContainerManager solutions: food: @@ -781,7 +774,7 @@ Quantity: 10 - type: entity - name: ambuzol plus pill + suffix: Ambuzol plus 5u parent: Pill id: PillAmbuzolPlus components: @@ -789,6 +782,8 @@ pillType: 2 - type: Sprite state: pill3 + - type: Label + currentLabel: ambuzol plus 5u - type: SolutionContainerManager solutions: food: diff --git a/Resources/Prototypes/Entities/Objects/Specific/chemical-containers.yml b/Resources/Prototypes/Entities/Objects/Specific/chemical-containers.yml index a09bd42e435..7915bb79476 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/chemical-containers.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/chemical-containers.yml @@ -85,7 +85,6 @@ - type: entity parent: Jug - name: jug (carbon) id: JugCarbon categories: [ HideSpawnMenu ] components: @@ -100,7 +99,6 @@ - type: entity parent: Jug - name: jug (iodine) id: JugIodine categories: [ HideSpawnMenu ] components: @@ -115,7 +113,6 @@ - type: entity parent: Jug - name: jug (fluorine) id: JugFluorine categories: [ HideSpawnMenu ] components: @@ -130,7 +127,6 @@ - type: entity parent: Jug - name: jug (chlorine) id: JugChlorine categories: [ HideSpawnMenu ] components: @@ -145,7 +141,6 @@ - type: entity parent: Jug - name: jug (aluminium) id: JugAluminium categories: [ HideSpawnMenu ] components: @@ -160,7 +155,6 @@ - type: entity parent: Jug - name: jug (phosphorus) id: JugPhosphorus categories: [ HideSpawnMenu ] components: @@ -175,7 +169,6 @@ - type: entity parent: Jug - name: jug (sulfur) id: JugSulfur categories: [ HideSpawnMenu ] components: @@ -190,7 +183,6 @@ - type: entity parent: Jug - name: jug (silicon) id: JugSilicon categories: [ HideSpawnMenu ] components: @@ -205,7 +197,6 @@ - type: entity parent: Jug - name: jug (hydrogen) id: JugHydrogen categories: [ HideSpawnMenu ] components: @@ -220,7 +211,6 @@ - type: entity parent: Jug - name: jug (lithium) id: JugLithium categories: [ HideSpawnMenu ] components: @@ -235,7 +225,6 @@ - type: entity parent: Jug - name: jug (sodium) id: JugSodium categories: [ HideSpawnMenu ] components: @@ -250,7 +239,6 @@ - type: entity parent: Jug - name: jug (potassium) id: JugPotassium categories: [ HideSpawnMenu ] components: @@ -265,7 +253,6 @@ - type: entity parent: Jug - name: jug (radium) id: JugRadium categories: [ HideSpawnMenu ] components: @@ -280,7 +267,6 @@ - type: entity parent: Jug - name: jug (iron) id: JugIron categories: [ HideSpawnMenu ] components: @@ -295,7 +281,6 @@ - type: entity parent: Jug - name: jug (copper) id: JugCopper categories: [ HideSpawnMenu ] components: @@ -310,7 +295,6 @@ - type: entity parent: Jug - name: jug (gold) id: JugGold categories: [ HideSpawnMenu ] components: @@ -325,7 +309,6 @@ - type: entity parent: Jug - name: jug (mercury) id: JugMercury categories: [ HideSpawnMenu ] components: @@ -340,7 +323,6 @@ - type: entity parent: Jug - name: jug (silver) id: JugSilver categories: [ HideSpawnMenu ] components: @@ -355,7 +337,6 @@ - type: entity parent: Jug - name: jug (ethanol) id: JugEthanol categories: [ HideSpawnMenu ] components: @@ -370,7 +351,6 @@ - type: entity parent: Jug - name: jug (sugar) id: JugSugar categories: [ HideSpawnMenu ] components: @@ -385,7 +365,6 @@ - type: entity parent: Jug - name: jug (nitrogen) id: JugNitrogen categories: [ HideSpawnMenu ] components: @@ -400,7 +379,6 @@ - type: entity parent: Jug - name: jug (oxygen) id: JugOxygen categories: [ HideSpawnMenu ] components: @@ -415,7 +393,6 @@ - type: entity parent: Jug - name: jug (Plant-B-Gone) id: JugPlantBGone categories: [ HideSpawnMenu ] components: @@ -430,7 +407,6 @@ - type: entity parent: Jug - name: jug (welding fuel) id: JugWeldingFuel categories: [ HideSpawnMenu ] components: diff --git a/Resources/Prototypes/Nyanotrasen/Entities/Objects/Specific/Medical/pills.yml b/Resources/Prototypes/Nyanotrasen/Entities/Objects/Specific/Medical/pills.yml index 1b0bf68fb09..2c51deb272d 100644 --- a/Resources/Prototypes/Nyanotrasen/Entities/Objects/Specific/Medical/pills.yml +++ b/Resources/Prototypes/Nyanotrasen/Entities/Objects/Specific/Medical/pills.yml @@ -27,7 +27,6 @@ Quantity: 20 - type: entity - name: pill canister (Cryptobiolin 20u) parent: PillCanister id: PillCanisterCryptobiolin suffix: Cryptobiolin, 5 @@ -54,13 +53,12 @@ Quantity: 20 - type: entity - name: pill canister (Chloral-Hydrate 20u) parent: PillCanister id: PillCanisterChloralHydrate suffix: ChloralHydrate, 5 components: - type: Label - currentLabel: ChloralHydrate 20u + currentLabel: chloral-hydrate 20u - type: StorageFill contents: - id: PillChloralHydrate