Replace IClickAlert with events (#30728)
* Replace IAlertClick with events * whoop * eek!
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user