From d3149784cbc1dca5b3e3e4772faf853f5e7fc384 Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Tue, 15 Sep 2020 16:31:41 +0200 Subject: [PATCH] Live-reload level list when clicking dropdown --- main.gd | 10 ++++++++-- main.tscn | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/main.gd b/main.gd index 27084d6..56c3151 100644 --- a/main.gd +++ b/main.gd @@ -15,8 +15,7 @@ onready var active_repository = $Repositories/ActiveRepository func _ready(): # Initialize level select. var options = $LevelSelect.get_popup() - for level in list_levels(): - options.add_item(level) + repopulate_levels() options.connect("id_pressed", self, "load_level") $LevelSelect.theme = Theme.new() $LevelSelect.theme.default_font = load("res://fonts/default.tres") @@ -149,3 +148,10 @@ func save_message(): func show_win_status(): $NextLevelButton.show() $LevelDescription.text = "Yay, you solved the puzzle! Enjoy the view or continue to the next level!" + + +func repopulate_levels(): + var options = $LevelSelect.get_popup() + options.clear() + for level in list_levels(): + options.add_item(level) diff --git a/main.tscn b/main.tscn index 472bfe2..0078b53 100644 --- a/main.tscn +++ b/main.tscn @@ -172,6 +172,7 @@ __meta__ = { "_edit_use_anchors_": false } [connection signal="pressed" from="TextEditor/SaveButton" to="." method="save_message"] +[connection signal="button_down" from="LevelSelect" to="." method="repopulate_levels"] [connection signal="pressed" from="NextLevelButton" to="." method="load_next_level"] [connection signal="pressed" from="ReloadButton" to="." method="reload_level"] [connection signal="data_received" from="Test/TCPServer" to="Test" method="data"]