OneNightDuel/ONDClient/GUI/LoadingUIElement.cs

44 lines
No EOL
1.6 KiB
C#

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace ONDClient.GUI;
public class LoadingUIElement : TextUIElement {
private Func<string> expectedEndpointGetter;
private Client.ConnectionState lastState = Client.ConnectionState.IDLE;
public LoadingUIElement(Point corner1, SpriteFont font, Func<string> expectedEndpointGetter, Alignment alignment = Alignment.CENTER, bool autoBounds = true) : base(corner1, font, alignment, autoBounds) {
this.expectedEndpointGetter = expectedEndpointGetter;
Active = true;
// Color = Color.LightGray;
}
public override void Update() {
if(lastState == Client.State) return;
lastState = Client.State;
switch (Client.State){
case Client.ConnectionState.CONNECTING:
Text = "Connecting to " + expectedEndpointGetter();
break;
case Client.ConnectionState.CONNECTED:
Text = "Connected to " + expectedEndpointGetter();
break;
case Client.ConnectionState.ACCEPTED:
Text = "Waiting for opponent...";
break;
case Client.ConnectionState.GAME_STARTING:
Text = "Opponent: " + Client.Opponent.username;
Color = Color.White;
// ScaleMultiplier = 1.5f;
break;
case Client.ConnectionState.IDLE:
Text = "Idle";
break;
case Client.ConnectionState.DISCONNECTED:
Text = "Disconnected: " + Client.StatusText;
break;
}
}
}