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

Inserted container visuals for Cryopod and grinder #34183

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Clothing;
using Content.Shared.Clothing.Components;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Hands;
using Content.Shared.Item;
using Content.Shared.Rounding;
Expand All @@ -16,6 +17,7 @@ public sealed class SolutionContainerVisualsSystem : VisualizerSystem<SolutionCo
{
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly ItemSystem _itemSystem = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;

public override void Initialize()
{
Expand Down Expand Up @@ -44,7 +46,20 @@ protected override void OnAppearanceChange(EntityUid uid, SolutionContainerVisua
}
}

if (!AppearanceSystem.TryGetData<float>(uid, SolutionContainerVisuals.FillFraction, out var fraction, args.Component))
EntityUid? insertedUid = null;
float fraction = 0;
if (component.InsertedItemSlotID != null)
{
if (!_entityManager.TryGetComponent(uid, out ItemSlotsComponent? itemSlotsComponent))
return;
var slot = itemSlotsComponent.Slots[component.InsertedItemSlotID];
insertedUid = slot.Item;

if (insertedUid != null && !AppearanceSystem.TryGetData<float>(insertedUid.Value, SolutionContainerVisuals.FillFraction, out fraction))
return;

}
else if (!AppearanceSystem.TryGetData<float>(uid, SolutionContainerVisuals.FillFraction, out fraction, args.Component))
return;

if (args.Sprite == null)
Expand Down Expand Up @@ -123,7 +138,13 @@ protected override void OnAppearanceChange(EntityUid uid, SolutionContainerVisua
args.Sprite.LayerSetSprite(fillLayer, fillSprite);
args.Sprite.LayerSetState(fillLayer, stateName);

if (changeColor && AppearanceSystem.TryGetData<Color>(uid, SolutionContainerVisuals.Color, out var color, args.Component))
if (changeColor &&
insertedUid != null &&
AppearanceSystem.TryGetData<Color>(insertedUid.Value, SolutionContainerVisuals.Color, out var color))
{
args.Sprite.LayerSetColor(fillLayer, color);
}
else if (changeColor && AppearanceSystem.TryGetData<Color>(uid, SolutionContainerVisuals.Color, out color, args.Component))
args.Sprite.LayerSetColor(fillLayer, color);
else
args.Sprite.LayerSetColor(fillLayer, Color.White);
Expand Down
41 changes: 33 additions & 8 deletions Content.Client/Medical/Cryogenics/CryoPodSystem.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using System.Numerics;
using System.Numerics;
using Content.Shared.Chemistry;
using Content.Shared.Emag.Systems;
using Content.Shared.Medical.Cryogenics;
using Content.Shared.Verbs;
using Robust.Client.GameObjects;
using static Content.Shared.Medical.Cryogenics.CryoPodComponent;
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;

namespace Content.Client.Medical.Cryogenics;

public sealed class CryoPodSystem: SharedCryoPodSystem
{
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedPointLightSystem _pointLightSystem = default!;

public override void Initialize()
{
Expand All @@ -19,8 +22,8 @@ public override void Initialize()
SubscribeLocalEvent<CryoPodComponent, GetVerbsEvent<AlternativeVerb>>(AddAlternativeVerbs);
SubscribeLocalEvent<CryoPodComponent, GotEmaggedEvent>(OnEmagged);
SubscribeLocalEvent<CryoPodComponent, CryoPodPryFinished>(OnCryoPodPryFinished);

SubscribeLocalEvent<CryoPodComponent, AppearanceChangeEvent>(OnAppearanceChange);

SubscribeLocalEvent<InsideCryoPodComponent, ComponentStartup>(OnCryoPodInsertion);
SubscribeLocalEvent<InsideCryoPodComponent, ComponentRemove>(OnCryoPodRemoval);
}
Expand Down Expand Up @@ -53,24 +56,46 @@ private void OnAppearanceChange(EntityUid uid, CryoPodComponent component, ref A
return;
}

if (!_appearance.TryGetData<bool>(uid, CryoPodComponent.CryoPodVisuals.ContainsEntity, out var isOpen, args.Component)
|| !_appearance.TryGetData<bool>(uid, CryoPodComponent.CryoPodVisuals.IsOn, out var isOn, args.Component))
if (!_appearance.TryGetData<bool>(uid, CryoPodVisuals.ContainsEntity, out var isOpen, args.Component) ||
!_appearance.TryGetData<bool>(uid, CryoPodVisuals.IsOn, out var isOn, args.Component) ||
!_appearance.TryGetData<Color>(uid, SolutionContainerVisuals.Color, out var color, args.Component))
{
return;
}

if (isOpen)
if (isOpen) // Cryo open, no one inside
{
args.Sprite.LayerSetState(CryoPodVisualLayers.Base, "pod-open");
args.Sprite.LayerSetVisible(CryoPodVisualLayers.Cover, false);
args.Sprite.DrawDepth = (int) DrawDepth.Objects;
args.Sprite.DrawDepth = (int)DrawDepth.Objects;
if (_pointLightSystem.TryGetLight(uid, out var pointLight))
{
_pointLightSystem.SetEnabled(uid, false, pointLight);
}
}
else
{
args.Sprite.DrawDepth = (int) DrawDepth.Mobs;
args.Sprite.LayerSetState(CryoPodVisualLayers.Base, isOn ? "pod-on" : "pod-off");
args.Sprite.DrawDepth = (int)DrawDepth.Mobs;
args.Sprite.LayerSetState(CryoPodVisualLayers.Base, "pod-off");
args.Sprite.LayerSetState(CryoPodVisualLayers.Cover, isOn ? "cover-on" : "cover-off");

args.Sprite.LayerSetColor(CryoPodVisualLayers.Cover, color);

args.Sprite.LayerSetVisible(CryoPodVisualLayers.Cover, true);


if (_pointLightSystem.TryGetLight(uid, out var pointLight))
{
if (!_appearance.TryGetData<float>(uid, SolutionContainerVisuals.FillFraction, out var fraction, args.Component) || fraction == 0)
{
_pointLightSystem.SetEnabled(uid, false, pointLight);
}
else
{
_pointLightSystem.SetEnabled(uid, true, pointLight);
_pointLightSystem.SetColor(uid, color, pointLight);
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Content.Client.Chemistry.Visualizers;
using Content.Client.Chemistry.Visualizers;
using Content.Shared.Chemistry.Components;

namespace Content.Client.Storage.Components;
Expand All @@ -20,6 +20,12 @@ public sealed partial class StorageContainerVisualsComponent : Component
[DataField("fillBaseName")]
public string? FillBaseName;

/// <summary>
/// Optional: visuals will be calculated based on item inserted into insertedItemSlotID instead of item itself
/// </summary>
[DataField("insertedItemSlotID")]
public string? InsertedItemSlotID;

[DataField("layer")]
public StorageContainerVisualLayers FillLayer = StorageContainerVisualLayers.Fill;
}
Expand Down
16 changes: 16 additions & 0 deletions Content.Server/Kitchen/EntitySystems/ReagentGrinderSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
using Content.Server.Jittering;
using Content.Shared.Jittering;
using Content.Shared.Power;
using Robust.Shared.Map;
using Content.Shared.Chemistry;

namespace Content.Server.Kitchen.EntitySystems
{
Expand All @@ -40,6 +42,7 @@ internal sealed class ReagentGrinderSystem : EntitySystem
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
[Dependency] private readonly RandomHelperSystem _randomHelper = default!;
[Dependency] private readonly JitteringSystem _jitter = default!;
[Dependency] private readonly IEntityManager _entManager = default!;

public override void Initialize()
{
Expand Down Expand Up @@ -162,6 +165,19 @@ private void OnContainerModified(EntityUid uid, ReagentGrinderComponent reagentG
var outputContainer = _itemSlotsSystem.GetItemOrNull(uid, SharedReagentGrinder.BeakerSlotId);
_appearanceSystem.SetData(uid, ReagentGrinderVisualState.BeakerAttached, outputContainer.HasValue);

if (outputContainer.HasValue)
{
var appearanceComponent = _entManager.GetComponent<AppearanceComponent>(outputContainer.Value);

_appearanceSystem.TryGetData(outputContainer.Value, SolutionContainerVisuals.Color, out var color);
_appearanceSystem.TryGetData(outputContainer.Value, SolutionContainerVisuals.FillFraction, out var fraction);

if (color != null)
_appearanceSystem.SetData(uid, ReagentGrinderVisualState.Color, color);
if (fraction != null)
_appearanceSystem.SetData(uid, ReagentGrinderVisualState.FillFraction, fraction);
}

if (reagentGrinder.AutoMode != GrinderAutoMode.Off && !HasComp<ActiveReagentGrinderComponent>(uid) && this.IsPowered(uid, EntityManager))
{
var program = reagentGrinder.AutoMode == GrinderAutoMode.Grind ? GrinderProgram.Grind : GrinderProgram.Juice;
Expand Down
33 changes: 33 additions & 0 deletions Content.Server/Medical/CryoPodSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public sealed partial class CryoPodSystem : SharedCryoPodSystem
[Dependency] private readonly ReactiveSystem _reactiveSystem = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly NodeContainerSystem _nodeContainer = default!;
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;

public override void Initialize()
{
Expand All @@ -70,6 +71,35 @@ public override void Initialize()
SubscribeLocalEvent<CryoPodComponent, ActivatableUIOpenAttemptEvent>(OnActivateUIAttempt);
SubscribeLocalEvent<CryoPodComponent, AfterActivatableUIOpenEvent>(OnActivateUI);
SubscribeLocalEvent<CryoPodComponent, EntRemovedFromContainerMessage>(OnEjected);
SubscribeLocalEvent<CryoPodComponent, EntInsertedIntoContainerMessage>(OnInsertedItemChanged);
}

private void OnInsertedItemChanged(Entity<CryoPodComponent> entity, ref EntInsertedIntoContainerMessage args)
{
OnInsertedItemChanged(entity.Owner, entity.Comp);
}

private void OnInsertedItemChanged(EntityUid uid, CryoPodComponent cryoPod)
{
var itemSlotsQuery = GetEntityQuery<ItemSlotsComponent>();
if (!itemSlotsQuery.TryGetComponent(uid, out var itemSlotsComponent))
return;

var insertedItem = _itemSlotsSystem.GetItemOrNull(uid, cryoPod.SolutionContainerName, itemSlotsComponent);
if (insertedItem.HasValue)
{
if (_appearanceSystem.TryGetData<Color>(insertedItem.Value, SolutionContainerVisuals.Color, out var color))
_appearanceSystem.SetData(uid, SolutionContainerVisuals.Color, color);

if (_appearanceSystem.TryGetData<float>(insertedItem.Value, SolutionContainerVisuals.FillFraction, out var friction))
_appearanceSystem.SetData(uid, SolutionContainerVisuals.FillFraction, friction);
}
else
{
_appearanceSystem.SetData(uid, SolutionContainerVisuals.Color, Color.Transparent);
_appearanceSystem.SetData(uid, SolutionContainerVisuals.FillFraction, 0.0);
}

}

public override void Update(float frameTime)
Expand Down Expand Up @@ -114,6 +144,7 @@ public override void Update(float frameTime)
var solutionToInject = _solutionContainerSystem.SplitSolution(containerSolution.Value, cryoPod.BeakerTransferAmount);
_bloodstreamSystem.TryAddToChemicals(patient.Value, solutionToInject, bloodstream);
_reactiveSystem.DoEntityReaction(patient.Value, solutionToInject, ReactionMethod.Injection);
OnInsertedItemChanged(uid, cryoPod);
}
}
}
Expand Down Expand Up @@ -290,6 +321,8 @@ private void OnGasAnalyzed(Entity<CryoPodComponent> entity, ref GasAnalyzerScanE

private void OnEjected(Entity<CryoPodComponent> cryoPod, ref EntRemovedFromContainerMessage args)
{
OnInsertedItemChanged(cryoPod.Owner, cryoPod.Comp);

if (TryComp<HealthAnalyzerComponent>(cryoPod.Owner, out var healthAnalyzer))
{
healthAnalyzer.ScannedEntity = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,11 @@ public sealed partial class SolutionContainerVisualsComponent : Component
/// </summary>
[DataField]
public int EquippedMaxFillLevels = 0;

/// <summary>
/// Optional, visuals will be calculated based on item inserted into insertedItemSlotID instead of item itself
/// </summary>
[DataField]
public string? InsertedItemSlotID = null;
}
}
4 changes: 3 additions & 1 deletion Content.Shared/Kitchen/SharedReagentGrinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public ReagentGrinderWorkCompleteMessage()
[Serializable, NetSerializable]
public enum ReagentGrinderVisualState : byte
{
BeakerAttached
BeakerAttached,
Color,
FillFraction
}

[Serializable, NetSerializable]
Expand Down
4 changes: 2 additions & 2 deletions Content.Shared/Medical/Cryogenics/CryoPodComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Robust.Shared.Containers;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
Expand All @@ -16,7 +16,7 @@ public sealed partial class CryoPodComponent : Component
public string PortName { get; set; } = "port";

/// <summary>
/// Specifies the name of the atmospherics port to draw gas from.
/// Specifies the name of the slot that holds beaker with medicine.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("solutionContainerName")]
Expand Down
5 changes: 0 additions & 5 deletions Content.Shared/Medical/Cryogenics/SharedCryoPodSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ protected void UpdateAppearance(EntityUid uid, CryoPodComponent? cryoPod = null,

var cryoPodEnabled = HasComp<ActiveCryoPodComponent>(uid);

if (_light.TryGetLight(uid, out var light))
{
_light.SetEnabled(uid, cryoPodEnabled && cryoPod.BodyContainer.ContainedEntity != null, light);
}

if (!Resolve(uid, ref appearance))
return;

Expand Down
8 changes: 4 additions & 4 deletions Resources/Prototypes/Chemistry/mixing_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
id: DummyGrind
verbText: mixing-verb-default-grind
icon:
sprite: Structures/Machines/juicer.rsi
state: juicer0
sprite: Structures/Machines/grinder.rsi
state: grinder_empty

- type: mixingCategory
id: DummyJuice
verbText: mixing-verb-default-juice
icon:
sprite: Structures/Machines/juicer.rsi
state: juicer0
sprite: Structures/Machines/grinder.rsi
state: grinder_beaker_attached

- type: mixingCategory
id: DummyCondense
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
- type: entity
- type: entity
parent: [BaseStructure, ConstructibleMachine] # Not a BaseMachinePowered since we don't want the anchorable component
id: CryoPod
name: cryo pod
description: A special machine intended to create a safe environment for the use of chemicals that react in cold environments.
components:
- type: Sprite
sprite: Structures/Machines/cryogenics.rsi
sprite: Structures/Machines/Medical/cryopod.rsi
drawdepth: Mobs
noRot: true
offset: 0, 0.5
Expand All @@ -22,6 +22,9 @@
- state: pod-panel
map: [ "enum.WiresVisualLayers.MaintenancePanel" ]
visible: false
- state: beakerSlot1
map: ["enum.SolutionContainerLayers.Fill"]
visible: false
- type: InteractionOutline
- type: Transform
noRot: true
Expand Down Expand Up @@ -101,7 +104,6 @@
requiresComplex: false
- type: ActivatableUIRequiresPower
- type: PointLight
color: "#3a807f"
radius: 2
energy: 10
enabled: false
Expand All @@ -115,3 +117,7 @@
- type: GuideHelp
guides:
- Cryogenics
- type: SolutionContainerVisuals
maxFillLevels: 4
insertedItemSlotID: beakerSlot
fillBaseName: beakerSlot
Loading
Loading