Files
wwdpublic/Content.Shared/_White/ItemSlotPicker/SharedItemSlotPickerSystem.cs
RedFoxIV 6d4215b08d dollar store spookston (#258)
* initial sidestream port

* ru locale

* blyatison

* упс

* jannie qol (#6)

* initial sidestream port

* blyadison

* cs1.4 (#4)

* initial sidestream port
* blyatison

* antitryaska (#7)

* initial sidestream port (still fucked though)

* blyatison

* o fugg (#8) speedmerge

* o fugg

* fugg :-DDD

* attempt numero uno (#9)

* fix desword sound (#10)

* раз уж я тут сижу

* whoops

* shit

---------

Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com>
2025-03-03 14:29:21 +02:00

67 lines
2.6 KiB
C#

using Content.Shared._White.ItemSlotPicker.UI;
using Content.Shared.ActionBlocker;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Hands.Components;
using Content.Shared.Interaction;
using Robust.Shared.Containers;
using Robust.Shared.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Content.Shared._White.ItemSlotPicker;
public abstract class SharedItemSlotPickerSystem : EntitySystem
{
[Dependency] protected readonly SharedUserInterfaceSystem _ui = default!;
[Dependency] protected readonly ItemSlotsSystem _itemSlots = default!;
[Dependency] protected readonly ActionBlockerSystem _blocker = default!;
[Dependency] protected readonly SharedInteractionSystem _interact = default!;
public override void Initialize()
{
SubscribeLocalEvent<ItemSlotPickerComponent, ComponentInit>(CompInit);
SubscribeLocalEvent<ItemSlotPickerComponent, AlternativeInteractionEvent>(AltInteract);
SubscribeLocalEvent<ItemSlotPickerComponent, ItemSlotPickerSlotPickedMessage>(OnMessage);
}
protected virtual void CompInit(EntityUid uid, ItemSlotPickerComponent comp, ComponentInit args)
{
_ui.SetUi(uid, ItemSlotPickerKey.Key, new InterfaceData("ItemSlotPickerBoundUserInterface", 1.5f));
}
protected virtual void AltInteract(EntityUid uid, ItemSlotPickerComponent comp, AlternativeInteractionEvent args)
{
var user = args.User;
if (!TryComp<ItemSlotsComponent>(uid, out var slots) ||
!TryComp<HandsComponent>(user, out var hands) ||
!_blocker.CanComplexInteract(user) ||
!_blocker.CanInteract(user, uid) ||
!_interact.InRangeAndAccessible(user, uid, 1.5f))
return;
args.Handled = true;
if (hands.ActiveHandEntity is EntityUid item)
foreach (var slot in comp.ItemSlots)
if (_itemSlots.TryInsert(uid, slot, item, user, slots, true))
return; // I wish this altverb bullshit wasn't a thing.
_ui.TryToggleUi(uid, ItemSlotPickerKey.Key, user);
}
protected virtual void OnMessage(EntityUid uid, ItemSlotPickerComponent comp, ItemSlotPickerSlotPickedMessage args)
{
if (!comp.ItemSlots.Contains(args.SlotId) ||
!_itemSlots.TryGetSlot(uid, args.SlotId, out var slot))
return;
_itemSlots.TryEjectToHands(uid, slot, args.Actor, true);
_ui.CloseUi(uid, ItemSlotPickerKey.Key, args.Actor);
}
}
[Serializable, NetSerializable]
public enum ItemSlotPickerKey { Key };