Skip to content

Commit

Permalink
Автоматический этикеровщик химикалиев (#172)
Browse files Browse the repository at this point in the history
* Labeler

* fix comment

* make it happen

* Update Resources/Prototypes/Entities/Structures/Dispensers/chem.yml

Co-authored-by: FN <[email protected]>

* Update Content.Server/Chemistry/EntitySystems/ReagentDispenserSystem.cs

Co-authored-by: FN <[email protected]>

* Update Content.Server/Chemistry/Components/ReagentDispenserComponent.cs

Co-authored-by: FN <[email protected]>

* Update Content.Server/Chemistry/EntitySystems/ReagentDispenserSystem.cs

Co-authored-by: FN <[email protected]>

* Update Content.Server/Chemistry/EntitySystems/ReagentDispenserSystem.cs

Co-authored-by: FN <[email protected]>

* Update Content.Server/Chemistry/EntitySystems/ReagentDispenserSystem.cs

Co-authored-by: FN <[email protected]>

* Update ReagentDispenserSystem.cs

* Update Content.Server/Chemistry/EntitySystems/ReagentDispenserSystem.cs

Co-authored-by: FN <[email protected]>

* Update Content.Server/Chemistry/EntitySystems/ReagentDispenserSystem.cs

Co-authored-by: FN <[email protected]>

* last and fast

* Update Content.Server/Chemistry/EntitySystems/ReagentDispenserSystem.cs

Co-authored-by: FN <[email protected]>

* Update ReagentDispenserSystem.cs

---------

Co-authored-by: 60093633 <[email protected]>
Co-authored-by: FN <[email protected]>
  • Loading branch information
3 people authored Dec 19, 2024
1 parent ef3e961 commit 403f991
Show file tree
Hide file tree
Showing 5 changed files with 90 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-Labeler-Start
[DataField]
public bool CanAutoLabel;

[ViewVariables]
public bool AutoLabel;
// Corvax-Next-Labeler-End
}
}
71 changes: 70 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,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
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 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)
{
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

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].
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

0 comments on commit 403f991

Please sign in to comment.