Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Автоматический этикеровщик химикалиев #172

Merged
merged 15 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Vonsant marked this conversation as resolved.
Show resolved Hide resolved
}
}
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
Vonsant marked this conversation as resolved.
Show resolved Hide resolved
SubscribeLocalEvent<ReagentDispenserComponent, EntRemovedFromContainerMessage>(SubscribeUpdateUiState);
SubscribeLocalEvent<ReagentDispenserComponent, BoundUIOpenedEvent>(SubscribeUpdateUiState);

SubscribeLocalEvent<ReagentDispenserComponent, GetVerbsEvent<AlternativeVerb>>(OnAlternateVerb); // Corvax-Next-ChemLabeler
SubscribeLocalEvent<ReagentDispenserComponent, ExaminedEvent>(OnExamined); // Corvax-Next-ChemLabeler
Vonsant marked this conversation as resolved.
Show resolved Hide resolved

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();
Vonsant marked this conversation as resolved.
Show resolved Hide resolved
if (reagentId != null && _prototypeManager.TryIndex<ReagentPrototype>(reagentId.Value.Prototype, out var reagent))
Vonsant marked this conversation as resolved.
Show resolved Hide resolved
Vonsant marked this conversation as resolved.
Show resolved Hide resolved
{
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)
Vonsant marked this conversation as resolved.
Show resolved Hide resolved
{
if (!ent.Comp.CanAutoLabel)
return;

args.Verbs.Add(new AlternativeVerb()
{
Act = () =>
{
SetAutoLabel(ent, !ent.Comp.AutoLabel);
},
Vonsant marked this conversation as resolved.
Show resolved Hide resolved
Text = ent.Comp.AutoLabel ?
Loc.GetString("reagent-dispenser-component-set-auto-label-off-verb")
: Loc.GetString("reagent-dispenser-component-set-auto-label-on-verb"),
Vonsant marked this conversation as resolved.
Show resolved Hide resolved
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
Vonsant marked this conversation as resolved.
Show resolved Hide resolved

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)
{
// Corvax-Next-ChemLabeler: set auto-labeller
component.AutoLabel = component.CanAutoLabel;
Vonsant marked this conversation as resolved.
Show resolved Hide resolved

// 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].
Vonsant marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
tags:
- ChemDispensable
pack: ChemDispenserStandardInventory
canAutoLabel: true # Corvax-Next-ChemLabeler
Vonsant marked this conversation as resolved.
Show resolved Hide resolved
- type: ApcPowerReceiver
- type: ExtensionCableReceiver
- type: Destructible
Expand Down
Loading