Node editor updates and support for alpha channel

Added initial support for alpha channel (in combine, decompose and blend nodes). Textures with alpha channels can be exported using the material node albedo input.
Updated node editor with a simple editor for enumerated parameters.
This commit is contained in:
RodZill4 2018-10-26 22:44:47 +02:00
parent 938397f3f6
commit bf4a125386
17 changed files with 421 additions and 39 deletions

View File

@ -7,7 +7,7 @@
[ext_resource path="res://addons/material_maker/renderer.tscn" type="PackedScene" id=5] [ext_resource path="res://addons/material_maker/renderer.tscn" type="PackedScene" id=5]
[ext_resource path="res://addons/material_maker/node_factory.gd" type="Script" id=6] [ext_resource path="res://addons/material_maker/node_factory.gd" type="Script" id=6]
[node name="MainWindow" type="Panel" index="0"] [node name="MainWindow" type="Panel"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0

View File

@ -116,15 +116,15 @@ func get_source_f(source):
var rv var rv
if source.has("f"): if source.has("f"):
rv = source.f rv = source.f
elif source.has("rgb"): elif source.has("rgb") or source.has("rgba"):
rv = "dot("+source.rgb+", vec3(1.0))/3.0" rv = "dot("+source.rgb+", vec3(1.0))/3.0"
else: else:
rv = "***error***" rv = "***error***"
return rv return rv
func get_source_rgb(source): func get_source_rgb(source):
var rv var rv
if source.has("rgb"): if source.has("rgb") or source.has("rgba"):
rv = source.rgb rv = source.rgb
elif source.has("f"): elif source.has("f"):
rv = "vec3("+source.f+")" rv = "vec3("+source.f+")"
@ -132,6 +132,18 @@ func get_source_rgb(source):
rv = "***error***" rv = "***error***"
return rv return rv
func get_source_rgba(source):
var rv
if source.has("rgba"):
rv = source.rgba
elif source.has("rgb"):
rv = "vec4("+source.rgb+", 1.0)"
elif source.has("f"):
rv = "vec4(vec3("+source.f+"), 1.0)"
else:
rv = "***error***"
return rv
func reset(): func reset():
generated = false generated = false
generated_variants = [] generated_variants = []
@ -145,13 +157,17 @@ func get_shader_code(uv, slot = 0):
if !rv.has("f"): if !rv.has("f"):
if rv.has("rgb"): if rv.has("rgb"):
rv.f = "(dot("+rv.rgb+", vec3(1.0))/3.0)" rv.f = "(dot("+rv.rgb+", vec3(1.0))/3.0)"
elif rv.has("rgba"):
rv.f = "(dot("+rv.rgba+".rgb, vec3(1.0))/3.0)"
else: else:
rv.f = "0.0" rv.f = "0.0"
if !rv.has("rgb"): if !rv.has("rgb"):
if rv.has("f"): if rv.has("rgba"):
rv.rgb = "vec3("+rv.f+")" rv.rgb = rv.rgba+".rgb"
else: else:
rv.f = "vec3(0.0)" rv.rgb = "vec3("+rv.f+")"
if !rv.has("rgba"):
rv.rgba = "vec4("+rv.rgb+", 1.0)"
return rv return rv
func get_shader_code_with_globals(uv, slot = 0): func get_shader_code_with_globals(uv, slot = 0):

View File

@ -43,8 +43,8 @@ func _get_shader_code(uv):
variant_index = generated_variants.size() variant_index = generated_variants.size()
generated_variants.append(uv) generated_variants.append(uv)
rv.code = src0_code.code+src1_code.code+src2_code.code rv.code = src0_code.code+src1_code.code+src2_code.code
rv.code += "vec3 %s_%d_rgb = blend_%s(%s, %s, %s, %s);\n" % [ name, variant_index, BLEND_TYPES[parameters.blend_type].shortname, uv, src0_code.rgb, src1_code.rgb, amount_str ] rv.code += "vec4 %s_%d_rgba = vec4(blend_%s(%s, %s, %s, %s * %s.a), min(1.0, %s.a + %s * %s.a));\n" % [ name, variant_index, BLEND_TYPES[parameters.blend_type].shortname, uv, src0_code.rgb, src1_code.rgb, amount_str, src0_code.rgba, src1_code.rgba, amount_str, src0_code.rgba ]
rv.rgb = "%s_%d_rgb" % [ name, variant_index ] rv.rgba = "%s_%d_rgba" % [ name, variant_index ]
return rv return rv
func _get_state_variables(): func _get_state_variables():

View File

@ -6,19 +6,24 @@ func _get_shader_code(uv):
var src0 = get_source(0) var src0 = get_source(0)
var src1 = get_source(1) var src1 = get_source(1)
var src2 = get_source(2) var src2 = get_source(2)
var src3 = get_source(3)
var src0_code = { defs="", code="", f="0.0" } var src0_code = { defs="", code="", f="0.0" }
var src1_code = { defs="", code="", f="0.0" } var src1_code = { defs="", code="", f="0.0" }
var src2_code = { defs="", code="", f="0.0" } var src2_code = { defs="", code="", f="0.0" }
var src3_code = { defs="", code="", f="1.0" }
if src0 != null: if src0 != null:
src0_code = src0.get_shader_code(uv) src0_code = src0.get_shader_code(uv)
if src1 != null: if src1 != null:
src1_code = src1.get_shader_code(uv) src1_code = src1.get_shader_code(uv)
if src2 != null: if src2 != null:
src2_code = src2.get_shader_code(uv) src2_code = src2.get_shader_code(uv)
if src3 != null:
src3_code = src3.get_shader_code(uv)
if generated_variants.empty(): if generated_variants.empty():
rv.defs = src0_code.defs; rv.defs = src0_code.defs;
rv.defs += src1_code.defs; rv.defs += src1_code.defs;
rv.defs += src2_code.defs; rv.defs += src2_code.defs;
rv.defs += src3_code.defs;
var variant_index = generated_variants.find(uv) var variant_index = generated_variants.find(uv)
if variant_index == -1: if variant_index == -1:
variant_index = generated_variants.size() variant_index = generated_variants.size()
@ -26,6 +31,7 @@ func _get_shader_code(uv):
rv.code = src0_code.code rv.code = src0_code.code
rv.code += src1_code.code rv.code += src1_code.code
rv.code += src2_code.code rv.code += src2_code.code
rv.code += "vec3 %s_%d_rgb = vec3(%s, %s, %s);\n" % [ name, variant_index, src0_code.f, src1_code.f, src2_code.f ] rv.code += src3_code.code
rv.rgb = "%s_%d_rgb" % [ name, variant_index ] rv.code += "vec4 %s_%d_rgba = vec4(%s, %s, %s, %s);\n" % [ name, variant_index, src0_code.f, src1_code.f, src2_code.f, src3_code.f ]
rv.rgba = "%s_%d_rgba" % [ name, variant_index ]
return rv return rv

View File

@ -2,7 +2,6 @@
[ext_resource path="res://addons/material_maker/nodes/combine/combine.gd" type="Script" id=1] [ext_resource path="res://addons/material_maker/nodes/combine/combine.gd" type="Script" id=1]
[sub_resource type="Theme" id=1] [sub_resource type="Theme" id=1]
@ -35,7 +34,7 @@ slot/0/left_type = 0
slot/0/left_color = Color( 0.756863, 0.756863, 0.756863, 1 ) slot/0/left_color = Color( 0.756863, 0.756863, 0.756863, 1 )
slot/0/right_enabled = true slot/0/right_enabled = true
slot/0/right_type = 0 slot/0/right_type = 0
slot/0/right_color = Color( 0.5, 0.5, 1, 1 ) slot/0/right_color = Color( 0.414353, 1, 0.388902, 0.353608 )
slot/1/left_enabled = true slot/1/left_enabled = true
slot/1/left_type = 0 slot/1/left_type = 0
slot/1/left_color = Color( 0.756863, 0.756863, 0.756863, 1 ) slot/1/left_color = Color( 0.756863, 0.756863, 0.756863, 1 )
@ -48,8 +47,14 @@ slot/2/left_color = Color( 0.756863, 0.756863, 0.756863, 1 )
slot/2/right_enabled = false slot/2/right_enabled = false
slot/2/right_type = 0 slot/2/right_type = 0
slot/2/right_color = Color( 0.498039, 0.498039, 1, 1 ) slot/2/right_color = Color( 0.498039, 0.498039, 1, 1 )
slot/3/left_enabled = true
slot/3/left_type = 0
slot/3/left_color = Color( 0.756863, 0.756863, 0.756863, 1 )
slot/3/right_enabled = false
slot/3/right_type = 0
slot/3/right_color = Color( 1, 1, 1, 1 )
script = ExtResource( 1 ) script = ExtResource( 1 )
_sections_unfolded = [ "Theme", "slot", "slot/0", "slot/1", "slot/2" ] _sections_unfolded = [ "Theme", "slot", "slot/0", "slot/1", "slot/2", "slot/3" ]
[node name="R" type="Label" parent="." index="0"] [node name="R" type="Label" parent="." index="0"]
@ -114,4 +119,25 @@ percent_visible = 1.0
lines_skipped = 0 lines_skipped = 0
max_lines_visible = -1 max_lines_visible = -1
[node name="A" type="Label" parent="." index="3"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 16.0
margin_top = 68.0
margin_right = 86.0
margin_bottom = 82.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
text = "A"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1

View File

@ -1,12 +1,12 @@
tool tool
extends "res://addons/material_maker/node_base.gd" extends "res://addons/material_maker/node_base.gd"
const OUTPUTS = [ "r", "g", "b" ] const OUTPUTS = [ "r", "g", "b", "a" ]
func _get_shader_code(uv, output = 0): func _get_shader_code(uv, output = 0):
var rv = { defs="", code="" } var rv = { defs="", code="" }
var src = get_source() var src = get_source()
var src_code = { defs="", code="", f="0.0" } var src_code = { defs="", code="", rgba="vec4(0.0)" }
if src != null: if src != null:
src_code = src.get_shader_code(uv) src_code = src.get_shader_code(uv)
if generated_variants.empty(): if generated_variants.empty():
@ -16,6 +16,6 @@ func _get_shader_code(uv, output = 0):
variant_index = generated_variants.size() variant_index = generated_variants.size()
generated_variants.append(uv) generated_variants.append(uv)
rv.code = src_code.code rv.code = src_code.code
rv.code += "vec3 %s_%d_rgb = %s;\n" % [ name, variant_index, src_code.rgb ] rv.code += "vec4 %s_%d_rgba = %s;\n" % [ name, variant_index, src_code.rgba ]
rv.f = "%s_%d_rgb.%s" % [ name, variant_index, OUTPUTS[output] ] rv.f = "%s_%d_rgba.%s" % [ name, variant_index, OUTPUTS[output] ]
return rv return rv

View File

@ -2,11 +2,10 @@
[ext_resource path="res://addons/material_maker/nodes/decompose/decompose.gd" type="Script" id=1] [ext_resource path="res://addons/material_maker/nodes/decompose/decompose.gd" type="Script" id=1]
[sub_resource type="Theme" id=1] [sub_resource type="Theme" id=1]
[node name="Decompose" type="GraphNode" index="0"] [node name="Decompose" type="GraphNode"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -32,7 +31,7 @@ comment = false
overlay = 0 overlay = 0
slot/0/left_enabled = true slot/0/left_enabled = true
slot/0/left_type = 0 slot/0/left_type = 0
slot/0/left_color = Color( 0.498039, 0.498039, 1, 1 ) slot/0/left_color = Color( 0.411765, 1, 0.388235, 0.352941 )
slot/0/right_enabled = true slot/0/right_enabled = true
slot/0/right_type = 0 slot/0/right_type = 0
slot/0/right_color = Color( 0.756863, 0.756863, 0.756863, 1 ) slot/0/right_color = Color( 0.756863, 0.756863, 0.756863, 1 )
@ -48,8 +47,14 @@ slot/2/left_color = Color( 0.756863, 0.756863, 0.756863, 1 )
slot/2/right_enabled = true slot/2/right_enabled = true
slot/2/right_type = 0 slot/2/right_type = 0
slot/2/right_color = Color( 0.756863, 0.756863, 0.756863, 1 ) slot/2/right_color = Color( 0.756863, 0.756863, 0.756863, 1 )
slot/3/left_enabled = false
slot/3/left_type = 0
slot/3/left_color = Color( 1, 1, 1, 1 )
slot/3/right_enabled = true
slot/3/right_type = 0
slot/3/right_color = Color( 0.756863, 0.756863, 0.756863, 1 )
script = ExtResource( 1 ) script = ExtResource( 1 )
_sections_unfolded = [ "Theme", "slot", "slot/0", "slot/1", "slot/2" ] _sections_unfolded = [ "Theme", "slot", "slot/0", "slot/1", "slot/2", "slot/3" ]
[node name="R" type="Label" parent="." index="0"] [node name="R" type="Label" parent="." index="0"]
@ -117,4 +122,26 @@ percent_visible = 1.0
lines_skipped = 0 lines_skipped = 0
max_lines_visible = -1 max_lines_visible = -1
[node name="A" type="Label" parent="." index="3"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 16.0
margin_top = 68.0
margin_right = 106.0
margin_bottom = 82.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
text = "A"
align = 2
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1

View File

@ -2,7 +2,6 @@
[ext_resource path="res://addons/material_maker/nodes/material/material.gd" type="Script" id=1] [ext_resource path="res://addons/material_maker/nodes/material/material.gd" type="Script" id=1]
[sub_resource type="Theme" id=1] [sub_resource type="Theme" id=1]
@ -30,13 +29,13 @@ comment = false
overlay = 0 overlay = 0
slot/0/left_enabled = false slot/0/left_enabled = false
slot/0/left_type = 0 slot/0/left_type = 0
slot/0/left_color = Color( 0.5, 0.5, 1, 1 ) slot/0/left_color = Color( 0.411765, 1, 0.388235, 0.352941 )
slot/0/right_enabled = false slot/0/right_enabled = false
slot/0/right_type = 0 slot/0/right_type = 0
slot/0/right_color = Color( 0.5, 0.5, 1, 1 ) slot/0/right_color = Color( 0.5, 0.5, 1, 1 )
slot/1/left_enabled = true slot/1/left_enabled = true
slot/1/left_type = 0 slot/1/left_type = 0
slot/1/left_color = Color( 0.5, 0.5, 1, 1 ) slot/1/left_color = Color( 0.411765, 1, 0.388235, 0.352941 )
slot/1/right_enabled = false slot/1/right_enabled = false
slot/1/right_type = 0 slot/1/right_type = 0
slot/1/right_color = Color( 0.5, 0.5, 1, 1 ) slot/1/right_color = Color( 0.5, 0.5, 1, 1 )
@ -72,12 +71,12 @@ slot/6/right_type = 0
slot/6/right_color = Color( 0.498039, 0.498039, 1, 1 ) slot/6/right_color = Color( 0.498039, 0.498039, 1, 1 )
slot/7/left_enabled = true slot/7/left_enabled = true
slot/7/left_type = 0 slot/7/left_type = 0
slot/7/left_color = Color( 0.494118, 0.494118, 1, 1 ) slot/7/left_color = Color( 0.756863, 0.756863, 0.756863, 1 )
slot/7/right_enabled = false slot/7/right_enabled = false
slot/7/right_type = 0 slot/7/right_type = 0
slot/7/right_color = Color( 0.494118, 0.494118, 1, 1 ) slot/7/right_color = Color( 0.494118, 0.494118, 1, 1 )
script = ExtResource( 1 ) script = ExtResource( 1 )
_sections_unfolded = [ "Theme", "slot", "slot/0", "slot/1", "slot/2", "slot/5" ] _sections_unfolded = [ "Theme", "slot", "slot/0", "slot/1", "slot/2", "slot/5", "slot/7" ]
[node name="resolution" type="OptionButton" parent="." index="0"] [node name="resolution" type="OptionButton" parent="." index="0"]

View File

@ -157,7 +157,7 @@ func _get_shader_code(uv, slot = 0):
func get_globals(): func get_globals():
var list = .get_globals() var list = .get_globals()
if model_data.has("global") and list.find(model_data.global) == -1: if typeof(model_data) == TYPE_DICTIONARY and model_data.has("global") and list.find(model_data.global) == -1:
list.append(model_data.global) list.append(model_data.global)
return list return list

View File

@ -21,7 +21,7 @@ static func generate_shader(src_code):
var shader_code = src_code.defs var shader_code = src_code.defs
shader_code += "void fragment() {\n" shader_code += "void fragment() {\n"
shader_code += src_code.code shader_code += src_code.code
shader_code += "COLOR = vec4("+src_code.rgb+", 1.0);\n" shader_code += "COLOR = "+src_code.rgba+";\n"
shader_code += "}\n" shader_code += "}\n"
#print("GENERATED SHADER:\n"+shader_code) #print("GENERATED SHADER:\n"+shader_code)
code += shader_code code += shader_code

View File

@ -16,13 +16,13 @@ void fragment() {
render_priority = 0 render_priority = 0
shader = SubResource( 1 ) shader = SubResource( 1 )
[node name="Renderer" type="Viewport"] [node name="Renderer" type="Viewport" index="0"]
arvr = false arvr = false
size = Vector2( 0, 0 ) size = Vector2( 0, 0 )
own_world = true own_world = true
world = null world = null
transparent_bg = false transparent_bg = true
msaa = 2 msaa = 2
hdr = false hdr = false
disable_3d = false disable_3d = false

View File

@ -0,0 +1,12 @@
tool
extends WindowDialog
signal ok
func set_value(n, v):
$VBoxContainer/GridContainer/name.text = n
$VBoxContainer/GridContainer/value.text = v
func _on_OK_pressed():
emit_signal("ok", $VBoxContainer/GridContainer/name.text, $VBoxContainer/GridContainer/value.text)
queue_free()

View File

@ -0,0 +1,220 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://addons/material_maker/widgets/node_editor/enum_editor.gd" type="Script" id=1]
[node name="EnumEditor" type="WindowDialog" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 137.0
margin_bottom = 79.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
popup_exclusive = true
window_title = "Enum Editor"
resizable = false
script = ExtResource( 1 )
_sections_unfolded = [ "Popup" ]
[node name="VBoxContainer" type="VBoxContainer" parent="." index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 1.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 0
[node name="GridContainer" type="GridContainer" parent="VBoxContainer" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 137.0
margin_bottom = 52.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
columns = 2
[node name="Label1" type="Label" parent="VBoxContainer/GridContainer" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 5.0
margin_right = 42.0
margin_bottom = 19.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
text = "Name:"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
[node name="name" type="LineEdit" parent="VBoxContainer/GridContainer" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 46.0
margin_right = 137.0
margin_bottom = 24.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 1
size_flags_horizontal = 3
size_flags_vertical = 1
focus_mode = 2
context_menu_enabled = true
placeholder_alpha = 0.6
caret_blink = false
caret_blink_speed = 0.65
caret_position = 0
[node name="Label2" type="Label" parent="VBoxContainer/GridContainer" index="2"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 33.0
margin_right = 42.0
margin_bottom = 47.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
text = "Value:"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
[node name="value" type="LineEdit" parent="VBoxContainer/GridContainer" index="3"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 46.0
margin_top = 28.0
margin_right = 137.0
margin_bottom = 52.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 1
size_flags_horizontal = 3
size_flags_vertical = 1
focus_mode = 2
context_menu_enabled = true
placeholder_alpha = 0.6
caret_blink = false
caret_blink_speed = 0.65
caret_position = 0
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 6.0
margin_top = 56.0
margin_right = 130.0
margin_bottom = 76.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 4
size_flags_vertical = 0
alignment = 0
_sections_unfolded = [ "Size Flags" ]
[node name="OK" type="Button" parent="VBoxContainer/HBoxContainer" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 60.0
margin_bottom = 20.0
rect_min_size = Vector2( 60, 0 )
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
group = null
text = "OK"
flat = false
align = 1
_sections_unfolded = [ "Rect" ]
[node name="Cancel" type="Button" parent="VBoxContainer/HBoxContainer" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 64.0
margin_right = 124.0
margin_bottom = 20.0
rect_min_size = Vector2( 60, 0 )
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
group = null
text = "Cancel"
flat = false
align = 1
_sections_unfolded = [ "Rect" ]
[connection signal="text_entered" from="VBoxContainer/GridContainer/name" to="." method="_on_LineEdit_text_entered"]
[connection signal="text_entered" from="VBoxContainer/GridContainer/value" to="." method="_on_LineEdit_text_entered"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/OK" to="." method="_on_OK_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Cancel" to="." method="queue_free"]

View File

@ -3,7 +3,7 @@
[ext_resource path="res://addons/material_maker/widgets/node_editor/node_editor.gd" type="Script" id=1] [ext_resource path="res://addons/material_maker/widgets/node_editor/node_editor.gd" type="Script" id=1]
[ext_resource path="res://addons/material_maker/icons/plus.png" type="Texture" id=2] [ext_resource path="res://addons/material_maker/icons/plus.png" type="Texture" id=2]
[node name="NodeEditor" type="WindowDialog" index="0"] [node name="NodeEditor" type="WindowDialog"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0

View File

@ -5,8 +5,18 @@ var size_first = 0
var size_last = 12 var size_last = 12
var size_default = 8 var size_default = 8
var enum_values = null
var enum_current = 0
const PARAMETER_TYPE = [ "float", "size", "enum", "boolean" ] const PARAMETER_TYPE = [ "float", "size", "enum", "boolean" ]
const ENUM_ADD = -1
const ENUM_EDIT = -2
const ENUM_REMOVE = -3
const ENUM_UP = -4
const ENUM_DOWN = -5
func _ready(): func _ready():
pass pass
@ -66,6 +76,9 @@ func set_model_data(data):
elif data.type == "enum": elif data.type == "enum":
$Type.selected = 2 $Type.selected = 2
w = $Types/T2 w = $Types/T2
data = data.duplicate()
enum_values = data.values
update_enum_list()
elif data.type == "boolean": elif data.type == "boolean":
$Type.selected = 3 $Type.selected = 3
w = $Types/T3 w = $Types/T3
@ -88,12 +101,72 @@ func get_model_data():
data.first = size_first data.first = size_first
data.last = size_last data.last = size_last
data.default = size_default data.default = size_default
elif $Type.selected == 2:
data.values = enum_values
return data return data
func _on_Delete_pressed(): func _on_Delete_pressed():
queue_free() queue_free()
func _on_OptionButton_item_selected(ID): func _on_Type_item_selected(ID):
for c in $Types.get_children(): for c in $Types.get_children():
c.visible = "T"+str(ID) == c.name c.visible = "T"+str(ID) == c.name
func update_enum_list():
var options = $Types/T2/EnumValues
options.clear()
if !enum_values.empty():
for i in range(enum_values.size()):
var v = enum_values[i]
options.add_item(v.name+" ("+v.value+")", i)
options.add_separator()
var v = enum_values[enum_current]
options.add_item("Edit "+v.value, ENUM_EDIT)
options.add_item("Remove "+v.value, ENUM_REMOVE)
if enum_current > 0:
options.add_item("Move "+v.value+" up", ENUM_UP)
if enum_current < enum_values.size() - 1:
options.add_item("Move "+v.value+" down", ENUM_DOWN)
options.add_separator()
options.add_item("Add value", ENUM_ADD)
options.selected = enum_current
func _on_EnumValues_item_selected(id):
id = $Types/T2/EnumValues.get_item_id(id)
if id >= 0 and id < enum_values.size():
enum_current = id
elif id == ENUM_EDIT:
var dialog = load("res://addons/material_maker/widgets/node_editor/enum_editor.tscn").instance()
var v = enum_values[enum_current]
add_child(dialog)
dialog.set_value(v.name, v.value)
dialog.connect("ok", self, "update_enum_value", [ enum_current ])
dialog.popup_centered()
elif id == ENUM_ADD:
var dialog = load("res://addons/material_maker/widgets/node_editor/enum_editor.tscn").instance()
add_child(dialog)
dialog.connect("ok", self, "update_enum_value", [ -1 ])
dialog.popup_centered()
elif id == ENUM_REMOVE:
enum_values.remove(enum_current)
enum_current = 0
elif id == ENUM_UP:
var tmp = enum_values[enum_current]
enum_values[enum_current] = enum_values[enum_current-1]
enum_values[enum_current-1] = tmp
enum_current -= 1
elif id == ENUM_DOWN:
var tmp = enum_values[enum_current]
enum_values[enum_current] = enum_values[enum_current+1]
enum_values[enum_current+1] = tmp
enum_current += 1
update_enum_list()
func update_enum_value(n, v, i):
if i == -1:
enum_values.append({ name=n, value=v })
enum_current = enum_values.size()-1
else:
enum_values[i] = { name=n, value=v }
enum_current = i
update_enum_list()

View File

@ -3,7 +3,7 @@
[ext_resource path="res://addons/material_maker/widgets/node_editor/parameter.gd" type="Script" id=1] [ext_resource path="res://addons/material_maker/widgets/node_editor/parameter.gd" type="Script" id=1]
[ext_resource path="res://addons/material_maker/icons/minus.png" type="Texture" id=2] [ext_resource path="res://addons/material_maker/icons/minus.png" type="Texture" id=2]
[node name="Parameter" type="HBoxContainer" index="0"] [node name="Parameter" type="HBoxContainer"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -370,6 +370,7 @@ align = 0
[node name="T1" type="HBoxContainer" parent="Types" index="1"] [node name="T1" type="HBoxContainer" parent="Types" index="1"]
editor/display_folded = true
visible = false visible = false
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -527,7 +528,6 @@ selected = -1
[node name="T2" type="HBoxContainer" parent="Types" index="2"] [node name="T2" type="HBoxContainer" parent="Types" index="2"]
editor/display_folded = true
visible = false visible = false
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -543,7 +543,7 @@ size_flags_horizontal = 1
size_flags_vertical = 1 size_flags_vertical = 1
alignment = 0 alignment = 0
[node name="OptionButton" type="OptionButton" parent="Types/T2" index="0"] [node name="EnumValues" type="OptionButton" parent="Types/T2" index="0"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -611,7 +611,7 @@ align = 0
[connection signal="pressed" from="Delete" to="." method="_on_Delete_pressed"] [connection signal="pressed" from="Delete" to="." method="_on_Delete_pressed"]
[connection signal="item_selected" from="Type" to="." method="_on_OptionButton_item_selected"] [connection signal="item_selected" from="Type" to="." method="_on_Type_item_selected"]
[connection signal="item_selected" from="Types/T1/First" to="." method="_on_First_item_selected"] [connection signal="item_selected" from="Types/T1/First" to="." method="_on_First_item_selected"]
@ -619,4 +619,6 @@ align = 0
[connection signal="item_selected" from="Types/T1/Default" to="." method="_on_Default_item_selected"] [connection signal="item_selected" from="Types/T1/Default" to="." method="_on_Default_item_selected"]
[connection signal="item_selected" from="Types/T2/EnumValues" to="." method="_on_EnumValues_item_selected"]

View File

@ -2,7 +2,7 @@
[ext_resource path="res://addons/material_maker/widgets/text_dialog.gd" type="Script" id=1] [ext_resource path="res://addons/material_maker/widgets/text_dialog.gd" type="Script" id=1]
[node name="TextDialog" type="WindowDialog"] [node name="TextDialog" type="WindowDialog" index="0"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -16,10 +16,11 @@ mouse_filter = 0
mouse_default_cursor_shape = 0 mouse_default_cursor_shape = 0
size_flags_horizontal = 1 size_flags_horizontal = 1
size_flags_vertical = 1 size_flags_vertical = 1
popup_exclusive = false popup_exclusive = true
window_title = "blah" window_title = "blah"
resizable = false resizable = false
script = ExtResource( 1 ) script = ExtResource( 1 )
_sections_unfolded = [ "Popup", "Rect" ]
[node name="VBoxContainer" type="VBoxContainer" parent="." index="1"] [node name="VBoxContainer" type="VBoxContainer" parent="." index="1"]