forked from team-sg/hero-mark-2
switchable lore entries (closes #176)
This commit is contained in:
parent
6c00959941
commit
10216b4e3d
3 changed files with 35 additions and 7 deletions
|
@ -29,9 +29,7 @@ func _physics_process(delta):
|
||||||
#Pause
|
#Pause
|
||||||
if Input.is_action_just_pressed("pause") && !get_tree().paused:
|
if Input.is_action_just_pressed("pause") && !get_tree().paused:
|
||||||
var pause = PauseScreen.instance()
|
var pause = PauseScreen.instance()
|
||||||
if lore_entries != null && !lore_entries.empty():
|
pause.lore_entries = lore_entries
|
||||||
var entry = lore_entries[randi() % lore_entries.size()]
|
|
||||||
pause.lore_entry = entry
|
|
||||||
get_parent().add_child(pause)
|
get_parent().add_child(pause)
|
||||||
# restart level
|
# restart level
|
||||||
if Input.is_action_just_pressed("restart"):
|
if Input.is_action_just_pressed("restart"):
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
extends CanvasLayer
|
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 options_screen = $OptionsScreen
|
||||||
onready var lore_container = $LoreContainer
|
onready var lore_container = $LoreContainer
|
||||||
|
@ -10,9 +12,9 @@ func _ready():
|
||||||
get_tree().paused = true
|
get_tree().paused = true
|
||||||
$Body/Resume.grab_focus()
|
$Body/Resume.grab_focus()
|
||||||
#Random lore
|
#Random lore
|
||||||
if lore_entry != null:
|
if lore_entries != null and not lore_entries.empty():
|
||||||
var lore = lore_entry.instance()
|
current_lore = randi() % lore_entries.size()
|
||||||
lore_container.add_child(lore)
|
_update_lore_entry()
|
||||||
#Pause music
|
#Pause music
|
||||||
Audio.ac_music.set_stream_paused(true)
|
Audio.ac_music.set_stream_paused(true)
|
||||||
Audio.ac_pause_music.play()
|
Audio.ac_pause_music.play()
|
||||||
|
@ -24,6 +26,24 @@ func _physics_process(delta):
|
||||||
|
|
||||||
Console.print(get_tree().paused)
|
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():
|
func _on_Resume_pressed():
|
||||||
unpause()
|
unpause()
|
||||||
|
|
||||||
|
@ -38,6 +58,7 @@ func _on_Restart_pressed():
|
||||||
|
|
||||||
func _on_Settings_pressed():
|
func _on_Settings_pressed():
|
||||||
$LoreContainer.visible = false
|
$LoreContainer.visible = false
|
||||||
|
can_switch_lore = false
|
||||||
options_screen.focus()
|
options_screen.focus()
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,6 +75,7 @@ func _on_OptionsScreen_exit():
|
||||||
options_screen.visible = false
|
options_screen.visible = false
|
||||||
$LoreContainer.visible = true
|
$LoreContainer.visible = true
|
||||||
$Body/Settings.grab_focus()
|
$Body/Settings.grab_focus()
|
||||||
|
can_switch_lore = true
|
||||||
|
|
||||||
func unpause():
|
func unpause():
|
||||||
get_tree().paused = false
|
get_tree().paused = false
|
||||||
|
|
|
@ -65,6 +65,8 @@ margin_left = 36.0
|
||||||
margin_top = 1.0
|
margin_top = 1.0
|
||||||
margin_right = 44.0
|
margin_right = 44.0
|
||||||
margin_bottom = 9.0
|
margin_bottom = 9.0
|
||||||
|
focus_neighbour_left = NodePath(".")
|
||||||
|
focus_neighbour_right = NodePath(".")
|
||||||
focus_neighbour_bottom = NodePath("../Restart")
|
focus_neighbour_bottom = NodePath("../Restart")
|
||||||
texture_focused = ExtResource( 3 )
|
texture_focused = ExtResource( 3 )
|
||||||
|
|
||||||
|
@ -75,7 +77,9 @@ margin_left = 32.0
|
||||||
margin_top = 14.0
|
margin_top = 14.0
|
||||||
margin_right = 40.0
|
margin_right = 40.0
|
||||||
margin_bottom = 22.0
|
margin_bottom = 22.0
|
||||||
|
focus_neighbour_left = NodePath(".")
|
||||||
focus_neighbour_top = NodePath("../Resume")
|
focus_neighbour_top = NodePath("../Resume")
|
||||||
|
focus_neighbour_right = NodePath(".")
|
||||||
focus_neighbour_bottom = NodePath("../Settings")
|
focus_neighbour_bottom = NodePath("../Settings")
|
||||||
texture_focused = ExtResource( 3 )
|
texture_focused = ExtResource( 3 )
|
||||||
|
|
||||||
|
@ -86,7 +90,9 @@ margin_left = 29.0
|
||||||
margin_top = 27.0
|
margin_top = 27.0
|
||||||
margin_right = 37.0
|
margin_right = 37.0
|
||||||
margin_bottom = 35.0
|
margin_bottom = 35.0
|
||||||
|
focus_neighbour_left = NodePath(".")
|
||||||
focus_neighbour_top = NodePath("../Restart")
|
focus_neighbour_top = NodePath("../Restart")
|
||||||
|
focus_neighbour_right = NodePath(".")
|
||||||
focus_neighbour_bottom = NodePath("../ExitLevel")
|
focus_neighbour_bottom = NodePath("../ExitLevel")
|
||||||
texture_focused = ExtResource( 3 )
|
texture_focused = ExtResource( 3 )
|
||||||
|
|
||||||
|
@ -97,7 +103,9 @@ margin_left = 22.0
|
||||||
margin_top = 40.0
|
margin_top = 40.0
|
||||||
margin_right = 30.0
|
margin_right = 30.0
|
||||||
margin_bottom = 48.0
|
margin_bottom = 48.0
|
||||||
|
focus_neighbour_left = NodePath(".")
|
||||||
focus_neighbour_top = NodePath("../Settings")
|
focus_neighbour_top = NodePath("../Settings")
|
||||||
|
focus_neighbour_right = NodePath(".")
|
||||||
texture_focused = ExtResource( 3 )
|
texture_focused = ExtResource( 3 )
|
||||||
|
|
||||||
[node name="LoreContainer" type="MarginContainer" parent="."]
|
[node name="LoreContainer" type="MarginContainer" parent="."]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue