Merge pull request 'feature/integrate-loader' (#13) from feature/integrate-loader into dev

Reviewed-on: Athena/game-source#13
This commit is contained in:
darknight
2021-05-09 17:12:42 +02:00
8 changed files with 149 additions and 18 deletions
+9 -1
View File
@@ -1,2 +1,10 @@
# game-source # Hiiden Object
Integrate scenes [Warcraft](https://www.artstation.com/artwork/9mZ65Q) in Android application.
## Tips
See log android :
```
adb logcat -s godot
```
+14
View File
@@ -15,10 +15,24 @@ run/main_scene="res://scenes/main.tscn"
config/icon="res://icon.png" config/icon="res://icon.png"
config/quit_on_go_back=false config/quit_on_go_back=false
[autoload]
Global="*res://scenes/Global.gd"
Loading="*res://scenes/UI/Loading.tscn"
[display] [display]
window/stretch/mode="2d" window/stretch/mode="2d"
[input]
ui_end={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777230,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777217,"unicode":0,"echo":false,"script":null)
]
}
[physics] [physics]
common/enable_pause_aware_picking=true common/enable_pause_aware_picking=true
+60
View File
@@ -0,0 +1,60 @@
extends Control
var current_scene = null
var loader = null
var wait_frames = 1
var time_max = 100 # msec
func _ready():
print("[global#_ready] get root scene")
var root = get_tree().get_root()
current_scene = root.get_child(root.get_child_count() - 1)
func goto_scene(path):
print("[global#goto_scene]")
loader = ResourceLoader.load_interactive(path)
if loader == null:
print("Error loading ....")
return
set_process(true)
current_scene.queue_free()
wait_frames = 1
func _process(_delta):
print("[global#_process]")
if loader == null:
set_process(false)
return
if wait_frames > 0:
wait_frames -= 1
var tick = OS.get_ticks_msec()
# Use "time_max" to control for how long we block this thread
while OS.get_ticks_msec() < tick + time_max:
var err = loader.poll()
if err == ERR_FILE_EOF: # Finished loading.
var resource = loader.get_resource()
loader = null
set_new_scene(resource)
get_node("/root/Loading").hide()
break
elif err == OK:
update_progress()
else:
print("[global#_process] Error loading")
loader = null
break
func update_progress():
var progress = float(loader.get_stage()) / loader.get_stage_count()
print("[global#update_progress] " + String(progress))
get_node("/root/Loading").visible = true
func set_new_scene(scene_resource):
print("[global#set_new_scene]")
current_scene = scene_resource.instance()
get_node("/root").add_child(current_scene)
+2 -1
View File
@@ -1,4 +1,5 @@
extends Control extends Control
# Load scene warcraft
func _on_WarCraft_pressed(): func _on_WarCraft_pressed():
get_tree().change_scene("res://scenes/levels/WarCraft.tscn") Global.goto_scene("res://scenes/levels/WarCraft.tscn")
+11 -4
View File
@@ -6,13 +6,20 @@
[node name="ChooseScene" type="Control"] [node name="ChooseScene" type="Control"]
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
margin_left = 200.0
script = ExtResource( 1 ) script = ExtResource( 1 )
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="GridContainer" type="GridContainer" parent="."] [node name="games" type="Control" parent="."]
margin_left = 200.0
margin_right = 1024.0
margin_bottom = 600.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="GridContainer" type="GridContainer" parent="games"]
margin_left = 25.0 margin_left = 25.0
margin_top = 26.2599 margin_top = 26.2599
margin_right = 824.0 margin_right = 824.0
@@ -21,10 +28,10 @@ __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="WarCraft" type="TextureButton" parent="GridContainer"] [node name="WarCraft" type="TextureButton" parent="games/GridContainer"]
margin_right = 150.0 margin_right = 150.0
margin_bottom = 150.0 margin_bottom = 150.0
mouse_default_cursor_shape = 2 mouse_default_cursor_shape = 2
texture_normal = ExtResource( 2 ) texture_normal = ExtResource( 2 )
[connection signal="pressed" from="GridContainer/WarCraft" to="." method="_on_WarCraft_pressed"] [connection signal="pressed" from="games/GridContainer/WarCraft" to="." method="_on_WarCraft_pressed"]
+35
View File
@@ -0,0 +1,35 @@
[gd_scene format=2]
[node name="Control" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ColorRect" type="ColorRect" parent="."]
margin_right = 1024.0
margin_bottom = 600.0
rect_scale = Vector2( 1.00231, 1 )
color = Color( 0, 0, 0, 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="CenterContainer" type="CenterContainer" parent="ColorRect"]
margin_right = 1024.0
margin_bottom = 600.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VBoxContainer" type="VBoxContainer" parent="ColorRect/CenterContainer"]
margin_left = 479.0
margin_top = 293.0
margin_right = 544.0
margin_bottom = 307.0
[node name="Label" type="Label" parent="ColorRect/CenterContainer/VBoxContainer"]
margin_right = 65.0
margin_bottom = 14.0
text = "Loading ..."
+10 -4
View File
@@ -1,9 +1,15 @@
extends Spatial extends Spatial
export (PackedScene) var main = load("res://scenes/main.tscn") func _process(_delta):
# Event key "escape" and "godot event" ui_end
if Input.is_action_just_pressed("ui_end"):
_quit_to_menu()
func _notification(what): func _notification(what):
# Back to main scene # Notification for android back action
if what == MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST: if what == MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST:
var scene = main.instance() _quit_to_menu()
call_deferred("add_child", scene)
# Back to main scene
func _quit_to_menu():
Global.goto_scene("res://scenes/main.tscn")
+8 -8
View File
@@ -3,7 +3,7 @@ extends Node
export (PackedScene) var about = load("res://scenes/UI/About.tscn") export (PackedScene) var about = load("res://scenes/UI/About.tscn")
export (PackedScene) var scenes = load("res://scenes/UI/ChooseScene.tscn") export (PackedScene) var scenes = load("res://scenes/UI/ChooseScene.tscn")
var scene var current_scene = null
# Quit the game # Quit the game
func _on_Quit_pressed(): func _on_Quit_pressed():
@@ -12,17 +12,17 @@ func _on_Quit_pressed():
# Load scene about # Load scene about
func _on_About_pressed(): func _on_About_pressed():
_prepare_change_scene() _prepare_change_scene()
scene = about.instance() current_scene = about.instance()
add_child(scene) add_child(current_scene)
# Load scene for select game # Load scene for select game
func _on_New_pressed(): func _on_New_pressed():
_prepare_change_scene() _prepare_change_scene()
scene = scenes.instance() current_scene = scenes.instance()
add_child(scene) add_child(current_scene)
## PRIVATE ## PRIVATE
func _prepare_change_scene(): func _prepare_change_scene():
if (scene != null): if (current_scene != null):
remove_child(scene) remove_child(current_scene)
scene.call_deferred("free") current_scene.call_deferred("free")