switchable lore entries (closes #176)
This commit is contained in:
parent
6c00959941
commit
10216b4e3d
3 changed files with 35 additions and 7 deletions
|
@ -1,6 +1,8 @@
|
|||
extends CanvasLayer
|
||||
|
||||
var lore_entry: PackedScene = null
|
||||
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
|
||||
|
@ -10,9 +12,9 @@ func _ready():
|
|||
get_tree().paused = true
|
||||
$Body/Resume.grab_focus()
|
||||
#Random lore
|
||||
if lore_entry != null:
|
||||
var lore = lore_entry.instance()
|
||||
lore_container.add_child(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()
|
||||
|
@ -24,6 +26,24 @@ func _physics_process(delta):
|
|||
|
||||
Console.print(get_tree().paused)
|
||||
|
||||
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()
|
||||
|
||||
|
@ -38,6 +58,7 @@ func _on_Restart_pressed():
|
|||
|
||||
func _on_Settings_pressed():
|
||||
$LoreContainer.visible = false
|
||||
can_switch_lore = false
|
||||
options_screen.focus()
|
||||
|
||||
|
||||
|
@ -54,6 +75,7 @@ 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue