Added color and editable title to comment nodes

This commit is contained in:
RodZill4 2020-02-03 20:55:32 +01:00
parent 6a8696b2fb
commit 6338680b32
5 changed files with 99 additions and 10 deletions

View File

@ -8,6 +8,8 @@ Comments to put in the graph
var text : String = "Double-click to write a comment"
var size : Vector2 = Vector2(0, 0)
var title : String = "Comment"
var color : Color = Color(1.0, 0.5, 0.0)
func _ready() -> void:
if !parameters.has("size"):
@ -30,6 +32,8 @@ func get_output_defs() -> Array:
func _serialize(data: Dictionary) -> Dictionary:
data.type = "comment"
data.title = title
data.color = MMType.serialize_value(color)
data.text = text
data.size = { x=size.x, y=size.y }
return data
@ -39,3 +43,7 @@ func _deserialize(data : Dictionary) -> void:
text = data.text
if data.has("size"):
size = Vector2(data.size.x, data.size.y)
if data.has("title"):
title = data.title
if data.has("color"):
color = MMType.deserialize_value(data.color)

View File

@ -0,0 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[ext_resource path="res://material_maker/icons/icons.svg" type="Texture" id=1]
[resource]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 16, 16, 16, 16 )

View File

@ -1,4 +1,3 @@
tool
extends GraphNode
class_name MMGraphNodeBase
@ -30,3 +29,4 @@ func _on_gui_input(event) -> void:
if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_LEFT and Rect2(rect_size.x-48, 4, 16, 16).has_point(event.position):
generator.toggle_lock_seed()
update()
get_parent().send_changed_signal()

View File

@ -1,13 +1,21 @@
tool
extends MMGraphNodeBase
onready var label = $VBox/Label
onready var editor = $VBox/TextEdit
func _draw() -> void:
var icon = preload("res://material_maker/icons/edit.tres")
draw_texture_rect(icon, Rect2(rect_size.x-68, 4, 16, 16), false)
draw_rect(Rect2(rect_size.x-48, 4, 16, 16), generator.color)
if !is_connected("gui_input", self, "_on_gui_input"):
connect("gui_input", self, "_on_gui_input")
func set_generator(g) -> void:
generator = g
label.text = generator.text
rect_size = generator.size
title = generator.title
set_color(generator.color)
func _on_resize_request(new_size) -> void:
rect_size = new_size
@ -27,3 +35,32 @@ func _on_TextEdit_focus_exited() -> void:
generator.text = editor.text
label.visible = true
editor.visible = false
func _on_gui_input(event) -> void:
if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_LEFT:
if Rect2(rect_size.x-48, 4, 16, 16).has_point(event.position):
$Popup/ColorPicker.color = generator.color
$Popup/ColorPicker.connect("color_changed", self, "set_color")
$Popup.rect_position = event.global_position
$Popup.popup()
accept_event()
elif Rect2(rect_size.x-68, 4, 16, 16).has_point(event.position):
var dialog = preload("res://material_maker/widgets/line_dialog.tscn").instance()
dialog.set_value(generator.title)
dialog.set_texts("Comment", "Enter the comment node title")
add_child(dialog)
dialog.connect("ok", self, "set_title")
dialog.popup_centered()
accept_event()
func set_color(c):
generator.color = c
var color = c
color.a = 0.3
get_stylebox("comment").bg_color = color
get_parent().send_changed_signal()
func set_title(t):
title = t
generator.title = t
get_parent().send_changed_signal()

View File

@ -1,18 +1,32 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=4 format=2]
[ext_resource path="res://material_maker/nodes/comment.gd" type="Script" id=1]
[sub_resource type="StyleBoxFlat" id=1]
resource_local_to_scene = true
content_margin_left = 28.0
content_margin_right = 28.0
content_margin_top = 24.0
content_margin_bottom = 5.0
bg_color = Color( 0, 0, 0, 0.3 )
border_width_left = 1
border_width_top = 1
border_width_right = 1
border_width_bottom = 1
border_color = Color( 1, 1, 1, 0.9 )
[sub_resource type="StyleBoxFlat" id=2]
bg_color = Color( 1, 1, 1, 0.0627451 )
[node name="GraphNode" type="GraphNode"]
margin_left = 1.0
margin_top = 1.0
margin_right = 250.0
margin_bottom = 44.0
margin_right = 256.0
margin_bottom = 82.0
size_flags_horizontal = 3
size_flags_vertical = 3
custom_styles/commentfocus = SubResource( 1 )
custom_styles/comment = SubResource( 1 )
title = "Comment"
show_close = true
resizable = true
@ -23,16 +37,25 @@ slot/0/left_color = Color( 1, 1, 1, 1 )
slot/0/right_enabled = false
slot/0/right_type = 0
slot/0/right_color = Color( 1, 1, 1, 1 )
slot/1/left_enabled = false
slot/1/left_type = 0
slot/1/left_color = Color( 1, 1, 1, 1 )
slot/1/right_enabled = false
slot/1/right_type = 0
slot/1/right_color = Color( 1, 1, 1, 1 )
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VBox" type="VBoxContainer" parent="."]
margin_left = 16.0
margin_top = 24.0
margin_right = 233.0
margin_right = 239.0
margin_bottom = 38.0
[node name="Label" type="Label" parent="VBox"]
margin_right = 217.0
margin_right = 223.0
margin_bottom = 14.0
mouse_filter = 0
text = "Double-click to write a comment"
@ -43,9 +66,22 @@ visible = false
margin_top = 18.0
margin_right = 221.0
margin_bottom = 18.0
custom_styles/focus = SubResource( 1 )
custom_styles/normal = SubResource( 1 )
custom_styles/focus = SubResource( 2 )
custom_styles/normal = SubResource( 2 )
wrap_enabled = true
[node name="Popup" type="Popup" parent="."]
margin_left = 16.0
margin_top = 39.0
margin_right = 239.0
margin_bottom = 39.0
[node name="ColorPicker" type="ColorPicker" parent="Popup"]
margin_left = 4.0
margin_top = 4.0
margin_right = 4.0
margin_bottom = 4.0
rect_scale = Vector2( 0.75, 0.75 )
[connection signal="resize_request" from="." to="." method="_on_resize_request"]
[connection signal="gui_input" from="VBox/Label" to="." method="_on_Label_gui_input"]
[connection signal="focus_exited" from="VBox/TextEdit" to="." method="_on_TextEdit_focus_exited"]