switchable lore entries (closes #176)

This commit is contained in:
Haze Weathers 2023-10-15 16:30:14 -04:00
parent 6c00959941
commit 10216b4e3d
3 changed files with 35 additions and 7 deletions

View file

@ -29,9 +29,7 @@ func _physics_process(delta):
#Pause
if Input.is_action_just_pressed("pause") && !get_tree().paused:
var pause = PauseScreen.instance()
if lore_entries != null && !lore_entries.empty():
var entry = lore_entries[randi() % lore_entries.size()]
pause.lore_entry = entry
pause.lore_entries = lore_entries
get_parent().add_child(pause)
# restart level
if Input.is_action_just_pressed("restart"):

View file

@ -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

View file

@ -65,6 +65,8 @@ margin_left = 36.0
margin_top = 1.0
margin_right = 44.0
margin_bottom = 9.0
focus_neighbour_left = NodePath(".")
focus_neighbour_right = NodePath(".")
focus_neighbour_bottom = NodePath("../Restart")
texture_focused = ExtResource( 3 )
@ -75,7 +77,9 @@ margin_left = 32.0
margin_top = 14.0
margin_right = 40.0
margin_bottom = 22.0
focus_neighbour_left = NodePath(".")
focus_neighbour_top = NodePath("../Resume")
focus_neighbour_right = NodePath(".")
focus_neighbour_bottom = NodePath("../Settings")
texture_focused = ExtResource( 3 )
@ -86,7 +90,9 @@ margin_left = 29.0
margin_top = 27.0
margin_right = 37.0
margin_bottom = 35.0
focus_neighbour_left = NodePath(".")
focus_neighbour_top = NodePath("../Restart")
focus_neighbour_right = NodePath(".")
focus_neighbour_bottom = NodePath("../ExitLevel")
texture_focused = ExtResource( 3 )
@ -97,7 +103,9 @@ margin_left = 22.0
margin_top = 40.0
margin_right = 30.0
margin_bottom = 48.0
focus_neighbour_left = NodePath(".")
focus_neighbour_top = NodePath("../Settings")
focus_neighbour_right = NodePath(".")
texture_focused = ExtResource( 3 )
[node name="LoreContainer" type="MarginContainer" parent="."]