From 10216b4e3d9276f3b1422d8e265159c5fda60dc1 Mon Sep 17 00:00:00 2001 From: Haze Weathers Date: Sun, 15 Oct 2023 16:30:14 -0400 Subject: [PATCH] switchable lore entries (closes #176) --- maps/map.gd | 4 +--- objects/hud/pause_screen.gd | 30 ++++++++++++++++++++++++++---- objects/hud/pause_screen.tscn | 8 ++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/maps/map.gd b/maps/map.gd index 017e668..4031f71 100644 --- a/maps/map.gd +++ b/maps/map.gd @@ -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"): diff --git a/objects/hud/pause_screen.gd b/objects/hud/pause_screen.gd index fba78b8..a495e0e 100644 --- a/objects/hud/pause_screen.gd +++ b/objects/hud/pause_screen.gd @@ -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 diff --git a/objects/hud/pause_screen.tscn b/objects/hud/pause_screen.tscn index 7e9eba1..e5a6d35 100644 --- a/objects/hud/pause_screen.tscn +++ b/objects/hud/pause_screen.tscn @@ -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="."]