Implemented a score table (accessible via TAB)
parent
2c98b4b6be
commit
9bb149e1e4
|
@ -6,11 +6,33 @@ extends Control
|
||||||
# var a = 2
|
# var a = 2
|
||||||
# var b = "text"
|
# var b = "text"
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
pass # Replace with function body.
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
func update_score_table():
|
||||||
|
var scores = []
|
||||||
|
|
||||||
|
for i in main.player_list.players.keys():
|
||||||
|
scores.append(main.player_list.get(i).score)
|
||||||
|
|
||||||
|
scores.sort()
|
||||||
|
scores.reverse()
|
||||||
|
|
||||||
|
for i in scores:
|
||||||
|
for j in main.player_list.players.keys():
|
||||||
|
if main.player_list.get(j).score == i:
|
||||||
|
$ScoreTable/VBoxContainer/ScoreTab.text += str(i) + " - " + main.player_list.get(j).name + "\n"
|
||||||
|
|
||||||
|
func score_table(show := true):
|
||||||
|
|
||||||
|
if show:
|
||||||
|
$ScoreTable/VBoxContainer/ScoreTab.text = ''
|
||||||
|
update_score_table()
|
||||||
|
|
||||||
|
$ScoreTable.show()
|
||||||
|
else:
|
||||||
|
$ScoreTable.hide()
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
# if main.local_player == null: # player is dead ATM
|
# if main.local_player == null: # player is dead ATM
|
||||||
|
@ -25,3 +47,6 @@ func _process(delta):
|
||||||
$RespawnCountdown.visible = true
|
$RespawnCountdown.visible = true
|
||||||
else:
|
else:
|
||||||
$RespawnCountdown.visible = false
|
$RespawnCountdown.visible = false
|
||||||
|
|
||||||
|
if $ScoreTable.visible: # update the scores every frame when player is watching the score table
|
||||||
|
update_score_table()
|
||||||
|
|
|
@ -255,4 +255,53 @@ __meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[node name="ScoreTable" type="Panel" parent="."]
|
||||||
|
visible = false
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_top = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
anchor_bottom = 0.5
|
||||||
|
offset_left = -309.5
|
||||||
|
offset_top = -157.5
|
||||||
|
offset_right = 309.5
|
||||||
|
offset_bottom = 157.5
|
||||||
|
script = null
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="VBoxContainer" type="VBoxContainer" parent="ScoreTable"]
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
script = null
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Header" type="Label" parent="ScoreTable/VBoxContainer"]
|
||||||
|
offset_right = 619.0
|
||||||
|
offset_bottom = 26.0
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
size_flags_vertical = 5
|
||||||
|
text = "LE SCORE TABLE"
|
||||||
|
align = 1
|
||||||
|
structured_text_bidi_override_options = []
|
||||||
|
script = null
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="ScoreTab" type="RichTextLabel" parent="ScoreTable/VBoxContainer"]
|
||||||
|
offset_top = 30.0
|
||||||
|
offset_right = 619.0
|
||||||
|
offset_bottom = 315.0
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
size_flags_vertical = 3
|
||||||
|
custom_effects = []
|
||||||
|
structured_text_bidi_override_options = []
|
||||||
|
script = null
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
[connection signal="text_submitted" from="Chat/VBoxContainer/Typing/Editor" to="Chat" method="_on_Editor_text_submitted"]
|
[connection signal="text_submitted" from="Chat/VBoxContainer/Typing/Editor" to="Chat" method="_on_Editor_text_submitted"]
|
||||||
|
|
31
Game/Main.gd
31
Game/Main.gd
|
@ -1,13 +1,13 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
enum GameFocus {MENU, GAME, CHAT, AWAY}
|
enum GameFocus {MENU, GAME, CHAT, AWAY, SCORETAB}
|
||||||
enum NetworkRole {NONE, CLIENT, SERVER, DEDICATED_SERVER, RELAY_SERVER}
|
enum NetworkRole {NONE, CLIENT, SERVER, DEDICATED_SERVER, RELAY_SERVER}
|
||||||
|
|
||||||
|
|
||||||
const NET_PORT = 12597
|
const NET_PORT = 12597
|
||||||
|
|
||||||
const NET_SERVER = "liblast.unfa.xyz"
|
#const NET_SERVER = "liblast.unfa.xyz"
|
||||||
#const NET_SERVER = "localhost"
|
const NET_SERVER = "localhost"
|
||||||
|
|
||||||
var peer = ENetMultiplayerPeer.new()
|
var peer = ENetMultiplayerPeer.new()
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ var focus = GameFocus.MENU :
|
||||||
3:
|
3:
|
||||||
if local_player:
|
if local_player:
|
||||||
local_player.input_active = true
|
local_player.input_active = true
|
||||||
|
|
||||||
focus = new_focus
|
focus = new_focus
|
||||||
|
|
||||||
#@remote set_info(info) -> void:
|
#@remote set_info(info) -> void:
|
||||||
|
@ -169,8 +169,18 @@ func _input(_event) -> void:
|
||||||
focus = GameFocus.MENU
|
focus = GameFocus.MENU
|
||||||
elif focus == GameFocus.MENU:
|
elif focus == GameFocus.MENU:
|
||||||
focus = GameFocus.GAME
|
focus = GameFocus.GAME
|
||||||
|
|
||||||
#@remote func st(player_list):
|
if Input.is_action_just_pressed("show_scoretab"):
|
||||||
|
if focus == GameFocus.GAME:
|
||||||
|
focus = GameFocus.SCORETAB
|
||||||
|
hud.score_table(true)
|
||||||
|
|
||||||
|
elif Input.is_action_just_released("show_scoretab"):
|
||||||
|
if focus == GameFocus.SCORETAB:
|
||||||
|
focus = GameFocus.GAME
|
||||||
|
hud.score_table(false)
|
||||||
|
|
||||||
|
#@remote func update_player_list(player_list):
|
||||||
# self.player_list = player_list
|
# self.player_list = player_list
|
||||||
|
|
||||||
func game_over():
|
func game_over():
|
||||||
|
@ -211,7 +221,7 @@ func update_hud():
|
||||||
else:
|
else:
|
||||||
hud.get_node("ScoreRank").text += str(rank) + "\nGAP: " + str(-lead)
|
hud.get_node("ScoreRank").text += str(rank) + "\nGAP: " + str(-lead)
|
||||||
|
|
||||||
@rpc(any, reliable) func player_list_update(info, pid = get_tree().get_rpc_sender_id()):
|
@rpc(any) func player_list_update(info, pid = get_tree().get_rpc_sender_id()):
|
||||||
var new_info = PlayerInfo.new()
|
var new_info = PlayerInfo.new()
|
||||||
new_info.deserialize(info)
|
new_info.deserialize(info)
|
||||||
print("Recieved player info: ", info)
|
print("Recieved player info: ", info)
|
||||||
|
@ -240,7 +250,12 @@ func update_hud():
|
||||||
func push_local_player_info(): #
|
func push_local_player_info(): #
|
||||||
var id = get_tree().multiplayer.get_network_unique_id()
|
var id = get_tree().multiplayer.get_network_unique_id()
|
||||||
|
|
||||||
rpc(&'player_list_update', player_list.get(id).serialize(), get_tree().multiplayer.get_network_unique_id())
|
#print("PLayer info vsr2str: ", var2str(player_list.get(id)) )
|
||||||
|
|
||||||
|
if id != 1:
|
||||||
|
rpc_id(1, &'player_list_update', player_list.get(id).serialize(), get_tree().multiplayer.get_network_unique_id())
|
||||||
|
else:
|
||||||
|
rpc(&'player_list_update', player_list.get(id).serialize(), 1)
|
||||||
|
|
||||||
@rpc(sync,auth,reliable) func destroy_player(pid: int):
|
@rpc(sync,auth,reliable) func destroy_player(pid: int):
|
||||||
var player_node = $Players.get_node(str(pid))
|
var player_node = $Players.get_node(str(pid))
|
||||||
|
|
|
@ -29,6 +29,13 @@ structured_text_bidi_override_options = []
|
||||||
[node name="ScoreRank" parent="HUD" index="4"]
|
[node name="ScoreRank" parent="HUD" index="4"]
|
||||||
structured_text_bidi_override_options = []
|
structured_text_bidi_override_options = []
|
||||||
|
|
||||||
|
[node name="Header" parent="HUD/ScoreTable/VBoxContainer" index="0"]
|
||||||
|
structured_text_bidi_override_options = []
|
||||||
|
|
||||||
|
[node name="ScoreTab" parent="HUD/ScoreTable/VBoxContainer" index="1"]
|
||||||
|
custom_effects = []
|
||||||
|
structured_text_bidi_override_options = []
|
||||||
|
|
||||||
[node name="GUI" parent="." instance=ExtResource( "2" )]
|
[node name="GUI" parent="." instance=ExtResource( "2" )]
|
||||||
|
|
||||||
[node name="Players" type="Node3D" parent="."]
|
[node name="Players" type="Node3D" parent="."]
|
||||||
|
@ -95,21 +102,6 @@ __meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="Panel" type="Panel" parent="."]
|
|
||||||
visible = false
|
|
||||||
anchor_left = 0.5
|
|
||||||
anchor_top = 0.5
|
|
||||||
anchor_right = 0.5
|
|
||||||
anchor_bottom = 0.5
|
|
||||||
offset_left = -309.5
|
|
||||||
offset_top = -157.5
|
|
||||||
offset_right = 309.5
|
|
||||||
offset_bottom = 157.5
|
|
||||||
script = null
|
|
||||||
__meta__ = {
|
|
||||||
"_edit_use_anchors_": false
|
|
||||||
}
|
|
||||||
|
|
||||||
[node name="LightmapProbe" type="LightmapProbe" parent="."]
|
[node name="LightmapProbe" type="LightmapProbe" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 17, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 17, 0)
|
||||||
visible = false
|
visible = false
|
||||||
|
|
|
@ -121,6 +121,11 @@ say_cancel={
|
||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"pressed":false,"keycode":16777217,"physical_keycode":0,"unicode":0,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"pressed":false,"keycode":16777217,"physical_keycode":0,"unicode":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
show_scoretab={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"pressed":false,"keycode":16777218,"physical_keycode":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[layer_names]
|
[layer_names]
|
||||||
|
|
||||||
|
|
Reference in New Issue