2026-03-25 16:37:18 +01:00
|
|
|
using System;
|
2026-03-11 22:35:30 +01:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
|
2026-03-22 18:31:05 +01:00
|
|
|
namespace ONDClient.GUI;
|
2026-03-11 22:35:30 +01:00
|
|
|
|
|
|
|
|
public class LoadingUIElement : TextUIElement {
|
2026-03-25 16:37:18 +01:00
|
|
|
private Func<string> expectedEndpointGetter;
|
2026-03-11 22:35:30 +01:00
|
|
|
private Client.ConnectionState lastState = Client.ConnectionState.IDLE;
|
2026-03-25 16:37:18 +01:00
|
|
|
|
|
|
|
|
public LoadingUIElement(Point corner1, SpriteFont font, Func<string> expectedEndpointGetter, Alignment alignment = Alignment.CENTER, bool autoBounds = true) : base(corner1, font, alignment, autoBounds) {
|
|
|
|
|
this.expectedEndpointGetter = expectedEndpointGetter;
|
2026-03-11 22:35:30 +01:00
|
|
|
Active = true;
|
|
|
|
|
// Color = Color.LightGray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Update() {
|
|
|
|
|
if(lastState == Client.State) return;
|
|
|
|
|
lastState = Client.State;
|
|
|
|
|
|
|
|
|
|
switch (Client.State){
|
|
|
|
|
case Client.ConnectionState.CONNECTING:
|
2026-03-25 16:37:18 +01:00
|
|
|
Text = "Connecting to " + expectedEndpointGetter();
|
2026-03-11 22:35:30 +01:00
|
|
|
break;
|
|
|
|
|
case Client.ConnectionState.CONNECTED:
|
2026-03-25 16:37:18 +01:00
|
|
|
Text = "Connected to " + expectedEndpointGetter();
|
2026-03-11 22:35:30 +01:00
|
|
|
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;
|
2026-03-25 16:37:18 +01:00
|
|
|
case Client.ConnectionState.IDLE:
|
|
|
|
|
Text = "Idle";
|
|
|
|
|
break;
|
|
|
|
|
case Client.ConnectionState.DISCONNECTED:
|
|
|
|
|
Text = "Disconnected: " + Client.StatusText;
|
|
|
|
|
break;
|
2026-03-11 22:35:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|