UI/Notifications/NotificationPanel.razor
@using Sandbox;
@using Sandbox.UI;
@inherits PanelComponent
@namespace HC3
<root>
</root>
@code
{
public static NotificationPanel Instance { get; private set; }
public bool HasAny => Count > 0;
public int Count => Panel.ChildrenCount;
protected override void OnAwake()
{
base.OnAwake();
Instance = this;
}
public void Add( string message, string icon = "", float duration = 8f )
{
var notification = new NotificationEntry();
notification.Message = message;
notification.Icon = icon;
notification.Duration = duration;
Panel.AddChild( notification );
// todo: probably don't do this for system sounds like saving
Sound.Play( "notification" );
}
[Rpc.Broadcast]
public void Broadcast( string message, string icon = "", float duration = 8f )
{
Add( message, icon, duration );
}
[ConCmd( "hc3.notification.add" )]
public static void AddNotification( string message )
{
Instance?.Add( message );
}
protected override int BuildHash() => System.HashCode.Combine( DayNightController.Instance?.GetTimeString() );
}