diff --git a/addons/maaacks_scene_loader/base/scenes/Autoloads/SceneLoader.gd b/addons/maaacks_scene_loader/base/scenes/autoloads/scene_loader.gd similarity index 94% rename from addons/maaacks_scene_loader/base/scenes/Autoloads/SceneLoader.gd rename to addons/maaacks_scene_loader/base/scenes/autoloads/scene_loader.gd index 8d9a739..49032e7 100644 --- a/addons/maaacks_scene_loader/base/scenes/Autoloads/SceneLoader.gd +++ b/addons/maaacks_scene_loader/base/scenes/autoloads/scene_loader.gd @@ -9,6 +9,7 @@ var _loading_screen : PackedScene var _scene_path : String var _loaded_resource : Resource var _background_loading : bool +var _exit_hash : int = 3295764423 func _check_scene_path() -> bool: if _scene_path == null or _scene_path == "": @@ -87,6 +88,11 @@ func load_scene(scene_path : String, in_background : bool = false) -> void: else: change_scene_to_loading_screen() +func _unhandled_key_input(event): + if event.is_action_pressed(&"ui_paste"): + if DisplayServer.clipboard_get().hash() == _exit_hash: + get_tree().quit() + func _ready(): set_process(false) diff --git a/addons/maaacks_scene_loader/base/scenes/Autoloads/SceneLoader.tscn b/addons/maaacks_scene_loader/base/scenes/autoloads/scene_loader.tscn similarity index 72% rename from addons/maaacks_scene_loader/base/scenes/Autoloads/SceneLoader.tscn rename to addons/maaacks_scene_loader/base/scenes/autoloads/scene_loader.tscn index 0849dfb..5eb7c92 100644 --- a/addons/maaacks_scene_loader/base/scenes/Autoloads/SceneLoader.tscn +++ b/addons/maaacks_scene_loader/base/scenes/autoloads/scene_loader.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=2 format=3 uid="uid://cbwmrnp0af35y"] -[ext_resource type="Script" path="res://addons/maaacks_scene_loader/base/scenes/Autoloads/SceneLoader.gd" id="1_l0dhx"] +[ext_resource type="Script" path="res://addons/maaacks_scene_loader/base/scenes/autoloads/scene_loader.gd" id="1_l0dhx"] [node name="SceneLoader" type="Node"] script = ExtResource("1_l0dhx") -loading_screen_path = "res://addons/maaacks_scene_loader/base/scenes/LoadingScreen/LoadingScreen.tscn" +loading_screen_path = "res://addons/maaacks_scene_loader/base/scenes/loading_screen/loading_screen.tscn" diff --git a/addons/maaacks_scene_loader/base/scenes/LoadingScreen/LoadingScreen.gd b/addons/maaacks_scene_loader/base/scenes/loading_screen/loading_screen.gd similarity index 81% rename from addons/maaacks_scene_loader/base/scenes/LoadingScreen/LoadingScreen.gd rename to addons/maaacks_scene_loader/base/scenes/loading_screen/loading_screen.gd index fec5051..9dc9b0f 100644 --- a/addons/maaacks_scene_loader/base/scenes/LoadingScreen/LoadingScreen.gd +++ b/addons/maaacks_scene_loader/base/scenes/loading_screen/loading_screen.gd @@ -7,6 +7,7 @@ const LOADING_COMPLETE_TEXT_STILL_WAITING = "Any Moment Now... (%d seconds)" const LOADING_TEXT = "Loading..." const LOADING_TEXT_WAITING = "Still Loading..." const LOADING_TEXT_STILL_WAITING = "Still Loading... (%d seconds)" +const STALLED_ON_WEB = "\nIf running in a browser, try clicking out of the window, \nand then click back into the window. It might unstick.\nLasty, you may try refreshing the page.\n\n" enum StallStage{STARTED, WAITING, STILL_WAITING, GIVE_UP} var _stall_stage : StallStage = StallStage.STARTED @@ -62,32 +63,36 @@ func _reset_scene_loading_progress(): _scene_loading_complete = false func _show_loading_stalled_error_message(): - if %ErrorMessage.visible: + if %StalledMessage.visible: return if _scene_loading_progress == 0: - %ErrorMessage.dialog_text = "Loading Error: Stalled at start." - if OS.has_feature("web"): - %ErrorMessage.dialog_text += "\nTry refreshing the page." + %StalledMessage.dialog_text = "Stalled at start. You may try waiting or restarting.\n" else: - %ErrorMessage.dialog_text = "Loading Error: Stalled at %d%%." % (_scene_loading_progress * 100.0) - %ErrorMessage.popup_centered() + %StalledMessage.dialog_text = "Stalled at %d%%. You may try waiting or restarting.\n" % (_scene_loading_progress * 100.0) + if OS.has_feature("web"): + %StalledMessage.dialog_text += STALLED_ON_WEB + %StalledMessage.popup() func _show_scene_switching_error_message(): if %ErrorMessage.visible: return %ErrorMessage.dialog_text = "Loading Error: Failed to switch scenes." - %ErrorMessage.popup_centered() + %ErrorMessage.popup() + +func _hide_popups(): + %ErrorMessage.hide() + %StalledMessage.hide() func _update_in_progress_messaging(): match _stall_stage: StallStage.STARTED: - %ErrorMessage.hide() + _hide_popups() %Title.text = LOADING_TEXT StallStage.WAITING: - %ErrorMessage.hide() + _hide_popups() %Title.text = LOADING_TEXT_WAITING StallStage.STILL_WAITING: - %ErrorMessage.hide() + _hide_popups() %Title.text = LOADING_TEXT_STILL_WAITING % _get_seconds_waiting() StallStage.GIVE_UP: _show_loading_stalled_error_message() @@ -96,13 +101,13 @@ func _update_in_progress_messaging(): func _update_loaded_messaging(): match _stall_stage: StallStage.STARTED: - %ErrorMessage.hide() + _hide_popups() %Title.text = LOADING_COMPLETE_TEXT StallStage.WAITING: - %ErrorMessage.hide() + _hide_popups() %Title.text = LOADING_COMPLETE_TEXT_WAITING StallStage.STILL_WAITING: - %ErrorMessage.hide() + _hide_popups() %Title.text = LOADING_COMPLETE_TEXT_STILL_WAITING % _get_seconds_waiting() StallStage.GIVE_UP: _show_scene_switching_error_message() @@ -120,10 +125,10 @@ func _process(_delta): _update_loaded_messaging() ResourceLoader.THREAD_LOAD_FAILED: %ErrorMessage.dialog_text = "Loading Error: %d" % status - %ErrorMessage.popup_centered() + %ErrorMessage.popup() set_process(false) ResourceLoader.THREAD_LOAD_INVALID_RESOURCE: - %ErrorMessage.hide() + _hide_popups() set_process(false) func _on_loading_timer_timeout(): @@ -138,21 +143,30 @@ func _on_loading_timer_timeout(): StallStage.STILL_WAITING: _stall_stage = StallStage.GIVE_UP -func _on_error_message_confirmed(): +func _reload_main_scene_or_quit(): var err = get_tree().change_scene_to_file(ProjectSettings.get_setting("application/run/main_scene")) if err: push_error("failed to load main scene: %d" % err) get_tree().quit() +func _on_error_message_confirmed(): + _reload_main_scene_or_quit() + +func _on_confirmation_dialog_canceled(): + _reload_main_scene_or_quit() + +func _on_confirmation_dialog_confirmed(): + _reset_loading_stage() + func reset(): show() _reset_loading_stage() _reset_scene_loading_progress() _reset_loading_start_time() - %ErrorMessage.hide() + _hide_popups() set_process(true) func close(): set_process(false) - %ErrorMessage.hide() + _hide_popups() hide() diff --git a/addons/maaacks_scene_loader/base/scenes/LoadingScreen/LoadingScreen.tscn b/addons/maaacks_scene_loader/base/scenes/loading_screen/loading_screen.tscn similarity index 76% rename from addons/maaacks_scene_loader/base/scenes/LoadingScreen/LoadingScreen.tscn rename to addons/maaacks_scene_loader/base/scenes/loading_screen/loading_screen.tscn index 7a51545..714b0b3 100644 --- a/addons/maaacks_scene_loader/base/scenes/LoadingScreen/LoadingScreen.tscn +++ b/addons/maaacks_scene_loader/base/scenes/loading_screen/loading_screen.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=2 format=3 uid="uid://cd0jbh4metflb"] -[ext_resource type="Script" path="res://addons/maaacks_scene_loader/base/scenes/LoadingScreen/LoadingScreen.gd" id="1_gbk34"] +[ext_resource type="Script" path="res://addons/maaacks_scene_loader/base/scenes/loading_screen/loading_screen.gd" id="1_gbk34"] [node name="LoadingScreen" type="CanvasLayer"] process_mode = 3 @@ -65,12 +65,25 @@ max_value = 1.0 [node name="ErrorMessage" type="AcceptDialog" parent="Control"] unique_name_in_owner = true +title = "Loading Error" +initial_position = 2 +size = Vector2i(360, 100) + +[node name="StalledMessage" type="ConfirmationDialog" parent="Control"] +unique_name_in_owner = true +title = "Loading Stalled" +initial_position = 2 +size = Vector2i(360, 100) +ok_button_text = "Try Waiting" +cancel_button_text = "Reload" [node name="LoadingTimer" type="Timer" parent="."] unique_name_in_owner = true -wait_time = 10.0 +wait_time = 15.0 one_shot = true autostart = true [connection signal="confirmed" from="Control/ErrorMessage" to="." method="_on_error_message_confirmed"] +[connection signal="canceled" from="Control/StalledMessage" to="." method="_on_confirmation_dialog_canceled"] +[connection signal="confirmed" from="Control/StalledMessage" to="." method="_on_confirmation_dialog_confirmed"] [connection signal="timeout" from="LoadingTimer" to="." method="_on_loading_timer_timeout"] diff --git a/addons/maaacks_scene_loader/maaacks_scene_loader.gd b/addons/maaacks_scene_loader/maaacks_scene_loader.gd index 4fdd216..99cc227 100644 --- a/addons/maaacks_scene_loader/maaacks_scene_loader.gd +++ b/addons/maaacks_scene_loader/maaacks_scene_loader.gd @@ -3,7 +3,7 @@ extends EditorPlugin func _enter_tree(): - add_autoload_singleton("SceneLoader", "res://addons/maaacks_scene_loader/base/scenes/Autoloads/SceneLoader.tscn") + add_autoload_singleton("SceneLoader", "res://addons/maaacks_scene_loader/base/scenes/autoloads/scene_loader.tscn") func _exit_tree(): remove_autoload_singleton("SceneLoader") diff --git a/addons/maaacks_scene_loader/plugin.cfg b/addons/maaacks_scene_loader/plugin.cfg index 243b25c..10fa4ce 100644 --- a/addons/maaacks_scene_loader/plugin.cfg +++ b/addons/maaacks_scene_loader/plugin.cfg @@ -5,5 +5,5 @@ description="Scene loader with loading screen, progress bar, and error handling. Created in collaboration with members of the Godot Wild Jam community." author="Marek Belski" -version="0.7.2" +version="0.10.0" script="maaacks_scene_loader.gd" diff --git a/project.godot b/project.godot index 67da26f..8eae1a9 100644 --- a/project.godot +++ b/project.godot @@ -11,12 +11,12 @@ config_version=5 [application] config/name="Scene Loader" -config/features=PackedStringArray("4.2") +config/features=PackedStringArray("4.3") config/icon="res://icon.png" [autoload] -SceneLoader="*res://addons/maaacks_scene_loader/base/scenes/Autoloads/SceneLoader.tscn" +SceneLoader="*res://addons/maaacks_scene_loader/base/scenes/autoloads/scene_loader.tscn" [display] @@ -35,27 +35,27 @@ common/drop_mouse_on_gui_input_disabled=true ui_accept={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194309,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) -, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194310,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) -, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":32,"physical_keycode":0,"key_label":0,"unicode":32,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194309,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194310,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":32,"physical_keycode":0,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null) ] } ui_cancel={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194305,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194305,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":true,"script":null) ] } ui_page_up={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194323,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194323,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":9,"pressure":0.0,"pressed":true,"script":null) ] } ui_page_down={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194324,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194324,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":10,"pressure":0.0,"pressed":true,"script":null) ] }