Skip to content

Commit

Permalink
Merge pull request #20 from Maaack/opening-fixes
Browse files Browse the repository at this point in the history
Opening screen fixes
  • Loading branch information
Maaack authored Jan 9, 2024
2 parents 3df1554 + 0771464 commit 6679879
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 27 deletions.
32 changes: 15 additions & 17 deletions App/Scenes/LoadingScreen/LoadingScreen.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,32 @@ const LOADING_TEXT_WAITING = "Still Loading..."
enum StallStage{STARTED, WAITING, GIVE_UP}
var _stall_stage : StallStage = StallStage.STARTED
var _loading_complete : bool = false

var loading_progress : float = 0.0 :
var _loading_progress : float = 0.0 :
set(value):
if value == loading_progress:
if value == _loading_progress:
return
loading_progress = value
%ProgressBar.value = loading_progress
_loading_progress = value
%ProgressBar.value = _loading_progress
_reset_loading_stage()
var _changing_to_next_scene : bool = false

func _reset_loading_stage():
_stall_stage = StallStage.STARTED
%LoadingTimer.start()

func _load_next_scene():
var resource = SceneLoader.get_resource()
get_tree().change_scene_to_packed(resource)

func _set_loading_complete():
if _loading_complete:
if _changing_to_next_scene:
return
_loading_complete = true
call_deferred("_load_next_scene")
_changing_to_next_scene = true
SceneLoader.change_scene_to_resource()

func _process(_delta):
if _loading_complete:
call_deferred("_load_next_scene")
var status = SceneLoader.get_status()
match(status):
ResourceLoader.THREAD_LOAD_IN_PROGRESS:
loading_progress = SceneLoader.get_progress()
_loading_progress = SceneLoader.get_progress()
match _stall_stage:
StallStage.STARTED:
%ErrorMessage.hide()
Expand All @@ -46,15 +44,16 @@ func _process(_delta):
StallStage.GIVE_UP:
if %ErrorMessage.visible:
return
if loading_progress == 0:
if _loading_progress == 0:
%ErrorMessage.dialog_text = "Loading Error: Failed to start."
if OS.has_feature("web"):
%ErrorMessage.dialog_text += "\nTry refreshing the page."
else:
%ErrorMessage.dialog_text = "Loading Error: Failed at %d%%." % (loading_progress * 100.0)
%ErrorMessage.dialog_text = "Loading Error: Failed at %d%%." % (_loading_progress * 100.0)
%ErrorMessage.popup_centered()
ResourceLoader.THREAD_LOAD_LOADED:
loading_progress = 1.0
_loading_progress = 1.0
_loading_complete = true
match _stall_stage:
StallStage.STARTED:
%ErrorMessage.hide()
Expand All @@ -67,7 +66,6 @@ func _process(_delta):
return
%ErrorMessage.dialog_text = "Loading Error: Failed to switch scenes."
%ErrorMessage.popup_centered()
_set_loading_complete()
ResourceLoader.THREAD_LOAD_FAILED, ResourceLoader.THREAD_LOAD_INVALID_RESOURCE:
%ErrorMessage.dialog_text = "Loading Error: %d" % status
%ErrorMessage.popup_centered()
Expand Down
8 changes: 4 additions & 4 deletions App/Scripts/SceneLoader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ func get_resource():
_loaded_resource = current_loaded_resource
return _loaded_resource

func _change_scene_to_resource() -> void:
func change_scene_to_resource() -> void:
var err = get_tree().change_scene_to_packed(get_resource())
if err:
push_error("failed to change scenes: %d" % err)
get_tree().quit()

func _change_scene_to_loading_screen() -> void:
func change_scene_to_loading_screen() -> void:
var err = get_tree().change_scene_to_packed(_loading_screen)
if err:
push_error("failed to change scenes to loading screen: %d" % err)
Expand Down Expand Up @@ -78,7 +78,7 @@ func load_scene(scene_path : String, in_background : bool = false) -> void:
if _background_loading or not _check_loading_screen():
set_process(true)
else:
_change_scene_to_loading_screen()
change_scene_to_loading_screen()

func _ready():
set_process(false)
Expand All @@ -92,4 +92,4 @@ func _process(_delta):
emit_signal("scene_loaded")
set_process(false)
if not _background_loading:
_change_scene_to_resource()
change_scene_to_resource()
Binary file added Assets/Images/logo_vertical_color_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions Assets/Images/logo_vertical_color_dark.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://b1o6mhwyq1j7s"
path="res://.godot/imported/logo_vertical_color_dark.png-0e177503e7cd89c15ca526651a313e29.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Assets/Images/logo_vertical_color_dark.png"
dest_files=["res://.godot/imported/logo_vertical_color_dark.png-0e177503e7cd89c15ca526651a313e29.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
9 changes: 5 additions & 4 deletions Extras/Scenes/Opening/Opening.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ extends Control
@export var images : Array[Texture2D]
@export var start_delay : float = 0.5
@export var end_delay : float = 0.5
@export var show_loading_screen : bool = false

func next():
var status = SceneLoader.get_status()
if status == ResourceLoader.THREAD_LOAD_LOADED:
var packed_scene = SceneLoader.get_resource()
get_tree().change_scene_to_packed(packed_scene)
if show_loading_screen or status != ResourceLoader.THREAD_LOAD_LOADED:
SceneLoader.change_scene_to_loading_screen()
else:
SceneLoader.show_loading_screen()
SceneLoader.change_scene_to_resource()

func _add_textures_to_container(textures : Array[Texture2D]):
for texture in textures:
var texture_rect : TextureRect = TextureRect.new()
texture_rect.texture = texture
texture_rect.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
texture_rect.expand_mode = TextureRect.EXPAND_FIT_WIDTH_PROPORTIONAL
texture_rect.visible = false
%ImagesContainer.call_deferred("add_child", texture_rect)

Expand Down
4 changes: 2 additions & 2 deletions Extras/Scenes/Opening/Opening.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_scene load_steps=6 format=3 uid="uid://sikc02ddepyt"]

[ext_resource type="Script" path="res://Extras/Scenes/Opening/Opening.gd" id="1_fcjph"]
[ext_resource type="Texture2D" uid="uid://b4xpcuksnx4y0" path="res://icon.svg" id="2_psnkk"]
[ext_resource type="Texture2D" uid="uid://b1o6mhwyq1j7s" path="res://Assets/Images/logo_vertical_color_dark.png" id="2_70swx"]

[sub_resource type="Animation" id="Animation_nsnod"]
resource_name = "FadeInOut"
Expand Down Expand Up @@ -49,7 +49,7 @@ grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_fcjph")
next_scene = "res://Extras/Scenes/Menus/MainMenu/MainMenu.tscn"
images = Array[Texture2D]([ExtResource("2_psnkk")])
images = Array[Texture2D]([ExtResource("2_70swx")])
end_delay = 1.0

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
Expand Down

0 comments on commit 6679879

Please sign in to comment.