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

55 lines
990 B
Plaintext

@using Sandbox;
@using Sandbox.UI;
@inherits Panel
<root onclick=@(() => Action?.Invoke())>
@if(!string.IsNullOrEmpty(Image))
{
<img src="@Image" />
}
<div class="contents">
<label>@Text</label>
<div class="progress-bar">
<div class="fill" style="width: @(100f - ((timeSinceCreated / Duration) * 100f))%;" />
</div>
</div>
</root>
@code
{
public string Text { get; set; } = "Hello World!";
public float Duration { get; set; } = 5.0f;
public string Image { get; set; }
public Action Action { get; set; }
TimeSince timeSinceCreated = 0f;
float hoverTime = 0f;
public override void Tick ()
{
base.Tick();
if ( HasHovered || LoadingScreen.IsVisible )
{
if (hoverTime == 0)
hoverTime = timeSinceCreated;
else
timeSinceCreated = hoverTime;
}
else
{
hoverTime = 0;
}
if(timeSinceCreated > Duration)
{
Delete();
}
}
protected override int BuildHash ()
{
return System.HashCode.Combine( timeSinceCreated.ToString() );
}
}