Files
puzzle-quest/scenes/UI/choose_scenes/ChooseScene.gd
T

77 lines
2.0 KiB
GDScript
Raw Normal View History

2021-05-08 13:44:51 +02:00
extends Control
2021-05-15 12:08:43 +02:00
export (PackedScene) var template = load("res://scenes/levels/Template.tscn")
2021-05-13 23:15:05 +02:00
onready var levels = Array()
func _ready():
_apply_scenes()
2021-05-09 17:10:40 +02:00
# Load scene warcraft
2021-05-13 23:15:05 +02:00
func _on_warcraft_pressed():
Global.goto_scene("res://scenes/levels/warcraft/WarCraft.tscn")
func _on_develop_pressed():
Global.goto_scene("res://developers/aurelien/CheckLightmap.tscn")
## PRIVATE
func _apply_scenes():
var table = Global.table_levels
var datas = null
var name = null
var thumb = null
var resource = null
for row_index in range(0, Global.table_levels.m_rows_count):
datas = Global.table_levels.get_data_at_row_idx(row_index)
for index in range(0, table.get_props_count()):
if name == null:
name = _get_name(index, table, datas)
if thumb == null:
thumb = _get_thumb(index, table, datas)
if resource == null:
resource = _get_resource(index, table, datas)
2021-05-15 12:08:43 +02:00
_apply_scene(_load_scene(name),
_load_texture(thumb),
_build_path(name),
_build_method(name))
2021-05-13 23:15:05 +02:00
name = null
thumb = null
resource = null
func _get_name(index, table, datas):
if table.get_prop_at(index).get_prop_name() == "name":
return datas[index].get_data()
func _get_thumb(index, table, datas):
if table.get_prop_at(index).get_prop_name() == "thumb":
return datas[index].get_data()
func _get_resource(index, table, datas):
if table.get_prop_at(index).get_prop_name() == "resource":
return datas[index].get_data()
2021-05-15 12:08:43 +02:00
func _build_path(name):
return "MarginContainer/HBoxContainer/"+name+"/TextureRect"
2021-05-15 01:20:47 +02:00
2021-05-15 12:08:43 +02:00
func _build_method(name):
return "_on_"+name.to_lower()+"_pressed"
2021-05-15 01:20:47 +02:00
2021-05-15 12:08:43 +02:00
func _load_scene(name):
var template_instance = template.instance()
template_instance.set_name(name)
2021-05-15 01:20:47 +02:00
2021-05-15 12:08:43 +02:00
return template_instance
2021-05-13 23:15:05 +02:00
2021-05-15 12:08:43 +02:00
func _load_texture(thumbnail):
return load(thumbnail)
2021-05-13 23:15:05 +02:00
2021-05-15 12:08:43 +02:00
func _apply_scene(instance, thumb, node, method):
$MarginContainer/HBoxContainer.add_child(instance)
var button = get_node(node+"/TextureButton")
button.set_normal_texture(thumb)
button.connect("pressed", self, method)
2021-05-13 23:15:05 +02:00