File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ extends Panel
55@export var game_scene : String
66@export var title_text : String
77@export var description_text : String
8+ @export var use_generic_pause_menu : bool
89
910var is_mouse_over : bool
1011
@@ -39,6 +40,9 @@ func spawn_window() -> void:
3940 window = load ("res://Scenes/Window/Game Window/game_window.tscn" ).instantiate ()
4041 window .get_node ("% Game Window" ).add_child (load (game_scene ).instantiate ())
4142
43+ if use_generic_pause_menu :
44+ window .get_node ("% GamePauseManager" ).process_mode = Node .PROCESS_MODE_INHERIT
45+
4246 window .title_text = % "Menu Title" .text
4347 get_tree ().current_scene .add_child (window )
4448
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ clip_contents = true
1616custom_minimum_size = Vector2 (0 , 50 )
1717script = ExtResource ("1_2fneu" )
1818game_scene = "res://Games/Cube Scene/cube_scene.tscn"
19+ use_generic_pause_menu = true
1920
2021[node name ="Background Panel" type ="Panel" parent ="." ]
2122visible = false
@@ -68,7 +69,7 @@ grow_horizontal = 2
6869size_flags_horizontal = 3
6970mouse_filter = 2
7071bbcode_enabled = true
71- text = "[center]GodotOS "
72+ text = "[center]Game Title "
7273
7374[node name ="Menu Description" type ="RichTextLabel" parent ="HBoxContainer/Control" ]
7475unique_name_in_owner = true
@@ -85,7 +86,7 @@ size_flags_horizontal = 3
8586mouse_filter = 2
8687theme_override_font_sizes/normal_font_size = 14
8788bbcode_enabled = true
88- text = "[center]GodotOS in GodotOS in GodotOS in "
89+ text = "[center]Your very cool game description "
8990
9091[connection signal ="mouse_entered" from ="." to ="." method ="_on_mouse_entered" ]
9192[connection signal ="mouse_exited" from ="." to ="." method ="_on_mouse_exited" ]
Original file line number Diff line number Diff line change 1+ extends Node
2+ class_name GamePauseManager
3+
4+ ## A generic pause manager for games in GodotOS.
5+ ## When you press ui_cancel, it pauses or unpauses.
6+
7+ ## NOTE: This node disabled by default but gets enabled by start menu option
8+ ## if the generic pause menu bool is enabled there.
9+
10+ @export var pause_packed_scene : PackedScene
11+
12+ @onready var window : FakeWindow = $ ".."
13+
14+ var is_paused : bool
15+ var current_pause_screen : CanvasLayer
16+
17+ func _input (event : InputEvent ) -> void :
18+ if ! window .is_selected :
19+ return
20+
21+ if event .is_action_pressed ("ui_cancel" ):
22+ toggle_pause ()
23+
24+ ## Pauses and adds the pause screen as a child to the game scene.
25+ ## The reason for this is so the pause screen scales with the viewport.
26+ func toggle_pause () -> void :
27+ if % "Game Window" .get_child_count () == 0 :
28+ NotificationManager .spawn_notification ("Error: No game scene to pause???" )
29+ return
30+
31+ var game_scene : Node = % "Game Window" .get_child (0 )
32+
33+ if is_paused :
34+ game_scene .process_mode = Node .PROCESS_MODE_INHERIT
35+ if current_pause_screen != null :
36+ current_pause_screen .queue_free ()
37+ else :
38+ game_scene .process_mode = Node .PROCESS_MODE_DISABLED
39+ var pause_screen : CanvasLayer = pause_packed_scene .instantiate ()
40+ game_scene .add_child (pause_screen )
41+ current_pause_screen = pause_screen
42+
43+ is_paused = ! is_paused
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ extends SubViewport
33## The game window, used to show games.
44
55@onready var window : FakeWindow = $ "../../.."
6+ @onready var game_pause_manager : GamePauseManager = % "GamePauseManager"
67
78func _ready () -> void :
89 window .minimized .connect (_handle_window_minimized )
@@ -14,6 +15,9 @@ func _ready() -> void:
1415 # $"../..".size *= get_window().content_scale_factor
1516
1617func _handle_window_minimized (is_minimized : bool ) -> void :
18+ if game_pause_manager .is_paused :
19+ return
20+
1721 if is_minimized :
1822 get_child (0 ).process_mode = Node .PROCESS_MODE_DISABLED
1923 else :
Original file line number Diff line number Diff line change 1- [gd_scene load_steps =4 format =3 uid ="uid://c73tsgfxmn37a" ]
1+ [gd_scene load_steps =6 format =3 uid ="uid://c73tsgfxmn37a" ]
22
33[ext_resource type ="PackedScene" uid ="uid://cojrqff5vocjv" path ="res://Scenes/Window/Window.tscn" id ="1_r6cfa" ]
44[ext_resource type ="Script" path ="res://Scenes/Window/Game Window/game_window.gd" id ="2_83d0v" ]
5+ [ext_resource type ="Script" path ="res://Scenes/Window/Game Window/game_pause_manager.gd" id ="2_sh1be" ]
6+ [ext_resource type ="PackedScene" uid ="uid://eprwl55n45fe" path ="res://Scenes/Window/Game Window/pause_screen.tscn" id ="3_uu1vi" ]
57
68[sub_resource type ="StyleBoxFlat" id ="StyleBoxFlat_5cq01" ]
79bg_color = Color (0.188235 , 0.105882 , 0.243137 , 0.6 )
@@ -19,7 +21,14 @@ theme_override_styles/panel = SubResource("StyleBoxFlat_5cq01")
1921[node name ="Title Text" parent ="Top Bar" index ="0" ]
2022texture_filter = 2
2123
22- [node name ="AspectRatioContainer" type ="AspectRatioContainer" parent ="." index ="1" ]
24+ [node name ="GamePauseManager" type ="Node" parent ="." index ="1" ]
25+ unique_name_in_owner = true
26+ process_mode = 4
27+ editor_description = "Disabled by default, gets enabled by start_menu_option at runtime."
28+ script = ExtResource ("2_sh1be" )
29+ pause_packed_scene = ExtResource ("3_uu1vi" )
30+
31+ [node name ="AspectRatioContainer" type ="AspectRatioContainer" parent ="." index ="2" ]
2332layout_mode = 1
2433anchors_preset = 15
2534anchor_right = 1.0
Original file line number Diff line number Diff line change 1+ [gd_scene format =3 uid ="uid://eprwl55n45fe" ]
2+
3+ [node name ="CanvasLayer" type ="CanvasLayer" ]
4+
5+ [node name ="ColorRect" type ="ColorRect" parent ="." ]
6+ anchors_preset = 15
7+ anchor_right = 1.0
8+ anchor_bottom = 1.0
9+ grow_horizontal = 2
10+ grow_vertical = 2
11+ mouse_filter = 1
12+ color = Color (0 , 0 , 0 , 0.784314 )
13+
14+ [node name ="RichTextLabel" type ="RichTextLabel" parent ="ColorRect" ]
15+ layout_mode = 1
16+ anchors_preset = 8
17+ anchor_left = 0.5
18+ anchor_top = 0.5
19+ anchor_right = 0.5
20+ anchor_bottom = 0.5
21+ offset_left = -200.0
22+ offset_top = -45.0
23+ offset_right = 200.0
24+ offset_bottom = 45.0
25+ grow_horizontal = 2
26+ grow_vertical = 2
27+ mouse_filter = 2
28+ theme_override_font_sizes/normal_font_size = 64
29+ bbcode_enabled = true
30+ text = "[center]- PAUSED -"
You can’t perform that action at this time.
0 commit comments