using AceField.Scripts.Logic; using Godot; namespace AceField.Scripts.UI; public partial class Leaderboard : Control { [Export] public Scoreboard Scoreboard; public override void _Process(double delta) { Visible = Input.IsActionPressed("ui_leaderboard"); if (!Visible) return; if (GetNode("List").GetChildCount() != Scoreboard.Players.Count) { CleanNodes(); CreateNodes(); return; } var place = 1; foreach (var node in GetNode("List").GetChildren()) { if (node is not LeaderboardRecord record) continue; var data = Scoreboard.GetData(record.PlayerId); if (data == null) continue; record.Place = place; record.Score = data.Score; record.PlayerName = data.Name; place++; } } private void CleanNodes() { foreach (var child in GetNode("List").GetChildren()) { child.QueueFree(); } } private void CreateNodes() { var blueprint = GD.Load("res://Scenes/UI/LeaderboardRecord.tscn"); var place = 1; foreach (var record in Scoreboard.Players) { var instance = blueprint.Instantiate(); instance.Place = place; instance.PlayerName = record.Value.Name; instance.Score = record.Value.Score; instance.PlayerId = record.Key; instance.CustomMinimumSize = new Vector2(0, 80); GetNode("List").AddChild(instance); place++; } } }