Some code organization
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
extends Control
|
||||
|
||||
|
||||
signal continue_game
|
||||
signal show_main_menu
|
||||
signal show_options
|
||||
|
||||
|
||||
@onready var continue_button := $%ContinueButton
|
||||
@onready var main_menu_button := $%MainMenuButton
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_init_focus()
|
||||
_setup_neighbors()
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("ui_up"):
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_previous)
|
||||
if event.is_action_pressed("ui_down"):
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_next)
|
||||
|
||||
|
||||
func _on_visibility_changed() -> void:
|
||||
if not is_node_ready(): return
|
||||
if not visible: return
|
||||
|
||||
_init_focus()
|
||||
_setup_neighbors()
|
||||
|
||||
|
||||
func _init_focus() -> void:
|
||||
continue_button.grab_focus()
|
||||
|
||||
|
||||
func _setup_neighbors() -> void:
|
||||
continue_button.focus_neighbor_top = main_menu_button.get_path()
|
||||
main_menu_button.focus_neighbor_bottom = continue_button.get_path()
|
||||
|
||||
|
||||
func _on_continue_button_pressed() -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
|
||||
continue_game.emit()
|
||||
|
||||
|
||||
func _on_options_button_pressed() -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
|
||||
show_options.emit()
|
||||
|
||||
|
||||
func _on_main_menu_button_pressed() -> void:
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
|
||||
show_main_menu.emit()
|
||||
@@ -0,0 +1 @@
|
||||
uid://npqs2m5g5bd6
|
||||
@@ -0,0 +1,49 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://bclo2wl8ibrcg"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://npqs2m5g5bd6" path="res://game/menu/pause/pause_menu.gd" id="1_inj1j"]
|
||||
[ext_resource type="Theme" uid="uid://dtnd3tqllufey" path="res://styles/menu_theme.tres" id="2_vy7sn"]
|
||||
|
||||
[sub_resource type="Shortcut" id="Shortcut_lgp46"]
|
||||
|
||||
[node name="PauseMenu" type="CenterContainer"]
|
||||
process_mode = 2
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 6
|
||||
size_flags_vertical = 6
|
||||
script = ExtResource("1_inj1j")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="ContinueButton" type="Button" parent="VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
z_index = 100
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_vy7sn")
|
||||
shortcut = SubResource("Shortcut_lgp46")
|
||||
text = "Continue"
|
||||
|
||||
[node name="OptionsButton" type="Button" parent="VBoxContainer"]
|
||||
z_index = 100
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_vy7sn")
|
||||
text = "Options"
|
||||
|
||||
[node name="MainMenuButton" type="Button" parent="VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
z_index = 100
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("2_vy7sn")
|
||||
text = "Main Menu"
|
||||
|
||||
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
|
||||
[connection signal="pressed" from="VBoxContainer/ContinueButton" to="." method="_on_continue_button_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/OptionsButton" to="." method="_on_options_button_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/MainMenuButton" to="." method="_on_main_menu_button_pressed"]
|
||||
@@ -0,0 +1,50 @@
|
||||
extends Control
|
||||
|
||||
|
||||
signal continue_game
|
||||
signal show_main_menu
|
||||
|
||||
|
||||
@onready var pause_menu : Control = $PauseMenu
|
||||
@onready var options : Control = $Options
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_show_menu(pause_menu)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("pause") or event.is_action_pressed("ui_cancel"):
|
||||
SoundManager.play_ui_stream(SoundManager.ui_stream_accept)
|
||||
_on_pause_menu_continue_game.call_deferred()
|
||||
|
||||
|
||||
func _show_menu(menu: Control) -> void:
|
||||
var menus : Array[Control] = [ pause_menu, options ]
|
||||
|
||||
for m in menus:
|
||||
m.hide()
|
||||
m.set_process_input(false)
|
||||
|
||||
menu.show()
|
||||
menu.set_process_input(true)
|
||||
|
||||
|
||||
func _on_pause_menu_continue_game() -> void:
|
||||
continue_game.emit()
|
||||
|
||||
|
||||
func _on_pause_menu_show_main_menu() -> void:
|
||||
show_main_menu.emit()
|
||||
|
||||
|
||||
func _on_pause_menu_show_options() -> void:
|
||||
_show_menu(options)
|
||||
|
||||
|
||||
func _on_options_back() -> void:
|
||||
_show_menu(pause_menu)
|
||||
|
||||
|
||||
func _on_visibility_changed() -> void:
|
||||
get_tree().paused = visible
|
||||
@@ -0,0 +1 @@
|
||||
uid://c5d2t2o53wkmt
|
||||
@@ -0,0 +1,24 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://d34nh3lc1gpb"]
|
||||
|
||||
[ext_resource type="Theme" uid="uid://dtnd3tqllufey" path="res://styles/menu_theme.tres" id="1_cked2"]
|
||||
[ext_resource type="Script" uid="uid://c5d2t2o53wkmt" path="res://game/menu/pause/pause_screen.gd" id="1_fe1q8"]
|
||||
[ext_resource type="PackedScene" uid="uid://bclo2wl8ibrcg" path="res://game/menu/pause/pause_menu.tscn" id="2_4r6ly"]
|
||||
[ext_resource type="PackedScene" uid="uid://btr60idiit4y7" path="res://game/menu/options/options.tscn" id="3_3gwb3"]
|
||||
|
||||
[node name="PauseScreen" type="MarginContainer"]
|
||||
offset_right = 640.0
|
||||
offset_bottom = 360.0
|
||||
theme = ExtResource("1_cked2")
|
||||
script = ExtResource("1_fe1q8")
|
||||
|
||||
[node name="PauseMenu" parent="." instance=ExtResource("2_4r6ly")]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Options" parent="." instance=ExtResource("3_3gwb3")]
|
||||
layout_mode = 2
|
||||
|
||||
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
|
||||
[connection signal="continue_game" from="PauseMenu" to="." method="_on_pause_menu_continue_game"]
|
||||
[connection signal="show_main_menu" from="PauseMenu" to="." method="_on_pause_menu_show_main_menu"]
|
||||
[connection signal="show_options" from="PauseMenu" to="." method="_on_pause_menu_show_options"]
|
||||
[connection signal="back" from="Options" to="." method="_on_options_back"]
|
||||
Reference in New Issue
Block a user