A UI panel Razor component that displays a timer and a title message. It waits for the player to press attack1 to start, then increments a timer while the mouse and inputs remain still, and marks failure if mouse moves or attack inputs are pressed, updating the on-screen text and color accordingly.
@using System;
@using Sandbox;
@using Sandbox.UI;
@inherits PanelComponent
@namespace Sandbox
<root>
<div class="timer">@Timer.ToString()</div>
<div class="title" style="color: @(IsFailed ? FaildColor.Hex : NormalColor.Hex);">@TextOnScreen</div>
</root>
@code
{
[Property]
public Color NormalColor;
[Property]
public Color FaildColor;
bool IsFailed = false;
bool IsStarted = false;
string TextOnScreen = "Click before start!";
float Timer = 0;
protected override void OnUpdate()
{
if ( !IsStarted)
{
if ( Input.Pressed( "attack1" ))
{
IsStarted = true;
TextOnScreen = "Just chill and don't move your mouse...";
}
return;
}
if ( Mouse.Delta.x != 0 && Mouse.Delta.y != 0 || Input.Pressed("attack1") || Input.Pressed("attack2") )
{
IsFailed = true;
TextOnScreen = "YOUR FUCKED, IDIOT!!!";
}
if( !IsFailed )
Timer += Time.Delta;
base.OnUpdate();
}
protected override int BuildHash() => System.HashCode.Combine( TextOnScreen, NormalColor, FaildColor, Timer );
}