Skip to content

Commit

Permalink
Label Rendering For Vending Machines and Item Preferences Menus (#1538)
Browse files Browse the repository at this point in the history
# 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

---

<!--
This is default collapsed, readers click to expand it and see all your
media
The PR media section can get very large at times, so this is a good way
to keep it clean
The title is written using HTML tags
The title must be within the <summary> tags or you won't see it
-->

<details><summary><h1>Media</h1></summary>
<p>

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)

</p>
</details>

---

# 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
  • Loading branch information
NeLepus authored Jan 15, 2025
1 parent 1b131c6 commit f0f9512
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 57 deletions.
10 changes: 10 additions & 0 deletions Content.Client/Lobby/UI/LoadoutPreferenceSelector.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -140,6 +141,15 @@ public LoadoutPreferenceSelector(LoadoutPrototype loadout, JobPrototype highJob,
Loc.GetString($"loadout-name-{loadout.ID}") == $"loadout-name-{loadout.ID}"
? entityManager.GetComponent<MetaDataComponent>(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<MetaDataComponent>(dummyLoadoutItem).EntityDescription
Expand Down
15 changes: 15 additions & 0 deletions Content.Client/VendingMachines/UI/VendingMachineMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -73,11 +77,21 @@ public void Populate(List<VendingMachineInventoryEntry> inventory, out List<int>
vendingItem.Icon = null;

var itemName = entry.ID;

Texture? icon = null;
if (_prototypeManager.TryIndex<EntityPrototype>(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
Expand All @@ -93,6 +107,7 @@ public void Populate(List<VendingMachineInventoryEntry> inventory, out List<int>
longestEntry = itemName;

vendingItem.Text = $"{itemName} [{entry.Amount}]";

vendingItem.Icon = icon;
filteredInventory.Add(i);
}
Expand Down
55 changes: 25 additions & 30 deletions Resources/Prototypes/Entities/Objects/Specific/Medical/healing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@

# Pills
- type: entity
name: pill (dexalin 10u)
suffix: Dexalin 10u
parent: Pill
id: PillDexalin
components:
Expand All @@ -367,7 +367,6 @@


- type: entity
name: pill canister (dexalin 10u)
parent: PillCanister
id: PillCanisterDexalin
suffix: Dexalin, 7
Expand All @@ -380,7 +379,7 @@
amount: 7

- type: entity
name: pill (dylovene 10u)
suffix: Dylovene 10u
parent: Pill
id: PillDylovene
components:
Expand All @@ -399,7 +398,6 @@
Quantity: 10

- type: entity
name: pill canister (dylovene 10u)
parent: PillCanister
id: PillCanisterDylovene
suffix: Dylovene, 5
Expand All @@ -412,7 +410,7 @@
amount: 5

- type: entity
name: pill (hyronalin 10u)
suffix: Hyronalin 10u
parent: Pill
id: PillHyronalin
components:
Expand All @@ -431,7 +429,6 @@
Quantity: 10

- type: entity
name: pill canister (hyronalin 10u)
parent: PillCanister
id: PillCanisterHyronalin
suffix: Hyronalin, 5
Expand All @@ -444,7 +441,6 @@
amount: 5

- type: entity
name: pill
suffix: Potassium iodide 10u
parent: Pill
id: PillPotassiumIodide
Expand All @@ -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
Expand All @@ -477,7 +472,6 @@
amount: 5

- type: entity
name: pill
suffix: Iron 10u
parent: Pill
id: PillIron
Expand All @@ -497,7 +491,7 @@
Quantity: 10

- type: entity
name: pill (copper 10u)
suffix: Copper 10u
parent: Pill
id: PillCopper
components:
Expand All @@ -516,7 +510,6 @@
Quantity: 10

- type: entity
name: pill canister (iron 10u)
parent: PillCanister
id: PillCanisterIron
suffix: Iron, 5
Expand All @@ -529,7 +522,6 @@
amount: 5

- type: entity
name: pill canister (copper 10u)
parent: PillCanister
id: PillCanisterCopper
suffix: Copper, 5
Expand All @@ -542,7 +534,7 @@
amount: 5

- type: entity
name: pill (kelotane 10u)
suffix: Kelotane 10u
parent: Pill
id: PillKelotane
components:
Expand All @@ -561,7 +553,6 @@
Quantity: 10

- type: entity
name: pill canister (kelotane 10u)
parent: PillCanister
id: PillCanisterKelotane
suffix: Kelotane, 5
Expand All @@ -574,7 +565,7 @@
amount: 5

- type: entity
name: pill (dermaline 10u)
suffix: Dermaline 10u
parent: Pill
id: PillDermaline
components:
Expand All @@ -593,7 +584,6 @@
Quantity: 10

- type: entity
name: pill canister (dermaline 10u)
parent: PillCanister
id: PillCanisterDermaline
suffix: Dermaline, 5
Expand All @@ -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:
Expand All @@ -619,7 +611,6 @@
Quantity: 15

- type: entity
name: pill canister (LSD 15u)
parent: PillCanister
id: PillCanisterSpaceDrugs
suffix: Space Drugs, 5
Expand All @@ -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:
Expand All @@ -645,7 +638,6 @@
Quantity: 10

- type: entity
name: pill canister (Pax 10u)
parent: PillCanister
id: PillCanisterPax
suffix: Pax, 5
Expand All @@ -659,7 +651,7 @@


- type: entity
name: pill (tricordrazine 10u)
suffix: Tricordrazine 10u
parent: Pill
id: PillTricordrazine
components:
Expand All @@ -678,7 +670,6 @@
Quantity: 10

- type: entity
name: pill canister (tricordrazine 10u)
parent: PillCanister
id: PillCanisterTricordrazine
suffix: Tricordrazine, 5
Expand All @@ -691,7 +682,7 @@
amount: 5

- type: entity
name: pill (bicaridine 10u)
suffix: Bicaridine 10u
parent: Pill
id: PillBicaridine
components:
Expand All @@ -710,7 +701,6 @@
Quantity: 10

- type: entity
name: pill canister (bicaridine 10u)
parent: PillCanister
id: PillCanisterBicaridine
suffix: Bicaridine, 5
Expand All @@ -723,7 +713,7 @@
amount: 5

- type: entity
name: pill (charcoal 10u)
suffix: Charcoal 10u
parent: Pill
id: PillCharcoal
components:
Expand All @@ -742,7 +732,6 @@
Quantity: 10

- type: entity
name: pill canister (charcoal 10u)
parent: PillCanister
id: PillCanisterCharcoal
suffix: Charcoal, 3
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -781,14 +774,16 @@
Quantity: 10

- type: entity
name: ambuzol plus pill
suffix: Ambuzol plus 5u
parent: Pill
id: PillAmbuzolPlus
components:
- type: Pill
pillType: 2
- type: Sprite
state: pill3
- type: Label
currentLabel: ambuzol plus 5u
- type: SolutionContainerManager
solutions:
food:
Expand Down
Loading

0 comments on commit f0f9512

Please sign in to comment.