From cb03131b85295d307b1323d7890ee528d1a59382 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Mon, 10 Sep 2018 08:00:03 +0200 Subject: [PATCH] Added control link check and editable labels Now linking new controls to a linked_control will check compatibility (same control type and parameters). Linked control labels are now editable. Modified the Switch node layout so it is easier to understand. Updated the bricks example to use the switch and remote nodes. --- addons/material_maker/examples/bricks.ptex | 2 +- addons/material_maker/nodes/combine.tscn | 2 +- addons/material_maker/nodes/material.tscn | 3 +- addons/material_maker/nodes/remote.tscn | 2 +- addons/material_maker/nodes/switch.gd | 2 +- addons/material_maker/nodes/switch.tscn | 76 +++++++++---------- .../widgets/linked_widgets/editable_label.gd | 12 +++ .../linked_widgets/editable_label.tscn | 27 +++++++ .../widgets/linked_widgets/linked_control.gd | 53 +++++++++---- .../linked_widgets/linked_control_base.gd | 21 +++-- .../linked_widgets/linked_control_buttons.gd | 5 -- .../linked_control_buttons.tscn | 6 +- 12 files changed, 139 insertions(+), 72 deletions(-) create mode 100644 addons/material_maker/widgets/linked_widgets/editable_label.gd create mode 100644 addons/material_maker/widgets/linked_widgets/editable_label.tscn diff --git a/addons/material_maker/examples/bricks.ptex b/addons/material_maker/examples/bricks.ptex index a8957c6..d10dd8d 100644 --- a/addons/material_maker/examples/bricks.ptex +++ b/addons/material_maker/examples/bricks.ptex @@ -1 +1 @@ -{"connections":[{"from":"Perlin","from_port":0,"to":"Warp","to_port":1},{"from":"Warp","from_port":0,"to":"colorize_2","to_port":0},{"from":"colorize_2","from_port":0,"to":"blend_0","to_port":2},{"from":"colorize_0","from_port":0,"to":"blend_0","to_port":1},{"from":"blend_0","from_port":0,"to":"Material","to_port":0},{"from":"colorize_2","from_port":0,"to":"colorize_4","to_port":0},{"from":"colorize_4","from_port":0,"to":"Material","to_port":2},{"from":"Bricks","from_port":0,"to":"Warp","to_port":0},{"from":"blend_1","from_port":0,"to":"colorize_1","to_port":0},{"from":"Bricks","from_port":1,"to":"blend_1","to_port":1},{"from":"Warp","from_port":0,"to":"blend_2","to_port":0},{"from":"Perlin","from_port":0,"to":"blend_2","to_port":1},{"from":"blend_2","from_port":0,"to":"colorize_3","to_port":0},{"from":"blend_2","from_port":0,"to":"colorize_6","to_port":0},{"from":"Perlin","from_port":0,"to":"blend_1","to_port":0},{"from":"Perlin","from_port":0,"to":"colorize_0","to_port":0},{"from":"uniform_0","from_port":0,"to":"Material","to_port":1},{"from":"colorize_3","from_port":0,"to":"Material","to_port":5},{"from":"uniform_0","from_port":0,"to":"combine_0","to_port":0},{"from":"colorize_4","from_port":0,"to":"combine_0","to_port":1},{"from":"combine_0","from_port":0,"to":"export_0","to_port":0},{"from":"normal_map_0","from_port":0,"to":"Material","to_port":4},{"from":"colorize_6","from_port":0,"to":"normal_map_0","to_port":0},{"from":"colorize_1","from_port":0,"to":"adjust_hsv_0","to_port":0},{"from":"adjust_hsv_0","from_port":0,"to":"blend_0","to_port":0}],"nodes":[{"gradient":[{"b":0,"g":0,"pos":0,"r":0},{"b":1,"g":1,"pos":1,"r":1}],"name":"colorize_0","node_position":{"x":560.943665,"y":50},"type":"colorize"},{"albedo_color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"ao_light_affect":1,"depth_scale":0,"emission_energy":1,"metallic":1,"name":"Material","node_position":{"x":1081,"y":208},"normal_scale":1,"resolution":1,"roughness":1,"type":"material"},{"amount":0.5,"blend_type":0,"name":"blend_2","node_position":{"x":536,"y":331},"type":"blend"},{"amount":0.5,"blend_type":0,"name":"blend_0","node_position":{"x":836.943726,"y":-71},"type":"blend"},{"gradient":[{"b":0,"g":0,"pos":0,"r":0},{"b":1,"g":1,"pos":0.1,"r":1}],"name":"colorize_2","node_position":{"x":544.943665,"y":159},"type":"colorize"},{"color":{"a":1,"b":0,"g":0,"r":0,"type":"Color"},"name":"uniform_0","node_position":{"x":764,"y":164},"type":"uniform"},{"name":"combine_0","node_position":{"x":896,"y":86},"type":"combine"},{"name":"export_0","node_position":{"x":1050,"y":79},"resolution":1,"suffix":"mr","type":"export"},{"iterations":6,"name":"Perlin","node_position":{"x":70,"y":192},"persistence":0.85,"scale_x":4,"scale_y":4,"type":"perlin"},{"gradient":[{"b":1,"g":1,"pos":0,"r":1},{"b":0.546875,"g":0.546875,"pos":1,"r":0.546875}],"name":"colorize_4","node_position":{"x":711,"y":215},"type":"colorize"},{"gradient":[{"b":1,"g":1,"pos":0,"r":1},{"b":0,"g":0,"pos":1,"r":0}],"name":"colorize_6","node_position":{"x":708,"y":289},"type":"colorize"},{"gradient":[{"b":0.838542,"g":0.838542,"pos":0.145455,"r":0.838542},{"b":1,"g":1,"pos":0.536364,"r":1}],"name":"colorize_3","node_position":{"x":711,"y":361},"type":"colorize"},{"amount":0.35,"name":"normal_map_0","node_position":{"x":881.045654,"y":309.691162},"size":4,"type":"normal_map"},{"amount":0.04,"name":"Warp","node_position":{"x":306,"y":55.75},"type":"warp"},{"hue":0,"name":"adjust_hsv_0","node_position":{"x":583.224792,"y":-74.268188},"saturation":1,"type":"adjust_hsv","value":1},{"gradient":[{"b":0.0016,"g":0.0016,"pos":0,"r":0.307292},{"b":0,"g":0.180135,"pos":0.2,"r":0.606771},{"b":0,"g":0,"pos":0.345455,"r":0.3125},{"b":0,"g":0.19869,"pos":0.545455,"r":0.669271},{"b":0.019368,"g":0.060224,"pos":0.745455,"r":0.309896},{"b":0,"g":0.180135,"pos":1,"r":0.606771}],"name":"colorize_1","node_position":{"x":406.943665,"y":-80},"type":"colorize"},{"bevel":0.2,"columns":4,"mortar":0.05,"name":"Bricks","node_position":{"x":79,"y":-36},"pattern":0,"repeat":1,"row_offset":0.5,"rows":8,"type":"bricks"},{"amount":0.5,"blend_type":6,"name":"blend_1","node_position":{"x":316,"y":217},"type":"blend"},{"editable":true,"node_position":{"x":496.669189,"y":-340.657043},"type":"remote","widgets":[{"configurations":{"Basket weave":[{"node":"Bricks","value":3,"widget":"pattern"},{"node":"Bricks","value":2,"widget":"repeat"},{"node":"Bricks","value":2,"widget":"rows"},{"node":"Bricks","value":2,"widget":"columns"}],"Herring bone":[{"node":"Bricks","value":2,"widget":"pattern"},{"node":"Bricks","value":2,"widget":"repeat"},{"node":"Bricks","value":2,"widget":"rows"},{"node":"Bricks","value":2,"widget":"columns"}],"Running bond 1":[{"node":"Bricks","value":0,"widget":"pattern"},{"node":"Bricks","value":1,"widget":"repeat"},{"node":"Bricks","value":8,"widget":"rows"},{"node":"Bricks","value":4,"widget":"columns"}],"Running bond 2":[{"node":"Bricks","value":1,"widget":"pattern"},{"node":"Bricks","value":1,"widget":"repeat"},{"node":"Bricks","value":8,"widget":"rows"},{"node":"Bricks","value":4,"widget":"columns"}],"Spanish bond":[{"node":"Bricks","value":4,"widget":"pattern"},{"node":"Bricks","value":3,"widget":"repeat"},{"node":"Bricks","value":2,"widget":"rows"},{"node":"Bricks","value":2,"widget":"columns"}]},"linked_widgets":[{"node":"Bricks","widget":"pattern"},{"node":"Bricks","widget":"repeat"},{"node":"Bricks","widget":"rows"},{"node":"Bricks","widget":"columns"}],"type":"config_control"},{"linked_widgets":[{"node":"adjust_hsv_0","widget":"hue"}],"type":"linked_control"},{"linked_widgets":[{"node":"adjust_hsv_0","widget":"saturation"}],"type":"linked_control"},{"linked_widgets":[{"node":"adjust_hsv_0","widget":"value"}],"type":"linked_control"}]}]} \ No newline at end of file +{"connections":[{"from":"Perlin","from_port":0,"to":"Warp","to_port":1},{"from":"Warp","from_port":0,"to":"colorize_2","to_port":0},{"from":"colorize_2","from_port":0,"to":"blend_0","to_port":2},{"from":"colorize_0","from_port":0,"to":"blend_0","to_port":1},{"from":"blend_0","from_port":0,"to":"Material","to_port":0},{"from":"colorize_2","from_port":0,"to":"colorize_4","to_port":0},{"from":"colorize_4","from_port":0,"to":"Material","to_port":2},{"from":"blend_1","from_port":0,"to":"colorize_1","to_port":0},{"from":"Warp","from_port":0,"to":"blend_2","to_port":0},{"from":"Perlin","from_port":0,"to":"blend_2","to_port":1},{"from":"blend_2","from_port":0,"to":"colorize_3","to_port":0},{"from":"blend_2","from_port":0,"to":"colorize_6","to_port":0},{"from":"Perlin","from_port":0,"to":"blend_1","to_port":0},{"from":"Perlin","from_port":0,"to":"colorize_0","to_port":0},{"from":"uniform_0","from_port":0,"to":"Material","to_port":1},{"from":"colorize_3","from_port":0,"to":"Material","to_port":5},{"from":"uniform_0","from_port":0,"to":"combine_0","to_port":0},{"from":"colorize_4","from_port":0,"to":"combine_0","to_port":1},{"from":"combine_0","from_port":0,"to":"export_0","to_port":0},{"from":"normal_map_0","from_port":0,"to":"Material","to_port":4},{"from":"colorize_6","from_port":0,"to":"normal_map_0","to_port":0},{"from":"colorize_1","from_port":0,"to":"adjust_hsv_0","to_port":0},{"from":"adjust_hsv_0","from_port":0,"to":"blend_0","to_port":0},{"from":"switch_0","from_port":0,"to":"Warp","to_port":0},{"from":"switch_0","from_port":1,"to":"blend_1","to_port":1},{"from":"Bricks","from_port":0,"to":"switch_0","to_port":0},{"from":"voronoi_0","from_port":2,"to":"switch_0","to_port":3},{"from":"voronoi_0","from_port":1,"to":"colorize_5","to_port":0},{"from":"colorize_5","from_port":0,"to":"switch_0","to_port":2},{"from":"Bricks","from_port":1,"to":"switch_0","to_port":1}],"nodes":[{"gradient":{"points":[{"b":0,"g":0,"pos":0,"r":0},{"b":1,"g":1,"pos":1,"r":1}],"type":"Gradient"},"name":"colorize_0","node_position":{"x":560.943665,"y":50},"type":"colorize"},{"albedo_color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"ao_light_affect":1,"depth_scale":0,"emission_energy":1,"metallic":1,"name":"Material","node_position":{"x":1081,"y":208},"normal_scale":1,"resolution":1,"roughness":1,"type":"material"},{"amount":0.5,"blend_type":0,"name":"blend_2","node_position":{"x":536,"y":331},"type":"blend"},{"amount":0.5,"blend_type":0,"name":"blend_0","node_position":{"x":836.943726,"y":-71},"type":"blend"},{"gradient":{"points":[{"b":0,"g":0,"pos":0,"r":0},{"b":1,"g":1,"pos":0.1,"r":1}],"type":"Gradient"},"name":"colorize_2","node_position":{"x":544.943665,"y":159},"type":"colorize"},{"color":{"a":1,"b":0,"g":0,"r":0,"type":"Color"},"name":"uniform_0","node_position":{"x":764,"y":164},"type":"uniform"},{"name":"combine_0","node_position":{"x":896,"y":86},"type":"combine"},{"name":"export_0","node_position":{"x":1050,"y":79},"resolution":1,"suffix":"mr","type":"export"},{"gradient":{"points":[{"b":1,"g":1,"pos":0,"r":1},{"b":0.546875,"g":0.546875,"pos":1,"r":0.546875}],"type":"Gradient"},"name":"colorize_4","node_position":{"x":711,"y":215},"type":"colorize"},{"gradient":{"points":[{"b":1,"g":1,"pos":0,"r":1},{"b":0,"g":0,"pos":1,"r":0}],"type":"Gradient"},"name":"colorize_6","node_position":{"x":708,"y":289},"type":"colorize"},{"gradient":{"points":[{"b":0.838542,"g":0.838542,"pos":0.145455,"r":0.838542},{"b":1,"g":1,"pos":0.536364,"r":1}],"type":"Gradient"},"name":"colorize_3","node_position":{"x":711,"y":361},"type":"colorize"},{"amount":0.35,"name":"normal_map_0","node_position":{"x":881.045654,"y":309.691162},"size":4,"type":"normal_map"},{"hue":0,"name":"adjust_hsv_0","node_position":{"x":583.224792,"y":-74.268188},"saturation":1,"type":"adjust_hsv","value":1},{"gradient":{"points":[{"b":0.0016,"g":0.0016,"pos":0,"r":0.307292},{"b":0,"g":0.180135,"pos":0.2,"r":0.606771},{"b":0,"g":0,"pos":0.345455,"r":0.3125},{"b":0,"g":0.19869,"pos":0.545455,"r":0.669271},{"b":0.019368,"g":0.060224,"pos":0.745455,"r":0.309896},{"b":0,"g":0.180135,"pos":1,"r":0.606771}],"type":"Gradient"},"name":"colorize_1","node_position":{"x":406.943665,"y":-80},"type":"colorize"},{"amount":0.5,"blend_type":6,"name":"blend_1","node_position":{"x":316,"y":217},"type":"blend"},{"iterations":6,"name":"Perlin","node_position":{"x":32,"y":238},"persistence":0.85,"scale_x":4,"scale_y":4,"type":"perlin"},{"gradient":{"points":[{"b":0,"g":0,"pos":0.027273,"r":0},{"b":1,"g":1,"pos":0.2,"r":1}],"type":"Gradient"},"name":"colorize_5","node_position":{"x":-135.515076,"y":101.237671},"type":"colorize"},{"amount":0.04,"name":"Warp","node_position":{"x":306,"y":55.75},"type":"warp"},{"editable":true,"node_position":{"x":107.669189,"y":-338.657043},"type":"remote","widgets":[{"configurations":{"Basket weave":[{"node":"Bricks","value":3,"widget":"pattern"},{"node":"Bricks","value":2,"widget":"repeat"},{"node":"Bricks","value":2,"widget":"rows"},{"node":"Bricks","value":2,"widget":"columns"},{"node":"switch_0","value":0,"widget":"source"},{"node":"voronoi_0","value":8,"widget":"scale_x"},{"node":"voronoi_0","value":8,"widget":"scale_y"}],"Herring bone":[{"node":"Bricks","value":2,"widget":"pattern"},{"node":"Bricks","value":2,"widget":"repeat"},{"node":"Bricks","value":2,"widget":"rows"},{"node":"Bricks","value":2,"widget":"columns"},{"node":"switch_0","value":0,"widget":"source"},{"node":"voronoi_0","value":8,"widget":"scale_x"},{"node":"voronoi_0","value":8,"widget":"scale_y"}],"Running bond 1":[{"node":"Bricks","value":0,"widget":"pattern"},{"node":"Bricks","value":1,"widget":"repeat"},{"node":"Bricks","value":8,"widget":"rows"},{"node":"Bricks","value":4,"widget":"columns"},{"node":"switch_0","value":0,"widget":"source"},{"node":"voronoi_0","value":8,"widget":"scale_x"},{"node":"voronoi_0","value":8,"widget":"scale_y"}],"Running bond 2":[{"node":"Bricks","value":1,"widget":"pattern"},{"node":"Bricks","value":1,"widget":"repeat"},{"node":"Bricks","value":8,"widget":"rows"},{"node":"Bricks","value":4,"widget":"columns"},{"node":"switch_0","value":0,"widget":"source"},{"node":"voronoi_0","value":8,"widget":"scale_x"},{"node":"voronoi_0","value":8,"widget":"scale_y"}],"Spanish bond":[{"node":"Bricks","value":4,"widget":"pattern"},{"node":"Bricks","value":3,"widget":"repeat"},{"node":"Bricks","value":2,"widget":"rows"},{"node":"Bricks","value":2,"widget":"columns"},{"node":"switch_0","value":0,"widget":"source"},{"node":"voronoi_0","value":8,"widget":"scale_x"},{"node":"voronoi_0","value":8,"widget":"scale_y"}],"Uneven":[{"node":"Bricks","value":3,"widget":"pattern"},{"node":"Bricks","value":2,"widget":"repeat"},{"node":"Bricks","value":2,"widget":"rows"},{"node":"Bricks","value":2,"widget":"columns"},{"node":"switch_0","value":1,"widget":"source"},{"node":"voronoi_0","value":8,"widget":"scale_x"},{"node":"voronoi_0","value":8,"widget":"scale_y"}]},"label":"Pattern","linked_widgets":[{"node":"Bricks","widget":"pattern"},{"node":"Bricks","widget":"repeat"},{"node":"Bricks","widget":"rows"},{"node":"Bricks","widget":"columns"},{"node":"switch_0","widget":"source"},{"node":"voronoi_0","widget":"scale_x"},{"node":"voronoi_0","widget":"scale_y"}],"type":"config_control"},{"label":"Hue","linked_widgets":[{"node":"adjust_hsv_0","widget":"hue"}],"type":"linked_control"},{"label":"Saturation","linked_widgets":[{"node":"adjust_hsv_0","widget":"saturation"}],"type":"linked_control"},{"label":"Value","linked_widgets":[{"node":"adjust_hsv_0","widget":"value"}],"type":"linked_control"}]},{"bevel":0.2,"columns":2,"mortar":0.05,"name":"Bricks","node_position":{"x":-233,"y":-131},"pattern":3,"repeat":2,"row_offset":0.5,"rows":2,"type":"bricks"},{"intensity":1,"name":"voronoi_0","node_position":{"x":-339.515076,"y":139.237671},"scale_x":8,"scale_y":8,"type":"voronoi"},{"name":"switch_0","node_position":{"x":113.484924,"y":70.237671},"source":1,"type":"switch"}]} \ No newline at end of file diff --git a/addons/material_maker/nodes/combine.tscn b/addons/material_maker/nodes/combine.tscn index 0f6bc87..844c985 100644 --- a/addons/material_maker/nodes/combine.tscn +++ b/addons/material_maker/nodes/combine.tscn @@ -5,7 +5,7 @@ [sub_resource type="Theme" id=1] -[node name="Combine" type="GraphNode" index="0"] +[node name="Combine" type="GraphNode"] anchor_left = 0.0 anchor_top = 0.0 diff --git a/addons/material_maker/nodes/material.tscn b/addons/material_maker/nodes/material.tscn index 0566c73..14baefd 100644 --- a/addons/material_maker/nodes/material.tscn +++ b/addons/material_maker/nodes/material.tscn @@ -108,7 +108,6 @@ selected = 1 [node name="Albedo" type="HBoxContainer" parent="." index="1"] -editor/display_folded = true anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 @@ -170,7 +169,7 @@ group = null flat = false align = 1 color = Color( 1, 1, 1, 1 ) -edit_alpha = true +edit_alpha = false _sections_unfolded = [ "Rect", "Size Flags" ] [node name="Metallic" type="HBoxContainer" parent="." index="2"] diff --git a/addons/material_maker/nodes/remote.tscn b/addons/material_maker/nodes/remote.tscn index d7a9ce0..e19728c 100644 --- a/addons/material_maker/nodes/remote.tscn +++ b/addons/material_maker/nodes/remote.tscn @@ -7,7 +7,7 @@ [sub_resource type="Theme" id=1] -[node name="Remote" type="GraphNode" index="0"] +[node name="Remote" type="GraphNode"] anchor_left = 0.0 anchor_top = 0.0 diff --git a/addons/material_maker/nodes/switch.gd b/addons/material_maker/nodes/switch.gd index 8adf31e..d6a493f 100644 --- a/addons/material_maker/nodes/switch.gd +++ b/addons/material_maker/nodes/switch.gd @@ -12,7 +12,7 @@ func reset(): func _get_shader_code(uv, index = 0): var rv = { defs="", code="" } - var src = get_source(source+2*index) + var src = get_source(2*source+index) var src_code = { defs="", code="", rgb="0.0" } if src != null: src_code = src.get_shader_code(uv) diff --git a/addons/material_maker/nodes/switch.tscn b/addons/material_maker/nodes/switch.tscn index 60ed342..d1da2b6 100644 --- a/addons/material_maker/nodes/switch.tscn +++ b/addons/material_maker/nodes/switch.tscn @@ -38,13 +38,13 @@ slot/0/right_color = Color( 0.498039, 0.498039, 1, 1 ) slot/1/left_enabled = true slot/1/left_type = 0 slot/1/left_color = Color( 0.498039, 0.498039, 1, 1 ) -slot/1/right_enabled = true +slot/1/right_enabled = false slot/1/right_type = 0 slot/1/right_color = Color( 0.498039, 0.498039, 1, 1 ) slot/2/left_enabled = true slot/2/left_type = 0 slot/2/left_color = Color( 0.498039, 0.498039, 1, 1 ) -slot/2/right_enabled = false +slot/2/right_enabled = true slot/2/right_type = 0 slot/2/right_color = Color( 0.498039, 0.498039, 1, 1 ) slot/3/left_enabled = true @@ -70,7 +70,7 @@ anchor_right = 0.0 anchor_bottom = 0.0 margin_left = 16.0 margin_top = 24.0 -margin_right = 103.0 +margin_right = 70.0 margin_bottom = 44.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false @@ -84,13 +84,13 @@ action_mode = 0 enabled_focus_mode = 2 shortcut = null group = null -text = "Objet 0" +text = "1" flat = false align = 0 items = [ "1", null, false, 0, null, "2", null, false, 1, null ] selected = 0 -[node name="HBoxContainer1" type="HBoxContainer" parent="." index="1"] +[node name="Label1" type="Label" parent="." index="1"] anchor_left = 0.0 anchor_top = 0.0 @@ -98,10 +98,31 @@ anchor_right = 0.0 anchor_bottom = 0.0 margin_left = 16.0 margin_top = 44.0 -margin_right = 103.0 +margin_right = 70.0 margin_bottom = 58.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 = "A1" +percent_visible = 1.0 +lines_skipped = 0 +max_lines_visible = -1 + +[node name="HBoxContainer1" type="HBoxContainer" parent="." index="2"] + +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 16.0 +margin_top = 59.0 +margin_right = 70.0 +margin_bottom = 73.0 +rect_pivot_offset = Vector2( 0, 0 ) +rect_clip_content = false mouse_filter = 1 mouse_default_cursor_shape = 0 size_flags_horizontal = 1 @@ -114,7 +135,7 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_right = 74.0 +margin_right = 41.0 margin_bottom = 14.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false @@ -122,7 +143,7 @@ mouse_filter = 2 mouse_default_cursor_shape = 0 size_flags_horizontal = 3 size_flags_vertical = 4 -text = "A1" +text = "B1" percent_visible = 1.0 lines_skipped = 0 max_lines_visible = -1 @@ -133,8 +154,8 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_left = 78.0 -margin_right = 87.0 +margin_left = 45.0 +margin_right = 54.0 margin_bottom = 14.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false @@ -147,27 +168,6 @@ percent_visible = 1.0 lines_skipped = 0 max_lines_visible = -1 -[node name="Label2" type="Label" parent="." index="2"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_left = 16.0 -margin_top = 59.0 -margin_right = 103.0 -margin_bottom = 73.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 = "A2" -percent_visible = 1.0 -lines_skipped = 0 -max_lines_visible = -1 - [node name="HBoxContainer2" type="HBoxContainer" parent="." index="3"] anchor_left = 0.0 @@ -176,7 +176,7 @@ anchor_right = 0.0 anchor_bottom = 0.0 margin_left = 16.0 margin_top = 74.0 -margin_right = 103.0 +margin_right = 70.0 margin_bottom = 88.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false @@ -192,7 +192,7 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_right = 74.0 +margin_right = 41.0 margin_bottom = 14.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false @@ -200,7 +200,7 @@ mouse_filter = 2 mouse_default_cursor_shape = 0 size_flags_horizontal = 3 size_flags_vertical = 4 -text = "B1" +text = "A2" percent_visible = 1.0 lines_skipped = 0 max_lines_visible = -1 @@ -211,8 +211,8 @@ anchor_left = 0.0 anchor_top = 0.0 anchor_right = 0.0 anchor_bottom = 0.0 -margin_left = 78.0 -margin_right = 87.0 +margin_left = 45.0 +margin_right = 54.0 margin_bottom = 14.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false @@ -225,7 +225,7 @@ percent_visible = 1.0 lines_skipped = 0 max_lines_visible = -1 -[node name="Label4" type="Label" parent="." index="4"] +[node name="Label2" type="Label" parent="." index="4"] anchor_left = 0.0 anchor_top = 0.0 @@ -233,7 +233,7 @@ anchor_right = 0.0 anchor_bottom = 0.0 margin_left = 16.0 margin_top = 89.0 -margin_right = 103.0 +margin_right = 70.0 margin_bottom = 103.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false diff --git a/addons/material_maker/widgets/linked_widgets/editable_label.gd b/addons/material_maker/widgets/linked_widgets/editable_label.gd new file mode 100644 index 0000000..04afd8f --- /dev/null +++ b/addons/material_maker/widgets/linked_widgets/editable_label.gd @@ -0,0 +1,12 @@ +extends Label + +func _ready(): + pass + +func _on_gui_input(ev): + if ev is InputEventMouseButton and ev.doubleclick and ev.button_index == BUTTON_LEFT: + var dialog = preload("res://addons/material_maker/widgets/line_dialog.tscn").instance() + add_child(dialog) + dialog.set_texts("Remote", "Enter a name this control") + dialog.connect("ok", self, "set_text", []) + dialog.popup_centered() diff --git a/addons/material_maker/widgets/linked_widgets/editable_label.tscn b/addons/material_maker/widgets/linked_widgets/editable_label.tscn new file mode 100644 index 0000000..9406658 --- /dev/null +++ b/addons/material_maker/widgets/linked_widgets/editable_label.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://addons/material_maker/widgets/linked_widgets/editable_label.gd" type="Script" id=1] + +[node name="Label" type="Label"] + +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_right = 40.0 +margin_bottom = 14.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 = 4 +percent_visible = 1.0 +lines_skipped = 0 +max_lines_visible = -1 +script = ExtResource( 1 ) +_sections_unfolded = [ "Mouse" ] + +[connection signal="gui_input" from="." to="." method="_on_gui_input"] + + diff --git a/addons/material_maker/widgets/linked_widgets/linked_control.gd b/addons/material_maker/widgets/linked_widgets/linked_control.gd index 5059173..d60fa56 100644 --- a/addons/material_maker/widgets/linked_widgets/linked_control.gd +++ b/addons/material_maker/widgets/linked_widgets/linked_control.gd @@ -1,38 +1,63 @@ tool extends "res://addons/material_maker/widgets/linked_widgets/linked_control_base.gd" +var control = null + func add_linked(node, widget): if linked_widgets.empty(): - var new_widget = null + control = null var type if widget is SpinBox: - new_widget = SpinBox.new() + control = SpinBox.new() type = "SpinBox" elif widget is ColorPickerButton: - new_widget = ColorPickerButton.new() + control = ColorPickerButton.new() type = "ColorPickerButton" elif widget is Control && widget.filename == "res://addons/material_maker/widgets/gradient_editor.tscn": - new_widget = preload("res://addons/material_maker/widgets/gradient_editor.tscn").instance() + control = preload("res://addons/material_maker/widgets/gradient_editor.tscn").instance() type = "GradientEditor" elif widget is HSlider: - new_widget = HSlider.new() + control = HSlider.new() type = "HSlider" elif widget is OptionButton: - new_widget = OptionButton.new() + control = OptionButton.new() type = "OptionButton" for i in range(widget.get_item_count()): - new_widget.add_item(widget.get_item_text(i), widget.get_item_id(i)) - if new_widget != null: - add_child(new_widget) - mirror(new_widget, widget, type) - new_widget.connect("mouse_entered", self, "_on_mouse_entered") - new_widget.connect("mouse_exited", self, "_on_mouse_exited") - new_widget.connect(WIDGETS[type].sig, self, WIDGETS[type].sig_handler) + control.add_item(widget.get_item_text(i), widget.get_item_id(i)) + if control != null: + add_child(control) + mirror(control, widget, type) + control.connect("mouse_entered", self, "_on_mouse_entered") + control.connect("mouse_exited", self, "_on_mouse_exited") + control.connect(WIDGETS[type].sig, self, WIDGETS[type].sig_handler) + else: + if !can_link_to(widget): + return linked_widgets.append({ node=node, widget=widget }) +func can_link_to(c): + if c == null: + return false + var widget_type = get_widget_type(c) + if control == null: + return widget_type != null + elif widget_type != get_widget_type(control): + return false + else: + for l in linked_widgets: + if l.widget == c: + return false + var winfo = WIDGETS[widget_type] + for a in winfo.attrs: + if c.get(a) != control.get(a): + return false + return true + func mirror(to, from, type): - for a in WIDGETS[type].attrs: + var winfo = WIDGETS[type] + for a in winfo.attrs: to.set(a, from.get(a)) + to.set(winfo.value_attr, from.get(winfo.value_attr)) func update_shaders(): var graph_edit = get_parent() diff --git a/addons/material_maker/widgets/linked_widgets/linked_control_base.gd b/addons/material_maker/widgets/linked_widgets/linked_control_base.gd index 7e6ea9f..d10854a 100644 --- a/addons/material_maker/widgets/linked_widgets/linked_control_base.gd +++ b/addons/material_maker/widgets/linked_widgets/linked_control_base.gd @@ -10,11 +10,11 @@ var links = null const Link = preload("res://addons/material_maker/widgets/linked_widgets/link.gd") const WIDGETS = { - SpinBox={ attrs=[ "min_value", "max_value", "step", "value" ], value_attr="value", sig="value_changed", sig_handler="_on_value_changed" }, - HSlider={ attrs=[ "min_value", "max_value", "step", "value" ], value_attr="value", sig="value_changed", sig_handler="_on_value_changed" }, - ColorPickerButton={ attrs=[ "edit_alpha", "color" ], value_attr="color", sig="color_changed", sig_handler="_on_color_changed" }, - OptionButton={ attrs=[ "selected" ], value_attr="selected", sig="item_selected", sig_handler="_on_item_selected" }, - GradientEditor={ attrs=[ "value" ], value_attr="value", sig="updated", sig_handler="_on_gradient_updated" } + SpinBox={ attrs=[ "min_value", "max_value", "step" ], value_attr="value", sig="value_changed", sig_handler="_on_value_changed" }, + HSlider={ attrs=[ "min_value", "max_value", "step" ], value_attr="value", sig="value_changed", sig_handler="_on_value_changed" }, + ColorPickerButton={ attrs=[ "edit_alpha", ], value_attr="color", sig="color_changed", sig_handler="_on_color_changed" }, + OptionButton={ attrs=[ ], value_attr="selected", sig="item_selected", sig_handler="_on_item_selected" }, + GradientEditor={ attrs=[ ], value_attr="value", sig="updated", sig_handler="_on_gradient_updated" } } func get_widget_type(widget): @@ -34,8 +34,11 @@ func get_widget_type(widget): func _ready(): set_process_input(false) +func can_link_to(c): + return c != null + func get_associated_controls(): - label = Label.new() + label = preload("res://addons/material_maker/widgets/linked_widgets/editable_label.tscn").instance() label.set_text("Unnamed") buttons = preload("res://addons/material_maker/widgets/linked_widgets/linked_control_buttons.tscn").instance() buttons.control = self @@ -90,7 +93,7 @@ func _input(event): elif event is InputEventMouseMotion: var control = find_control(event.global_position) link.end = event.global_position - link.target = control.widget if control != null else null + link.target = control.widget if control != null && can_link_to(control.widget) else null link.update() elif event is InputEventMouseButton: if event.pressed: @@ -120,12 +123,14 @@ func pick_linked(): pointed_control = null func serialize(): - var data = { linked_widgets=[] } + var data = { label=label.text, linked_widgets=[] } for w in linked_widgets: data.linked_widgets.append( { node=w.node.name, widget=w.widget.name } ) return data func deserialize(data): + if data.has("label"): + label.text = data.label if !data.has("linked_widgets"): return var graph_edit = get_parent() diff --git a/addons/material_maker/widgets/linked_widgets/linked_control_buttons.gd b/addons/material_maker/widgets/linked_widgets/linked_control_buttons.gd index d4fcfdc..139a2cf 100644 --- a/addons/material_maker/widgets/linked_widgets/linked_control_buttons.gd +++ b/addons/material_maker/widgets/linked_widgets/linked_control_buttons.gd @@ -3,11 +3,6 @@ extends HBoxContainer var control = null -func _ready(): - # Called when the node is added to the scene for the first time. - # Initialization here - pass - func _on_Link_pressed(): control.pick_linked() diff --git a/addons/material_maker/widgets/linked_widgets/linked_control_buttons.tscn b/addons/material_maker/widgets/linked_widgets/linked_control_buttons.tscn index df95de9..f87a71b 100644 --- a/addons/material_maker/widgets/linked_widgets/linked_control_buttons.tscn +++ b/addons/material_maker/widgets/linked_widgets/linked_control_buttons.tscn @@ -4,7 +4,7 @@ [ext_resource path="res://addons/material_maker/icons/link.png" type="Texture" id=2] [ext_resource path="res://addons/material_maker/icons/remove.png" type="Texture" id=3] -[node name="Buttons" type="HBoxContainer"] +[node name="Buttons" type="HBoxContainer" index="0"] anchor_left = 0.0 anchor_top = 0.0 @@ -31,6 +31,7 @@ margin_right = 28.0 margin_bottom = 22.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false +hint_tooltip = "Link new parameter" focus_mode = 2 mouse_filter = 0 mouse_default_cursor_shape = 0 @@ -43,6 +44,7 @@ group = null icon = ExtResource( 2 ) flat = false align = 1 +_sections_unfolded = [ "Hint" ] [node name="Remove" type="Button" parent="." index="1"] @@ -55,6 +57,7 @@ margin_right = 60.0 margin_bottom = 22.0 rect_pivot_offset = Vector2( 0, 0 ) rect_clip_content = false +hint_tooltip = "Delete this control" focus_mode = 2 mouse_filter = 0 mouse_default_cursor_shape = 0 @@ -67,6 +70,7 @@ group = null icon = ExtResource( 3 ) flat = false align = 1 +_sections_unfolded = [ "Hint" ] [connection signal="pressed" from="Link" to="." method="_on_Link_pressed"]