mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-07-13 07:25:06 +00:00
👽 interstellar delivery
This commit is contained in:
parent
547c97bfba
commit
97c8292858
257 changed files with 7309 additions and 4637 deletions
35
interfaces/scoreboard/components/deathmatch.gd
Normal file
35
interfaces/scoreboard/components/deathmatch.gd
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# 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 DeathmatchScoringComponent extends Node
|
||||
|
||||
@export var ON_KILL_SCORE := Vector3i(1,0,0)
|
||||
|
||||
signal add_score(peer_id:int, score:Vector3i)
|
||||
|
||||
## This method returns a new bound deathmatch scoring component to be added in tree.
|
||||
func _init(scoreboard:Scoreboard, players: Node) -> void:
|
||||
add_score.connect(scoreboard.add_score)
|
||||
players.child_entered_tree.connect(register)
|
||||
players.child_exiting_tree.connect(unregister)
|
||||
|
||||
func register(player: Player) -> void:
|
||||
player.killed.connect(_on_player_killed)
|
||||
|
||||
func unregister(player: Player) -> void:
|
||||
player.killed.disconnect(_on_player_killed)
|
||||
|
||||
func _on_player_killed(victim: Player, killer:int) -> void:
|
||||
if victim.peer_id != killer:
|
||||
add_score.emit(killer, ON_KILL_SCORE)
|
||||
56
interfaces/scoreboard/components/rabbit.gd
Normal file
56
interfaces/scoreboard/components/rabbit.gd
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
# 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/>.
|
||||
## This defines a rabbit scoring component.
|
||||
class_name RabbitScoringComponent extends Node
|
||||
|
||||
const ON_GRAB_SCORE := Vector3i(1,0,0)
|
||||
const ON_HOLD_SCORE := Vector3i(1,0,0)
|
||||
const HOLD_SCORING_TIMER:float = 10.0 # seconds
|
||||
|
||||
var timer:= Timer.new()
|
||||
|
||||
signal add_score(peer_id:int, score:Vector3i)
|
||||
|
||||
# @TODO: remove this variable by passing flag to signals `grabbed` and `dropped`
|
||||
# this if fine for rabbit but will be required for CTF
|
||||
var _flag: Flag
|
||||
|
||||
# This method initializes a new rabbit scoring component.
|
||||
func _init(scoreboard:Scoreboard, flag:Flag) -> void:
|
||||
timer.timeout.connect(_on_timer_timeout.bind(flag))
|
||||
add_score.connect(scoreboard.add_score)
|
||||
flag.grabbed.connect(_on_flag_grabbed)
|
||||
flag.dropped.connect(_on_flag_dropped)
|
||||
_flag = flag
|
||||
|
||||
func _ready() -> void:
|
||||
add_child(timer)
|
||||
|
||||
func _on_flag_grabbed(carry: FlagCarryComponent) -> void:
|
||||
assert(_flag)
|
||||
# prevent chained grab scoring abuse
|
||||
if _flag and (not _flag.last_carrier or _flag.last_carrier.owner.peer_id != carry.owner.peer_id):
|
||||
# set new carrier for `_on_timer_timeout`
|
||||
_flag.last_carrier = carry
|
||||
add_score.emit(carry.owner.peer_id, ON_GRAB_SCORE)
|
||||
timer.start(HOLD_SCORING_TIMER)
|
||||
|
||||
func _on_flag_dropped(_carry: FlagCarryComponent) -> void:
|
||||
assert(_flag)
|
||||
timer.stop()
|
||||
|
||||
func _on_timer_timeout(flag:Flag) -> void:
|
||||
assert(_flag)
|
||||
add_score.emit(flag.last_carrier.owner.peer_id, ON_HOLD_SCORE)
|
||||
21
interfaces/scoreboard/ping_label.gd
Normal file
21
interfaces/scoreboard/ping_label.gd
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# 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 PingLabel extends Label
|
||||
|
||||
@export var entry : ScorePanelEntry
|
||||
|
||||
func _on_sync(state: Dictionary) -> void:
|
||||
if entry.peer_id in state: # update clients only
|
||||
text = str(state[entry.peer_id])
|
||||
80
interfaces/scoreboard/score_panel.gd
Normal file
80
interfaces/scoreboard/score_panel.gd
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
# 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/>.
|
||||
## This defines a score panel to hold [ScorePanelEntry] instances.
|
||||
class_name ScorePanel extends Panel
|
||||
|
||||
# The ScorePanelEntry packed scene to instantiate
|
||||
@export var _SCORE_PANEL_ENTRY:PackedScene
|
||||
## This is the panel title.
|
||||
@export var title:Label
|
||||
## This is the container for [ScorePanelEntry] child nodes.
|
||||
@export var entries:VBoxContainer
|
||||
|
||||
# This is the iterator index cursor.
|
||||
var _iter_cursor:int = 0
|
||||
|
||||
# This method is an iterator initializer.
|
||||
func _iter_init(_arg:Variant) -> bool:
|
||||
_iter_cursor = 0 # reset
|
||||
return _iter_cursor < entries.get_child_count()
|
||||
|
||||
# This method checks if the iterator has a next value.
|
||||
func _iter_next(_arg:Variant) -> bool:
|
||||
_iter_cursor += 1
|
||||
return _iter_cursor < entries.get_child_count()
|
||||
|
||||
# This method gets the next iterator value.
|
||||
func _iter_get(_arg:Variant) -> ScorePanelEntry:
|
||||
return entries.get_child(_iter_cursor)
|
||||
|
||||
func _to_string() -> String:
|
||||
return "<ScorePanel#%s>" % get_instance_id()
|
||||
|
||||
## This method adds an entry to the panel.
|
||||
func add_entry(peer_id:int, username:String, score:Vector3i = Vector3i.ZERO) -> ScorePanelEntry:
|
||||
var entry:ScorePanelEntry = _SCORE_PANEL_ENTRY.instantiate()
|
||||
entry.name = str(peer_id)
|
||||
entry.peer_id = peer_id
|
||||
entries.add_child(entry)
|
||||
entry.ping.text = "" # @TODO: get player ping
|
||||
entry._username = username
|
||||
entry._score = score
|
||||
return entry
|
||||
|
||||
## This method removes a [ScorePanelEntry] from the [ScorePanel].
|
||||
func remove_entry(entry:ScorePanelEntry) -> void:
|
||||
entries.remove_child(entry)
|
||||
entry.free()
|
||||
|
||||
## This method returns a [ScorePanelEntry] from the [ScorePanel].
|
||||
func get_entry(index:int) -> ScorePanelEntry:
|
||||
return entries.get_child(index)
|
||||
|
||||
## This method removes a [ScorePanelEntry] from the [ScorePanel] by [param name]
|
||||
## and returns a boolean to indicate removal state.
|
||||
func remove_entry_by_name(entry_name:String) -> bool:
|
||||
var path := NodePath(entry_name)
|
||||
if entries.has_node(path):
|
||||
var entry:ScorePanelEntry = entries.get_node(path)
|
||||
remove_entry(entry)
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
|
||||
func remove_entry_by_peer_id(peer_id:int) -> bool:
|
||||
return remove_entry_by_name(str(peer_id))
|
||||
|
||||
func size() -> int:
|
||||
return entries.get_child_count()
|
||||
66
interfaces/scoreboard/score_panel.tscn
Normal file
66
interfaces/scoreboard/score_panel.tscn
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://p1q2lu7mtte1"]
|
||||
|
||||
[ext_resource type="Script" path="res://interfaces/scoreboard/score_panel.gd" id="1_diy54"]
|
||||
[ext_resource type="PackedScene" uid="uid://bu186wanwk1kh" path="res://interfaces/scoreboard/score_panel_entry.tscn" id="2_54ms2"]
|
||||
|
||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_bhp7i"]
|
||||
properties/0/path = NodePath("MarginContainer/VBoxContainer/Title:text")
|
||||
properties/0/spawn = true
|
||||
properties/0/replication_mode = 2
|
||||
properties/1/path = NodePath("MarginContainer/VBoxContainer/Title:visible")
|
||||
properties/1/spawn = true
|
||||
properties/1/replication_mode = 2
|
||||
|
||||
[node name="ScorePanel" type="Panel" node_paths=PackedStringArray("title", "entries")]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
mouse_filter = 2
|
||||
script = ExtResource("1_diy54")
|
||||
_SCORE_PANEL_ENTRY = ExtResource("2_54ms2")
|
||||
title = NodePath("MarginContainer/VBoxContainer/Title")
|
||||
entries = NodePath("MarginContainer/VBoxContainer/Entries")
|
||||
|
||||
[node name="ScorePanelSync" type="MultiplayerSynchronizer" parent="."]
|
||||
replication_interval = 1.0
|
||||
delta_interval = 1.0
|
||||
replication_config = SubResource("SceneReplicationConfig_bhp7i")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
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 = 10
|
||||
theme_override_constants/margin_top = 10
|
||||
theme_override_constants/margin_right = 10
|
||||
theme_override_constants/margin_bottom = 10
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Title" type="Label" parent="MarginContainer/VBoxContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
theme_type_variation = &"HeaderSmall"
|
||||
text = "PANEL TITLE"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
uppercase = true
|
||||
|
||||
[node name="Headers" parent="MarginContainer/VBoxContainer" instance=ExtResource("2_54ms2")]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Entries" type="VBoxContainer" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="EntrySpawner" type="MultiplayerSpawner" parent="MarginContainer/VBoxContainer"]
|
||||
_spawnable_scenes = PackedStringArray("res://interfaces/scoreboard/score_panel_entry.tscn")
|
||||
spawn_path = NodePath("../Entries")
|
||||
61
interfaces/scoreboard/score_panel_entry.gd
Normal file
61
interfaces/scoreboard/score_panel_entry.gd
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
# 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 ScorePanelEntry extends HBoxContainer
|
||||
|
||||
@export var scoring: bool = true
|
||||
|
||||
@export var _ping : int:
|
||||
set = set_ping
|
||||
@export var _username : String:
|
||||
set = set_username
|
||||
@export var _score : Vector3i = Vector3i.ZERO:
|
||||
set = set_score
|
||||
|
||||
@export var ping : PingLabel
|
||||
@export var username : Label
|
||||
@export var offense : Label
|
||||
@export var defense : Label
|
||||
@export var style : Label
|
||||
@export var score : Label
|
||||
|
||||
var peer_id : int
|
||||
|
||||
func get_total() -> int:
|
||||
return _score.x + _score.y + _score.z
|
||||
|
||||
func _to_string() -> String:
|
||||
return "<ScorePanelEntry(%s)#%s>" % [name, get_instance_id()]
|
||||
|
||||
# setters
|
||||
|
||||
func set_username(new_username : String) -> void:
|
||||
_username = new_username
|
||||
username.text = new_username
|
||||
|
||||
func set_ping(new_ping : int) -> void:
|
||||
_ping = new_ping
|
||||
ping.text = str(_ping)
|
||||
|
||||
func set_score(new_score : Vector3i) -> void:
|
||||
if scoring:
|
||||
_score = new_score
|
||||
offense.text = str(_score.x)
|
||||
defense.text = str(_score.y)
|
||||
style.text = str(_score.z)
|
||||
score.text = str(get_total())
|
||||
|
||||
# This is called when the Scoreboard.scoring_state_changed signal is emmitted
|
||||
func _on_scoring_state_changed(new_scoring: bool) -> void:
|
||||
scoring = new_scoring
|
||||
92
interfaces/scoreboard/score_panel_entry.tscn
Normal file
92
interfaces/scoreboard/score_panel_entry.tscn
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://bu186wanwk1kh"]
|
||||
|
||||
[ext_resource type="Script" path="res://interfaces/scoreboard/score_panel_entry.gd" id="1_ohfvg"]
|
||||
[ext_resource type="Script" path="res://interfaces/scoreboard/ping_label.gd" id="2_rlg8k"]
|
||||
|
||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_hpwcf"]
|
||||
properties/0/path = NodePath("Ping:text")
|
||||
properties/0/spawn = true
|
||||
properties/0/replication_mode = 2
|
||||
properties/1/path = NodePath("Username:text")
|
||||
properties/1/spawn = true
|
||||
properties/1/replication_mode = 2
|
||||
properties/2/path = NodePath("Offense:text")
|
||||
properties/2/spawn = true
|
||||
properties/2/replication_mode = 2
|
||||
properties/3/path = NodePath("Defense:text")
|
||||
properties/3/spawn = true
|
||||
properties/3/replication_mode = 2
|
||||
properties/4/path = NodePath("Style:text")
|
||||
properties/4/spawn = true
|
||||
properties/4/replication_mode = 2
|
||||
properties/5/path = NodePath("Score:text")
|
||||
properties/5/spawn = true
|
||||
properties/5/replication_mode = 2
|
||||
|
||||
[node name="Entry" type="HBoxContainer" node_paths=PackedStringArray("ping", "username", "offense", "defense", "style", "score")]
|
||||
anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
offset_bottom = 17.0
|
||||
grow_horizontal = 2
|
||||
script = ExtResource("1_ohfvg")
|
||||
ping = NodePath("Ping")
|
||||
username = NodePath("Username")
|
||||
offense = NodePath("Offense")
|
||||
defense = NodePath("Defense")
|
||||
style = NodePath("Style")
|
||||
score = NodePath("Score")
|
||||
|
||||
[node name="EntrySync" type="MultiplayerSynchronizer" parent="."]
|
||||
replication_interval = 0.5
|
||||
delta_interval = 0.5
|
||||
replication_config = SubResource("SceneReplicationConfig_hpwcf")
|
||||
|
||||
[node name="Ping" type="Label" parent="." node_paths=PackedStringArray("entry")]
|
||||
custom_minimum_size = Vector2(64, 0)
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 12
|
||||
text = "PING"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
script = ExtResource("2_rlg8k")
|
||||
entry = NodePath("..")
|
||||
|
||||
[node name="Username" type="Label" parent="."]
|
||||
custom_minimum_size = Vector2(128, 0)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_font_sizes/font_size = 12
|
||||
text = "USERNAME"
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="Offense" type="Label" parent="."]
|
||||
custom_minimum_size = Vector2(32, 0)
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 12
|
||||
text = "O"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="Defense" type="Label" parent="."]
|
||||
custom_minimum_size = Vector2(32, 0)
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 12
|
||||
text = "D"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="Style" type="Label" parent="."]
|
||||
custom_minimum_size = Vector2(32, 0)
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 12
|
||||
text = "S"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="Score" type="Label" parent="."]
|
||||
custom_minimum_size = Vector2(96, 0)
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 12
|
||||
text = "SCORE"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
|
@ -12,73 +12,118 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
## This defines a scoreboard to track players, scores and teams.
|
||||
## It is a container for [ScorePanel] instances.
|
||||
class_name Scoreboard extends Control
|
||||
|
||||
@export var _entries : Dictionary = {}
|
||||
signal scoring_state_changed(new_scoring: bool)
|
||||
|
||||
class ScoreboardEntry:
|
||||
var username : String
|
||||
var kills : int
|
||||
var score : int
|
||||
var username_label : Label = Label.new()
|
||||
var kills_label : Label = Label.new()
|
||||
var score_label : Label = Label.new()
|
||||
# The score panel scene to spawn.
|
||||
@export var _SCORE_PANEL: PackedScene
|
||||
## This is the container for [ScorePanel] child nodes.
|
||||
@export var panels: GridContainer
|
||||
## This controls whether [Entry] scores can be updated or not.
|
||||
@export var scoring: bool:
|
||||
set = set_scoring
|
||||
|
||||
func set_scoring(new_scoring: bool) -> void:
|
||||
scoring = new_scoring
|
||||
scoring_state_changed.emit(scoring)
|
||||
|
||||
func _unhandled_input(event : InputEvent) -> void:
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("scoreboard"):
|
||||
show()
|
||||
elif event.is_action_released("scoreboard"):
|
||||
hide()
|
||||
|
||||
func _ready() -> void:
|
||||
panels.child_entered_tree.connect(_on_score_panel_added)
|
||||
panels.child_exiting_tree.connect(_on_score_panel_removed)
|
||||
|
||||
func add_participant(participant : MatchParticipant) -> void:
|
||||
_add_scoreboard_entry.rpc(participant.player_id, participant.username)
|
||||
func _on_score_panel_added(panel: ScorePanel) -> void:
|
||||
if not panel.entries.child_entered_tree.is_connected(_on_entry_added):
|
||||
panel.entries.child_entered_tree.connect(_on_entry_added)
|
||||
|
||||
func remove_participant(participant : MatchParticipant) -> void:
|
||||
_remove_scoreboard_entry.rpc(participant.player_id)
|
||||
func _on_score_panel_removed(panel: ScorePanel) -> void:
|
||||
if panel.entries.child_entered_tree.is_connected(_on_entry_added):
|
||||
panel.entries.child_entered_tree.disconnect(_on_entry_added)
|
||||
|
||||
func _on_entry_added(entry: ScorePanelEntry) -> void:
|
||||
if not scoring_state_changed.is_connected(entry._on_scoring_state_changed):
|
||||
scoring_state_changed.connect(entry._on_scoring_state_changed)
|
||||
|
||||
func _on_entry_removed(entry: ScorePanelEntry) -> void:
|
||||
if scoring_state_changed.is_connected(entry._on_scoring_state_changed):
|
||||
scoring_state_changed.disconnect(entry._on_scoring_state_changed)
|
||||
|
||||
func increment_kill_count(participant : MatchParticipant) -> void:
|
||||
_entries[participant.player_id].kills += 1
|
||||
func _on_ping_sync(state: Dictionary) -> void:
|
||||
for panel: ScorePanel in panels.get_children():
|
||||
for entry in panel:
|
||||
entry.ping._on_sync(state)
|
||||
|
||||
func add_score_to_player(participant : MatchParticipant, amount : int) -> void:
|
||||
var player_id : int = participant.player_id
|
||||
var entry : ScoreboardEntry = _entries[player_id]
|
||||
_update_scoreboard_entry.rpc(player_id, entry.username, entry.kills, entry.score + amount)
|
||||
func _to_string() -> String:
|
||||
return "<Scoreboard#%s>" % get_instance_id()
|
||||
|
||||
@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.username, entry.kills, entry.score)
|
||||
## This method adds a [ScorePanel] to the [Scoreboard] and returns a reference to the added [ScorePanel].
|
||||
func add_panel(panel_name : String = "") -> ScorePanel:
|
||||
var score_panel: ScorePanel = _SCORE_PANEL.instantiate()
|
||||
var score_panel_name := str(panel_name)
|
||||
if score_panel_name.is_valid_identifier():
|
||||
score_panel.name = score_panel_name
|
||||
panels.add_child(score_panel)
|
||||
panels.columns = 2 if panels.get_child_count() > 2 else panels.get_child_count()
|
||||
return score_panel
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func _add_scoreboard_entry(player_id : int, username : String, kills : int = 0, score : int = 0) -> void:
|
||||
var new_entry : ScoreboardEntry = ScoreboardEntry.new()
|
||||
_entries[player_id] = new_entry
|
||||
%Scores.add_child(new_entry.username_label)
|
||||
%Scores.add_child(new_entry.kills_label)
|
||||
%Scores.add_child(new_entry.score_label)
|
||||
_update_scoreboard_entry(player_id, username, kills, score)
|
||||
## This method removes a [ScorePanel] from the [Scoreboard].
|
||||
func remove_panel(panel: ScorePanel) -> void:
|
||||
panels.remove_child(panel)
|
||||
panel.free()
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func _update_scoreboard_entry(player_id : int, username : String, kills : int, score : int) -> void:
|
||||
var entry : ScoreboardEntry = _entries[player_id]
|
||||
entry.username = username
|
||||
entry.kills = kills
|
||||
entry.score = score
|
||||
_update_scoreboard_entry_ui(player_id)
|
||||
## This method returns a [ScorePanel] from the [Scoreboard].
|
||||
func get_panel(index: int) -> ScorePanel:
|
||||
return panels.get_child(index)
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func _remove_scoreboard_entry(player_id : int) -> void:
|
||||
var entry : ScoreboardEntry = _entries[player_id]
|
||||
entry.username_label.queue_free()
|
||||
entry.kills_label.queue_free()
|
||||
entry.score_label.queue_free()
|
||||
_entries.erase(player_id)
|
||||
## This method removes an entry by its node name in the tree.
|
||||
func remove_entry_by_name(entry_name: String) -> bool:
|
||||
for panel : ScorePanel in panels.get_children():
|
||||
if panel.remove_entry_by_name(entry_name):
|
||||
return true
|
||||
return false
|
||||
|
||||
func _update_scoreboard_entry_ui(player_id : int) -> void:
|
||||
var entry : ScoreboardEntry = _entries[player_id]
|
||||
entry.username_label.text = entry.username
|
||||
entry.kills_label.text = str(entry.kills)
|
||||
entry.score_label.text = str(entry.score)
|
||||
func get_entry(peer_id: int) -> ScorePanelEntry:
|
||||
for panel : ScorePanel in panels.get_children():
|
||||
for entry in panel:
|
||||
if entry.peer_id == peer_id:
|
||||
return entry
|
||||
return null
|
||||
|
||||
## This method returns the score of the given [param peer_id].
|
||||
func get_score(peer_id: int) -> Vector3i:
|
||||
var entry : ScorePanelEntry = get_entry(peer_id)
|
||||
return entry._score if entry else Vector3i.ZERO
|
||||
|
||||
## This method sets the score of the given [param peer_id].
|
||||
func set_score(peer_id:int, score:Vector3i) -> bool:
|
||||
var entry : ScorePanelEntry = get_entry(peer_id)
|
||||
if entry:
|
||||
entry._score = score
|
||||
return true
|
||||
return false
|
||||
|
||||
## This method adds to the score of the given [param peer_id].
|
||||
func add_score(peer_id:int, score:Vector3i) -> bool:
|
||||
var entry : ScorePanelEntry = get_entry(peer_id)
|
||||
if entry:
|
||||
entry._score += score
|
||||
return true
|
||||
return false
|
||||
|
||||
## This method resets the scores of all [Entry] nodes.
|
||||
func reset_scores() -> void:
|
||||
for panel : ScorePanel in panels.get_children():
|
||||
for entry in panel:
|
||||
entry._score = Vector3.ZERO
|
||||
|
||||
## This method returns the number of [ScorePanel] children.
|
||||
func size() -> int:
|
||||
return panels.get_child_count()
|
||||
|
|
|
|||
|
|
@ -1,8 +1,16 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://b8bosdd0o1lu7"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://b8bosdd0o1lu7"]
|
||||
|
||||
[ext_resource type="Script" path="res://interfaces/scoreboard/scoreboard.gd" id="1_k2wav"]
|
||||
[ext_resource type="Theme" uid="uid://bec7g0fax3c8o" path="res://interfaces/global_theme.tres" id="1_p81gx"]
|
||||
[ext_resource type="PackedScene" uid="uid://p1q2lu7mtte1" path="res://interfaces/scoreboard/score_panel.tscn" id="2_oa7t6"]
|
||||
|
||||
[node name="Scoreboard" type="Control"]
|
||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_jx1ww"]
|
||||
properties/0/path = NodePath(".:columns")
|
||||
properties/0/spawn = true
|
||||
properties/0/replication_mode = 2
|
||||
|
||||
[node name="Scoreboard" type="Control" node_paths=PackedStringArray("panels")]
|
||||
visible = false
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
|
|
@ -10,9 +18,12 @@ anchor_bottom = 1.0
|
|||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("1_p81gx")
|
||||
script = ExtResource("1_k2wav")
|
||||
_SCORE_PANEL = ExtResource("2_oa7t6")
|
||||
panels = NodePath("MarginContainer/VBoxContainer/ScorePanels")
|
||||
|
||||
[node name="Panel" type="Panel" parent="."]
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
|
|
@ -20,45 +31,51 @@ anchor_bottom = 1.0
|
|||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
theme_override_constants/margin_left = 12
|
||||
theme_override_constants/margin_top = 12
|
||||
theme_override_constants/margin_right = 12
|
||||
theme_override_constants/margin_bottom = 12
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="Panel"]
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="Header" type="Panel" parent="MarginContainer/VBoxContainer"]
|
||||
custom_minimum_size = Vector2(0, 48)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/Header"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -76.5
|
||||
offset_top = -19.5
|
||||
offset_right = 76.5
|
||||
offset_bottom = 19.5
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
theme_override_constants/margin_left = 64
|
||||
theme_override_constants/margin_top = 64
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="Panel/MarginContainer"]
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="Label" type="Label" parent="Panel/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
theme_type_variation = &"HeaderLarge"
|
||||
text = "Scoreboard"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
uppercase = true
|
||||
|
||||
[node name="Scores" type="GridContainer" parent="Panel/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
[node name="ScorePanels" type="GridContainer" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 3
|
||||
mouse_filter = 2
|
||||
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="PanelSpawner" type="MultiplayerSpawner" parent="MarginContainer/VBoxContainer"]
|
||||
_spawnable_scenes = PackedStringArray("res://interfaces/scoreboard/score_panel.tscn")
|
||||
spawn_path = NodePath("../ScorePanels")
|
||||
spawn_limit = 4
|
||||
|
||||
[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"
|
||||
[node name="ScoreboardSync" type="MultiplayerSynchronizer" parent="MarginContainer/VBoxContainer"]
|
||||
root_path = NodePath("../ScorePanels")
|
||||
replication_interval = 1.0
|
||||
delta_interval = 1.0
|
||||
replication_config = SubResource("SceneReplicationConfig_jx1ww")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue