fuzzyworld

godot-shooter / commit

Got the game over panel working better.

5f3f5126c3b9aa50780b1376d886b2868721b051 · Pavel Safronov · 2023-11-09 16:35:38 -0800 · parents a343368e08fc

Got the game over panel working better.
 World.gd   | 10 +++++++---
 World.tscn | 54 +++++++++++++++++++++++++++++-------------------------
 2 files changed, 36 insertions(+), 28 deletions(-)

diff --git a/World.gd b/World.gd
index e7a62ae..af9ac2a 100644
--- a/World.gd
+++ b/World.gd
@@ -108,7 +108,8 @@ func _process(_delta: float) -> void:
 		get_tree().paused = true
 		var score = $UI/HUD.score
 		var final_message = "You won with %s points!" % score
-		$UI/GameFinishedMenu/Panel/VBoxContainer/Label.text = final_message
+		($UI/GameFinishedMenu.find_node("Button") as Button).connect("pressed", self, "restart")
+		$UI/GameFinishedMenu.find_node("Label").text = final_message
 		$UI/GameFinishedMenu.show()
 		return
 
@@ -191,9 +192,8 @@ func _on_Button_pressed() -> void:
 	$UI/PauseMenu.hide()
 
 func _on_Game_over_button_pressed() -> void:
-	get_tree().paused = false
 	$UI/GameFinishedMenu.hide()
-	var _err = get_tree().reload_current_scene()
+	restart()
 
 func _on_Player_shield_changed(shield_active: bool) -> void:
 	var message = "Shield Activated" if shield_active else "Shield Lost!"
@@ -202,6 +202,10 @@ func _on_Player_shield_changed(shield_active: bool) -> void:
 func _on_HUD_paused() -> void:
 	pause()
 
+func restart() -> void:
+	get_tree().paused = false
+	var _err = get_tree().reload_current_scene()
+
 func _on_HUD_debug_signal() -> void:
 	completed_objectives = 5
 	pass # Replace with function body.
diff --git a/World.tscn b/World.tscn
index 8d682d0..80017b5 100644
--- a/World.tscn
+++ b/World.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=8 format=2]
+[gd_scene load_steps=9 format=2]
 
 [ext_resource path="res://assets/kenney_simple-space/PNG/Default/icon_crossLarge.png" type="Texture" id=1]
 [ext_resource path="res://Player.tscn" type="PackedScene" id=2]
@@ -6,6 +6,7 @@
 [ext_resource path="res://World.gd" type="Script" id=4]
 [ext_resource path="res://StarField.tscn" type="PackedScene" id=5]
 [ext_resource path="res://CharacterTheme.tres" type="Theme" id=6]
+[ext_resource path="res://Theme.tres" type="Theme" id=7]
 
 [sub_resource type="CircleShape2D" id=1]
 radius = 29.0172
@@ -93,35 +94,39 @@ pause_mode = 2
 visible = false
 anchor_right = 1.0
 anchor_bottom = 1.0
-margin_right = 40.0
-margin_bottom = 40.0
 mouse_filter = 2
+theme = ExtResource( 7 )
 
-[node name="Panel" type="Panel" parent="UI/GameFinishedMenu"]
-margin_left = 120.0
-margin_top = 233.0
-margin_right = 400.0
-margin_bottom = 483.0
-
-[node name="VBoxContainer" type="VBoxContainer" parent="UI/GameFinishedMenu/Panel"]
-margin_left = 68.0
-margin_top = 72.0
-margin_right = 132.0
-margin_bottom = 110.0
+[node name="CenterContainer" type="CenterContainer" parent="UI/GameFinishedMenu"]
+anchor_right = 1.0
+anchor_bottom = 1.0
 
-[node name="Label" type="Label" parent="UI/GameFinishedMenu/Panel/VBoxContainer"]
-margin_right = 148.0
-margin_bottom = 35.0
-theme = ExtResource( 6 )
+[node name="PanelContainer" type="PanelContainer" parent="UI/GameFinishedMenu/CenterContainer"]
+margin_left = 236.0
+margin_top = 386.0
+margin_right = 264.0
+margin_bottom = 414.0
+
+[node name="VBoxContainer" type="VBoxContainer" parent="UI/GameFinishedMenu/CenterContainer/PanelContainer"]
+margin_left = 166.0
+margin_top = 303.0
+margin_right = 334.0
+margin_bottom = 497.0
+
+[node name="Label" type="Label" parent="UI/GameFinishedMenu/CenterContainer/PanelContainer/VBoxContainer"]
+margin_right = 168.0
+margin_bottom = 118.0
+theme = ExtResource( 7 )
 text = "You've won!"
 align = 1
+valign = 1
+autowrap = true
 
-[node name="Button" type="Button" parent="UI/GameFinishedMenu/Panel/VBoxContainer"]
-margin_top = 43.0
-margin_right = 148.0
-margin_bottom = 90.0
-theme = ExtResource( 6 )
-text = "Restart"
+[node name="Button" type="Button" parent="UI/GameFinishedMenu/CenterContainer/PanelContainer/VBoxContainer"]
+margin_top = 126.0
+margin_right = 168.0
+margin_bottom = 194.0
+text = "Replay!"
 
 [node name="ShootTimer" type="Timer" parent="."]
 process_mode = 0
@@ -144,5 +149,4 @@ antialiased = true
 [connection signal="debug_signal" from="UI/HUD" to="." method="_on_HUD_debug_signal"]
 [connection signal="paused" from="UI/HUD" to="." method="_on_HUD_paused"]
 [connection signal="pressed" from="UI/PauseMenu/Panel/VBoxContainer/Button" to="." method="_on_Button_pressed"]
-[connection signal="pressed" from="UI/GameFinishedMenu/Panel/VBoxContainer/Button" to="." method="_on_Game_over_button_pressed"]
 [connection signal="timeout" from="ShootTimer" to="." method="_on_ShootTimer_timeout"]