Replace IClickAlert with events (#30728)

* Replace IAlertClick with events

* whoop

* eek!
This commit is contained in:
Nemanja
2024-08-07 01:15:35 -04:00
committed by GitHub
parent 2dabf33d46
commit ce97225c2d
33 changed files with 177 additions and 270 deletions

View File

@@ -0,0 +1,7 @@
using Content.Shared.Alert;
namespace Content.Shared.Abilities.Mime;
public sealed partial class BreakVowAlertEvent : BaseAlertEvent;
public sealed partial class RetakeVowAlertEvent : BaseAlertEvent;

View File

@@ -76,11 +76,11 @@ public sealed partial class AlertPrototype : IPrototype
public bool SupportsSeverity => MaxSeverity != -1;
/// <summary>
/// Defines what to do when the alert is clicked.
/// This will always be null on clientside.
/// Event raised on the user when they click on this alert.
/// Can be null.
/// </summary>
[DataField(serverOnly: true)]
public IAlertClick? OnClick { get; private set; }
[DataField]
public BaseAlertEvent? ClickEvent;
/// <param name="severity">severity level, if supported by this alert</param>
/// <returns>the icon path to the texture for the provided severity level</returns>
@@ -114,3 +114,17 @@ public sealed partial class AlertPrototype : IPrototype
return Icons[severity.Value - _minSeverity];
}
}
[ImplicitDataDefinitionForInheritors]
public abstract partial class BaseAlertEvent : HandledEntityEventArgs
{
public EntityUid User;
public ProtoId<AlertPrototype> AlertId;
protected BaseAlertEvent(EntityUid user, ProtoId<AlertPrototype> alertId)
{
User = user;
AlertId = alertId;
}
}

View File

@@ -195,7 +195,7 @@ public abstract class AlertsSystem : EntitySystem
SubscribeLocalEvent<AlertAutoRemoveComponent, EntityUnpausedEvent>(OnAutoRemoveUnPaused);
SubscribeNetworkEvent<ClickAlertEvent>(HandleClickAlert);
SubscribeAllEvent<ClickAlertEvent>(HandleClickAlert);
SubscribeLocalEvent<PrototypesReloadedEventArgs>(HandlePrototypesReloaded);
LoadPrototypes();
}
@@ -328,7 +328,20 @@ public abstract class AlertsSystem : EntitySystem
return;
}
alert.OnClick?.AlertClicked(player.Value);
ActivateAlert(player.Value, alert);
}
public bool ActivateAlert(EntityUid user, AlertPrototype alert)
{
if (alert.ClickEvent is not { } clickEvent)
return false;
clickEvent.Handled = false;
clickEvent.User = user;
clickEvent.AlertId = alert.ID;
RaiseLocalEvent(user, (object) clickEvent, true);
return clickEvent.Handled;
}
private void OnPlayerAttached(EntityUid uid, AlertsComponent component, PlayerAttachedEvent args)

View File

@@ -1,14 +0,0 @@
namespace Content.Shared.Alert
{
/// <summary>
/// Defines what should happen when an alert is clicked.
/// </summary>
public interface IAlertClick
{
/// <summary>
/// Invoked on server side when user clicks an alert.
/// </summary>
/// <param name="player"></param>
void AlertClicked(EntityUid player);
}
}

View File

@@ -1,3 +1,4 @@
using Content.Shared.Alert;
using Robust.Shared.Audio;
namespace Content.Shared.Atmos.Components;
@@ -27,3 +28,5 @@ public sealed partial class ExtinguishOnInteractComponent : Component
[DataField]
public LocId ExtinguishFailed = "candle-extinguish-failed";
}
public sealed partial class ResistFireAlertEvent : BaseAlertEvent;

View File

@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Alert;
using Content.Shared.Interaction;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
@@ -79,6 +80,7 @@ public sealed class BuckleState(NetEntity? buckledTo, bool dontCollide, TimeSpan
public readonly TimeSpan? BuckleTime = buckleTime;
}
public sealed partial class UnbuckleAlertEvent : BaseAlertEvent;
/// <summary>
/// Event raised directed at a strap entity before some entity gets buckled to it.

View File

@@ -41,6 +41,7 @@ public abstract partial class SharedBuckleSystem
SubscribeLocalEvent<BuckleComponent, StartPullAttemptEvent>(OnPullAttempt);
SubscribeLocalEvent<BuckleComponent, BeingPulledAttemptEvent>(OnBeingPulledAttempt);
SubscribeLocalEvent<BuckleComponent, PullStartedMessage>(OnPullStarted);
SubscribeLocalEvent<BuckleComponent, UnbuckleAlertEvent>(OnUnbuckleAlert);
SubscribeLocalEvent<BuckleComponent, InsertIntoEntityStorageAttemptEvent>(OnBuckleInsertIntoEntityStorageAttempt);
@@ -86,6 +87,13 @@ public abstract partial class SharedBuckleSystem
Unbuckle(ent!, args.PullerUid);
}
private void OnUnbuckleAlert(Entity<BuckleComponent> ent, ref UnbuckleAlertEvent args)
{
if (args.Handled)
return;
args.Handled = TryUnbuckle(ent, ent, ent);
}
#endregion
#region Transform

View File

@@ -46,6 +46,8 @@ public sealed partial class CuffableComponent : Component
public ProtoId<AlertPrototype> CuffedAlert = "Handcuffed";
}
public sealed partial class RemoveCuffsAlertEvent : BaseAlertEvent;
[Serializable, NetSerializable]
public sealed class CuffableComponentState : ComponentState
{

View File

@@ -66,6 +66,7 @@ namespace Content.Shared.Cuffs
SubscribeLocalEvent<CuffableComponent, RejuvenateEvent>(OnRejuvenate);
SubscribeLocalEvent<CuffableComponent, ComponentInit>(OnStartup);
SubscribeLocalEvent<CuffableComponent, AttemptStopPullingEvent>(HandleStopPull);
SubscribeLocalEvent<CuffableComponent, RemoveCuffsAlertEvent>(OnRemoveCuffsAlert);
SubscribeLocalEvent<CuffableComponent, UpdateCanMoveEvent>(HandleMoveAttempt);
SubscribeLocalEvent<CuffableComponent, IsEquippingAttemptEvent>(OnEquipAttempt);
SubscribeLocalEvent<CuffableComponent, IsUnequippingAttemptEvent>(OnUnequipAttempt);
@@ -248,6 +249,14 @@ namespace Content.Shared.Cuffs
args.Cancelled = true;
}
private void OnRemoveCuffsAlert(Entity<CuffableComponent> ent, ref RemoveCuffsAlertEvent args)
{
if (args.Handled)
return;
TryUncuff(ent, ent, cuffable: ent.Comp);
args.Handled = true;
}
private void AddUncuffVerb(EntityUid uid, CuffableComponent component, GetVerbsEvent<Verb> args)
{
// Can the user access the cuffs, and is there even anything to uncuff?

View File

@@ -47,6 +47,8 @@ public sealed partial class EnsnareableComponent : Component
public ProtoId<AlertPrototype> EnsnaredAlert = "Ensnared";
}
public sealed partial class RemoveEnsnareAlertEvent : BaseAlertEvent;
[Serializable, NetSerializable]
public sealed class EnsnareableComponentState : ComponentState
{

View File

@@ -1,4 +1,5 @@
using Content.Shared.DoAfter;
using Content.Shared.Alert;
using Content.Shared.DoAfter;
using Robust.Shared.Serialization;
namespace Content.Shared.Internals;
@@ -7,3 +8,5 @@ namespace Content.Shared.Internals;
public sealed partial class InternalsDoAfterEvent : SimpleDoAfterEvent
{
}
public sealed partial class ToggleInternalsAlertEvent : BaseAlertEvent;

View File

@@ -42,3 +42,5 @@ public sealed partial class PullableComponent : Component
[DataField]
public ProtoId<AlertPrototype> PulledAlert = "Pulled";
}
public sealed partial class StopBeingPulledAlertEvent : BaseAlertEvent;

View File

@@ -44,3 +44,5 @@ public sealed partial class PullerComponent : Component
[DataField]
public ProtoId<AlertPrototype> PullingAlert = "Pulling";
}
public sealed partial class StopPullingAlertEvent : BaseAlertEvent;

View File

@@ -58,6 +58,7 @@ public sealed class PullingSystem : EntitySystem
SubscribeLocalEvent<PullableComponent, GetVerbsEvent<Verb>>(AddPullVerbs);
SubscribeLocalEvent<PullableComponent, EntGotInsertedIntoContainerMessage>(OnPullableContainerInsert);
SubscribeLocalEvent<PullableComponent, ModifyUncuffDurationEvent>(OnModifyUncuffDuration);
SubscribeLocalEvent<PullableComponent, StopBeingPulledAlertEvent>(OnStopBeingPulledAlert);
SubscribeLocalEvent<PullerComponent, AfterAutoHandleStateEvent>(OnAfterState);
SubscribeLocalEvent<PullerComponent, EntGotInsertedIntoContainerMessage>(OnPullerContainerInsert);
@@ -65,6 +66,7 @@ public sealed class PullingSystem : EntitySystem
SubscribeLocalEvent<PullerComponent, VirtualItemDeletedEvent>(OnVirtualItemDeleted);
SubscribeLocalEvent<PullerComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
SubscribeLocalEvent<PullerComponent, DropHandItemsEvent>(OnDropHandItems);
SubscribeLocalEvent<PullerComponent, StopPullingAlertEvent>(OnStopPullingAlert);
SubscribeLocalEvent<PullableComponent, StrappedEvent>(OnBuckled);
SubscribeLocalEvent<PullableComponent, BuckledEvent>(OnGotBuckled);
@@ -105,6 +107,15 @@ public sealed class PullingSystem : EntitySystem
TryStopPull(pullerComp.Pulling.Value, pullableComp, uid);
}
private void OnStopPullingAlert(Entity<PullerComponent> ent, ref StopPullingAlertEvent args)
{
if (args.Handled)
return;
if (!TryComp<PullableComponent>(ent.Comp.Pulling, out var pullable))
return;
args.Handled = TryStopPull(ent.Comp.Pulling.Value, pullable, ent);
}
private void OnPullerContainerInsert(Entity<PullerComponent> ent, ref EntGotInsertedIntoContainerMessage args)
{
if (ent.Comp.Pulling == null)
@@ -133,6 +144,14 @@ public sealed class PullingSystem : EntitySystem
args.Duration *= 2;
}
private void OnStopBeingPulledAlert(Entity<PullableComponent> ent, ref StopBeingPulledAlertEvent args)
{
if (args.Handled)
return;
args.Handled = TryStopPull(ent, ent, ent);
}
public override void Shutdown()
{
base.Shutdown();
@@ -491,6 +510,9 @@ public sealed class PullingSystem : EntitySystem
if (pullerUidNull == null)
return true;
if (user != null && !_blocker.CanInteract(user.Value, pullableUid))
return false;
var msg = new AttemptStopPullingEvent(user);
RaiseLocalEvent(pullableUid, msg, true);

View File

@@ -39,4 +39,6 @@ namespace Content.Shared.Shuttles.Components
public override bool SendOnlyToOwner => true;
}
public sealed partial class StopPilotingAlertEvent : BaseAlertEvent;
}