Fix template select scene
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
extends Control
|
||||
|
||||
export (PackedScene) var template = load("res://scenes/levels/Template.tscn")
|
||||
|
||||
onready var levels = Array()
|
||||
|
||||
func _ready():
|
||||
@@ -31,7 +33,10 @@ func _apply_scenes():
|
||||
if resource == null:
|
||||
resource = _get_resource(index, table, datas)
|
||||
|
||||
_apply_scene(name, thumb, resource)
|
||||
_apply_scene(_load_scene(name),
|
||||
_load_texture(thumb),
|
||||
_build_path(name),
|
||||
_build_method(name))
|
||||
name = null
|
||||
thumb = null
|
||||
resource = null
|
||||
@@ -48,42 +53,24 @@ func _get_resource(index, table, datas):
|
||||
if table.get_prop_at(index).get_prop_name() == "resource":
|
||||
return datas[index].get_data()
|
||||
|
||||
func _apply_scene(name, thumb, resource):
|
||||
$MarginContainer/HBoxContainer.add_child(_configure_margin_container())
|
||||
_configure_button(thumb, $MarginContainer/HBoxContainer/MarginContainer, name)
|
||||
$MarginContainer/HBoxContainer/MarginContainer.add_child(_configure_vbox())
|
||||
$MarginContainer/HBoxContainer/MarginContainer/VBoxContainer.add_child(_configure_hbox())
|
||||
$MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/HBoxContainer.add_child(_configure_label("reset"))
|
||||
$MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/HBoxContainer.add_child(_configure_label("0 / 10"))
|
||||
func _build_path(name):
|
||||
return "MarginContainer/HBoxContainer/"+name+"/TextureRect"
|
||||
|
||||
func _configure_margin_container():
|
||||
var margin = MarginContainer.new()
|
||||
margin.set_name("MarginContainer")
|
||||
func _build_method(name):
|
||||
return "_on_"+name.to_lower()+"_pressed"
|
||||
|
||||
func _load_scene(name):
|
||||
var template_instance = template.instance()
|
||||
template_instance.set_name(name)
|
||||
|
||||
return margin
|
||||
return template_instance
|
||||
|
||||
func _configure_hbox():
|
||||
var hbox = HBoxContainer.new()
|
||||
hbox.set_name("HBoxContainer")
|
||||
|
||||
return hbox
|
||||
func _load_texture(thumbnail):
|
||||
return load(thumbnail)
|
||||
|
||||
func _configure_vbox():
|
||||
var vbox = VBoxContainer.new()
|
||||
vbox.set_name("VBoxContainer")
|
||||
|
||||
return vbox
|
||||
|
||||
func _configure_label(name):
|
||||
var label = Label.new()
|
||||
label.set_text(name)
|
||||
|
||||
return label
|
||||
|
||||
func _configure_button(thumb, parent, name):
|
||||
var thumbnail = TextureButton.new()
|
||||
parent.add_child(thumbnail)
|
||||
# $MarginContainer/HBoxContainer/VBoxContainer.add_child(thumbnail)
|
||||
thumbnail.set_normal_texture(load(thumb))
|
||||
thumbnail.connect("pressed", self, "_on_"+name.to_lower()+"_pressed")
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user