Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions Content.Shared/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,12 @@ public static readonly CVarDef<bool>
public static readonly CVarDef<bool> GamePressToSprint =
CVarDef.Create("game.press_to_sprint", true, CVar.REPLICATED);

/// <summary>
/// Whether item slots, such as power cell slots or AME fuel cell slots, should support quick swap if it is not otherwise specified in their YAML prototype.
/// </summary>
public static readonly CVarDef<bool> AllowSlotQuickSwap =
CVarDef.Create("game.slot_quick_swap", false, CVar.REPLICATED);

#if EXCEPTION_TOLERANCE
/// <summary>
/// Amount of times round start must fail before the server is shut down.
Expand Down
3 changes: 2 additions & 1 deletion Content.Shared/Containers/ItemSlot/ItemSlotsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,15 @@ public ItemSlot(ItemSlot other)

/// <summary>
/// If the user interacts with an entity with an already-filled item slot, should they attempt to swap out the item?
/// If set to null, will be deduced based on the relevant config variable.
/// </summary>
/// <remarks>
/// Useful for things like chem dispensers, but undesirable for things like the ID card console, where you
/// want to insert more than one item that matches the same whitelist.
/// </remarks>
[DataField]
[Access(typeof(ItemSlotsSystem), Other = AccessPermissions.ReadWriteExecute)]
public bool Swap = true;
public bool? Swap = null;

public string? ID => ContainerSlot?.ID;

Expand Down
9 changes: 8 additions & 1 deletion Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using Content.Shared.ActionBlocker;
using Content.Shared.Administration.Logs;
using Content.Shared.CCVar;
using Content.Shared.Database;
using Content.Shared.Destructible;
using Content.Shared.Hands.Components;
Expand All @@ -10,6 +11,7 @@
using Content.Shared.Popups;
using Content.Shared.Verbs;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Configuration;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Utility;
Expand All @@ -27,11 +29,14 @@ public sealed class ItemSlotsSystem : EntitySystem
{
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
[Dependency] private readonly IConfigurationManager _config = default!;
[Dependency] private readonly SharedContainerSystem _containers = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;

private bool _defaultQuickSwap;

public override void Initialize()
{
base.Initialize();
Expand All @@ -53,6 +58,8 @@ public override void Initialize()
SubscribeLocalEvent<ItemSlotsComponent, ComponentHandleState>(HandleItemSlotsState);

SubscribeLocalEvent<ItemSlotsComponent, ItemSlotButtonPressedEvent>(HandleButtonPressed);

_config.OnValueChanged(CCVars.AllowSlotQuickSwap, b => _defaultQuickSwap = b, true);
}

#region ComponentManagement
Expand Down Expand Up @@ -202,7 +209,7 @@ private void OnInteractUsing(EntityUid uid, ItemSlotsComponent itemSlots, Intera
if (!slot.InsertOnInteract)
continue;

if (!CanInsert(uid, args.Used, args.User, slot, swap: slot.Swap, popup: args.User))
if (!CanInsert(uid, args.Used, args.User, slot, swap: slot.Swap ?? _defaultQuickSwap, popup: args.User))
continue;

// Drop the held item onto the floor. Return if the user cannot drop.
Expand Down