Basic UI Logic and game state
This commit is contained in:
@@ -4,6 +4,7 @@ extends Node3D
|
||||
@export var camera_array: Array[Camera3D] = []
|
||||
@export var current_camera: int = 0
|
||||
@export var game_started: bool = false
|
||||
@export var is_paused: bool = false
|
||||
|
||||
|
||||
func _process(delta):
|
||||
|
||||
@@ -7,6 +7,7 @@ extends Control
|
||||
func _ready():
|
||||
start_button.pressed.connect(_on_start_button_pressed)
|
||||
quit_button.pressed.connect(_on_quit_button_pressed)
|
||||
self.visibility_changed.connect(_on_visibility_changed)
|
||||
start_button.grab_focus()
|
||||
|
||||
|
||||
@@ -17,3 +18,8 @@ func _on_start_button_pressed():
|
||||
|
||||
func _on_quit_button_pressed():
|
||||
get_tree().quit()
|
||||
|
||||
|
||||
func _on_visibility_changed() -> void:
|
||||
if visible:
|
||||
start_button.grab_focus()
|
||||
|
||||
38
core/scripts/pause_menu.gd
Normal file
38
core/scripts/pause_menu.gd
Normal file
@@ -0,0 +1,38 @@
|
||||
extends Control
|
||||
|
||||
|
||||
@export var resume_button: Button
|
||||
@export var quit_button: Button
|
||||
|
||||
|
||||
func _ready():
|
||||
resume_button.pressed.connect(_on_resume_button_pressed)
|
||||
quit_button.pressed.connect(_on_quit_button_pressed)
|
||||
self.visibility_changed.connect(_on_visibility_changed)
|
||||
|
||||
|
||||
func _on_resume_button_pressed():
|
||||
hide()
|
||||
_toggle_pause_state(false)
|
||||
|
||||
|
||||
func _on_quit_button_pressed():
|
||||
get_tree().quit()
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if Input.is_action_just_pressed("start") and !GameManager.is_paused and GameManager.game_started:
|
||||
_toggle_pause_state(true)
|
||||
elif Input.is_action_just_pressed("start") and GameManager.is_paused:
|
||||
_toggle_pause_state(false)
|
||||
|
||||
|
||||
func _toggle_pause_state(state: bool):
|
||||
get_tree().paused = state
|
||||
GameManager.is_paused = state
|
||||
visible = state
|
||||
|
||||
|
||||
func _on_visibility_changed() -> void:
|
||||
if visible:
|
||||
resume_button.grab_focus()
|
||||
Reference in New Issue
Block a user