Skip to content

Commit

Permalink
Merge pull request #4 from Maaack/updates-from-game-template
Browse files Browse the repository at this point in the history
Updates from game template
  • Loading branch information
Maaack committed Aug 27, 2024
2 parents 93022e0 + 6b5c1a8 commit 5f3ee64
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "":
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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():
Expand All @@ -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()
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion addons/maaacks_scene_loader/maaacks_scene_loader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 1 addition & 1 deletion addons/maaacks_scene_loader/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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"
16 changes: 8 additions & 8 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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)
]
}
Expand Down

0 comments on commit 5f3ee64

Please sign in to comment.