Browse Source

:lipstick: Add pause mode

DricomDragon 2 years ago
parent
commit
35d06e385e
3 changed files with 49 additions and 2 deletions
  1. 23 0
      godot/component/ui/pause/PausePopup.gd
  2. 17 2
      godot/main.tscn
  3. 9 0
      godot/project.godot

+ 23 - 0
godot/component/ui/pause/PausePopup.gd

@@ -0,0 +1,23 @@
+extends Popup
+
+
+func trigger_pause() -> void:
+	popup()
+	get_tree().paused = true
+
+
+func end_pause() -> void:
+	get_tree().paused = false
+
+
+func _input(event: InputEvent) -> void:
+	if event is InputEventKey:
+		if event.is_action_pressed("ui_home"):
+			if get_tree().paused:
+				hide()
+			else:
+				trigger_pause()
+
+
+func _on_self_popup_hide() -> void:
+	end_pause()

+ 17 - 2
godot/main.tscn

@@ -1,4 +1,4 @@
-[gd_scene load_steps=11 format=2]
+[gd_scene load_steps=12 format=2]
 
 [ext_resource path="res://component/ui/message_panel/MessagePanel.tscn" type="PackedScene" id=1]
 [ext_resource path="res://component/entity/launcher/Launcher.tscn" type="PackedScene" id=2]
@@ -9,6 +9,7 @@
 [ext_resource path="res://component/entity/death/Death.tscn" type="PackedScene" id=7]
 [ext_resource path="res://main.gd" type="Script" id=8]
 [ext_resource path="res://component/ui/background/background_texture.png" type="Texture" id=9]
+[ext_resource path="res://component/ui/pause/PausePopup.gd" type="Script" id=10]
 [ext_resource path="res://component/entity/border/Border.tscn" type="PackedScene" id=13]
 
 [node name="Game" type="Node"]
@@ -64,10 +65,23 @@ margin_top = -40.0
 margin_right = 50.0
 margin_bottom = -10.0
 title = "Balls"
-[connection signal="start_new_game" from="." to="UI/ScoreCounter" method="reset_counter"]
+
+[node name="PausePopup" type="Popup" parent="UI"]
+pause_mode = 2
+anchor_right = 1.0
+anchor_bottom = 0.8
+margin_left = 40.0
+margin_top = 40.0
+margin_right = -40.0
+margin_bottom = -40.0
+script = ExtResource( 10 )
+
+[node name="PauseMessage" parent="UI/PausePopup" instance=ExtResource( 1 )]
+message = "PAUSE"
 [connection signal="start_new_game" from="." to="Grid" method="_on_Game_start_new_game"]
 [connection signal="start_new_game" from="." to="Launcher" method="_on_Game_start_new_game"]
 [connection signal="start_new_game" from="." to="UI/GameOverPanel" method="hide"]
+[connection signal="start_new_game" from="." to="UI/ScoreCounter" method="reset_counter"]
 [connection signal="start_new_game" from="." to="UI/BallCounter" method="reset_counter"]
 [connection signal="gain_new_bullet" from="Launcher" to="UI/BallCounter" method="increase_counter"]
 [connection signal="get_firing" from="Launcher" to="UI" method="_on_Launcher_get_firing"]
@@ -79,3 +93,4 @@ title = "Balls"
 [connection signal="game_lost" from="DeadLine" to="Launcher" method="_on_DeadLine_game_lost"]
 [connection signal="game_lost" from="DeadLine" to="." method="_on_game_lost"]
 [connection signal="game_lost" from="DeadLine" to="UI" method="_on_DeadLine_game_lost"]
+[connection signal="popup_hide" from="UI/PausePopup" to="UI/PausePopup" method="_on_self_popup_hide"]

+ 9 - 0
godot/project.godot

@@ -125,6 +125,15 @@ window/handheld/orientation="portrait"
 window/stretch/mode="2d"
 window/stretch/aspect="keep"
 
+[input]
+
+ui_home={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":80,"unicode":0,"echo":false,"script":null)
+, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777229,"unicode":0,"echo":false,"script":null)
+ ]
+}
+
 [layer_names]
 
 2d_physics/layer_1="balls"