Refactor pause and settings menu input handling to use UiManager for screen management
This commit is contained in:
@@ -11,7 +11,6 @@ extends Node
|
||||
|
||||
@onready var gm: GM = $"/root/GameManager"
|
||||
|
||||
var is_paused: bool = false
|
||||
var is_console_open: bool = false
|
||||
|
||||
|
||||
@@ -46,23 +45,19 @@ func _ready() -> void:
|
||||
Console.console_closed.connect(_on_console_close)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("pause") and not is_console_open:
|
||||
if is_paused:
|
||||
if UiManager.is_visible_on_stack(pause_menu_control):
|
||||
_on_resume_button_pressed()
|
||||
else:
|
||||
UiManager.push_screen(pause_menu_control)
|
||||
gm.pause_game()
|
||||
is_paused = true
|
||||
pause_menu_control.show()
|
||||
resume_button.grab_focus()
|
||||
|
||||
|
||||
func _on_resume_button_pressed() -> void:
|
||||
pause_menu_control.hide()
|
||||
if settings_menu:
|
||||
settings_menu.hide()
|
||||
UiManager.pop_screen()
|
||||
gm.resume_game()
|
||||
is_paused = false
|
||||
|
||||
|
||||
func _on_quit_button_pressed() -> void:
|
||||
@@ -74,9 +69,8 @@ func _on_settings_button_pressed() -> void:
|
||||
printerr("PauseMenu: Settings menu scene not set.")
|
||||
return
|
||||
|
||||
settings_menu.show()
|
||||
UiManager.push_screen(settings_menu)
|
||||
gm.pause_game()
|
||||
is_paused = true
|
||||
|
||||
|
||||
func _on_exit_to_menu_button_pressed() -> void:
|
||||
|
@@ -26,7 +26,6 @@ func _ready() -> void:
|
||||
audio_settings.hide()
|
||||
|
||||
if display_settings:
|
||||
|
||||
display_settings_button.pressed.connect(_on_display_settings_button_pressed)
|
||||
display_settings.hide()
|
||||
|
||||
@@ -35,61 +34,38 @@ func _ready() -> void:
|
||||
gameplay_settings.hide()
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("ui_cancel"):
|
||||
if settings_menu_control.is_visible():
|
||||
settings_menu_control.hide()
|
||||
if UiManager.is_screen_on_top(settings_menu_control):
|
||||
UiManager.pop_screen()
|
||||
|
||||
|
||||
func _on_input_settings_button_pressed() -> void:
|
||||
if not input_settings:
|
||||
return
|
||||
|
||||
if input_settings.is_visible():
|
||||
input_settings.hide()
|
||||
else:
|
||||
input_settings.show()
|
||||
audio_settings.hide()
|
||||
display_settings.hide()
|
||||
gameplay_settings.hide()
|
||||
UiManager.push_screen(input_settings)
|
||||
|
||||
|
||||
func _on_audio_settings_button_pressed() -> void:
|
||||
if not audio_settings:
|
||||
return
|
||||
|
||||
if audio_settings.is_visible():
|
||||
audio_settings.hide()
|
||||
else:
|
||||
audio_settings.show()
|
||||
input_settings.hide()
|
||||
display_settings.hide()
|
||||
gameplay_settings.hide()
|
||||
UiManager.push_screen(audio_settings)
|
||||
|
||||
|
||||
func _on_display_settings_button_pressed() -> void:
|
||||
if not display_settings:
|
||||
return
|
||||
|
||||
if display_settings.is_visible():
|
||||
display_settings.hide()
|
||||
else:
|
||||
display_settings.show()
|
||||
input_settings.hide()
|
||||
audio_settings.hide()
|
||||
gameplay_settings.hide()
|
||||
UiManager.push_screen(display_settings)
|
||||
|
||||
|
||||
func _on_gameplay_settings_button_pressed() -> void:
|
||||
if not gameplay_settings:
|
||||
return
|
||||
|
||||
if gameplay_settings.is_visible():
|
||||
gameplay_settings.hide()
|
||||
else:
|
||||
gameplay_settings.show()
|
||||
input_settings.hide()
|
||||
audio_settings.hide()
|
||||
display_settings.hide()
|
||||
UiManager.push_screen(gameplay_settings)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user