forked from team-sg/hero-mark-2
95 lines
2.5 KiB
GDScript
95 lines
2.5 KiB
GDScript
extends CanvasLayer
|
|
|
|
var lore_entries: Array = []
|
|
var current_lore: int = -1
|
|
var can_switch_lore: bool = true
|
|
|
|
onready var options_screen = $OptionsScreen
|
|
onready var lore_container = $LoreContainer
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
|
|
get_tree().paused = true
|
|
$Body/Resume.grab_focus()
|
|
if Game.marathon_mode:
|
|
$Body/Restart.disabled = true
|
|
$Body/Restart.focus_mode = Control.FOCUS_NONE
|
|
$"%GreyedRestart".visible = true
|
|
$Body.text = "RESUME\nRESTART\nOPTIONS\nQUIT GAME"
|
|
else:
|
|
$Body.text = "RESUME\nRESTART\nOPTIONS\nEXIT LEVEL"
|
|
#Random lore
|
|
if lore_entries != null and not lore_entries.empty():
|
|
current_lore = randi() % lore_entries.size()
|
|
_update_lore_entry()
|
|
#Pause music
|
|
Audio.ac_music.set_stream_paused(true)
|
|
Audio.ac_pause_music.play()
|
|
|
|
func _physics_process(delta):
|
|
#Resume with pause button
|
|
if Input.is_action_just_pressed("pause"):
|
|
unpause()
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if can_switch_lore:
|
|
if event.is_action_pressed("ui_left"):
|
|
current_lore = posmod(current_lore - 1, lore_entries.size())
|
|
_update_lore_entry()
|
|
$MenuSounds.play_select_sound()
|
|
elif event.is_action_pressed("ui_right"):
|
|
current_lore = posmod(current_lore + 1, lore_entries.size())
|
|
_update_lore_entry()
|
|
$MenuSounds.play_select_sound()
|
|
|
|
func _update_lore_entry() -> void:
|
|
if current_lore >= 0 and lore_entries != null and not lore_entries.empty():
|
|
for child in lore_container.get_children():
|
|
lore_container.remove_child(child)
|
|
var lore = lore_entries[current_lore].instance()
|
|
lore_container.add_child(lore)
|
|
|
|
func _on_Resume_pressed():
|
|
unpause()
|
|
|
|
|
|
func _on_Restart_pressed():
|
|
Audio.ac_music.set_stream_paused(false)
|
|
Audio.ac_pause_music.stop()
|
|
Game.call_deferred("restart_level")
|
|
get_tree().paused = false
|
|
queue_free()
|
|
|
|
|
|
func _on_Settings_pressed():
|
|
$LoreContainer.visible = false
|
|
options_screen.visible = true
|
|
can_switch_lore = false
|
|
options_screen.focus()
|
|
|
|
|
|
func _on_ExitLevel_pressed():
|
|
Audio.ac_music.set_stream_paused(false)
|
|
Audio.ac_pause_music.stop()
|
|
get_tree().paused = false
|
|
if Game.marathon_mode:
|
|
Game.change_map(load("res://menus/marathon_start.tscn"))
|
|
else:
|
|
Game.change_map(load("res://menus/level_select_scholar.tscn"))
|
|
yield(Fade, "fade_finished")
|
|
queue_free()
|
|
|
|
|
|
func _on_OptionsScreen_exit():
|
|
options_screen.visible = false
|
|
$LoreContainer.visible = true
|
|
$Body/Settings.grab_focus()
|
|
can_switch_lore = true
|
|
|
|
func unpause():
|
|
get_tree().paused = false
|
|
#Stop pause music
|
|
Audio.ac_music.set_stream_paused(false)
|
|
Audio.ac_pause_music.stop()
|
|
queue_free()
|