Add verbs to Open/Close Openable containers, and add optional seals (#24780)
* Implement closing; add open/close verbs * Add breakable seals * Allow custom verb names; make condiment bottles closeable * Remove pointless VV annotations and false defaults * Split Sealable off into a new component * Should have a Closed event too * Oh hey, there are icons I could use * Ternary operator * Add support for seal visualizers * Moved Sealable to Shared, added networking * Replaced bottle_close1.ogg
This commit is contained in:
@@ -14,20 +14,20 @@ public sealed partial class OpenableComponent : Component
|
||||
/// Whether this drink or food is opened or not.
|
||||
/// Drinks can only be drunk or poured from/into when open, and food can only be eaten when open.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField]
|
||||
public bool Opened;
|
||||
|
||||
/// <summary>
|
||||
/// If this is false you cant press Z to open it.
|
||||
/// Requires an OpenBehavior damage threshold or other logic to open.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField]
|
||||
public bool OpenableByHand = true;
|
||||
|
||||
/// <summary>
|
||||
/// Text shown when examining and its open.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField]
|
||||
public LocId ExamineText = "drink-component-on-examine-is-opened";
|
||||
|
||||
/// <summary>
|
||||
@@ -35,12 +35,38 @@ public sealed partial class OpenableComponent : Component
|
||||
/// Defaults to the popup drink uses since its "correct".
|
||||
/// It's still generic enough that you should change it if you make openable non-drinks, i.e. unwrap it first, peel it first.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField]
|
||||
public LocId ClosedPopup = "drink-component-try-use-drink-not-open";
|
||||
|
||||
/// <summary>
|
||||
/// Text to show in the verb menu for the "Open" action.
|
||||
/// You may want to change this for non-drinks, i.e. "Peel", "Unwrap"
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public LocId OpenVerbText = "openable-component-verb-open";
|
||||
|
||||
/// <summary>
|
||||
/// Text to show in the verb menu for the "Close" action.
|
||||
/// You may want to change this for non-drinks, i.e. "Wrap"
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public LocId CloseVerbText = "openable-component-verb-close";
|
||||
|
||||
/// <summary>
|
||||
/// Sound played when opening.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public SoundSpecifier Sound = new SoundCollectionSpecifier("canOpenSounds");
|
||||
|
||||
/// <summary>
|
||||
/// Can this item be closed again after opening?
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public bool Closeable;
|
||||
|
||||
/// <summary>
|
||||
/// Sound played when closing.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public SoundSpecifier? CloseSound;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Fluids.EntitySystems;
|
||||
using Content.Shared.Nutrition.EntitySystems;
|
||||
using Content.Server.Nutrition.Components;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Nutrition.Components;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Shared.Weapons.Melee.Events;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Nutrition.EntitySystems;
|
||||
|
||||
/// <summary>
|
||||
/// Provides API for openable food and drinks, handles opening on use and preventing transfer when closed.
|
||||
/// </summary>
|
||||
public sealed class OpenableSystem : EntitySystem
|
||||
public sealed class OpenableSystem : SharedOpenableSystem
|
||||
{
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
@@ -32,6 +33,7 @@ public sealed class OpenableSystem : EntitySystem
|
||||
SubscribeLocalEvent<OpenableComponent, SolutionTransferAttemptEvent>(OnTransferAttempt);
|
||||
SubscribeLocalEvent<OpenableComponent, MeleeHitEvent>(HandleIfClosed);
|
||||
SubscribeLocalEvent<OpenableComponent, AfterInteractEvent>(HandleIfClosed);
|
||||
SubscribeLocalEvent<OpenableComponent, GetVerbsEvent<Verb>>(AddOpenCloseVerbs);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, OpenableComponent comp, ComponentInit args)
|
||||
@@ -71,6 +73,36 @@ public sealed class OpenableSystem : EntitySystem
|
||||
args.Handled = !comp.Opened;
|
||||
}
|
||||
|
||||
private void AddOpenCloseVerbs(EntityUid uid, OpenableComponent comp, GetVerbsEvent<Verb> args)
|
||||
{
|
||||
if (args.Hands == null || !args.CanAccess || !args.CanInteract)
|
||||
return;
|
||||
|
||||
Verb verb;
|
||||
if (comp.Opened)
|
||||
{
|
||||
if (!comp.Closeable)
|
||||
return;
|
||||
|
||||
verb = new()
|
||||
{
|
||||
Text = Loc.GetString(comp.CloseVerbText),
|
||||
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/close.svg.192dpi.png")),
|
||||
Act = () => TryClose(args.Target, comp)
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
verb = new()
|
||||
{
|
||||
Text = Loc.GetString(comp.OpenVerbText),
|
||||
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/open.svg.192dpi.png")),
|
||||
Act = () => TryOpen(args.Target, comp)
|
||||
};
|
||||
}
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the entity either does not have OpenableComponent or it is opened.
|
||||
/// Drinks that don't have OpenableComponent are automatically open, so it returns true.
|
||||
@@ -123,6 +155,17 @@ public sealed class OpenableSystem : EntitySystem
|
||||
|
||||
comp.Opened = opened;
|
||||
|
||||
if (opened)
|
||||
{
|
||||
var ev = new OpenableOpenedEvent();
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
}
|
||||
else
|
||||
{
|
||||
var ev = new OpenableClosedEvent();
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
}
|
||||
|
||||
UpdateAppearance(uid, comp);
|
||||
}
|
||||
|
||||
@@ -139,4 +182,19 @@ public sealed class OpenableSystem : EntitySystem
|
||||
_audio.PlayPvs(comp.Sound, uid);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If opened, closes it and plays the close sound, if one is defined.
|
||||
/// </summary>
|
||||
/// <returns>Whether it got closed</returns>
|
||||
public bool TryClose(EntityUid uid, OpenableComponent? comp = null)
|
||||
{
|
||||
if (!Resolve(uid, ref comp, false) || !comp.Opened || !comp.Closeable)
|
||||
return false;
|
||||
|
||||
SetOpen(uid, false, comp);
|
||||
if (comp.CloseSound != null)
|
||||
_audio.PlayPvs(comp.CloseSound, uid);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user