474 lines
19 KiB
C#
474 lines
19 KiB
C#
|
|
using System;
|
|||
|
|
using System.Globalization;
|
|||
|
|
using Godot;
|
|||
|
|
using RustToDust.Core;
|
|||
|
|
|
|||
|
|
namespace RustToDust.Client;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Authoritative pre-match orbital lobby overlay (<see cref="MatchPhase.Lobby"/>).
|
|||
|
|
/// Displays the 12 contender slots, ready states, host-only map/seed controls,
|
|||
|
|
/// live 5-second orbital insertion countdown banner, and launch/leave actions.
|
|||
|
|
/// </summary>
|
|||
|
|
public sealed partial class LobbyScreen : CanvasLayer
|
|||
|
|
{
|
|||
|
|
private sealed class SlotRowView
|
|||
|
|
{
|
|||
|
|
public required PanelContainer Frame;
|
|||
|
|
public required Label IndexLabel;
|
|||
|
|
public required Label NameLabel;
|
|||
|
|
public required Label RoleBadge;
|
|||
|
|
public required Label ReadyBadge;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private readonly SlotRowView[] _slotViews = new SlotRowView[MatchState.ContenderCount];
|
|||
|
|
|
|||
|
|
private Control _root = null!;
|
|||
|
|
private ImperialChromePanel _panel = null!;
|
|||
|
|
private Label _modeBadge = null!;
|
|||
|
|
private PanelContainer _countdownBanner = null!;
|
|||
|
|
private Label _countdownLabel = null!;
|
|||
|
|
private Label _rosterSummaryLabel = null!;
|
|||
|
|
|
|||
|
|
private OptionButton _mapOption = null!;
|
|||
|
|
private LineEdit _seedEdit = null!;
|
|||
|
|
private Button _applyConfigBtn = null!;
|
|||
|
|
private Button _randomSeedBtn = null!;
|
|||
|
|
private Label _authorityNoteLabel = null!;
|
|||
|
|
private Label _netStatusLabel = null!;
|
|||
|
|
|
|||
|
|
private Button _readyBtn = null!;
|
|||
|
|
private Button _launchBtn = null!;
|
|||
|
|
private Button _leaveBtn = null!;
|
|||
|
|
|
|||
|
|
private IClientArenaSession? _activeSession;
|
|||
|
|
private int? _lastSyncedSeed;
|
|||
|
|
private byte? _lastSyncedMap;
|
|||
|
|
|
|||
|
|
public LobbyScreen()
|
|||
|
|
{
|
|||
|
|
Layer = 20;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public event Action? LeaveRequested;
|
|||
|
|
|
|||
|
|
public bool IsTextInputFocused => Visible && _seedEdit is not null && _seedEdit.HasFocus();
|
|||
|
|
|
|||
|
|
public override void _Ready()
|
|||
|
|
{
|
|||
|
|
BuildUi();
|
|||
|
|
SetLobbyVisible(false);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void SetLobbyVisible(bool visible)
|
|||
|
|
{
|
|||
|
|
Visible = visible;
|
|||
|
|
if (_root is not null)
|
|||
|
|
{
|
|||
|
|
_root.Visible = visible;
|
|||
|
|
}
|
|||
|
|
if (!visible)
|
|||
|
|
{
|
|||
|
|
_activeSession = null;
|
|||
|
|
_lastSyncedSeed = null;
|
|||
|
|
_lastSyncedMap = null;
|
|||
|
|
_seedEdit?.ReleaseFocus();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Sync(IClientArenaSession session)
|
|||
|
|
{
|
|||
|
|
_activeSession = session;
|
|||
|
|
var net = session.ConnectionStatus;
|
|||
|
|
var lobby = session.LobbyState;
|
|||
|
|
|
|||
|
|
_modeBadge.Text = net.Mode switch
|
|||
|
|
{
|
|||
|
|
NetworkMode.ListenHost => net.StateLabel,
|
|||
|
|
NetworkMode.RemoteClient => net.Connected
|
|||
|
|
? $"CONNECTED • PING {net.PingMs} ms"
|
|||
|
|
: (net.LastError is not null ? $"DISCONNECTED: {net.LastError}" : "CONNECTING TO LOBBY..."),
|
|||
|
|
_ => "SOLO"
|
|||
|
|
};
|
|||
|
|
_modeBadge.AddThemeColorOverride("font_color",
|
|||
|
|
net.LastError is not null ? ImperialChrome.RedCol : (net.Connected ? ImperialChrome.CyanCol : ImperialChrome.OrangeCol));
|
|||
|
|
|
|||
|
|
if (lobby is null)
|
|||
|
|
{
|
|||
|
|
_countdownLabel.Text = net.LastError is not null
|
|||
|
|
? $"CONNECTION LOST — {net.LastError}"
|
|||
|
|
: "ESTABLISHING RUDP UPLINK TO SERVER LOBBY...";
|
|||
|
|
_countdownLabel.AddThemeColorOverride("font_color", net.LastError is not null ? ImperialChrome.RedCol : ImperialChrome.OrangeCol);
|
|||
|
|
_rosterSummaryLabel.Text = "Awaiting authoritative lobby roster...";
|
|||
|
|
_readyBtn.Disabled = true;
|
|||
|
|
_launchBtn.Visible = false;
|
|||
|
|
_mapOption.Disabled = true;
|
|||
|
|
_seedEdit.Editable = false;
|
|||
|
|
_applyConfigBtn.Disabled = true;
|
|||
|
|
_randomSeedBtn.Disabled = true;
|
|||
|
|
_authorityNoteLabel.Text = "Waiting for server snapshot...";
|
|||
|
|
_netStatusLabel.Text = net.StateLabel;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int localId = session.LocalContenderId;
|
|||
|
|
bool isHost = lobby.HostSlotId.HasValue && lobby.HostSlotId.Value == localId;
|
|||
|
|
bool localReady = false;
|
|||
|
|
int humanCount = 0;
|
|||
|
|
int readyCount = 0;
|
|||
|
|
int aiCount = 0;
|
|||
|
|
|
|||
|
|
for (int i = 0; i < _slotViews.Length; i++)
|
|||
|
|
{
|
|||
|
|
var view = _slotViews[i];
|
|||
|
|
if (i < lobby.Slots.Count)
|
|||
|
|
{
|
|||
|
|
var slot = lobby.Slots[i];
|
|||
|
|
bool isLocalSlot = slot.SlotId == localId;
|
|||
|
|
bool isHostSlot = lobby.HostSlotId.HasValue && slot.SlotId == lobby.HostSlotId.Value;
|
|||
|
|
|
|||
|
|
view.IndexLabel.Text = $"SLOT {slot.SlotId + 1:00}";
|
|||
|
|
if (slot.IsHuman)
|
|||
|
|
{
|
|||
|
|
humanCount++;
|
|||
|
|
if (slot.IsReady) readyCount++;
|
|||
|
|
if (isLocalSlot) localReady = slot.IsReady;
|
|||
|
|
|
|||
|
|
view.NameLabel.Text = string.IsNullOrWhiteSpace(slot.Callsign) ? $"Pilot {slot.SlotId + 1}" : slot.Callsign;
|
|||
|
|
view.NameLabel.AddThemeColorOverride("font_color", isLocalSlot ? ImperialChrome.TextLight : Colors.White);
|
|||
|
|
|
|||
|
|
view.RoleBadge.Text = isHostSlot
|
|||
|
|
? (isLocalSlot ? "[HOST / YOU]" : "[HOST]")
|
|||
|
|
: (isLocalSlot ? "[YOU]" : "[PILOT]");
|
|||
|
|
view.RoleBadge.AddThemeColorOverride("font_color", isHostSlot ? ImperialChrome.GoldCol : ImperialChrome.CyanCol);
|
|||
|
|
|
|||
|
|
view.ReadyBadge.Text = slot.IsReady ? "[READY]" : "[WAIT]";
|
|||
|
|
view.ReadyBadge.AddThemeColorOverride("font_color", slot.IsReady ? ImperialChrome.OliveCol : ImperialChrome.OrangeCol);
|
|||
|
|
|
|||
|
|
ApplyRowFrame(view.Frame, isLocalSlot ? ImperialChrome.CyanCol : ImperialChrome.BorderCol, highlighted: isLocalSlot);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
aiCount++;
|
|||
|
|
view.NameLabel.Text = "AI BACKFILL";
|
|||
|
|
view.NameLabel.AddThemeColorOverride("font_color", ImperialChrome.TextMuted);
|
|||
|
|
view.RoleBadge.Text = "[BOT]";
|
|||
|
|
view.RoleBadge.AddThemeColorOverride("font_color", ImperialChrome.TextMuted);
|
|||
|
|
view.ReadyBadge.Text = "[ARMED]";
|
|||
|
|
view.ReadyBadge.AddThemeColorOverride("font_color", ImperialChrome.TextMuted);
|
|||
|
|
ApplyRowFrame(view.Frame, new Color(ImperialChrome.BorderCol.R, ImperialChrome.BorderCol.G, ImperialChrome.BorderCol.B, 0.45f), highlighted: false);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
_rosterSummaryLabel.Text = $"HUMANS: {humanCount}/{MatchState.ContenderCount} • READY: {readyCount}/{Math.Max(1, humanCount)} • AI BACKFILL: {aiCount}";
|
|||
|
|
|
|||
|
|
// Countdown banner
|
|||
|
|
if (lobby.CountdownSeconds is float cd)
|
|||
|
|
{
|
|||
|
|
int ceilSec = Math.Max(1, (int)MathF.Ceiling(cd));
|
|||
|
|
_countdownLabel.Text = $"ORBITAL INSERTION IN {ceilSec}...";
|
|||
|
|
_countdownLabel.AddThemeColorOverride("font_color", ceilSec <= 2 ? ImperialChrome.OrangeCol : ImperialChrome.GoldCol);
|
|||
|
|
_panel.SetAccentColor(ImperialChrome.GoldCol);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
string readyHint = humanCount < lobby.MinHumansToAutoStart
|
|||
|
|
? $"NEED {lobby.MinHumansToAutoStart} HUMANS FOR AUTO-LAUNCH"
|
|||
|
|
: "ALL PILOTS READY UP TO BEGIN DROP";
|
|||
|
|
_countdownLabel.Text = isHost
|
|||
|
|
? $"PRE-MATCH STANDBY • {readyHint} (OR LAUNCH DROP)"
|
|||
|
|
: $"PRE-MATCH STANDBY • {readyHint}";
|
|||
|
|
_countdownLabel.AddThemeColorOverride("font_color", ImperialChrome.CyanCol);
|
|||
|
|
_panel.SetAccentColor(ImperialChrome.CyanCol);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Sync Map & Seed without clobbering active typing by host
|
|||
|
|
if (_lastSyncedMap != lobby.SelectedMap)
|
|||
|
|
{
|
|||
|
|
_lastSyncedMap = lobby.SelectedMap;
|
|||
|
|
_mapOption.Select((ArenaMapKind)lobby.SelectedMap == ArenaMapKind.Desert ? 1 : 0);
|
|||
|
|
}
|
|||
|
|
if (_lastSyncedSeed != lobby.SelectedSeed && (!_seedEdit.HasFocus() || !isHost))
|
|||
|
|
{
|
|||
|
|
_lastSyncedSeed = lobby.SelectedSeed;
|
|||
|
|
_seedEdit.Text = lobby.SelectedSeed.ToString(CultureInfo.InvariantCulture);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Strict host authority gating
|
|||
|
|
_mapOption.Disabled = !isHost;
|
|||
|
|
_seedEdit.Editable = isHost;
|
|||
|
|
_applyConfigBtn.Disabled = !isHost;
|
|||
|
|
_randomSeedBtn.Disabled = !isHost;
|
|||
|
|
_authorityNoteLabel.Text = isHost
|
|||
|
|
? "HOST AUTHORITY: You control drop zone, seed, and forced launch."
|
|||
|
|
: "READ-ONLY: Only the match host can edit map, seed, or force launch.";
|
|||
|
|
_authorityNoteLabel.AddThemeColorOverride("font_color", isHost ? ImperialChrome.GoldCol : ImperialChrome.TextMuted);
|
|||
|
|
|
|||
|
|
_readyBtn.Disabled = false;
|
|||
|
|
_readyBtn.Text = localReady ? "READY [ON] — CLICK TO UNREADY" : "READY UP";
|
|||
|
|
ImperialChrome.StyleButton(_readyBtn, localReady ? ImperialChrome.OliveCol : ImperialChrome.CyanCol, 14);
|
|||
|
|
|
|||
|
|
_launchBtn.Visible = isHost;
|
|||
|
|
_launchBtn.Disabled = !isHost;
|
|||
|
|
_launchBtn.Text = lobby.ForceLaunched ? "LAUNCHING NOW..." : "LAUNCH DROP";
|
|||
|
|
|
|||
|
|
_netStatusLabel.Text = $"{net.StateLabel} • MAP: {((ArenaMapKind)lobby.SelectedMap == ArenaMapKind.Sion ? "SION 3KM" : "DESERT RING")} • SEED {lobby.SelectedSeed}";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void BuildUi()
|
|||
|
|
{
|
|||
|
|
_root = new Control
|
|||
|
|
{
|
|||
|
|
Name = "LobbyScreenRoot",
|
|||
|
|
MouseFilter = Control.MouseFilterEnum.Stop
|
|||
|
|
};
|
|||
|
|
_root.SetAnchorsPreset(Control.LayoutPreset.FullRect);
|
|||
|
|
AddChild(_root);
|
|||
|
|
|
|||
|
|
var scrim = new ColorRect
|
|||
|
|
{
|
|||
|
|
Color = new Color(0.03f, 0.04f, 0.03f, 0.36f),
|
|||
|
|
MouseFilter = Control.MouseFilterEnum.Stop
|
|||
|
|
};
|
|||
|
|
scrim.SetAnchorsPreset(Control.LayoutPreset.FullRect);
|
|||
|
|
_root.AddChild(scrim);
|
|||
|
|
|
|||
|
|
_panel = ImperialChrome.CreatePanel(ImperialChrome.CyanCol, cornerLen: 18f, borderPx: 2f, bgAlpha: 0.92f, padH: 18, padV: 16);
|
|||
|
|
_panel.Name = "LobbyScreenPanel";
|
|||
|
|
_panel.AnchorLeft = 0.5f;
|
|||
|
|
_panel.AnchorRight = 0.5f;
|
|||
|
|
_panel.AnchorTop = 0.5f;
|
|||
|
|
_panel.AnchorBottom = 0.5f;
|
|||
|
|
_panel.OffsetLeft = -500f;
|
|||
|
|
_panel.OffsetRight = 500f;
|
|||
|
|
_panel.OffsetTop = -305f;
|
|||
|
|
_panel.OffsetBottom = 305f;
|
|||
|
|
_root.AddChild(_panel);
|
|||
|
|
|
|||
|
|
var vbox = new VBoxContainer();
|
|||
|
|
vbox.AddThemeConstantOverride("separation", 10);
|
|||
|
|
_panel.AddChild(vbox);
|
|||
|
|
|
|||
|
|
// Header row
|
|||
|
|
var headerRow = new HBoxContainer();
|
|||
|
|
headerRow.AddThemeConstantOverride("separation", 12);
|
|||
|
|
vbox.AddChild(headerRow);
|
|||
|
|
|
|||
|
|
var titleLbl = ImperialChrome.CreateLabel("PRE-MATCH ORBITAL LOBBY", 20, ImperialChrome.TextLight);
|
|||
|
|
titleLbl.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
|||
|
|
headerRow.AddChild(titleLbl);
|
|||
|
|
|
|||
|
|
_modeBadge = ImperialChrome.CreateLabel("HOST :3076", 12, ImperialChrome.CyanCol, HorizontalAlignment.Right);
|
|||
|
|
headerRow.AddChild(_modeBadge);
|
|||
|
|
|
|||
|
|
// Countdown Banner
|
|||
|
|
_countdownBanner = new PanelContainer();
|
|||
|
|
var cdStyle = new StyleBoxFlat
|
|||
|
|
{
|
|||
|
|
BgColor = ImperialChrome.BgInner,
|
|||
|
|
BorderColor = ImperialChrome.GoldCol,
|
|||
|
|
ContentMarginLeft = 12,
|
|||
|
|
ContentMarginRight = 12,
|
|||
|
|
ContentMarginTop = 8,
|
|||
|
|
ContentMarginBottom = 8
|
|||
|
|
};
|
|||
|
|
cdStyle.SetBorderWidthAll(1);
|
|||
|
|
_countdownBanner.AddThemeStyleboxOverride("panel", cdStyle);
|
|||
|
|
vbox.AddChild(_countdownBanner);
|
|||
|
|
|
|||
|
|
_countdownLabel = ImperialChrome.CreateLabel("PRE-MATCH STANDBY", 15, ImperialChrome.CyanCol, HorizontalAlignment.Center);
|
|||
|
|
_countdownBanner.AddChild(_countdownLabel);
|
|||
|
|
|
|||
|
|
// Body: Two columns (Left Roster | Right Config & Actions)
|
|||
|
|
var bodyRow = new HBoxContainer
|
|||
|
|
{
|
|||
|
|
SizeFlagsVertical = Control.SizeFlags.ExpandFill
|
|||
|
|
};
|
|||
|
|
bodyRow.AddThemeConstantOverride("separation", 16);
|
|||
|
|
vbox.AddChild(bodyRow);
|
|||
|
|
|
|||
|
|
// Left Column: Roster (Slot 01..12)
|
|||
|
|
var leftCol = new VBoxContainer
|
|||
|
|
{
|
|||
|
|
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill,
|
|||
|
|
SizeFlagsStretchRatio = 1.35f
|
|||
|
|
};
|
|||
|
|
leftCol.AddThemeConstantOverride("separation", 4);
|
|||
|
|
bodyRow.AddChild(leftCol);
|
|||
|
|
|
|||
|
|
leftCol.AddChild(ImperialChrome.CreateLabel("CONTENDER ROSTER (SLOTS 01 – 12)", 12, ImperialChrome.OrangeCol));
|
|||
|
|
|
|||
|
|
for (int i = 0; i < _slotViews.Length; i++)
|
|||
|
|
{
|
|||
|
|
var frame = new PanelContainer();
|
|||
|
|
ApplyRowFrame(frame, ImperialChrome.BorderCol, highlighted: false);
|
|||
|
|
|
|||
|
|
var row = new HBoxContainer();
|
|||
|
|
row.AddThemeConstantOverride("separation", 8);
|
|||
|
|
frame.AddChild(row);
|
|||
|
|
|
|||
|
|
var idxLbl = ImperialChrome.CreateLabel($"SLOT {i + 1:00}", 11, ImperialChrome.TextMuted);
|
|||
|
|
idxLbl.CustomMinimumSize = new Vector2(64f, 0f);
|
|||
|
|
row.AddChild(idxLbl);
|
|||
|
|
|
|||
|
|
var nameLbl = ImperialChrome.CreateLabel("AI BACKFILL", 12, ImperialChrome.TextMuted);
|
|||
|
|
nameLbl.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
|||
|
|
nameLbl.ClipText = true;
|
|||
|
|
row.AddChild(nameLbl);
|
|||
|
|
|
|||
|
|
var roleLbl = ImperialChrome.CreateLabel("[BOT]", 11, ImperialChrome.TextMuted);
|
|||
|
|
roleLbl.CustomMinimumSize = new Vector2(92f, 0f);
|
|||
|
|
roleLbl.HorizontalAlignment = HorizontalAlignment.Right;
|
|||
|
|
row.AddChild(roleLbl);
|
|||
|
|
|
|||
|
|
var readyLbl = ImperialChrome.CreateLabel("[ARMED]", 11, ImperialChrome.TextMuted);
|
|||
|
|
readyLbl.CustomMinimumSize = new Vector2(72f, 0f);
|
|||
|
|
readyLbl.HorizontalAlignment = HorizontalAlignment.Right;
|
|||
|
|
row.AddChild(readyLbl);
|
|||
|
|
|
|||
|
|
leftCol.AddChild(frame);
|
|||
|
|
_slotViews[i] = new SlotRowView
|
|||
|
|
{
|
|||
|
|
Frame = frame,
|
|||
|
|
IndexLabel = idxLbl,
|
|||
|
|
NameLabel = nameLbl,
|
|||
|
|
RoleBadge = roleLbl,
|
|||
|
|
ReadyBadge = readyLbl
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
_rosterSummaryLabel = ImperialChrome.CreateLabel("HUMANS: 1/12 • READY: 0/1 • AI BACKFILL: 11", 11, ImperialChrome.OliveCol);
|
|||
|
|
leftCol.AddChild(_rosterSummaryLabel);
|
|||
|
|
|
|||
|
|
// Right Column: Drop Zone Config & Launch Actions
|
|||
|
|
var rightCol = new VBoxContainer
|
|||
|
|
{
|
|||
|
|
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill,
|
|||
|
|
SizeFlagsStretchRatio = 1.0f
|
|||
|
|
};
|
|||
|
|
rightCol.AddThemeConstantOverride("separation", 10);
|
|||
|
|
bodyRow.AddChild(rightCol);
|
|||
|
|
|
|||
|
|
rightCol.AddChild(ImperialChrome.CreateLabel("DROP ZONE CONFIGURATION", 12, ImperialChrome.GoldCol));
|
|||
|
|
rightCol.AddChild(ImperialChrome.MakeRule());
|
|||
|
|
|
|||
|
|
var mapRow = new HBoxContainer();
|
|||
|
|
mapRow.AddThemeConstantOverride("separation", 8);
|
|||
|
|
rightCol.AddChild(mapRow);
|
|||
|
|
var mapLbl = ImperialChrome.CreateLabel("MAP", 12, ImperialChrome.TextMuted);
|
|||
|
|
mapLbl.CustomMinimumSize = new Vector2(68f, 0f);
|
|||
|
|
mapRow.AddChild(mapLbl);
|
|||
|
|
_mapOption = new OptionButton { SizeFlagsHorizontal = Control.SizeFlags.ExpandFill };
|
|||
|
|
_mapOption.AddItem("SION (3KM ALPINE)", 0);
|
|||
|
|
_mapOption.AddItem("DESERT RING", 1);
|
|||
|
|
ImperialChrome.StyleOptionButton(_mapOption, ImperialChrome.OliveCol, 13);
|
|||
|
|
_mapOption.ItemSelected += _ => ApplyConfigFromUi();
|
|||
|
|
mapRow.AddChild(_mapOption);
|
|||
|
|
|
|||
|
|
var seedRow = new HBoxContainer();
|
|||
|
|
seedRow.AddThemeConstantOverride("separation", 8);
|
|||
|
|
rightCol.AddChild(seedRow);
|
|||
|
|
var seedLbl = ImperialChrome.CreateLabel("SEED", 12, ImperialChrome.TextMuted);
|
|||
|
|
seedLbl.CustomMinimumSize = new Vector2(68f, 0f);
|
|||
|
|
seedRow.AddChild(seedLbl);
|
|||
|
|
_seedEdit = new LineEdit
|
|||
|
|
{
|
|||
|
|
Text = "42",
|
|||
|
|
MaxLength = 12,
|
|||
|
|
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill
|
|||
|
|
};
|
|||
|
|
ImperialChrome.StyleLineEdit(_seedEdit, ImperialChrome.GoldCol, 13);
|
|||
|
|
_seedEdit.TextSubmitted += _ => ApplyConfigFromUi();
|
|||
|
|
seedRow.AddChild(_seedEdit);
|
|||
|
|
|
|||
|
|
_randomSeedBtn = ImperialChrome.CreateButton("RND", ImperialChrome.BorderCol, 12, 30f);
|
|||
|
|
_randomSeedBtn.CustomMinimumSize = new Vector2(54f, 30f);
|
|||
|
|
_randomSeedBtn.Pressed += () =>
|
|||
|
|
{
|
|||
|
|
int nextSeed = Random.Shared.Next(1, 999999);
|
|||
|
|
_seedEdit.Text = nextSeed.ToString(CultureInfo.InvariantCulture);
|
|||
|
|
ApplyConfigFromUi();
|
|||
|
|
};
|
|||
|
|
seedRow.AddChild(_randomSeedBtn);
|
|||
|
|
|
|||
|
|
_applyConfigBtn = ImperialChrome.CreateButton("APPLY MAP & SEED", ImperialChrome.GoldCol, 12, 32f);
|
|||
|
|
_applyConfigBtn.Pressed += ApplyConfigFromUi;
|
|||
|
|
rightCol.AddChild(_applyConfigBtn);
|
|||
|
|
|
|||
|
|
_authorityNoteLabel = ImperialChrome.CreateLabel("HOST AUTHORITY", 11, ImperialChrome.TextMuted);
|
|||
|
|
_authorityNoteLabel.AutowrapMode = TextServer.AutowrapMode.Word;
|
|||
|
|
rightCol.AddChild(_authorityNoteLabel);
|
|||
|
|
|
|||
|
|
rightCol.AddChild(ImperialChrome.MakeRule());
|
|||
|
|
|
|||
|
|
var spacer = new Control { SizeFlagsVertical = Control.SizeFlags.ExpandFill };
|
|||
|
|
rightCol.AddChild(spacer);
|
|||
|
|
|
|||
|
|
_readyBtn = ImperialChrome.CreateButton("READY UP", ImperialChrome.CyanCol, 14, 42f);
|
|||
|
|
_readyBtn.Pressed += OnReadyPressed;
|
|||
|
|
rightCol.AddChild(_readyBtn);
|
|||
|
|
|
|||
|
|
_launchBtn = ImperialChrome.CreateButton("LAUNCH DROP", ImperialChrome.OliveCol, 14, 42f);
|
|||
|
|
_launchBtn.Pressed += OnLaunchPressed;
|
|||
|
|
rightCol.AddChild(_launchBtn);
|
|||
|
|
|
|||
|
|
_leaveBtn = ImperialChrome.CreateButton("LEAVE TO MENU", ImperialChrome.RedCol, 13, 36f);
|
|||
|
|
_leaveBtn.Pressed += () => LeaveRequested?.Invoke();
|
|||
|
|
rightCol.AddChild(_leaveBtn);
|
|||
|
|
|
|||
|
|
_netStatusLabel = ImperialChrome.CreateLabel(string.Empty, 11, ImperialChrome.TextMuted);
|
|||
|
|
_netStatusLabel.AutowrapMode = TextServer.AutowrapMode.Word;
|
|||
|
|
vbox.AddChild(_netStatusLabel);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void OnReadyPressed()
|
|||
|
|
{
|
|||
|
|
if (_activeSession is null || _activeSession.LobbyState is not { } lobby) return;
|
|||
|
|
int localId = _activeSession.LocalContenderId;
|
|||
|
|
bool currentReady = false;
|
|||
|
|
for (int i = 0; i < lobby.Slots.Count; i++)
|
|||
|
|
{
|
|||
|
|
if (lobby.Slots[i].SlotId == localId)
|
|||
|
|
{
|
|||
|
|
currentReady = lobby.Slots[i].IsReady;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
_activeSession.SetLobbyReady(!currentReady);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void OnLaunchPressed()
|
|||
|
|
{
|
|||
|
|
_activeSession?.RequestLobbyStart();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void ApplyConfigFromUi()
|
|||
|
|
{
|
|||
|
|
if (_activeSession is null || _activeSession.LobbyState is not { } lobby) return;
|
|||
|
|
if (!lobby.HostSlotId.HasValue || lobby.HostSlotId.Value != _activeSession.LocalContenderId) return;
|
|||
|
|
|
|||
|
|
var mapKind = _mapOption.Selected == 1 ? ArenaMapKind.Desert : ArenaMapKind.Sion;
|
|||
|
|
int seed = int.TryParse(_seedEdit.Text.Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out int parsed)
|
|||
|
|
? parsed
|
|||
|
|
: lobby.SelectedSeed;
|
|||
|
|
|
|||
|
|
_seedEdit.ReleaseFocus();
|
|||
|
|
_activeSession.RequestLobbyConfig(seed, mapKind);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static void ApplyRowFrame(PanelContainer frame, Color borderColor, bool highlighted)
|
|||
|
|
{
|
|||
|
|
var style = new StyleBoxFlat
|
|||
|
|
{
|
|||
|
|
BgColor = highlighted ? ImperialChrome.BgHover : ImperialChrome.BgInner,
|
|||
|
|
BorderColor = borderColor,
|
|||
|
|
ContentMarginLeft = 8,
|
|||
|
|
ContentMarginRight = 8,
|
|||
|
|
ContentMarginTop = 4,
|
|||
|
|
ContentMarginBottom = 4
|
|||
|
|
};
|
|||
|
|
style.SetBorderWidthAll(1);
|
|||
|
|
frame.AddThemeStyleboxOverride("panel", style);
|
|||
|
|
}
|
|||
|
|
}
|