Implement SmartFridge functionality (#3207)

* Implement SmartFridge functionality

* Add dumpable support to the SmartFridge

* Don't use an item slot

* Medical smartfridge real

* less extraneous components

* medical smartfridge default
This commit is contained in:
pathetic meowmeow 2025-03-18 08:52:10 -04:00 committed by GitHub
parent a0500a9f3d
commit 5976b75ed3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 509 additions and 1 deletions

View File

@ -0,0 +1,42 @@
using Robust.Client.UserInterface;
using Robust.Shared.Input;
using Content.Client.UserInterface.Controls;
using Content.Shared._DV.SmartFridge;
namespace Content.Client._DV.SmartFridge;
public sealed class SmartFridgeBoundUserInterface : BoundUserInterface
{
private SmartFridgeMenu? _menu;
public SmartFridgeBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
_menu = this.CreateWindow<SmartFridgeMenu>();
_menu.OnItemSelected += OnItemSelected;
Refresh();
}
public void Refresh()
{
if (_menu is not {} menu || !EntMan.TryGetComponent(Owner, out SmartFridgeComponent? fridge))
return;
menu.Populate((Owner, fridge));
}
private void OnItemSelected(GUIBoundKeyEventArgs args, ListData data)
{
if (args.Function != EngineKeyFunctions.UIClick)
return;
if (data is not SmartFridgeListData entry)
return;
SendPredictedMessage(new SmartFridgeDispenseItemMessage(entry.Entry));
}
}

View File

@ -0,0 +1,16 @@
<BoxContainer xmlns="https://spacestation14.io"
Orientation="Horizontal"
HorizontalExpand="True"
SeparationOverride="4">
<SpriteView
Name="EntityView"
Margin="4 0 0 0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
MinSize="32 32"
/>
<Label Name="NameLabel"
SizeFlagsStretchRatio="3"
HorizontalExpand="True"
ClipText="True"/>
</BoxContainer>

View File

@ -0,0 +1,18 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
namespace Content.Client._DV.SmartFridge;
[GenerateTypedNameReferences]
public sealed partial class SmartFridgeItem : BoxContainer
{
public SmartFridgeItem(EntityUid uid, string text)
{
RobustXamlLoader.Load(this);
EntityView.SetEntity(uid);
NameLabel.Text = text;
}
}

View File

@ -0,0 +1,24 @@
<controls:FancyWindow
xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:co="clr-namespace:Content.Client.UserInterface.Controls"
MinHeight="450"
MinWidth="350"
Title="{Loc 'smart-fridge-component-title'}">
<BoxContainer Name="MainContainer" Orientation="Vertical">
<LineEdit Name="SearchBar" PlaceHolder="{Loc 'smart-fridge-component-search-filter'}" HorizontalExpand="True" Margin ="4 4"/>
<co:SearchListContainer Name="VendingContents" VerticalExpand="True" Margin="4 4"/>
<!-- Footer -->
<BoxContainer Orientation="Vertical">
<PanelContainer StyleClasses="LowDivider" />
<BoxContainer Orientation="Horizontal" Margin="10 2 5 0" VerticalAlignment="Bottom">
<Label Text="{Loc 'vending-machine-flavor-left'}" StyleClasses="WindowFooterText" />
<Label Text="{Loc 'vending-machine-flavor-right'}" StyleClasses="WindowFooterText"
HorizontalAlignment="Right" HorizontalExpand="True" Margin="0 0 5 0" />
<TextureRect StyleClasses="NTLogoDark" Stretch="KeepAspectCentered"
VerticalAlignment="Center" HorizontalAlignment="Right" SetSize="19 19"/>
</BoxContainer>
</BoxContainer>
</BoxContainer>
</controls:FancyWindow>

View File

@ -0,0 +1,75 @@
using System.Numerics;
using Robust.Client.Graphics;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
using Robust.Client.UserInterface;
using Content.Client.UserInterface.Controls;
using Content.Shared._DV.SmartFridge;
namespace Content.Client._DV.SmartFridge;
public record SmartFridgeListData(EntityUid Representative, SmartFridgeEntry Entry, int Amount) : ListData;
[GenerateTypedNameReferences]
public sealed partial class SmartFridgeMenu : FancyWindow
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public event Action<GUIBoundKeyEventArgs, ListData>? OnItemSelected;
private readonly StyleBoxFlat _styleBox = new() { BackgroundColor = new Color(70, 73, 102) };
public SmartFridgeMenu()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
VendingContents.SearchBar = SearchBar;
VendingContents.DataFilterCondition += DataFilterCondition;
VendingContents.GenerateItem += GenerateButton;
VendingContents.ItemKeyBindDown += (args, data) => OnItemSelected?.Invoke(args, data);
}
private bool DataFilterCondition(string filter, ListData data)
{
if (data is not SmartFridgeListData entry)
return false;
if (string.IsNullOrEmpty(filter))
return true;
return entry.Entry.Name.Contains(filter, StringComparison.CurrentCultureIgnoreCase);
}
private void GenerateButton(ListData data, ListContainerButton button)
{
if (data is not SmartFridgeListData entry)
return;
var label = Loc.GetString("smart-fridge-list-item", ("item", entry.Entry.Name), ("amount", entry.Amount));
button.AddChild(new SmartFridgeItem(entry.Representative, label));
button.ToolTip = label;
button.StyleBoxOverride = _styleBox;
}
public void Populate(Entity<SmartFridgeComponent> ent)
{
var listData = new List<ListData>();
foreach (var item in ent.Comp.Entries)
{
if (!ent.Comp.ContainedEntries.TryGetValue(item, out var items) || items.Count == 0)
{
listData.Add(new SmartFridgeListData(EntityUid.Invalid, item, 0));
}
else
{
var representative = _entityManager.GetEntity(items[0]);
listData.Add(new SmartFridgeListData(representative, item, items.Count));
}
}
VendingContents.PopulateList(listData);
}
}

View File

@ -0,0 +1,24 @@
using Content.Shared._DV.SmartFridge;
using Robust.Shared.Analyzers;
namespace Content.Client._DV.SmartFridge;
public sealed class SmartFridgeUISystem : EntitySystem
{
[Dependency] private readonly SharedUserInterfaceSystem _uiSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SmartFridgeComponent, AfterAutoHandleStateEvent>(OnSmartFridgeAfterState);
}
private void OnSmartFridgeAfterState(Entity<SmartFridgeComponent> ent, ref AfterAutoHandleStateEvent args)
{
if (!_uiSystem.TryGetOpenUi<SmartFridgeBoundUserInterface>(ent.Owner, SmartFridgeUiKey.Key, out var bui))
return;
bui.Refresh();
}
}

View File

@ -1,4 +1,5 @@
using System.Linq;
using Content.Shared._DV.SmartFridge; // DeltaV - ough why do you not use events for this
using Content.Shared.Disposal;
using Content.Shared.DoAfter;
using Content.Shared.Interaction;
@ -23,6 +24,7 @@ public sealed class DumpableSystem : EntitySystem
[Dependency] private readonly SharedDisposalUnitSystem _disposalUnitSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
[Dependency] private readonly SharedContainerSystem _container = default!; // DeltaV - ough why do you not use events for this
private EntityQuery<ItemComponent> _itemQuery;
@ -82,7 +84,7 @@ public sealed class DumpableSystem : EntitySystem
if (!TryComp<StorageComponent>(uid, out var storage) || !storage.Container.ContainedEntities.Any())
return;
if (_disposalUnitSystem.HasDisposals(args.Target))
if (_disposalUnitSystem.HasDisposals(args.Target) || HasComp<SmartFridgeComponent>(args.Target)) // DeltaV - ough why do you not use events for this
{
UtilityVerb verb = new()
{
@ -181,6 +183,20 @@ public sealed class DumpableSystem : EntitySystem
_transformSystem.SetWorldPositionRotation(entity, targetPos + _random.NextVector2Box() / 4, targetRot);
}
}
// Begin DeltaV - ough why do you not use events for this
else if (TryComp<SmartFridgeComponent>(target, out var fridge))
{
dumped = true;
if (_container.TryGetContainer(target!.Value, fridge.Container, out var container))
{
foreach (var entity in dumpQueue)
{
_container.Insert(entity, container);
}
}
}
// End DeltaV - ough why do you not use events for this
else
{
var targetPos = _transformSystem.GetWorldPosition(uid);

View File

@ -0,0 +1,73 @@
using Content.Shared.Whitelist;
using Robust.Shared.Analyzers;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
namespace Content.Shared._DV.SmartFridge;
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
public sealed partial class SmartFridgeComponent : Component
{
[DataField]
public string Container = "smart_fridge_inventory";
[DataField]
public EntityWhitelist? Whitelist;
[DataField]
public EntityWhitelist? Blacklist;
[DataField]
public SoundSpecifier? InsertSound = new SoundPathSpecifier("/Audio/Weapons/Guns/MagIn/revolver_magin.ogg");
[DataField, AutoNetworkedField]
public List<SmartFridgeEntry> Entries = new();
[DataField, AutoNetworkedField]
public Dictionary<SmartFridgeEntry, List<NetEntity>> ContainedEntries = new();
/// <summary>
/// Sound that plays when ejecting an item
/// </summary>
[DataField]
public SoundSpecifier SoundVend = new SoundPathSpecifier("/Audio/Machines/machine_vend.ogg")
{
Params = new AudioParams
{
Volume = -4f,
Variation = 0.15f
}
};
/// <summary>
/// Sound that plays when an item can't be ejected
/// </summary>
[DataField]
public SoundSpecifier SoundDeny = new SoundPathSpecifier("/Audio/Machines/custom_deny.ogg");
}
[Serializable, NetSerializable, DataRecord]
public record struct SmartFridgeEntry
{
public string Name;
public SmartFridgeEntry(string name)
{
Name = name;
}
}
[Serializable, NetSerializable]
public enum SmartFridgeUiKey
{
Key,
}
[Serializable, NetSerializable]
public sealed class SmartFridgeDispenseItemMessage(SmartFridgeEntry entry) : BoundUserInterfaceMessage
{
public SmartFridgeEntry Entry = entry;
}

View File

@ -0,0 +1,111 @@
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Whitelist;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
namespace Content.Shared._DV.SmartFridge;
public sealed class SmartFridgeSystem : EntitySystem
{
[Dependency] private readonly AccessReaderSystem _accessReader = default!;
[Dependency] private readonly EntityWhitelistSystem _whitelist = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SmartFridgeComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<SmartFridgeComponent, EntRemovedFromContainerMessage>(OnItemRemoved);
Subs.BuiEvents<SmartFridgeComponent>(SmartFridgeUiKey.Key,
sub =>
{
sub.Event<SmartFridgeDispenseItemMessage>(OnDispenseItem);
});
}
private void OnInteractUsing(Entity<SmartFridgeComponent> ent, ref InteractUsingEvent args)
{
if (!_container.TryGetContainer(ent, ent.Comp.Container, out var container))
return;
if (_whitelist.IsWhitelistFail(ent.Comp.Whitelist, args.Used) || _whitelist.IsBlacklistPass(ent.Comp.Blacklist, args.Used))
return;
if (!Allowed(ent, args.User))
return;
if (!_hands.TryDrop(args.User, args.Used))
return;
_audio.PlayPredicted(ent.Comp.InsertSound, ent, args.User);
_container.Insert(args.Used, container);
var key = new SmartFridgeEntry(Identity.Name(args.Used, EntityManager));
if (!ent.Comp.Entries.Contains(key))
ent.Comp.Entries.Add(key);
ent.Comp.ContainedEntries.TryAdd(key, new());
var entries = ent.Comp.ContainedEntries[key];
if (!entries.Contains(GetNetEntity(args.Used)))
entries.Add(GetNetEntity(args.Used));
Dirty(ent);
}
private void OnItemRemoved(Entity<SmartFridgeComponent> ent, ref EntRemovedFromContainerMessage args)
{
var key = new SmartFridgeEntry(Identity.Name(args.Entity, EntityManager));
if (ent.Comp.ContainedEntries.TryGetValue(key, out var contained))
{
contained.Remove(GetNetEntity(args.Entity));
}
Dirty(ent);
}
private bool Allowed(Entity<SmartFridgeComponent> machine, EntityUid user)
{
if (_accessReader.IsAllowed(user, machine))
return true;
_popup.PopupPredicted(Loc.GetString("smart-fridge-component-try-eject-access-denied"), machine, user);
_audio.PlayPredicted(machine.Comp.SoundDeny, machine, user);
return false;
}
private void OnDispenseItem(Entity<SmartFridgeComponent> ent, ref SmartFridgeDispenseItemMessage args)
{
if (!Allowed(ent, args.Actor))
return;
if (!ent.Comp.ContainedEntries.TryGetValue(args.Entry, out var contained))
{
_audio.PlayPredicted(ent.Comp.SoundDeny, ent, args.Actor);
_popup.PopupPredicted(Loc.GetString("smart-fridge-component-try-eject-unknown-entry"), ent, args.Actor);
return;
}
foreach (var item in contained)
{
if (!_container.TryRemoveFromContainer(GetEntity(item)))
continue;
_audio.PlayPredicted(ent.Comp.SoundVend, ent, args.Actor);
contained.Remove(item);
Dirty(ent);
return;
}
_audio.PlayPredicted(ent.Comp.SoundDeny, ent, args.Actor);
_popup.PopupPredicted(Loc.GetString("smart-fridge-component-try-eject-out-of-stock"), ent, args.Actor);
}
}

View File

@ -0,0 +1,6 @@
smart-fridge-component-try-eject-unknown-entry = Invalid selection!
smart-fridge-component-try-eject-out-of-stock = Out of stock!
smart-fridge-component-try-eject-access-denied = Access denied!
smart-fridge-component-search-filter = Search...
smart-fridge-component-title = SmartFridge
smart-fridge-list-item = {$item} [{$amount}]

View File

@ -146,3 +146,6 @@ BarSignWhiskeyEcho: BarSignWhiskeyEchoes
# 2025-03-10
MetempsychoticMachine: null
MetempsychoticMachineCircuitboard: null
# 2025-03-12
SmartFridge: DVSmartFridgeMedical

View File

@ -3,6 +3,7 @@
id: SmartFridge
name: SmartFridge
description: A refrigerated storage unit for keeping items cold and fresh.
categories: [ HideSpawnMenu ] # DeltaV - apparently we can't migrate abstract/disabled prototypes
components:
- type: StationAiWhitelist
- type: Advertise

View File

@ -0,0 +1,99 @@
- type: entity
parent: BaseMachinePowered
id: DVSmartFridge
name: SmartFridge
description: A refrigerated storage unit for keeping items cold and fresh.
components:
- type: StationAiWhitelist
- type: Advertise
pack: SmartFridgeAds
- type: Speech
- type: Sprite
sprite: Structures/Machines/smartfridge.rsi
snapCardinals: true
layers:
- state: smartfridge
map: ["enum.StorageVisualLayers.Base"]
- state: smartfridge_door
map: ["enum.StorageVisualLayers.Door"]
shader: unshaded
- type: PointLight
enabled: false
radius: 1.5
energy: 1.6
color: "#9dc5c9"
- type: ContainerContainer
containers:
smart_fridge_inventory: !type:Container
smart_fridge_insertion: !type:ContainerSlot
- type: LitOnPowered
- type: ApcPowerReceiver
powerLoad: 200
- type: SmartFridge
whitelist:
components:
- FitsInDispenser
- Pill
- Produce
- Seed
tags:
- PillCanister
- Bottle
- Syringe
- ChemDispensable
- type: ActivatableUI
key: enum.SmartFridgeUiKey.Key
- type: ActivatableUIRequiresPower
- type: UserInterface
interfaces:
enum.SmartFridgeUiKey.Key:
type: SmartFridgeBoundUserInterface
- type: Fixtures
fixtures:
fix1:
shape:
!type:PhysShapeAabb
bounds: "-0.45,-0.45,0.45,0.45"
mask:
- MachineMask
layer:
- MachineLayer
density: 200
- type: Anchorable
delay: 2
- type: InteractionOutline
- type: Destructible
thresholds:
- trigger:
!type:DamageTrigger
damage: 100
behaviors:
- !type:DoActsBehavior
acts: ["Breakage"]
- trigger:
!type:DamageTrigger
damage: 200
behaviors:
- !type:SpawnEntitiesBehavior
spawn:
SheetSteel1:
min: 1
max: 1
- !type:DoActsBehavior
acts: [ "Destruction" ]
- !type:PlaySoundBehavior
sound:
collection: MetalBreak
- type: Dumpable
- type: AccessReader
- type: ExplosionResistance
damageCoefficient: 0.6
- type: entity
parent: DVSmartFridge
id: DVSmartFridgeMedical
name: Medical SmartFridge
description: A refrigerated storage unit for keeping lifesaving medications cold and fresh.
components:
- type: AccessReader
access: [["Medical"]]