From 3acbd84bc3c7ac4dc4a03cc360bc0403c9655123 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 18 Mar 2024 07:23:17 +0100 Subject: [PATCH] done --- scenes/hole_score.tscn | 4 +++ scenes/main.gd | 19 ++++++++++-- scenes/putt_controller.gd | 1 + scenes/results_menu.gd | 61 +++++++++++++++++++++++++++++++++++++++ scenes/results_menu.tscn | 60 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 scenes/hole_score.tscn create mode 100644 scenes/results_menu.gd create mode 100644 scenes/results_menu.tscn diff --git a/scenes/hole_score.tscn b/scenes/hole_score.tscn new file mode 100644 index 0000000..bd6f540 --- /dev/null +++ b/scenes/hole_score.tscn @@ -0,0 +1,4 @@ +[gd_scene format=3 uid="uid://c4o6rtunoqywm"] + +[node name="HoleScore" type="Label"] +text = "5" diff --git a/scenes/main.gd b/scenes/main.gd index d188af1..5c25fe7 100644 --- a/scenes/main.gd +++ b/scenes/main.gd @@ -19,6 +19,10 @@ var lobby_menu_instance: LobbyMenu = null const game_hud_scene: PackedScene = preload("res://scenes/game_hud.tscn") var game_hud_instance: GameHUD = null +const results_menu_scene: PackedScene = preload("res://scenes/results_menu.tscn") +var results_menu_instance: ResultsMenu = null + + func init_main_menu() -> void: main_menu_instance = main_menu_scene.instantiate() main_menu_instance.hosting_confirmed.connect(_on_hosting_confirmed) @@ -130,6 +134,17 @@ func deinit_game_hud() -> void: game_hud_instance.queue_free() game_hud_instance = null +func init_results_menu() -> void: + results_menu_instance = results_menu_scene.instantiate() + results_menu_instance.player_dir = client_game_instance.player_dir + results_menu_instance.leave_confirmed.connect(_on_lost_connection) + interface_instance.add_child(results_menu_instance) + +func deinit_results_menu() -> void: + results_menu_instance.queue_free() + results_menu_instance = null + + func _ready() -> void: init_main_menu() @@ -163,7 +178,7 @@ func _on_phase_changed(old: PhaseTracker.Phase, new: PhaseTracker.Phase) -> void PhaseTracker.Phase.PLAYING: deinit_game_hud() PhaseTracker.Phase.ENDED: - pass # TODO + deinit_results_menu() # Then, initialize the new one match new: PhaseTracker.Phase.LOBBY: @@ -171,4 +186,4 @@ func _on_phase_changed(old: PhaseTracker.Phase, new: PhaseTracker.Phase) -> void PhaseTracker.Phase.PLAYING: init_game_hud() PhaseTracker.Phase.ENDED: - pass # TODO + init_results_menu() diff --git a/scenes/putt_controller.gd b/scenes/putt_controller.gd index 8f41bd3..66f9c12 100644 --- a/scenes/putt_controller.gd +++ b/scenes/putt_controller.gd @@ -111,3 +111,4 @@ func play_putt_sound(putt_vector: Vector2): var putt_impulse: float = putt_vector.length() sound.volume_db = putt_volume.sample(putt_impulse / putt_max_impulse) sound.play() + diff --git a/scenes/results_menu.gd b/scenes/results_menu.gd new file mode 100644 index 0000000..f44a1a9 --- /dev/null +++ b/scenes/results_menu.gd @@ -0,0 +1,61 @@ +extends Control +class_name ResultsMenu + + +@export_category("References") + +@export var results_grid: GridContainer + +const label_scene: PackedScene = preload("res://scenes/player_label.tscn") + + +var player_dir: PlayerNodeDirectory = null + + + +func _ready(): + var max_hole_scores = 0 + + for playernode in player_dir.get_children(): + var player: PlayerLabel = label_scene.instantiate() + player.set_player_name(playernode.player_name) + player.set_player_color(playernode.player_color) + player.set_possessed(playernode.get_multiplayer_authority()) + results_grid.add_child(player) + + max_hole_scores = max(max_hole_scores, len(playernode.hole_scores)) + var total_score = 0 + for hole_score in playernode.hole_scores: + var score: PlayerLabel = label_scene.instantiate() + if hole_score != -1: + score.text = "%d" % hole_score + else: + score.text = "-" + score.set_player_color(playernode.player_color) + score.set_possessed(playernode.get_multiplayer_authority()) + score.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT + score.vertical_alignment = VERTICAL_ALIGNMENT_CENTER + results_grid.add_child(score) + if hole_score == -1 or total_score == -1: + total_score = -1 + else: + total_score += hole_score + + var total: PlayerLabel = label_scene.instantiate() + if total_score != -1: + total.text = "[%d]" % total_score + else: + total.text = "-" + total.set_player_color(playernode.player_color) + total.set_possessed(playernode.get_multiplayer_authority()) + total.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT + total.vertical_alignment = VERTICAL_ALIGNMENT_CENTER + results_grid.add_child(total) + + results_grid.columns = max_hole_scores + 2 + + +signal leave_confirmed + +func _on_leave_button_pressed() -> void: + leave_confirmed.emit() diff --git a/scenes/results_menu.tscn b/scenes/results_menu.tscn new file mode 100644 index 0000000..4c25723 --- /dev/null +++ b/scenes/results_menu.tscn @@ -0,0 +1,60 @@ +[gd_scene load_steps=2 format=3 uid="uid://cdieahvbjaqx6"] + +[ext_resource type="Script" path="res://scenes/results_menu.gd" id="1_b1mjj"] + +[node name="ResultsMenu" type="Control" node_paths=PackedStringArray("results_grid")] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_b1mjj") +results_grid = NodePath("Layout/ResultsList/Scrollable/PlayerResults") + +[node name="Layout" type="VBoxContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="Title" type="RichTextLabel" parent="Layout"] +layout_mode = 2 +bbcode_enabled = true +text = "[center][font_size=32px][b]Nanogolf[/b][/font_size] +Risultati[/center]" +fit_content = true + +[node name="Padding" type="Control" parent="Layout"] +custom_minimum_size = Vector2(0, 16) +layout_mode = 2 + +[node name="ResultsList" type="PanelContainer" parent="Layout"] +layout_mode = 2 +size_flags_vertical = 3 + +[node name="Scrollable" type="ScrollContainer" parent="Layout/ResultsList"] +layout_mode = 2 + +[node name="PlayerResults" type="GridContainer" parent="Layout/ResultsList/Scrollable"] +layout_mode = 2 +size_flags_vertical = 6 +theme_override_constants/h_separation = 12 +theme_override_constants/v_separation = 12 +columns = 7 + +[node name="Padding2" type="Control" parent="Layout"] +custom_minimum_size = Vector2(0, 16) +layout_mode = 2 + +[node name="HBoxContainer" type="HBoxContainer" parent="Layout"] +layout_mode = 2 + +[node name="LeaveButton" type="Button" parent="Layout/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +text = "Esci" + +[connection signal="pressed" from="Layout/HBoxContainer/LeaveButton" to="." method="_on_leave_button_pressed"]