Skip to content

Commit

Permalink
Labeler
Browse files Browse the repository at this point in the history
  • Loading branch information
60093633 authored and 60093633 committed Dec 19, 2024
1 parent 9f340a1 commit cbb3a6b
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,13 @@ public sealed partial class ReagentDispenserComponent : Component

[ViewVariables(VVAccess.ReadWrite)]
public ReagentDispenserDispenseAmount DispenseAmount = ReagentDispenserDispenseAmount.U10;

// Corvax-Next: whether or not this entity can auto-label items
[DataField]
public bool CanAutoLabel;

// Corvax-Next: whether or not this entity is currently auto-labeling items
[ViewVariables]
public bool AutoLabel;
}
}
73 changes: 72 additions & 1 deletion Content.Server/Chemistry/EntitySystems/ReagentDispenserSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
using Robust.Shared.Containers;
using Robust.Shared.Prototypes;
using Content.Shared.Labels.Components;
using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Server.Labels;
using Content.Shared.Verbs;
using Content.Shared.Examine;

namespace Content.Server.Chemistry.EntitySystems
{
Expand All @@ -30,17 +36,21 @@ public sealed class ReagentDispenserSystem : EntitySystem
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly OpenableSystem _openable = default!;
[Dependency] private readonly LabelSystem _label = default!; // Corvax-Next-ChemLabeler

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<ReagentDispenserComponent, ComponentStartup>(SubscribeUpdateUiState);
SubscribeLocalEvent<ReagentDispenserComponent, SolutionContainerChangedEvent>(SubscribeUpdateUiState);
SubscribeLocalEvent<ReagentDispenserComponent, EntInsertedIntoContainerMessage>(SubscribeUpdateUiState);
SubscribeLocalEvent<ReagentDispenserComponent, EntInsertedIntoContainerMessage>(OnEntInserted); // Corvax-Next-ChemLabeler: SubscribeUpdateUiState < OnEntInserted
SubscribeLocalEvent<ReagentDispenserComponent, EntRemovedFromContainerMessage>(SubscribeUpdateUiState);
SubscribeLocalEvent<ReagentDispenserComponent, BoundUIOpenedEvent>(SubscribeUpdateUiState);

SubscribeLocalEvent<ReagentDispenserComponent, GetVerbsEvent<AlternativeVerb>>(OnAlternateVerb); // Corvax-Next-ChemLabeler
SubscribeLocalEvent<ReagentDispenserComponent, ExaminedEvent>(OnExamined); // Corvax-Next-ChemLabeler

SubscribeLocalEvent<ReagentDispenserComponent, ReagentDispenserSetDispenseAmountMessage>(OnSetDispenseAmountMessage);
SubscribeLocalEvent<ReagentDispenserComponent, ReagentDispenserDispenseReagentMessage>(OnDispenseReagentMessage);
SubscribeLocalEvent<ReagentDispenserComponent, ReagentDispenserClearContainerSolutionMessage>(OnClearContainerSolutionMessage);
Expand All @@ -53,6 +63,64 @@ private void SubscribeUpdateUiState<T>(Entity<ReagentDispenserComponent> ent, re
UpdateUiState(ent);
}

// Corvax-Next-ChemLabeler-Start: auto-label on insert
private void OnEntInserted(Entity<ReagentDispenserComponent> ent, ref EntInsertedIntoContainerMessage ev)
{
if (ent.Comp.AutoLabel && _solutionContainerSystem.TryGetDrainableSolution(ev.Entity, out _, out var sol))
{
ReagentId? reagentId = sol.GetPrimaryReagentId();
if (reagentId != null && _prototypeManager.TryIndex<ReagentPrototype>(reagentId.Value.Prototype, out var reagent))
{
var reagentQuantity = sol.GetReagentQuantity(reagentId.Value);
var totalQuantity = sol.Volume;
if (reagentQuantity == totalQuantity)
_label.Label(ev.Entity, reagent.LocalizedName);
else
_label.Label(ev.Entity, Loc.GetString("reagent-dispenser-component-impure-auto-label", ("reagent", reagent.LocalizedName), ("purity", 100.0f * reagentQuantity / totalQuantity)));
}
}

UpdateUiState(ent);
}

private void OnAlternateVerb(Entity<ReagentDispenserComponent> ent, ref GetVerbsEvent<AlternativeVerb> args)
{
if (!ent.Comp.CanAutoLabel)
return;

args.Verbs.Add(new AlternativeVerb()
{
Act = () =>
{
SetAutoLabel(ent, !ent.Comp.AutoLabel);
},
Text = ent.Comp.AutoLabel ?
Loc.GetString("reagent-dispenser-component-set-auto-label-off-verb")
: Loc.GetString("reagent-dispenser-component-set-auto-label-on-verb"),
Priority = -1, //Not important, low priority.
});
}

private void SetAutoLabel(Entity<ReagentDispenserComponent> ent, bool autoLabel)
{
if (!ent.Comp.CanAutoLabel)
return;

ent.Comp.AutoLabel = autoLabel;
}

private void OnExamined(Entity<ReagentDispenserComponent> ent, ref ExaminedEvent args)
{
if (!args.IsInDetailsRange || !ent.Comp.CanAutoLabel)
return;

if (ent.Comp.AutoLabel)
args.PushMarkup(Loc.GetString("reagent-dispenser-component-examine-auto-label-on"));
else
args.PushMarkup(Loc.GetString("reagent-dispenser-component-examine-auto-label-off"));
}
// End Corvax-Next-ChemLabeler-End

private void UpdateUiState(Entity<ReagentDispenserComponent> reagentDispenser)
{
var outputContainer = _itemSlotsSystem.GetItemOrNull(reagentDispenser, SharedReagentDispenser.OutputSlotName);
Expand Down Expand Up @@ -168,6 +236,9 @@ private void ClickSound(Entity<ReagentDispenserComponent> reagentDispenser)
/// </summary>
private void OnMapInit(EntityUid uid, ReagentDispenserComponent component, MapInitEvent args)
{
// Frontier: set auto-labeller
component.AutoLabel = component.CanAutoLabel;

// Get list of pre-loaded containers
List<string> preLoad = new List<string>();
if (component.PackPrototypeId is not null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
reagent-dispenser-component-impure-auto-label = {$reagent} ({$purity}%)
reagent-dispenser-component-set-auto-label-on-verb = Turn on auto-labeler
reagent-dispenser-component-set-auto-label-off-verb = Turn off auto-labeler
reagent-dispenser-component-examine-auto-label-on = The auto-labeler is turned [color=darkgreen]on[/color].
reagent-dispenser-component-examine-auto-label-off = The auto-labeler is turned [color=red]off[/color].
reagent-dispenser-component-examine-extra-slots = Number of jug slots
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
reagent-dispenser-component-impure-auto-label = {$reagent} ({$purity}%)
reagent-dispenser-component-set-auto-label-on-verb = Включить авто-этикеровщик
reagent-dispenser-component-set-auto-label-off-verb = Выключить авто-этикеровщик
reagent-dispenser-component-examine-auto-label-on = Авто-этикеровщик [color=darkgreen]включен[/color].
reagent-dispenser-component-examine-auto-label-off = Авто-этикеровщик [color=red]выключен[/color].

0 comments on commit cbb3a6b

Please sign in to comment.