UI/EscapeMenu.razor
@using System;
@using Sandbox;
@using Sandbox.UI;
@inherits PanelComponent
@namespace Sandbox
<root class="@(isEnabled ? "" : "hidden")">
<div class="body">
<div class="buttons">
<div class="button" onclick="@(() => OnClose())">#menu.resume</div>
<div class="button" onclick="@(() => OnResetBall())">#menu.resetball</div>
<div class="button" onclick="@(() => OnQuit())">#menu.quit</div>
</div>
</div>
<div class="panel right">
<div class="option">
@* <div class="button reset" onclick="@(() => { ResetSens(ref Sensitivity, 1.0f); })">R</div> *@
<label class="option name">#settings.sensitivity</label>
<div class="adjuster">
<label class="option adjust" onclick=@(() => SetSens("decrement", 0.1f, 0.1f))><</label>
<label class="option value">@Sensitivity</label>
<label class="option adjust" onclick=@(() => SetSens("increment", 0.1f, 0.1f))>></label>
</div>
</div>
</div>
<div class="panel left">
<div class="playerlist">
@foreach (var player in Connection.All)
{
<div class="player">
<div class="left">
@if (player.IsHost)
{
<div class="prefix">[Host]</div>
}
@if (Networking.IsHost && !player.IsHost)
{
<div class="prefix" onclick="@(() => player.Kick("You were kicked by the host"))">❌</div>
}
<div class="name">@player.DisplayName</div>
</div>
<div class="right">
<div class="ping">
<img src="@pingIcon" style="width: 35px; margin: 0px 5px;" alt="Ping" />@player.Latency
</div>
</div>
</div>
}
</div>
</div>
</root>
@code
{
[Property, ImageAssetPath] string pingIcon {get; set;}
float Sensitivity = GameSettings.Sensitivity;
GameObject ball;
GameObject gameOver;
bool isEnabled = false;
float resetTimer = 0;
bool isTimerActive = false;
protected override void OnEnabled()
{
ball = Scene.FindAllWithTag("ball").FirstOrDefault();
gameOver = Scene.FindAllWithTag("gameover").FirstOrDefault();
}
protected override void OnUpdate()
{
if (isTimerActive)
{
resetTimer += Time.Delta;
if (resetTimer >= 1f)
{
ball.GetComponent<Ball>().Start();
resetTimer = 0;
isTimerActive = false;
}
}
if (gameOver.Enabled)
{
isEnabled = false;
}
if ( Input.Pressed("Score"))
{
if (isEnabled)
{
isEnabled = false;
}
else
{
isEnabled = true;
}
}
}
void SetSens(string operation, float min, float step)
{
if (operation == "increment")
{
Sensitivity = MathF.Round(Math.Max(min, Sensitivity + step), 3);
GameSettings.Sensitivity = Sensitivity;
}
else if (operation == "decrement")
{
Sensitivity = MathF.Round(Math.Max(min, Sensitivity - step), 3);
GameSettings.Sensitivity = Sensitivity;
}
}
void ResetSens(ref float variable, float value)
{
variable = value;
GameSettings.Sensitivity = value;
}
void OnClose()
{
isEnabled = false;
}
void OnResetBall()
{
isTimerActive = true;
}
void OnQuit()
{
if (Networking.IsHost)
{
SceneLoadOptions load = new SceneLoadOptions();
load.SetScene("scenes/lobby.scene");
Game.ChangeScene(load);
}
else
{
Networking.Disconnect();
Scene.LoadFromFile("scenes/lobby.scene");
}
}
/// <summary>
/// the hash determines if the system should be rebuilt. If it changes, it will be rebuilt
/// </summary>
protected override int BuildHash() => System.HashCode.Combine( isEnabled, Connection.All.Count );
}