Files
sbox-public/game/addons/menu/Code/MenuUI/Toasts/Toasts.razor

45 lines
838 B
Plaintext

@using MenuProject.MenuUI.Toasts
@using Sandbox;
@using Sandbox.UI;
@namespace Menu
@inherits Panel
<root>
</root>
@code
{
public static Toasts Instance { get; private set; }
protected override void OnAfterTreeRender ( bool firstTime )
{
base.OnAfterTreeRender( firstTime );
if ( firstTime )
{
Instance = this;
}
}
public void AddToast ( string message, Action action, float duration = 10f )
{
var entry = new ToastEntry();
entry.Text = message;
entry.Duration = duration * Scene.TimeScale;
entry.Action = action;
AddChild( entry );
}
public void AddToast(string message, string image, Action action, float duration = 10f)
{
var entry = new ToastEntry();
entry.Text = message;
entry.Duration = duration * Scene.TimeScale;
entry.Image = image;
entry.Action = action;
AddChild(entry);
}
}