Fix clientsided alerts being overwritten by server (#37033)

Initial commit
This commit is contained in:
SlamBamActionman 2025-04-29 15:32:18 +02:00 committed by BarryNorfolk
parent c98d7cbb13
commit 43832b5d5a
3 changed files with 23 additions and 0 deletions

View File

@ -60,8 +60,24 @@ public sealed class ClientAlertsSystem : AlertsSystem
if (args.Current is not AlertComponentState cast)
return;
// Save all client-sided alerts to later put back in
var clientAlerts = new Dictionary<AlertKey, AlertState>();
foreach (var alert in alerts.Comp.Alerts)
{
if (alert.Key.AlertType != null && TryGet(alert.Key.AlertType.Value, out var alertProto))
{
if (alertProto.ClientHandled)
clientAlerts[alert.Key] = alert.Value;
}
}
alerts.Comp.Alerts = new(cast.Alerts);
foreach (var alert in clientAlerts)
{
alerts.Comp.Alerts[alert.Key] = alert.Value;
}
UpdateHud(alerts);
}

View File

@ -75,6 +75,12 @@ public sealed partial class AlertPrototype : IPrototype
/// </summary>
public bool SupportsSeverity => MaxSeverity != -1;
/// <summary>
/// If true, this alert is being handled by the client and will not be overwritten when handling server -> client states.
/// </summary>
[DataField]
public bool ClientHandled = false;
/// <summary>
/// Event raised on the user when they click on this alert.
/// Can be null.

View File

@ -137,6 +137,7 @@
state: walking
name: alerts-walking-name
description: alerts-walking-desc
clientHandled: true
- type: alert
id: Stun