Add Alt-click insertion to ItemSlots (#15094)
This commit is contained in:
@@ -43,7 +43,7 @@ namespace Content.Shared.Containers.ItemSlots
|
|||||||
SubscribeLocalEvent<ItemSlotsComponent, InteractHandEvent>(OnInteractHand);
|
SubscribeLocalEvent<ItemSlotsComponent, InteractHandEvent>(OnInteractHand);
|
||||||
SubscribeLocalEvent<ItemSlotsComponent, UseInHandEvent>(OnUseInHand);
|
SubscribeLocalEvent<ItemSlotsComponent, UseInHandEvent>(OnUseInHand);
|
||||||
|
|
||||||
SubscribeLocalEvent<ItemSlotsComponent, GetVerbsEvent<AlternativeVerb>>(AddEjectVerbs);
|
SubscribeLocalEvent<ItemSlotsComponent, GetVerbsEvent<AlternativeVerb>>(AddAlternativeVerbs);
|
||||||
SubscribeLocalEvent<ItemSlotsComponent, GetVerbsEvent<InteractionVerb>>(AddInteractionVerbsVerbs);
|
SubscribeLocalEvent<ItemSlotsComponent, GetVerbsEvent<InteractionVerb>>(AddInteractionVerbsVerbs);
|
||||||
|
|
||||||
SubscribeLocalEvent<ItemSlotsComponent, BreakageEventArgs>(OnBreak);
|
SubscribeLocalEvent<ItemSlotsComponent, BreakageEventArgs>(OnBreak);
|
||||||
@@ -405,13 +405,62 @@ namespace Content.Shared.Containers.ItemSlots
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Verbs
|
#region Verbs
|
||||||
private void AddEjectVerbs(EntityUid uid, ItemSlotsComponent itemSlots, GetVerbsEvent<AlternativeVerb> args)
|
private void AddAlternativeVerbs(EntityUid uid, ItemSlotsComponent itemSlots, GetVerbsEvent<AlternativeVerb> args)
|
||||||
{
|
{
|
||||||
if (args.Hands == null || !args.CanAccess ||!args.CanInteract)
|
if (args.Hands == null || !args.CanAccess ||!args.CanInteract)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add the insert-item verbs
|
||||||
|
if (args.Using != null && _actionBlockerSystem.CanDrop(args.User))
|
||||||
|
{
|
||||||
|
var canInsertAny = false;
|
||||||
|
foreach (var slot in itemSlots.Slots.Values)
|
||||||
|
{
|
||||||
|
// Disable slot insert if InsertOnInteract is true
|
||||||
|
if (slot.InsertOnInteract || !CanInsert(uid, args.Using.Value, slot))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var verbSubject = slot.Name != string.Empty
|
||||||
|
? Loc.GetString(slot.Name)
|
||||||
|
: Name(args.Using.Value) ?? string.Empty;
|
||||||
|
|
||||||
|
AlternativeVerb verb = new();
|
||||||
|
verb.IconEntity = args.Using;
|
||||||
|
verb.Act = () => Insert(uid, slot, args.Using.Value, args.User, excludeUserAudio: true);
|
||||||
|
|
||||||
|
if (slot.InsertVerbText != null)
|
||||||
|
{
|
||||||
|
verb.Text = Loc.GetString(slot.InsertVerbText);
|
||||||
|
verb.Icon = new SpriteSpecifier.Texture(
|
||||||
|
new ResourcePath("/Textures/Interface/VerbIcons/insert.svg.192dpi.png"));
|
||||||
|
}
|
||||||
|
else if (slot.EjectOnInteract)
|
||||||
|
{
|
||||||
|
// Inserting/ejecting is a primary interaction for this entity. Instead of using the insert
|
||||||
|
// category, we will use a single "Place <item>" verb.
|
||||||
|
verb.Text = Loc.GetString("place-item-verb-text", ("subject", verbSubject));
|
||||||
|
verb.Icon = new SpriteSpecifier.Texture(
|
||||||
|
new ResourcePath("/Textures/Interface/VerbIcons/drop.svg.192dpi.png"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
verb.Category = VerbCategory.Insert;
|
||||||
|
verb.Text = verbSubject;
|
||||||
|
}
|
||||||
|
|
||||||
|
verb.Priority = slot.Priority;
|
||||||
|
args.Verbs.Add(verb);
|
||||||
|
canInsertAny = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If can insert then insert. Don't run eject verbs.
|
||||||
|
if (canInsertAny)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the eject-item verbs
|
||||||
foreach (var slot in itemSlots.Slots.Values)
|
foreach (var slot in itemSlots.Slots.Values)
|
||||||
{
|
{
|
||||||
if (slot.EjectOnInteract)
|
if (slot.EjectOnInteract)
|
||||||
|
|||||||
@@ -165,11 +165,13 @@
|
|||||||
tags:
|
tags:
|
||||||
- Mop
|
- Mop
|
||||||
insertOnInteract: false # or it conflicts with bucket logic
|
insertOnInteract: false # or it conflicts with bucket logic
|
||||||
|
priority: 4 # Higher than trash bag slot
|
||||||
trashbag_slot:
|
trashbag_slot:
|
||||||
name: Bag
|
name: Bag
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- TrashBag
|
- TrashBag
|
||||||
|
priority: 3 # Higher than drinking priority
|
||||||
- type: Fixtures
|
- type: Fixtures
|
||||||
fixtures:
|
fixtures:
|
||||||
- shape:
|
- shape:
|
||||||
|
|||||||
Reference in New Issue
Block a user