Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Scenes/demo.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene format=4 uid="uid://cwk1s3v2wvxo3"]
[gd_scene format=4 uid="uid://7c4jde8i3gyh"]

[ext_resource type="Script" uid="uid://dwpnag6ymsmow" path="res://Scripts/demo_renderer.gd" id="1_demo"]
[ext_resource type="Texture2D" uid="uid://c1rj0im3pw7gd" path="res://Shapes/sand_background.png" id="1_glc8m"]
Expand All @@ -10,6 +10,7 @@
[ext_resource type="FontFile" uid="uid://hp5u4fxb5ifw" path="res://Assets/fonts/PixeloidSans-Bold.ttf" id="4_font"]
[ext_resource type="Texture2D" uid="uid://dle4xt8upfg42" path="res://Shapes/Square.svg" id="4_qdju7"]
[ext_resource type="Script" uid="uid://d2y578q176xkm" path="res://Scripts/high_stage.gd" id="5_high_stage"]
[ext_resource type="PackedScene" uid="uid://dao1hqwdldnlw" path="res://Scenes/demo_result_screen.tscn" id="6_a1i4p"]
[ext_resource type="Texture2D" uid="uid://f5ertr28h6kq" path="res://Shapes/feather.svg" id="6_feather"]
[ext_resource type="Script" uid="uid://cxd17lrphypsv" path="res://Scripts/game_camera.gd" id="7_camera"]

Expand Down Expand Up @@ -110,6 +111,7 @@ font_size = 56
font = ExtResource("4_font")
font_size = 36


[node name="DemoMain" type="Control" unique_id=1296044060]
layout_mode = 3
anchors_preset = 15
Expand Down Expand Up @@ -589,3 +591,5 @@ high_stage_a = NodePath("../HigherThanPlayerA/Stage")
high_stage_b = NodePath("../HigherThanPlayerB/Stage")
camera_a = NodePath("../ScreenA/SubViewport/Camera2D")
camera_b = NodePath("../ScreenB/SubViewport/Camera2D")

[node name="DemoResultScreen" parent="." unique_id=250910659 instance=ExtResource("6_a1i4p")]
218 changes: 218 additions & 0 deletions Scenes/demo_result_screen.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
[gd_scene format=3 uid="uid://dao1hqwdldnlw"]

[ext_resource type="Script" uid="uid://dltobunw2epqg" path="res://Scripts/demo_result_screen.gd" id="1_dcoi0"]
[ext_resource type="Texture2D" uid="uid://du0qdbs7y7rcf" path="res://Shapes/result_background.JPG" id="2_2qkro"]
[ext_resource type="FontFile" uid="uid://hp5u4fxb5ifw" path="res://Assets/fonts/PixeloidSans-Bold.ttf" id="3_5u2eh"]
[ext_resource type="Script" uid="uid://ddqb3djaesce4" path="res://Scripts/health_icon.gd" id="4_6ykjf"]
[ext_resource type="Texture2D" uid="uid://f5ertr28h6kq" path="res://Shapes/feather.svg" id="5_56pta"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ib03x"]
bg_color = Color(0.27450982, 0.27450982, 0.23529412, 0.7019608)

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_n8x6i"]
bg_color = Color(0, 0, 0, 0)
border_width_left = 3
border_width_top = 3
border_width_right = 3
border_width_bottom = 3
border_color = Color(1, 1, 1, 0.92156863)
corner_radius_top_left = 26
corner_radius_top_right = 27
corner_radius_bottom_right = 26
corner_radius_bottom_left = 27

[sub_resource type="StyleBoxLine" id="StyleBoxLine_qk7ap"]
color = Color(1, 1, 1, 1)
thickness = 3

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_qk7ap"]
bg_color = Color(0.27450982, 0.1764706, 0.078431375, 1)
corner_radius_top_left = 6
corner_radius_top_right = 7
corner_radius_bottom_right = 6
corner_radius_bottom_left = 7

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_o517f"]
bg_color = Color(0.18431373, 0.12156863, 0.07058824, 1)
corner_radius_top_left = 6
corner_radius_top_right = 7
corner_radius_bottom_right = 6
corner_radius_bottom_left = 7

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ndexe"]
bg_color = Color(0.33333334, 0.21568628, 0.101960786, 1)
corner_radius_top_left = 6
corner_radius_top_right = 7
corner_radius_bottom_right = 6
corner_radius_bottom_left = 7

[node name="DemoResultScreen" type="CanvasLayer" unique_id=250910659]
process_mode = 3
layer = 100
script = ExtResource("1_dcoi0")

[node name="ResultRoot" type="Control" parent="." unique_id=80173994]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="Background" type="TextureRect" parent="ResultRoot" unique_id=50513428]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -373.0
offset_top = -130.0
offset_right = 141.0
offset_bottom = -1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
texture = ExtResource("2_2qkro")
expand_mode = 2
stretch_mode = 5

[node name="CenterContainer" type="CenterContainer" parent="ResultRoot" unique_id=863430935]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2

[node name="Panel" type="Panel" parent="ResultRoot/CenterContainer" unique_id=1170119724]
custom_minimum_size = Vector2(1152, 648)
layout_mode = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_ib03x")

[node name="PanelContainer" type="PanelContainer" parent="ResultRoot/CenterContainer" unique_id=1914732084]
custom_minimum_size = Vector2(750, 420)
layout_mode = 2
mouse_filter = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_n8x6i")

[node name="MarginContainer" type="MarginContainer" parent="ResultRoot/CenterContainer/PanelContainer" unique_id=533272811]
layout_mode = 2
mouse_filter = 2
theme_override_constants/margin_left = 44
theme_override_constants/margin_top = 32
theme_override_constants/margin_right = 44
theme_override_constants/margin_bottom = 32

[node name="VBoxContainer" type="VBoxContainer" parent="ResultRoot/CenterContainer/PanelContainer/MarginContainer" unique_id=94432051]
unique_name_in_owner = true
layout_mode = 2
mouse_filter = 2
theme_override_constants/separation = 14

[node name="TitleLabel" type="Label" parent="ResultRoot/CenterContainer/PanelContainer/MarginContainer/VBoxContainer" unique_id=1068592199]
unique_name_in_owner = true
layout_mode = 2
theme_override_fonts/font = ExtResource("3_5u2eh")
theme_override_font_sizes/font_size = 36
text = "RESULT"
horizontal_alignment = 1

[node name="Separator" type="HSeparator" parent="ResultRoot/CenterContainer/PanelContainer/MarginContainer/VBoxContainer" unique_id=412927854]
layout_mode = 2
theme_override_styles/separator = SubResource("StyleBoxLine_qk7ap")

[node name="HBoxContainer" type="HBoxContainer" parent="ResultRoot/CenterContainer/PanelContainer/MarginContainer/VBoxContainer" unique_id=224187305]
layout_mode = 2
theme_override_constants/separation = 40

[node name="StatNamesLabel" type="Label" parent="ResultRoot/CenterContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer" unique_id=635769938]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
theme_override_constants/line_spacing = 7
theme_override_fonts/font = ExtResource("3_5u2eh")
theme_override_font_sizes/font_size = 22
text = "
Remaining Health
Energy Balls Collected
Jumps
Distance Traveled
Total Energy Spent"

[node name="StatValuesALabel" type="Label" parent="ResultRoot/CenterContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer" unique_id=119839190]
unique_name_in_owner = true
layout_mode = 2
theme_override_constants/line_spacing = 7
theme_override_fonts/font = ExtResource("3_5u2eh")
theme_override_font_sizes/font_size = 22
horizontal_alignment = 2

[node name="StatValuesBLabel" type="Label" parent="ResultRoot/CenterContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer" unique_id=1618690426]
unique_name_in_owner = true
layout_mode = 2
theme_override_constants/line_spacing = 7
theme_override_fonts/font = ExtResource("3_5u2eh")
theme_override_font_sizes/font_size = 22
horizontal_alignment = 2

[node name="spacer" type="Control" parent="ResultRoot/CenterContainer/PanelContainer/MarginContainer/VBoxContainer" unique_id=419185334]
custom_minimum_size = Vector2(0, 6.7)
layout_mode = 2

[node name="HBoxContainer2" type="HBoxContainer" parent="ResultRoot/CenterContainer/PanelContainer/MarginContainer/VBoxContainer" unique_id=1952087552]
layout_mode = 2
theme_override_constants/separation = 145
alignment = 1

[node name="HomeButton" type="Button" parent="ResultRoot/CenterContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer2" unique_id=882486403]
custom_minimum_size = Vector2(150, 40)
layout_mode = 2
size_flags_horizontal = 4
theme_override_fonts/font = ExtResource("3_5u2eh")
theme_override_font_sizes/font_size = 26
theme_override_styles/normal = SubResource("StyleBoxFlat_qk7ap")
theme_override_styles/pressed = SubResource("StyleBoxFlat_o517f")
theme_override_styles/hover = SubResource("StyleBoxFlat_ndexe")
text = "Home"

[node name="ExitButton" type="Button" parent="ResultRoot/CenterContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer2" unique_id=2007003856]
custom_minimum_size = Vector2(150, 40)
layout_mode = 2
size_flags_horizontal = 4
theme_override_fonts/font = ExtResource("3_5u2eh")
theme_override_font_sizes/font_size = 26
theme_override_styles/normal = SubResource("StyleBoxFlat_qk7ap")
theme_override_styles/pressed = SubResource("StyleBoxFlat_o517f")
theme_override_styles/hover = SubResource("StyleBoxFlat_ndexe")
text = "Exit"

[node name="HealthIconsA" type="HBoxContainer" parent="ResultRoot" unique_id=970283826]
unique_name_in_owner = true
layout_mode = 0
offset_left = 300.0
offset_top = 350.0
offset_right = 300.0
offset_bottom = 350.0
pivot_offset_ratio = Vector2(0.5, 0.5)
mouse_filter = 2
alignment = 1
script = ExtResource("4_6ykjf")
unit_icon = ExtResource("5_56pta")
icon_size = Vector2(30, 30)

[node name="HealthIconsB" type="HBoxContainer" parent="ResultRoot" unique_id=338515395]
unique_name_in_owner = true
layout_mode = 0
offset_left = 300.0
offset_top = 350.0
offset_right = 300.0
offset_bottom = 350.0
pivot_offset_ratio = Vector2(0.5, 0.5)
mouse_filter = 2
alignment = 1
script = ExtResource("4_6ykjf")
unit_icon = ExtResource("5_56pta")
icon_size = Vector2(30, 30)

[connection signal="button_up" from="ResultRoot/CenterContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer2/HomeButton" to="." method="_on_home_button_button_up"]
[connection signal="button_up" from="ResultRoot/CenterContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer2/ExitButton" to="." method="_on_exit_button_button_up"]
39 changes: 38 additions & 1 deletion Scripts/demo_renderer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const FALLBACK_HEALTH_TEXTURE = preload("res://Shapes/feather.svg")
@export var high_stage_b: Node2D
@export var camera_a: Camera2D
@export var camera_b: Camera2D
@export var result_screen: CanvasLayer

var _ghosts_a: Dictionary = {}
var _ghosts_b: Dictionary = {}
Expand Down Expand Up @@ -54,6 +55,11 @@ func _ready() -> void:
if nm.has_signal("connection_succeeded"):
nm.connection_succeeded.connect(_identify_as_demo.bind(nm))

if nm.has_signal("multiplayer_finish"):
nm.multiplayer_finish.connect(_on_multiplayer_finish)
if not result_screen:
result_screen = get_node_or_null("../DemoResultScreen")

# Draw arena walls on both stages
# Use get_node as fallback — exported NodePath may fail across SubViewport boundaries
if not stage_a:
Expand Down Expand Up @@ -134,9 +140,12 @@ func _apply_screen(screen: Dictionary, screen_data: Dictionary) -> void:
return
var ghosts: Dictionary = screen["ghosts"]

screen["peer_id"] = screen_data.get("peer_id", -1)
var player_state: Dictionary = screen_data.get("player", {})
screen["last_player_state"] = player_state

Global.high_stage = screen.get("high_stage", stage)

var player_state: Dictionary = screen_data.get("player", {})
_apply_player(screen, stage, player_state)

# Apply trap ghosts
Expand Down Expand Up @@ -540,3 +549,31 @@ func _create_player_ghost(stage: Node2D) -> Node2D:
ghost.modulate = Color(0.2, 0.6, 1.0, 1.0)
stage.add_child(ghost)
return ghost


func _on_multiplayer_finish(winner_peer_ids: Array, draw: bool, forfeit: bool) -> void:
var nm := get_node_or_null("/root/NetworkManager")
if nm and nm.demo_state_received.is_connected(_on_demo_state_received):
nm.demo_state_received.disconnect(_on_demo_state_received)

get_tree().paused = true

if result_screen:
var state_a: Dictionary = _screens[0].get("last_player_state", {})
var state_b: Dictionary = _screens[1].get("last_player_state", {})
var peer_id_a: int = _screens[0].get("peer_id", -1)
var peer_id_b: int = _screens[1].get("peer_id", -1)

# 獲取 HUD 上的玩家名稱,若無則預設為 Player A / Player B
var name_a := "Player A (Left)"
var name_b := "Player B (Right)"
var name_label_a = get_node_or_null("../HUD/NameLabelA")
if name_label_a and name_label_a.text != "":
name_a = name_label_a.text + " (Left)"
var name_label_b = get_node_or_null("../HUD/NameLabelB")
if name_label_b and name_label_b.text != "":
name_b = name_label_b.text + " (Right)"

result_screen.show_demo_results(
state_a, state_b, winner_peer_ids, draw, forfeit, peer_id_a, peer_id_b, name_a, name_b
)
Loading
Loading