57 lines
1.2 KiB
GDScript
57 lines
1.2 KiB
GDScript
extends CanvasLayer
|
|
|
|
signal shown
|
|
signal hidden
|
|
|
|
@onready var save_button: Button = $Control/HBoxContainer/Save
|
|
@onready var load_button: Button = $Control/HBoxContainer/Load
|
|
@onready var item_description: Label = $Control/ItemDescription
|
|
@onready var audio_player: AudioStreamPlayer = $Control/AudioStreamPlayer
|
|
|
|
var is_paused := false
|
|
|
|
func _ready() -> void:
|
|
hide_pause()
|
|
save_button.pressed.connect(on_save)
|
|
load_button.pressed.connect(on_load)
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
if event.is_action_pressed("pause"):
|
|
if !is_paused:
|
|
show_pause()
|
|
else:
|
|
hide_pause()
|
|
get_viewport().set_input_as_handled()
|
|
|
|
func show_pause() -> void:
|
|
get_tree().paused = true
|
|
visible = true
|
|
is_paused = true
|
|
shown.emit()
|
|
|
|
func hide_pause() -> void:
|
|
get_tree().paused = false
|
|
visible = false
|
|
is_paused = false
|
|
hidden.emit()
|
|
|
|
func on_save() -> void:
|
|
if !is_paused:
|
|
return
|
|
SaveManager.save_game()
|
|
hide_pause()
|
|
|
|
func on_load() -> void:
|
|
if !is_paused:
|
|
return
|
|
SaveManager.load_game()
|
|
await LevelManager.level_load_started
|
|
hide_pause()
|
|
|
|
func update_item_description(new_description: String) -> void:
|
|
item_description.text = new_description
|
|
|
|
func play_audio(audio: AudioStream) -> void:
|
|
audio_player.stream = audio
|
|
audio_player.play()
|