mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-04-29 16:25:35 +00:00
Cleanup: move Scoreboard, it's not a HUD
This commit is contained in:
parent
2bd61aff8d
commit
3901a17f0e
3 changed files with 2 additions and 2 deletions
|
|
@ -1,84 +0,0 @@
|
|||
# This file is part of open-fpsz.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
class_name Scoreboard extends Control
|
||||
|
||||
@export var _entries : Dictionary = {}
|
||||
|
||||
class ScoreboardEntry:
|
||||
var nickname : String
|
||||
var kills : int
|
||||
var score : int
|
||||
var nickname_label : Label = Label.new()
|
||||
var kills_label : Label = Label.new()
|
||||
var score_label : Label = Label.new()
|
||||
|
||||
func _unhandled_input(event : InputEvent) -> void:
|
||||
if event.is_action_pressed("scoreboard"):
|
||||
show()
|
||||
elif event.is_action_released("scoreboard"):
|
||||
hide()
|
||||
|
||||
func add_player(player : Player) -> void:
|
||||
_add_scoreboard_entry.rpc(player.player_id, player.nickname)
|
||||
|
||||
func remove_player(player : Player) -> void:
|
||||
_remove_scoreboard_entry.rpc(player.player_id)
|
||||
|
||||
func increment_kill_count(player : Player) -> void:
|
||||
_entries[player.player_id].kills += 1
|
||||
|
||||
func add_score_to_player(player : Player, amount : int) -> void:
|
||||
var player_id : int = player.player_id
|
||||
var entry : ScoreboardEntry = _entries[player_id]
|
||||
_update_scoreboard_entry.rpc(player_id, entry.nickname, entry.kills, entry.score + amount)
|
||||
|
||||
@rpc("any_peer", "call_remote", "reliable")
|
||||
func request_scoreboard_from_authority() -> void:
|
||||
if is_multiplayer_authority():
|
||||
var recipient_id : int = multiplayer.get_remote_sender_id()
|
||||
for entry_player_id : int in _entries:
|
||||
var entry : ScoreboardEntry = _entries[entry_player_id]
|
||||
_add_scoreboard_entry.rpc_id(recipient_id, entry_player_id, entry.nickname, entry.kills, entry.score)
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func _add_scoreboard_entry(player_id : int, nickname : String, kills : int = 0, score : int = 0) -> void:
|
||||
var new_entry : ScoreboardEntry = ScoreboardEntry.new()
|
||||
_entries[player_id] = new_entry
|
||||
%Scores.add_child(new_entry.nickname_label)
|
||||
%Scores.add_child(new_entry.kills_label)
|
||||
%Scores.add_child(new_entry.score_label)
|
||||
_update_scoreboard_entry(player_id, nickname, kills, score)
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func _update_scoreboard_entry(player_id : int, nickname : String, kills : int, score : int) -> void:
|
||||
var entry : ScoreboardEntry = _entries[player_id]
|
||||
entry.nickname = nickname
|
||||
entry.kills = kills
|
||||
entry.score = score
|
||||
_update_scoreboard_entry_ui(player_id)
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func _remove_scoreboard_entry(player_id : int) -> void:
|
||||
var entry : ScoreboardEntry = _entries[player_id]
|
||||
entry.nickname_label.queue_free()
|
||||
entry.kills_label.queue_free()
|
||||
entry.score_label.queue_free()
|
||||
_entries.erase(player_id)
|
||||
|
||||
func _update_scoreboard_entry_ui(player_id : int) -> void:
|
||||
var entry : ScoreboardEntry = _entries[player_id]
|
||||
entry.nickname_label.text = entry.nickname
|
||||
entry.kills_label.text = str(entry.kills)
|
||||
entry.score_label.text = str(entry.score)
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://b8bosdd0o1lu7"]
|
||||
|
||||
[ext_resource type="Script" path="res://interfaces/hud/scoreboard.gd" id="1_k2wav"]
|
||||
|
||||
[node name="Scoreboard" 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_k2wav")
|
||||
|
||||
[node name="Panel" type="Panel" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="Panel"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_constants/margin_left = 64
|
||||
theme_override_constants/margin_top = 64
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="Panel/MarginContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="Panel/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
theme_type_variation = &"HeaderLarge"
|
||||
text = "Scoreboard"
|
||||
|
||||
[node name="Scores" type="GridContainer" parent="Panel/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
theme_override_constants/h_separation = 32
|
||||
theme_override_constants/v_separation = 16
|
||||
columns = 3
|
||||
|
||||
[node name="PlayerLabel" type="Label" parent="Panel/MarginContainer/VBoxContainer/Scores"]
|
||||
layout_mode = 2
|
||||
text = "Player"
|
||||
|
||||
[node name="KillsLabel" type="Label" parent="Panel/MarginContainer/VBoxContainer/Scores"]
|
||||
layout_mode = 2
|
||||
text = "Kills"
|
||||
|
||||
[node name="ScoreLabel" type="Label" parent="Panel/MarginContainer/VBoxContainer/Scores"]
|
||||
layout_mode = 2
|
||||
text = "Score"
|
||||
Loading…
Add table
Add a link
Reference in a new issue