PopupOnTrigger (#39913)
* commit * comment * changes * Update Content.Shared/Trigger/Systems/PopupOnTriggerSystem.cs --------- Co-authored-by: iaada <iaada@users.noreply.github.com> Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
This commit is contained in:
62
Content.Shared/Trigger/Systems/PopupOnTriggerSystem.cs
Normal file
62
Content.Shared/Trigger/Systems/PopupOnTriggerSystem.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Trigger.Components.Effects;
|
||||
|
||||
namespace Content.Shared.Trigger.Systems;
|
||||
|
||||
/// <summary>
|
||||
/// This handles <see cref="PopupOnTriggerComponent"/>
|
||||
/// </summary>
|
||||
public sealed class PopupOnTriggerSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<PopupOnTriggerComponent, TriggerEvent>(OnTrigger);
|
||||
}
|
||||
|
||||
private void OnTrigger(Entity<PopupOnTriggerComponent> ent, ref TriggerEvent args)
|
||||
{
|
||||
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
|
||||
return;
|
||||
|
||||
var target = ent.Comp.TargetUser ? args.User : ent.Owner;
|
||||
|
||||
if (target == null)
|
||||
return;
|
||||
|
||||
// Popups only play for one entity
|
||||
if (ent.Comp.Quiet)
|
||||
{
|
||||
if (ent.Comp.Predicted)
|
||||
_popup.PopupClient(Loc.GetString(ent.Comp.Text),
|
||||
target.Value,
|
||||
ent.Comp.UserIsRecipient ? args.User : ent.Owner,
|
||||
ent.Comp.PopupType);
|
||||
|
||||
else if (args.User != null)
|
||||
_popup.PopupEntity(Loc.GetString(ent.Comp.OtherText ?? ent.Comp.Text),
|
||||
target.Value,
|
||||
args.User.Value,
|
||||
ent.Comp.PopupType);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Popups play for all entities
|
||||
if (ent.Comp.Predicted)
|
||||
_popup.PopupPredicted(Loc.GetString(ent.Comp.Text),
|
||||
Loc.GetString(ent.Comp.OtherText ?? ent.Comp.Text),
|
||||
target.Value,
|
||||
ent.Comp.UserIsRecipient ? args.User : ent.Owner,
|
||||
ent.Comp.PopupType);
|
||||
|
||||
else
|
||||
_popup.PopupEntity(Loc.GetString(ent.Comp.OtherText ?? ent.Comp.Text),
|
||||
target.Value,
|
||||
ent.Comp.PopupType);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user