diff --git a/scenes/UI/choose_scenes/ChooseScene.gd b/scenes/UI/choose_scenes/ChooseScene.gd index 1efe1d1..8fbcdff 100644 --- a/scenes/UI/choose_scenes/ChooseScene.gd +++ b/scenes/UI/choose_scenes/ChooseScene.gd @@ -1,5 +1,7 @@ extends Control +export (PackedScene) var template = load("res://scenes/levels/Template.tscn") + onready var levels = Array() func _ready(): @@ -33,7 +35,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 @@ -50,41 +55,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 _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) -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") diff --git a/scenes/UI/choose_scenes/ChooseScene.tscn b/scenes/UI/choose_scenes/ChooseScene.tscn index 766ed52..dddb6f4 100644 --- a/scenes/UI/choose_scenes/ChooseScene.tscn +++ b/scenes/UI/choose_scenes/ChooseScene.tscn @@ -1,31 +1,45 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://scenes/UI/choose_scenes/ChooseScene.gd" type="Script" id=1] +[ext_resource path="res://scenes/levels/Template.tscn" type="PackedScene" id=2] [node name="ChooseScene" type="CenterContainer"] anchor_right = 1.0 anchor_bottom = 1.0 +margin_left = 73.7365 +margin_top = -67.0147 +margin_right = 73.7366 +margin_bottom = -67.0146 script = ExtResource( 1 ) __meta__ = { "_edit_use_anchors_": false } [node name="MarginContainer" type="MarginContainer" parent="."] -margin_left = 712.0 +margin_left = 705.0 margin_top = 435.0 -margin_right = 727.0 +margin_right = 735.0 margin_bottom = 465.0 size_flags_horizontal = 3 size_flags_vertical = 3 custom_constants/margin_right = 15 custom_constants/margin_top = 15 +custom_constants/margin_left = 15 custom_constants/margin_bottom = 15 __meta__ = { "_edit_use_anchors_": false } [node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer"] +margin_left = 15.0 margin_top = 15.0 +margin_right = 15.0 margin_bottom = 15.0 size_flags_horizontal = 3 size_flags_vertical = 3 +custom_constants/separation = 120 + +[node name="example" parent="MarginContainer/HBoxContainer" instance=ExtResource( 2 )] +visible = false + +[editable path="MarginContainer/HBoxContainer/example"] diff --git a/scenes/levels/Template.tscn b/scenes/levels/Template.tscn new file mode 100644 index 0000000..0ad350d --- /dev/null +++ b/scenes/levels/Template.tscn @@ -0,0 +1,75 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://assets/levels/warcraft.jpg" type="Texture" id=1] + +[node name="VBoxContainer" type="VBoxContainer"] +margin_right = 150.0 +margin_bottom = 174.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="TextureRect" type="TextureRect" parent="."] +margin_right = 150.0 +margin_bottom = 150.0 +texture = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="TextureButton" type="TextureButton" parent="TextureRect"] +margin_right = 40.0 +margin_bottom = 40.0 +mouse_default_cursor_shape = 2 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="VBoxContainer" type="HBoxContainer" parent="."] +margin_top = 154.0 +margin_right = 150.0 +margin_bottom = 174.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +custom_constants/separation = 25 +alignment = 1 + +[node name="ButtonReset" type="Button" parent="VBoxContainer"] +margin_right = 62.0 +margin_bottom = 20.0 +mouse_default_cursor_shape = 2 +size_flags_horizontal = 3 + +[node name="Label" type="Label" parent="VBoxContainer/ButtonReset"] +anchor_right = 1.0 +anchor_bottom = 1.0 +size_flags_horizontal = 3 +size_flags_vertical = 7 +text = "Reset" +align = 1 +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="ButtonCount" type="Button" parent="VBoxContainer"] +margin_left = 87.0 +margin_right = 150.0 +margin_bottom = 20.0 +mouse_default_cursor_shape = 2 +size_flags_horizontal = 3 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Label" type="Label" parent="VBoxContainer/ButtonCount"] +anchor_right = 1.0 +anchor_bottom = 1.0 +size_flags_horizontal = 3 +size_flags_vertical = 7 +text = "X / 10" +align = 1 +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +}