private void OnContainerModified(EntityUid uid, ItemCabinetComponent cabinet, ContainerModifiedMessage args) { if (args.Container.ID == cabinet.CabinetSlot.ID) { UpdateAppearance(uid, cabinet); } }
/// <summary> /// If the cabinet is opened and has an entity, try and take it. Otherwise toggle the cabinet open/closed; /// </summary> private void OnInteractHand(EntityUid uid, ItemCabinetComponent comp, InteractHandEvent args) { if (args.Handled) { return; } if (!EntityManager.TryGetComponent(uid, out SharedItemSlotsComponent itemSlots)) { return; } if (!itemSlots.Slots.TryGetValue(comp.CabinetSlot, out var slot)) { return; } if (comp.Opened && slot.HasEntity) { _itemSlotsSystem.TryEjectContent(uid, comp.CabinetSlot, args.User); } else { ToggleItemCabinet(uid, comp); } args.Handled = true; }
private static void UpdateVisuals(ItemCabinetComponent comp) { if (comp.Owner.TryGetComponent(out SharedAppearanceComponent? appearance)) { appearance.SetData(ItemCabinetVisuals.IsOpen, comp.Opened); appearance.SetData(ItemCabinetVisuals.ContainsItem, comp.ItemContainer.ContainedEntity != null); } }
private static void ClickLatchSound(ItemCabinetComponent comp) { if (comp.DoorSound == null) { return; } SoundSystem.Play(Filter.Pvs(comp.Owner), comp.DoorSound, comp.Owner, AudioHelpers.WithVariation(0.15f)); }
private void OnActivateInWorld(EntityUid uid, ItemCabinetComponent comp, ActivateInWorldEvent args) { if (args.Handled) { return; } args.Handled = true; ToggleItemCabinet(uid, comp); }
/// <summary> /// Tries to insert an entity into the ItemCabinet's slot from the user's hands. /// </summary> private static void OnTryInsertItemCabinet(EntityUid uid, ItemCabinetComponent comp, TryInsertItemCabinetEvent args) { if (comp.ItemContainer.ContainedEntity != null || args.Cancelled || (comp.Whitelist != null && !comp.Whitelist.IsValid(args.Item))) { return; } if (!args.User.TryGetComponent <HandsComponent>(out var hands) || !hands.Drop(args.Item, comp.ItemContainer)) { return; } UpdateVisuals(comp); }
private void OnInteractUsing(EntityUid uid, ItemCabinetComponent comp, InteractUsingEvent args) { args.Handled = true; if (!comp.Opened) { RaiseLocalEvent(uid, new ToggleItemCabinetEvent(), false); } else { RaiseLocalEvent(uid, new TryInsertItemCabinetEvent(args.User, args.Used), false); } args.Handled = true; }
private void OnMapInitialize(EntityUid uid, ItemCabinetComponent comp, MapInitEvent args) { var owner = EntityManager.GetEntity(uid); comp.ItemContainer = owner.EnsureContainer <ContainerSlot>("item_cabinet", out _); if (comp.SpawnPrototype != null) { comp.ItemContainer.Insert(EntityManager.SpawnEntity(comp.SpawnPrototype, owner.Transform.Coordinates)); } UpdateVisuals(comp); }
private void OnInteractHand(EntityUid uid, ItemCabinetComponent comp, InteractHandEvent args) { args.Handled = true; if (comp.Opened) { if (comp.ItemContainer.ContainedEntity == null) { RaiseLocalEvent(uid, new ToggleItemCabinetEvent(), false); return; } RaiseLocalEvent(uid, new TryEjectItemCabinetEvent(args.User), false); } else { RaiseLocalEvent(uid, new ToggleItemCabinetEvent(), false); } }
/// <summary> /// Try insert an item if the cabinet is opened. Otherwise, just try open it. /// </summary> private void OnInteractUsing(EntityUid uid, ItemCabinetComponent comp, InteractUsingEvent args) { if (args.Handled) { return; } if (!comp.Opened) { ToggleItemCabinet(uid, comp); } else { _itemSlotsSystem.TryInsertContent(uid, args.Used, args.User); } args.Handled = true; }
private void AddToggleOpenVerb(EntityUid uid, ItemCabinetComponent cabinet, GetActivationVerbsEvent args) { if (args.Hands == null || !args.CanAccess || !args.CanInteract) { return; } // Toggle open verb Verb toggleVerb = new(); toggleVerb.Act = () => ToggleItemCabinet(uid, cabinet); if (cabinet.Opened) { toggleVerb.Text = Loc.GetString("verb-common-close"); toggleVerb.IconTexture = "/Textures/Interface/VerbIcons/close.svg.192dpi.png"; } else { toggleVerb.Text = Loc.GetString("verb-common-open"); toggleVerb.IconTexture = "/Textures/Interface/VerbIcons/open.svg.192dpi.png"; } args.Verbs.Add(toggleVerb); }
/// <summary> /// Tries to eject the ItemCabinet's item, either into the user's hands or onto the floor. /// </summary> private static void OnTryEjectItemCabinet(EntityUid uid, ItemCabinetComponent comp, TryEjectItemCabinetEvent args) { if (comp.ItemContainer.ContainedEntity == null || args.Cancelled) { return; } if (args.User.TryGetComponent(out HandsComponent? hands)) { if (comp.ItemContainer.ContainedEntity.TryGetComponent <ItemComponent>(out var item)) { comp.Owner.PopupMessage(args.User, Loc.GetString("comp-item-cabinet-successfully-taken", ("item", comp.ItemContainer.ContainedEntity), ("cabinet", comp.Owner))); hands.PutInHandOrDrop(item); } } else if (comp.ItemContainer.Remove(comp.ItemContainer.ContainedEntity)) { comp.ItemContainer.ContainedEntity.Transform.Coordinates = args.User.Transform.Coordinates; } UpdateVisuals(comp); }
private void OnComponentStartup(EntityUid uid, ItemCabinetComponent cabinet, ComponentStartup args) { UpdateAppearance(uid, cabinet); _itemSlotsSystem.SetLock(uid, cabinet.CabinetSlot, !cabinet.Opened); }
private void OnComponentRemove(EntityUid uid, ItemCabinetComponent cabinet, ComponentRemove args) { _itemSlotsSystem.RemoveItemSlot(uid, cabinet.CabinetSlot); }
private void OnComponentInit(EntityUid uid, ItemCabinetComponent cabinet, ComponentInit args) { _itemSlotsSystem.AddItemSlot(uid, cabinet.Name, cabinet.CabinetSlot); }
/// <summary> /// Toggles the ItemCabinet's state. /// </summary> private void OnToggleItemCabinet(EntityUid uid, ItemCabinetComponent comp, ToggleItemCabinetEvent args) { comp.Opened = !comp.Opened; ClickLatchSound(comp); UpdateVisuals(comp); }
private void OnActivateInWorld(EntityUid uid, ItemCabinetComponent comp, ActivateInWorldEvent args) { args.Handled = true; RaiseLocalEvent(uid, new ToggleItemCabinetEvent(), false); }
private void InitializeAppearance(EntityUid uid, ItemCabinetComponent component, ComponentStartup args) { UpdateAppearance(uid, component); }
private static void ClickLatchSound(ItemCabinetComponent comp) { SoundSystem.Play(Filter.Pvs(comp.Owner), comp.DoorSound.GetSound(), comp.Owner, AudioHelpers.WithVariation(0.15f)); }
private void OnItemSlotChanged(EntityUid uid, ItemCabinetComponent cabinet, ItemSlotChangedEvent args) { UpdateAppearance(uid, cabinet, args.SlotsComponent); }