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 13 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-Labeler-Start
[DataField]
public bool CanAutoLabel;

[ViewVariables]
public bool AutoLabel;
// Corvax-Next-Labeler-End
}
}
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,23 @@ 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-Labeler

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

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

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

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

// // Corvax-Next-Labeler-Start
Vonsant marked this conversation as resolved.
Show resolved Hide resolved
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 is not 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)
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),
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"));
}
// Corvax-Next-Labeler-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 +235,8 @@ private void ClickSound(Entity<ReagentDispenserComponent> reagentDispenser)
/// </summary>
private void OnMapInit(EntityUid uid, ReagentDispenserComponent component, MapInitEvent args)
{
component.AutoLabel = component.CanAutoLabel; // Corvax-Next-Labeler

// 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-Labeler
- type: ApcPowerReceiver
- type: ExtensionCableReceiver
- type: Destructible
Expand Down
Loading