Browse Source

Upgraded the score table, players now report their ping and packet loss

test/collision-test
unfa 5 months ago
parent
commit
a661669d2f
  1. 77
      Asset Sources/HUD/theme.tres
  2. 42
      Game/Assets/HUD/HUD.gd
  3. 7
      Game/Assets/HUD/Performance.gd
  4. 12
      Game/Main.gd
  5. 8
      Game/Main.tscn

77
Asset Sources/HUD/theme.tres

@ -0,0 +1,77 @@
[gd_resource type="Theme" load_steps=7 format=2]
[ext_resource path="res://Assets/Fonts/Roboto_Condensed/RobotoCondensed-Regular-dynamic.tres" type="DynamicFont" id=1]
[sub_resource type="StyleBoxFlat" id=1]
[sub_resource type="StyleBoxFlat" id=2]
bg_color = Color( 0.113725, 0.0784314, 0.0392157, 0.513726 )
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
[sub_resource type="StyleBoxFlat" id=3]
bg_color = Color( 0.172549, 0.109804, 0.109804, 0.372549 )
border_width_left = 5
border_width_top = 5
border_width_right = 5
border_width_bottom = 5
border_color = Color( 0, 0, 0, 1 )
border_blend = true
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
corner_detail = 5
shadow_color = Color( 0.113725, 0.0862745, 0.0235294, 0.6 )
[sub_resource type="StyleBoxFlat" id=4]
bg_color = Color( 0.168627, 0.105882, 0.0470588, 0.611765 )
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
shadow_size = 1
shadow_offset = Vector2( 2, 2 )
[sub_resource type="StyleBoxFlat" id=5]
bg_color = Color( 0.172549, 0.109804, 0.109804, 0.372549 )
border_width_left = 5
border_width_top = 5
border_width_right = 5
border_width_bottom = 5
border_color = Color( 0, 0, 0, 1 )
border_blend = true
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
[resource]
default_font = ExtResource( 1 )
Button/colors/font_color = Color( 0.88, 0.88, 0.88, 1 )
Button/colors/font_color_disabled = Color( 0.9, 0.9, 0.9, 0.2 )
Button/colors/font_color_hover = Color( 0.94, 0.94, 0.94, 1 )
Button/colors/font_color_pressed = Color( 1, 1, 1, 1 )
Button/constants/hseparation = 2
Button/fonts/font = null
Button/styles/disabled = null
Button/styles/focus = SubResource( 1 )
Button/styles/hover = SubResource( 2 )
Button/styles/normal = SubResource( 3 )
Button/styles/pressed = SubResource( 4 )
LineEdit/colors/Test = Color( 0, 0, 0, 1 )
LineEdit/colors/clear_button_color = Color( 0.88, 0.88, 0.88, 1 )
LineEdit/colors/clear_button_color_pressed = Color( 1, 1, 1, 1 )
LineEdit/colors/cursor_color = Color( 0.94, 0.94, 0.94, 1 )
LineEdit/colors/font_color = Color( 0.88, 0.88, 0.88, 1 )
LineEdit/colors/font_color_selected = Color( 0, 0, 0, 1 )
LineEdit/colors/font_color_uneditable = Color( 0.88, 0.88, 0.88, 0.5 )
LineEdit/colors/selection_color = Color( 0.49, 0.49, 0.49, 1 )
LineEdit/constants/minimum_spaces = 12
LineEdit/fonts/font = null
LineEdit/icons/clear = null
LineEdit/styles/focus = null
LineEdit/styles/normal = SubResource( 5 )
LineEdit/styles/read_only = null

42
Game/Assets/HUD/HUD.gd

@ -30,26 +30,50 @@ func hide():
func show():
$Crosshair.show()
$Chat.show()
func get_pid_info(pid: int) -> Dictionary:
var player_name = main.player_list.get(pid).name
var player_color = main.player_list.get(pid).color
var ping = main.player_list.get(pid).ping
if not ping:
ping = "?"
var packet_loss = main.player_list.get(pid).packet_loss
if not packet_loss:
packet_loss = "?"
return {
'name' = player_name,
'color' = player_color,
'ping' = ping,
'loss' = packet_loss,
}
func update_scoretab():
$ScoreTable/VBoxContainer/ScoreTab.text = ''
var scores = []
for i in main.player_list.players.keys():
scores.append(main.player_list.get(i).score)
for pid in main.player_list.players.keys():
scores.append(main.player_list.get(pid).score)
scores.sort()
scores.reverse()
var done = []
for i in scores:
for j in main.player_list.players.keys():
if main.player_list.get(j).score == i:
if j not in done:
$ScoreTable/VBoxContainer/ScoreTab.text += str(i) + " - " + main.player_list.get(j).name + "\n"
done.append(j)
for score in scores:
for pid in main.player_list.players.keys():
if main.player_list.get(pid).score == score:
if pid not in done:
var info = get_pid_info(pid)
# var j_name = main.player_list.get(j).name
# var j_peer = get_tree().multiplayer.multiplayer_peer.get_peer(j as int)
# var j_ping = "?"
# var j_packet_loss = "?"
# if j_peer:
# j_ping = j_peer.get_statistic(ENetPacketPeer.PEER_ROUND_TRIP_TIME)
# j_packet_loss = j_peer.get_statistic(ENetPacketPeer.PEER_PACKET_LOSS)
$ScoreTable/VBoxContainer/ScoreTab.text += "[b]" + str(score) + "[color=" + Color(info['color']).to_html() + "] - " + info['name'] + "[/color][/b]" + " (" + str(info['ping']) + " ms · " + str(info['loss']) +")\n"
done.append(pid)
func scoretab(show: bool, winner = null):
if show:

7
Game/Assets/HUD/Performance.gd

@ -27,11 +27,18 @@ func _process(delta):
text += str(peers) + " peers"
else:
text = "Connected · "
#print(get_multiplayer_authority())
var own_peer = get_tree().multiplayer.multiplayer_peer.get_peer(get_multiplayer_authority())
var ping = own_peer.get_statistic(ENetPacketPeer.PEER_ROUND_TRIP_TIME)
var packet_loss = own_peer.get_statistic(ENetPacketPeer.PEER_PACKET_LOSS)
text += str(ping) + " ms · " + str(packet_loss)
# propagate this info
var local_pid = get_tree().multiplayer.get_unique_id()
if main.local_player and main.player_list.players.has(local_pid):
main.player_list.players[local_pid].ping = ping
main.player_list.players[local_pid].packet_loss = packet_loss
main.push_local_player_info()
text += "\nFPS: " + str(Engine.get_frames_per_second())

12
Game/Main.gd

@ -34,6 +34,8 @@ class PlayerInfo:
var focus: GameFocus
var health: int
var score: int
var ping: int
var packet_loss: int
func _init():#name: String, team: int, color: Color):
# var player_name = ""
@ -45,6 +47,8 @@ class PlayerInfo:
self.focus = 999
self.health = 100
self.score = 0
self.ping = -1
self.packet_loss = -1
func serialize():
return {
@ -54,14 +58,18 @@ class PlayerInfo:
'focus': self.focus,
'health': self.health,
'score': self.score,
'ping': self.ping,
'loss': self.packet_loss,
}
func set(name: String, team: int, color: Color, focus: int, health: int, score: int):
func set(name: String, team: int, color: Color, focus: int, health: int, score: int, ping: int, packet_loss: int):
self.name = name
self.team = team
self.color = color
self.focus = focus
self.health = health
self.score = score
self.ping = ping
self.packet_loss = packet_loss
func deserialize(info):
self.name = info['name']
@ -70,6 +78,8 @@ class PlayerInfo:
self.focus = info['focus']
self.health = info['health']
self.score = info['score']
self.ping = info['ping']
self.packet_loss = info['loss']
#func generate():
var uptime = 0 # seconds

8
Game/Main.tscn

@ -1,11 +1,12 @@
[gd_scene load_steps=23 format=3 uid="uid://o68cawatyat2"]
[gd_scene load_steps=24 format=3 uid="uid://o68cawatyat2"]
[ext_resource type="PackedScene" uid="uid://b856vwmg8a6o4" path="res://Assets/UI/GUI.tscn" id="2"]
[ext_resource type="Script" path="res://Main.gd" id="3"]
[ext_resource type="Theme" uid="uid://ddtu7o1dbp0s8" path="res://Assets/HUD/Theme.tres" id="3_eicet"]
[ext_resource type="PackedScene" uid="uid://bs80rhfpgh2m2" path="res://Assets/HUD/HUD.tscn" id="4"]
[ext_resource type="AudioStream" uid="uid://j42e203vte7h" path="res://Assets/Announcer/Go.wav" id="5_ilayd"]
[ext_resource type="Script" path="res://Assets/Announcer/Announcer.gd" id="6_gcsgr"]
[ext_resource type="PackedScene" uid="uid://b7txmrrvh1q4e" path="res://Assets/Maps/DM1.tscn" id="7_yvic5"]
[ext_resource type="PackedScene" uid="uid://dm18jgmxy1b78" path="res://Assets/Maps/DM1.tscn" id="7_yvic5"]
[sub_resource type="VisualShaderNodeFloatFunc" id="VisualShaderNodeFloatFunc_6ihsi"]
function = 31
@ -192,6 +193,9 @@ theme_override_font_sizes/font_size = 30
[node name="ScoreTab" parent="HUD/ScoreTable/VBoxContainer" index="1"]
offset_top = 49.0
theme = ExtResource( "3_eicet" )
theme_override_font_sizes/normal_font_size = 16
bbcode_enabled = true
[node name="GUI" parent="." instance=ExtResource( "2" )]
anchor_left = 0.1