Make grinder use item slots (& misc eject-button changes) (#7197)

This commit is contained in:
Leon Friedrich
2022-03-28 17:03:03 +13:00
committed by GitHub
parent 9cccc6da99
commit 80699543d9
31 changed files with 163 additions and 297 deletions

View File

@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using Content.Shared.Containers.ItemSlots;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Shared.Access.Components
{
@@ -12,29 +8,15 @@ namespace Content.Shared.Access.Components
public const int MaxFullNameLength = 256;
public const int MaxJobTitleLength = 256;
public static string PrivilegedIdCardSlotId = "IdCardConsole-privilegedId";
public static string TargetIdCardSlotId = "IdCardConsole-targetId";
[DataField("privilegedIdSlot")]
public ItemSlot PrivilegedIdSlot = new();
[DataField("targetIdSlot")]
public ItemSlot TargetIdSlot = new();
public enum UiButton
{
PrivilegedId,
TargetId,
}
[Serializable, NetSerializable]
public sealed class IdButtonPressedMessage : BoundUserInterfaceMessage
{
public readonly UiButton Button;
public IdButtonPressedMessage(UiButton button)
{
Button = button;
}
}
[Serializable, NetSerializable]
public sealed class WriteToTargetIdMessage : BoundUserInterfaceMessage
{

View File

@@ -1,8 +1,6 @@
using Content.Shared.Access.Components;
using Content.Shared.Containers.ItemSlots;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Shared.Access.Systems
{
@@ -21,8 +19,8 @@ namespace Content.Shared.Access.Systems
private void OnComponentInit(EntityUid uid, SharedIdCardConsoleComponent component, ComponentInit args)
{
_itemSlotsSystem.AddItemSlot(uid, $"{component.Name}-privilegedId", component.PrivilegedIdSlot);
_itemSlotsSystem.AddItemSlot(uid, $"{component.Name}-targetId", component.TargetIdSlot);
_itemSlotsSystem.AddItemSlot(uid, SharedIdCardConsoleComponent.PrivilegedIdCardSlotId, component.PrivilegedIdSlot);
_itemSlotsSystem.AddItemSlot(uid, SharedIdCardConsoleComponent.TargetIdCardSlotId, component.TargetIdSlot);
}
private void OnComponentRemove(EntityUid uid, SharedIdCardConsoleComponent component, ComponentRemove args)

View File

@@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using Content.Shared.Cloning;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.FixedPoint;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Shared.Chemistry.Components
{
@@ -16,6 +12,8 @@ namespace Content.Shared.Chemistry.Components
[Virtual]
public class SharedChemMasterComponent : Component
{
public static string BeakerSlotId = "ChemMaster-beaker";
[DataField("beakerSlot")]
public ItemSlot BeakerSlot = new();
public const string SolutionName = "buffer";
@@ -124,7 +122,6 @@ namespace Content.Shared.Chemistry.Components
/// </summary>
public enum UiAction
{
Eject,
Transfer,
Discard,
ChemButton,

View File

@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.FixedPoint;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Shared.Chemistry.Dispenser
{
@@ -18,6 +13,8 @@ namespace Content.Shared.Chemistry.Dispenser
[Virtual]
public class SharedReagentDispenserComponent : Component
{
public const string BeakerSlotId = "ReagentDispenser-beaker";
[DataField("beakerSlot")]
public ItemSlot BeakerSlot = new();
@@ -87,7 +84,6 @@ namespace Content.Shared.Chemistry.Dispenser
/// </summary>
public enum UiButton
{
Eject,
Clear,
SetDispenseAmount1,
SetDispenseAmount5,

View File

@@ -21,7 +21,7 @@ namespace Content.Shared.Chemistry.EntitySystems
private void OnComponentInit(EntityUid uid, SharedChemMasterComponent component, ComponentInit args)
{
_itemSlotsSystem.AddItemSlot(uid, $"{component.Name}-beaker", component.BeakerSlot);
_itemSlotsSystem.AddItemSlot(uid, SharedChemMasterComponent.BeakerSlotId, component.BeakerSlot);
}
private void OnComponentRemove(EntityUid uid, SharedChemMasterComponent component, ComponentRemove args)

View File

@@ -1,6 +1,4 @@
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Chemistry.Dispenser;
@@ -21,7 +19,7 @@ namespace Content.Shared.Chemistry.EntitySystems
private void OnComponentInit(EntityUid uid, SharedReagentDispenserComponent component, ComponentInit args)
{
_itemSlotsSystem.AddItemSlot(uid, $"{component.Name}-beaker", component.BeakerSlot);
_itemSlotsSystem.AddItemSlot(uid, SharedReagentDispenserComponent.BeakerSlotId, component.BeakerSlot);
}
private void OnComponentRemove(EntityUid uid, SharedReagentDispenserComponent component, ComponentRemove args)

View File

@@ -0,0 +1,32 @@
using Robust.Shared.Serialization;
namespace Content.Shared.Containers.ItemSlots;
/// <summary>
/// Used for various "eject this item" buttons.
/// </summary>
[Serializable, NetSerializable]
public sealed class ItemSlotButtonPressedEvent : BoundUserInterfaceMessage
{
/// <summary>
/// The name of the slot/container from which to insert or eject an item.
/// </summary>
public string SlotId;
/// <summary>
/// Whether to attempt to insert an item into the slot, if there is not already one inside.
/// </summary>
public bool TryInsert;
/// <summary>
/// Whether to attempt to eject the item from the slot, if it has one.
/// </summary>
public bool TryEject;
public ItemSlotButtonPressedEvent(string slotId, bool tryEject = true, bool tryInsert = true)
{
SlotId = slotId;
TryEject = tryEject;
TryInsert = tryInsert;
}
}

View File

@@ -45,6 +45,8 @@ namespace Content.Shared.Containers.ItemSlots
SubscribeLocalEvent<ItemSlotsComponent, ComponentGetState>(GetItemSlotsState);
SubscribeLocalEvent<ItemSlotsComponent, ComponentHandleState>(HandleItemSlotsState);
SubscribeLocalEvent<ItemSlotsComponent, ItemSlotButtonPressedEvent>(HandleButtonPressed);
}
#region ComponentManagement
@@ -291,7 +293,7 @@ namespace Content.Shared.Containers.ItemSlots
return false;
// hands.Drop(item) checks CanDrop action blocker
if (_handsSystem.TryDrop(user, hands.ActiveHand))
if (!_handsSystem.TryDrop(user, hands.ActiveHand))
return false;
Insert(uid, slot, held, user);
@@ -490,6 +492,19 @@ namespace Content.Shared.Containers.ItemSlots
}
#endregion
#region BUIs
private void HandleButtonPressed(EntityUid uid, ItemSlotsComponent component, ItemSlotButtonPressedEvent args)
{
if (!component.Slots.TryGetValue(args.SlotId, out var slot))
return;
if (args.TryEject && slot.HasItem)
TryEjectToHands(uid, slot, args.Session.AttachedEntity);
else if (args.TryInsert && !slot.HasItem && args.Session.AttachedEntity is EntityUid user)
TryInsertFromHand(uid, slot, user);
}
#endregion
/// <summary>
/// Eject items from (some) slots when the entity is destroyed.
/// </summary>

View File

@@ -5,8 +5,11 @@ using Robust.Shared.Serialization;
namespace Content.Shared.Kitchen.Components
{
public abstract class SharedReagentGrinderComponent : Component
{
public static string BeakerSlotId = "ReagentGrinder-reagentContainerContainer";
[Serializable, NetSerializable]
public sealed class ReagentGrinderGrindStartMessage : BoundUserInterfaceMessage
{
@@ -31,14 +34,6 @@ namespace Content.Shared.Kitchen.Components
}
}
[Serializable, NetSerializable]
public sealed class ReagentGrinderEjectBeakerMessage : BoundUserInterfaceMessage
{
public ReagentGrinderEjectBeakerMessage()
{
}
}
[Serializable, NetSerializable]
public sealed class ReagentGrinderEjectChamberContentMessage : BoundUserInterfaceMessage
{

View File

@@ -1,12 +1,10 @@
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Shared.Nuke
{
[Serializable, NetSerializable]
public sealed class NukeEjectMessage : BoundUserInterfaceMessage
public abstract class SharedNukeComponent : Component
{
public const string NukeDiskSlotId = "Nuke";
}
[Serializable, NetSerializable]

View File

@@ -1,16 +1,16 @@
using Content.Shared.Access.Components;
using Content.Shared.Containers.ItemSlots;
using Robust.Shared.GameObjects;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.ViewVariables;
namespace Content.Shared.PDA
{
[RegisterComponent]
public sealed class PDAComponent : Component
{
public const string PDAIdSlotId = "PDA-id";
public const string PDAPenSlotId = "PDA-pen";
[DataField("idSlot")]
public ItemSlot IdSlot = new();

View File

@@ -13,23 +13,6 @@ namespace Content.Shared.PDA
}
}
[Serializable, NetSerializable]
public sealed class PDAEjectIDMessage : BoundUserInterfaceMessage
{
public PDAEjectIDMessage()
{
}
}
[Serializable, NetSerializable]
public sealed class PDAEjectPenMessage : BoundUserInterfaceMessage
{
public PDAEjectPenMessage()
{
}
}
[Serializable, NetSerializable]
public sealed class PDAShowRingtoneMessage : BoundUserInterfaceMessage
{

View File

@@ -26,8 +26,8 @@ namespace Content.Shared.PDA
if (pda.IdCard != null)
pda.IdSlot.StartingItem = pda.IdCard;
ItemSlotsSystem.AddItemSlot(uid, $"{pda.Name}-id", pda.IdSlot);
ItemSlotsSystem.AddItemSlot(uid, $"{pda.Name}-pen", pda.PenSlot);
ItemSlotsSystem.AddItemSlot(uid, PDAComponent.PDAIdSlotId, pda.IdSlot);
ItemSlotsSystem.AddItemSlot(uid, PDAComponent.PDAPenSlotId, pda.PenSlot);
UpdatePDAAppearance(pda);
}