bricasse/screens/level_select_screen.gd

44 lines
1.2 KiB
GDScript

extends Node
signal next_screen(screen_name)
var level_list = null
var highscore_list = null
var shown_level = null
# Called when the node enters the scene tree for the first time.
func _ready():
pass
# Init with the level list
func init(levels, highscores):
level_list = levels
highscore_list = highscores
display_level()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
if Input.is_action_just_pressed('ui_accept'):
emit_signal("next_screen", "game")
if Input.is_action_just_pressed("ui_menu"):
emit_signal("next_screen", "start")
if Input.is_action_just_pressed("ui_left"):
level_list.go_to_prev()
display_level()
if Input.is_action_just_pressed("ui_right"):
level_list.go_to_next()
display_level()
# Display the level
func display_level():
if shown_level != null:
shown_level.queue_free()
shown_level = level_list.get_current().instance()
$LevelName.text = shown_level.level_name
var high = highscore_list.get_score(shown_level.level_name)
if high == null:
$Score.text = "-no highscore-"
else:
$Score.text = str(high)
$Level.call_deferred("add_child", shown_level)