✨ Leaderboard
This commit is contained in:
		@@ -1,4 +1,4 @@
 | 
			
		||||
[gd_scene load_steps=10 format=3 uid="uid://bjhmjrldq4lkt"]
 | 
			
		||||
[gd_scene load_steps=11 format=3 uid="uid://bjhmjrldq4lkt"]
 | 
			
		||||
 | 
			
		||||
[ext_resource type="PackedScene" uid="uid://b3gx0bl43lku3" path="res://Scenes/Player.tscn" id="1_vby0g"]
 | 
			
		||||
[ext_resource type="PackedScene" uid="uid://dk8x2aeq1eevf" path="res://Scenes/UI/BootScreen.tscn" id="2_7aede"]
 | 
			
		||||
@@ -8,6 +8,7 @@
 | 
			
		||||
[ext_resource type="Script" path="res://Scripts/Logic/World.cs" id="3_xwguj"]
 | 
			
		||||
[ext_resource type="PackedScene" uid="uid://bb704b0kpwwkr" path="res://Scenes/UI/PlayerDiedScreen.tscn" id="5_pimes"]
 | 
			
		||||
[ext_resource type="PackedScene" uid="uid://c7w5sgq0bshk0" path="res://Scenes/UI/HUD.tscn" id="5_qvun1"]
 | 
			
		||||
[ext_resource type="PackedScene" uid="uid://dfoy57v3q4of5" path="res://Scenes/UI/Leaderboard.tscn" id="7_j24m7"]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_gyspy"]
 | 
			
		||||
properties/0/path = NodePath(".:RoundProgress")
 | 
			
		||||
@@ -37,6 +38,10 @@ script = ExtResource("3_as2wg")
 | 
			
		||||
 | 
			
		||||
[node name="OverlayLayer" type="CanvasLayer" parent="."]
 | 
			
		||||
 | 
			
		||||
[node name="Leaderboard" parent="OverlayLayer" node_paths=PackedStringArray("Scoreboard") instance=ExtResource("7_j24m7")]
 | 
			
		||||
visible = false
 | 
			
		||||
Scoreboard = NodePath("../../ScoreboardNode")
 | 
			
		||||
 | 
			
		||||
[node name="Hud" parent="OverlayLayer" node_paths=PackedStringArray("World") instance=ExtResource("5_qvun1")]
 | 
			
		||||
visible = false
 | 
			
		||||
World = NodePath("../../World")
 | 
			
		||||
 
 | 
			
		||||
@@ -94,7 +94,7 @@ text = "(0, 0)"
 | 
			
		||||
[node name="RoundLabel" type="Label" parent="BottomBox/HBox"]
 | 
			
		||||
layout_mode = 2
 | 
			
		||||
size_flags_horizontal = 3
 | 
			
		||||
text = "Round 1"
 | 
			
		||||
text = "Round 01/20"
 | 
			
		||||
horizontal_alignment = 1
 | 
			
		||||
 | 
			
		||||
[node name="ScoreLabel" type="Label" parent="BottomBox/HBox"]
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										36
									
								
								Scenes/UI/Leaderboard.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								Scenes/UI/Leaderboard.tscn
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
[gd_scene load_steps=3 format=3 uid="uid://dfoy57v3q4of5"]
 | 
			
		||||
 | 
			
		||||
[ext_resource type="PackedScene" uid="uid://b8s2m7gujfmp6" path="res://Scenes/UI/LeaderboardRecord.tscn" id="1_mr7v4"]
 | 
			
		||||
[ext_resource type="Script" path="res://Scripts/UI/Leaderboard.cs" id="1_sbkyu"]
 | 
			
		||||
 | 
			
		||||
[node name="Leaderboard" type="Control"]
 | 
			
		||||
layout_mode = 3
 | 
			
		||||
anchors_preset = 15
 | 
			
		||||
anchor_right = 1.0
 | 
			
		||||
anchor_bottom = 1.0
 | 
			
		||||
grow_horizontal = 2
 | 
			
		||||
grow_vertical = 2
 | 
			
		||||
script = ExtResource("1_sbkyu")
 | 
			
		||||
 | 
			
		||||
[node name="Label" type="Label" parent="."]
 | 
			
		||||
layout_mode = 0
 | 
			
		||||
offset_left = 16.0
 | 
			
		||||
offset_top = 21.0
 | 
			
		||||
offset_right = 1136.0
 | 
			
		||||
offset_bottom = 85.0
 | 
			
		||||
theme_override_font_sizes/font_size = 24
 | 
			
		||||
text = "Leaderboard"
 | 
			
		||||
horizontal_alignment = 1
 | 
			
		||||
vertical_alignment = 1
 | 
			
		||||
 | 
			
		||||
[node name="List" type="VBoxContainer" parent="."]
 | 
			
		||||
layout_mode = 0
 | 
			
		||||
offset_left = 16.0
 | 
			
		||||
offset_top = 97.0
 | 
			
		||||
offset_right = 1136.0
 | 
			
		||||
offset_bottom = 631.0
 | 
			
		||||
theme_override_constants/separation = 16
 | 
			
		||||
 | 
			
		||||
[node name="LeaderboardRecord" parent="List" instance=ExtResource("1_mr7v4")]
 | 
			
		||||
custom_minimum_size = Vector2(2.08165e-12, 80)
 | 
			
		||||
layout_mode = 2
 | 
			
		||||
							
								
								
									
										53
									
								
								Scenes/UI/LeaderboardRecord.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								Scenes/UI/LeaderboardRecord.tscn
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,53 @@
 | 
			
		||||
[gd_scene load_steps=2 format=3 uid="uid://b8s2m7gujfmp6"]
 | 
			
		||||
 | 
			
		||||
[ext_resource type="Script" path="res://Scripts/UI/LeaderboardRecord.cs" id="1_jc2uj"]
 | 
			
		||||
 | 
			
		||||
[node name="LeaderboardRecord" type="Control"]
 | 
			
		||||
layout_mode = 3
 | 
			
		||||
anchor_left = 0.014
 | 
			
		||||
anchor_top = 0.025
 | 
			
		||||
anchor_right = 0.986
 | 
			
		||||
anchor_bottom = 0.148
 | 
			
		||||
offset_left = -0.128
 | 
			
		||||
offset_top = -0.2
 | 
			
		||||
offset_right = 0.12793
 | 
			
		||||
offset_bottom = 0.0959988
 | 
			
		||||
grow_horizontal = 2
 | 
			
		||||
grow_vertical = 2
 | 
			
		||||
script = ExtResource("1_jc2uj")
 | 
			
		||||
 | 
			
		||||
[node name="Panel" type="Panel" parent="."]
 | 
			
		||||
layout_mode = 0
 | 
			
		||||
offset_right = 1120.0
 | 
			
		||||
offset_bottom = 80.0
 | 
			
		||||
 | 
			
		||||
[node name="VBoxContainer" type="HBoxContainer" parent="Panel"]
 | 
			
		||||
layout_mode = 0
 | 
			
		||||
offset_right = 1120.0
 | 
			
		||||
offset_bottom = 80.0
 | 
			
		||||
 | 
			
		||||
[node name="PlaceTag" type="Label" parent="Panel/VBoxContainer"]
 | 
			
		||||
custom_minimum_size = Vector2(80, 80)
 | 
			
		||||
layout_mode = 2
 | 
			
		||||
size_flags_horizontal = 0
 | 
			
		||||
theme_override_font_sizes/font_size = 32
 | 
			
		||||
text = "1"
 | 
			
		||||
horizontal_alignment = 1
 | 
			
		||||
vertical_alignment = 1
 | 
			
		||||
 | 
			
		||||
[node name="NameTag" type="Label" parent="Panel/VBoxContainer"]
 | 
			
		||||
custom_minimum_size = Vector2(80, 80)
 | 
			
		||||
layout_mode = 2
 | 
			
		||||
size_flags_horizontal = 3
 | 
			
		||||
theme_override_font_sizes/font_size = 24
 | 
			
		||||
text = "Player"
 | 
			
		||||
vertical_alignment = 1
 | 
			
		||||
 | 
			
		||||
[node name="ScoreTag" type="Label" parent="Panel/VBoxContainer"]
 | 
			
		||||
custom_minimum_size = Vector2(80, 80)
 | 
			
		||||
layout_mode = 2
 | 
			
		||||
size_flags_horizontal = 8
 | 
			
		||||
theme_override_font_sizes/font_size = 32
 | 
			
		||||
text = "0"
 | 
			
		||||
horizontal_alignment = 1
 | 
			
		||||
vertical_alignment = 1
 | 
			
		||||
@@ -8,6 +8,7 @@ public partial class World : Node2D
 | 
			
		||||
	[Export] public PackedScene PlayerScene;
 | 
			
		||||
 | 
			
		||||
	[Export] public int RoundCount = 1;
 | 
			
		||||
	[Export] public int RoundTotalCount = 20;
 | 
			
		||||
	[Export] public double RoundDuration = 60;
 | 
			
		||||
	[Export] public double RoundProgress;
 | 
			
		||||
	[Export] public double RoundTimeLeft;
 | 
			
		||||
@@ -106,6 +107,12 @@ public partial class World : Node2D
 | 
			
		||||
 | 
			
		||||
	private void NewRound()
 | 
			
		||||
	{
 | 
			
		||||
		if (RoundCount >= RoundTotalCount)
 | 
			
		||||
		{
 | 
			
		||||
			// TODO End this game
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		RoundCount++;
 | 
			
		||||
		foreach (var child in GetChildren())
 | 
			
		||||
		{
 | 
			
		||||
 
 | 
			
		||||
@@ -33,7 +33,7 @@ public partial class BootScreen : Control
 | 
			
		||||
		EmitSignal(SignalName.StartGame);
 | 
			
		||||
		var name = string.IsNullOrEmpty(PlayerNameInput.Text) ? null : PlayerNameInput.Text;
 | 
			
		||||
		// TODO Fix this I don't know why the first round player's name won't fully apply
 | 
			
		||||
		World.Scoreboard.SetName(Multiplayer.GetUniqueId(), name);
 | 
			
		||||
		World.Scoreboard.SetName(Multiplayer.GetUniqueId(), name ?? $"Player#{Multiplayer.GetUniqueId()}");
 | 
			
		||||
		World.StartGame(currentPlayerName: name);
 | 
			
		||||
		Hide();
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										63
									
								
								Scripts/UI/Leaderboard.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								Scripts/UI/Leaderboard.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,63 @@
 | 
			
		||||
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<Control>("List").GetChildCount() != Scoreboard.Players.Count)
 | 
			
		||||
		{
 | 
			
		||||
			CleanNodes();
 | 
			
		||||
			CreateNodes();
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		var place = 1;
 | 
			
		||||
		foreach (var node in GetNode<Control>("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<Control>("List").GetChildren())
 | 
			
		||||
		{
 | 
			
		||||
			child.QueueFree();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void CreateNodes()
 | 
			
		||||
	{
 | 
			
		||||
		var blueprint = GD.Load<PackedScene>("res://Scenes/UI/LeaderboardRecord.tscn");
 | 
			
		||||
		var place = 1;
 | 
			
		||||
		foreach (var record in Scoreboard.Players)
 | 
			
		||||
		{
 | 
			
		||||
			var instance = blueprint.Instantiate<LeaderboardRecord>();
 | 
			
		||||
			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++;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								Scripts/UI/LeaderboardRecord.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								Scripts/UI/LeaderboardRecord.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
using Godot;
 | 
			
		||||
 | 
			
		||||
namespace AceField.Scripts.UI;
 | 
			
		||||
 | 
			
		||||
public partial class LeaderboardRecord : Control
 | 
			
		||||
{
 | 
			
		||||
	[Export] public int Place;
 | 
			
		||||
	[Export] public string PlayerName;
 | 
			
		||||
	[Export] public int Score;
 | 
			
		||||
 | 
			
		||||
	[Export] public int PlayerId;
 | 
			
		||||
 | 
			
		||||
	public override void _Process(double delta)
 | 
			
		||||
	{
 | 
			
		||||
		GetNode<Label>("Panel/VBoxContainer/PlaceTag").Text = Place.ToString();
 | 
			
		||||
		GetNode<Label>("Panel/VBoxContainer/NameTag").Text = PlayerName;
 | 
			
		||||
		GetNode<Label>("Panel/VBoxContainer/ScoreTag").Text = Score.ToString();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -65,6 +65,11 @@ skill_place_tile={
 | 
			
		||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":2,"position":Vector2(174, 42),"global_position":Vector2(182, 122),"factor":1.0,"button_index":2,"canceled":false,"pressed":true,"double_click":false,"script":null)
 | 
			
		||||
]
 | 
			
		||||
}
 | 
			
		||||
ui_leaderboard={
 | 
			
		||||
"deadzone": 0.5,
 | 
			
		||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194306,"key_label":0,"unicode":0,"echo":false,"script":null)
 | 
			
		||||
]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[rendering]
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user