mirror of
https://github.com/Relintai/broken_seals.git
synced 2025-03-12 03:49:54 +01:00
Removed everythogn from the mat_maker_gd addon that's not needed anymore.
This commit is contained in:
parent
4f8f036204
commit
41f94f63d4
@ -1,65 +0,0 @@
|
||||
tool
|
||||
extends ConfirmationDialog
|
||||
|
||||
signal ok_pressed
|
||||
|
||||
export(NodePath) var line_edit_path : NodePath
|
||||
export(NodePath) var tree_path : NodePath
|
||||
|
||||
export(PoolStringArray) var type_folders : PoolStringArray
|
||||
|
||||
var _resource_type : String = "MMNode"
|
||||
|
||||
var _line_edit : LineEdit
|
||||
var _tree : Tree
|
||||
|
||||
func _ready():
|
||||
_line_edit = get_node(line_edit_path) as LineEdit
|
||||
_tree = get_node(tree_path) as Tree
|
||||
|
||||
connect("confirmed", self, "_on_OK_pressed")
|
||||
connect("about_to_show", self, "about_to_show")
|
||||
|
||||
func set_resource_type(resource_type : String) -> void:
|
||||
_resource_type = resource_type
|
||||
|
||||
func about_to_show():
|
||||
_tree.clear()
|
||||
|
||||
var root : TreeItem = _tree.create_item()
|
||||
|
||||
for s in type_folders:
|
||||
evaluate_folder(s, root)
|
||||
|
||||
func evaluate_folder(folder : String, root : TreeItem) -> void:
|
||||
var ti : TreeItem = _tree.create_item(root)
|
||||
ti.set_text(0, folder.substr(folder.find_last("/") + 1))
|
||||
|
||||
var dir = Directory.new()
|
||||
if dir.open(folder) == OK:
|
||||
dir.list_dir_begin()
|
||||
var file_name = dir.get_next()
|
||||
while file_name != "":
|
||||
if !dir.current_is_dir():
|
||||
print("Found file: " + file_name)
|
||||
var e : TreeItem = _tree.create_item(ti)
|
||||
|
||||
e.set_text(0, file_name.get_file())
|
||||
e.set_meta("file", folder + "/" + file_name)
|
||||
|
||||
file_name = dir.get_next()
|
||||
else:
|
||||
print("An error occurred when trying to access the path.")
|
||||
|
||||
func _on_OK_pressed():
|
||||
var selected : TreeItem = _tree.get_selected()
|
||||
|
||||
if selected:
|
||||
if !selected.has_meta("file"):
|
||||
hide()
|
||||
return
|
||||
|
||||
var file_name : String = selected.get_meta("file")
|
||||
emit_signal("ok_pressed", file_name)
|
||||
|
||||
hide()
|
@ -1,61 +0,0 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/editor/CreateNamePopup.gd" type="Script" id=1]
|
||||
|
||||
[node name="CreateNamePopup" type="ConfirmationDialog"]
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
margin_left = -245.5
|
||||
margin_top = -220.0
|
||||
margin_right = 245.5
|
||||
margin_bottom = 220.0
|
||||
window_title = "Create New Resource"
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
line_edit_path = NodePath("VBoxContainer/LineEdit")
|
||||
tree_path = NodePath("VBoxContainer/Tree")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
margin_left = 8.0
|
||||
margin_top = 8.0
|
||||
margin_right = 483.0
|
||||
margin_bottom = 404.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Label2" type="Label" parent="VBoxContainer"]
|
||||
margin_right = 475.0
|
||||
margin_bottom = 14.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Type"
|
||||
|
||||
[node name="Tree" type="Tree" parent="VBoxContainer"]
|
||||
margin_top = 18.0
|
||||
margin_right = 475.0
|
||||
margin_bottom = 350.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
hide_root = true
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer"]
|
||||
visible = false
|
||||
margin_top = 354.0
|
||||
margin_right = 475.0
|
||||
margin_bottom = 368.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Name"
|
||||
|
||||
[node name="LineEdit" type="LineEdit" parent="VBoxContainer"]
|
||||
visible = false
|
||||
margin_top = 372.0
|
||||
margin_right = 475.0
|
||||
margin_bottom = 396.0
|
||||
size_flags_horizontal = 3
|
||||
caret_blink = true
|
@ -1,218 +0,0 @@
|
||||
tool
|
||||
extends MarginContainer
|
||||
|
||||
var MMGraphNode = preload("res://addons/mat_maker_gd/editor/mm_graph_node.gd")
|
||||
|
||||
export(NodePath) var graph_edit_path : NodePath = "VBoxContainer/GraphEdit"
|
||||
export(NodePath) var add_popup_path : NodePath = "Popups/AddPopup"
|
||||
|
||||
var _graph_edit : GraphEdit = null
|
||||
|
||||
var _material : MMMaterial
|
||||
var _ignore_material_change_event : int = 0
|
||||
var _recreation_in_progress : bool = false
|
||||
|
||||
var _plugin : EditorPlugin = null
|
||||
var _undo_redo : UndoRedo = null
|
||||
|
||||
func _enter_tree():
|
||||
ensure_objs()
|
||||
|
||||
func set_plugin(plugin : EditorPlugin) -> void:
|
||||
_plugin = plugin
|
||||
_undo_redo = plugin.get_undo_redo()
|
||||
|
||||
func get_undo_redo() -> UndoRedo:
|
||||
return _undo_redo
|
||||
|
||||
func ensure_objs() -> void:
|
||||
if !_graph_edit:
|
||||
_graph_edit = get_node(graph_edit_path)
|
||||
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SLOT_TYPE_IMAGE, MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SLOT_TYPE_INT, MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SLOT_TYPE_FLOAT, MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SLOT_TYPE_VECTOR2, MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SLOT_TYPE_VECTOR3, MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SLOT_TYPE_COLOR, MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL)
|
||||
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SLOT_TYPE_IMAGE)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SLOT_TYPE_INT)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SLOT_TYPE_FLOAT)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SLOT_TYPE_VECTOR2)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SLOT_TYPE_VECTOR3)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SLOT_TYPE_COLOR)
|
||||
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL)
|
||||
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SLOT_TYPE_IMAGE, MMNodeUniversalProperty.SLOT_TYPE_IMAGE)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SLOT_TYPE_INT, MMNodeUniversalProperty.SLOT_TYPE_INT)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SLOT_TYPE_FLOAT, MMNodeUniversalProperty.SLOT_TYPE_FLOAT)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SLOT_TYPE_VECTOR2, MMNodeUniversalProperty.SLOT_TYPE_VECTOR2)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SLOT_TYPE_VECTOR3, MMNodeUniversalProperty.SLOT_TYPE_VECTOR3)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SLOT_TYPE_COLOR, MMNodeUniversalProperty.SLOT_TYPE_COLOR)
|
||||
|
||||
_graph_edit.connect("connection_request", self, "on_graph_edit_connection_request")
|
||||
_graph_edit.connect("disconnection_request", self, "on_graph_edit_disconnection_request")
|
||||
|
||||
func recreate() -> void:
|
||||
ignore_changes(true)
|
||||
|
||||
if _recreation_in_progress:
|
||||
return
|
||||
|
||||
_recreation_in_progress = true
|
||||
|
||||
ensure_objs()
|
||||
|
||||
_graph_edit.clear_connections()
|
||||
|
||||
for c in _graph_edit.get_children():
|
||||
if c is GraphNode:
|
||||
_graph_edit.remove_child(c)
|
||||
c.queue_free()
|
||||
|
||||
if !_material:
|
||||
return
|
||||
|
||||
_material.cancel_render_and_wait()
|
||||
|
||||
for n in _material.nodes:
|
||||
var gn : GraphNode = MMGraphNode.new()
|
||||
gn.set_editor(self)
|
||||
gn.set_node(_material, n)
|
||||
_graph_edit.add_child(gn)
|
||||
|
||||
#connect them
|
||||
for n in _material.nodes:
|
||||
if n:
|
||||
for ip in n.input_properties:
|
||||
if ip.input_property:
|
||||
var input_node : Node = find_graph_node_for(n)
|
||||
var output_node : Node = find_graph_node_for(ip.input_property.owner)
|
||||
|
||||
var to_slot : int = input_node.get_input_property_graph_node_slot_index(ip)
|
||||
var from_slot : int = output_node.get_output_property_graph_node_slot_index(ip.input_property)
|
||||
|
||||
_graph_edit.connect_node(output_node.name, from_slot, input_node.name, to_slot)
|
||||
|
||||
_material.render()
|
||||
|
||||
_recreation_in_progress = false
|
||||
|
||||
ignore_changes(false)
|
||||
|
||||
func find_graph_node_for(nnode) -> Node:
|
||||
for c in _graph_edit.get_children():
|
||||
if c is GraphNode:
|
||||
if c.has_method("get_material_node"):
|
||||
var n = c.get_material_node()
|
||||
|
||||
if n == nnode:
|
||||
return c
|
||||
|
||||
return null
|
||||
|
||||
func set_mmmaterial(object : MMMaterial):
|
||||
if _material:
|
||||
_material.disconnect("changed", self, "on_material_changed")
|
||||
|
||||
_material = object
|
||||
|
||||
recreate()
|
||||
|
||||
if _material:
|
||||
_material.connect("changed", self, "on_material_changed")
|
||||
|
||||
func on_material_changed() -> void:
|
||||
if _ignore_material_change_event > 0:
|
||||
return
|
||||
|
||||
if _recreation_in_progress:
|
||||
return
|
||||
|
||||
call_deferred("recreate")
|
||||
|
||||
func ignore_changes(val : bool) -> void:
|
||||
if val:
|
||||
_ignore_material_change_event += 1
|
||||
else:
|
||||
_ignore_material_change_event -= 1
|
||||
|
||||
func on_graph_edit_connection_request(from: String, from_slot: int, to: String, to_slot: int):
|
||||
var from_node : GraphNode = _graph_edit.get_node(from)
|
||||
var to_node : GraphNode = _graph_edit.get_node(to)
|
||||
|
||||
ignore_changes(true)
|
||||
|
||||
_material.cancel_render_and_wait()
|
||||
|
||||
if from_node.connect_slot(from_slot, to_node, to_slot):
|
||||
_graph_edit.connect_node(from, from_slot, to, to_slot)
|
||||
|
||||
ignore_changes(false)
|
||||
|
||||
func on_graph_edit_disconnection_request(from: String, from_slot: int, to: String, to_slot: int):
|
||||
var from_node : GraphNode = _graph_edit.get_node(from)
|
||||
var to_node : GraphNode = _graph_edit.get_node(to)
|
||||
|
||||
ignore_changes(true)
|
||||
|
||||
_material.cancel_render_and_wait()
|
||||
|
||||
if from_node.disconnect_slot(from_slot, to_node, to_slot):
|
||||
_graph_edit.disconnect_node(from, from_slot, to, to_slot)
|
||||
|
||||
ignore_changes(false)
|
||||
|
||||
func on_graph_node_close_request(node : GraphNode) -> void:
|
||||
if _material:
|
||||
ignore_changes(true)
|
||||
|
||||
_material.cancel_render_and_wait()
|
||||
|
||||
#_material.remove_node(node._node)
|
||||
|
||||
_undo_redo.create_action("MMGD: Remove Node")
|
||||
_undo_redo.add_do_method(_material, "remove_node", node._node)
|
||||
_undo_redo.add_undo_method(_material, "add_node", node._node)
|
||||
_undo_redo.commit_action()
|
||||
|
||||
recreate()
|
||||
|
||||
ignore_changes(false)
|
||||
|
||||
func _on_AddButton_pressed():
|
||||
get_node(add_popup_path).popup_centered()
|
||||
|
||||
func _on_AddPopup_ok_pressed(script_path : String):
|
||||
if !_material:
|
||||
return
|
||||
|
||||
ensure_objs()
|
||||
|
||||
_material.cancel_render_and_wait()
|
||||
|
||||
var sc = load(script_path)
|
||||
var nnode : MMNode = sc.new()
|
||||
|
||||
if !nnode:
|
||||
print("_on_AddPopup_ok_pressed: Error !nnode! script: " + script_path)
|
||||
return
|
||||
|
||||
ignore_changes(true)
|
||||
|
||||
#_material.add_node(nnode)
|
||||
|
||||
_undo_redo.create_action("MMGD: Add Node")
|
||||
_undo_redo.add_do_method(_material, "add_node", nnode)
|
||||
_undo_redo.add_undo_method(_material, "remove_node", nnode)
|
||||
_undo_redo.commit_action()
|
||||
|
||||
var gn : GraphNode = MMGraphNode.new()
|
||||
gn.set_editor(self)
|
||||
gn.set_node(_material, nnode)
|
||||
_graph_edit.add_child(gn)
|
||||
|
||||
ignore_changes(false)
|
||||
|
@ -1,51 +0,0 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/editor/MatMakerGDEditor.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/mat_maker_gd/editor/CreateNamePopup.tscn" type="PackedScene" id=2]
|
||||
|
||||
[node name="MatMakerGDEditor" type="MarginContainer"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
rect_min_size = Vector2( 0, 200 )
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
margin_right = 1024.0
|
||||
margin_bottom = 600.0
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="VBoxContainer"]
|
||||
margin_right = 1024.0
|
||||
margin_bottom = 34.0
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/PanelContainer"]
|
||||
margin_left = 7.0
|
||||
margin_top = 7.0
|
||||
margin_right = 1017.0
|
||||
margin_bottom = 27.0
|
||||
|
||||
[node name="AddButton" type="Button" parent="VBoxContainer/PanelContainer/HBoxContainer"]
|
||||
margin_right = 37.0
|
||||
margin_bottom = 20.0
|
||||
text = "Add"
|
||||
|
||||
[node name="GraphEdit" type="GraphEdit" parent="VBoxContainer"]
|
||||
margin_top = 38.0
|
||||
margin_right = 1024.0
|
||||
margin_bottom = 600.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
right_disconnects = true
|
||||
scroll_offset = Vector2( 0, -20 )
|
||||
|
||||
[node name="Popups" type="Control" parent="."]
|
||||
margin_right = 1024.0
|
||||
margin_bottom = 600.0
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="AddPopup" parent="Popups" instance=ExtResource( 2 )]
|
||||
type_folders = PoolStringArray( "res://addons/mat_maker_gd/nodes/uniform", "res://addons/mat_maker_gd/nodes/noise", "res://addons/mat_maker_gd/nodes/filter", "res://addons/mat_maker_gd/nodes/gradient", "res://addons/mat_maker_gd/nodes/pattern", "res://addons/mat_maker_gd/nodes/sdf2d", "res://addons/mat_maker_gd/nodes/sdf3d", "res://addons/mat_maker_gd/nodes/transform", "res://addons/mat_maker_gd/nodes/simple", "res://addons/mat_maker_gd/nodes/other" )
|
||||
|
||||
[connection signal="pressed" from="VBoxContainer/PanelContainer/HBoxContainer/AddButton" to="." method="_on_AddButton_pressed"]
|
||||
[connection signal="ok_pressed" from="Popups/AddPopup" to="." method="_on_AddPopup_ok_pressed"]
|
@ -1,742 +0,0 @@
|
||||
tool
|
||||
extends GraphNode
|
||||
|
||||
var gradient_editor_scene : PackedScene = preload("res://addons/mat_maker_gd/widgets/gradient_editor/gradient_editor.tscn")
|
||||
var polygon_edit_scene : PackedScene = preload("res://addons/mat_maker_gd/widgets/polygon_edit/polygon_edit.tscn")
|
||||
var curve_edit_scene : PackedScene = preload("res://addons/mat_maker_gd/widgets/curve_edit/curve_edit.tscn")
|
||||
|
||||
var _material : MMMaterial = null
|
||||
var _node : MMNode = null
|
||||
var properties : Array = Array()
|
||||
|
||||
var _editor_node
|
||||
var _undo_redo : UndoRedo = null
|
||||
var _ignore_change_event : bool = false
|
||||
|
||||
func _init():
|
||||
show_close = true
|
||||
connect("dragged", self, "on_dragged")
|
||||
connect("close_request", self, "on_close_request")
|
||||
|
||||
func set_editor(editor_node) -> void:
|
||||
_editor_node = editor_node
|
||||
|
||||
_undo_redo = _editor_node.get_undo_redo()
|
||||
|
||||
func ignore_changes(val : bool) -> void:
|
||||
_ignore_change_event = val
|
||||
_editor_node.ignore_changes(val)
|
||||
|
||||
func add_slot_texture(getter : String, setter : String) -> int:
|
||||
var t : TextureRect = TextureRect.new()
|
||||
t.rect_min_size = Vector2(128, 128)
|
||||
t.expand = true
|
||||
t.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
||||
|
||||
var slot_idx : int = add_slot(MMNodeUniversalProperty.SLOT_TYPE_NONE, MMNodeUniversalProperty.SLOT_TYPE_NONE, getter, setter, t)
|
||||
|
||||
t.texture = _node.call(getter, _material, slot_idx)
|
||||
properties[slot_idx].append(t.texture)
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_texture_universal(property : MMNodeUniversalProperty) -> int:
|
||||
var t : TextureRect = TextureRect.new()
|
||||
t.rect_min_size = Vector2(128, 128)
|
||||
t.expand = true
|
||||
t.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
||||
|
||||
var slot_idx : int = add_slot(property.input_slot_type, property.output_slot_type, "", "", t)
|
||||
|
||||
var img : Image = property.get_active_image()
|
||||
|
||||
var tex : ImageTexture = ImageTexture.new()
|
||||
|
||||
if img:
|
||||
tex.create_from_image(img, 0)
|
||||
|
||||
t.texture = tex
|
||||
|
||||
properties[slot_idx].append(property)
|
||||
|
||||
property.connect("changed", self, "on_universal_texture_changed", [ slot_idx ])
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_image_path_universal(property : MMNodeUniversalProperty, getter : String, setter : String) -> int:
|
||||
var t : TextureButton = load("res://addons/mat_maker_gd/widgets/image_picker_button/image_picker_button.tscn").instance()
|
||||
|
||||
var slot_idx : int = add_slot(property.input_slot_type, property.output_slot_type, "", "", t)
|
||||
|
||||
properties[slot_idx].append(property)
|
||||
properties[slot_idx].append(getter)
|
||||
properties[slot_idx].append(setter)
|
||||
|
||||
property.connect("changed", self, "on_universal_texture_changed_image_picker", [ slot_idx ])
|
||||
|
||||
t.connect("on_file_selected", self, "on_universal_image_path_changed", [ slot_idx ])
|
||||
|
||||
t.call_deferred("do_set_image_path", _node.call(getter))
|
||||
|
||||
return slot_idx
|
||||
|
||||
|
||||
func add_slot_gradient() -> int:
|
||||
var ge : Control = gradient_editor_scene.instance()
|
||||
ge.graph_node = self
|
||||
ge.set_undo_redo(_undo_redo)
|
||||
|
||||
var slot_idx : int = add_slot(MMNodeUniversalProperty.SLOT_TYPE_NONE, MMNodeUniversalProperty.SLOT_TYPE_NONE, "", "", ge)
|
||||
|
||||
ge.set_value(_node)
|
||||
#ge.texture = _node.call(getter, _material, slot_idx)
|
||||
#properties[slot_idx].append(ge.texture)
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_polygon() -> int:
|
||||
var ge : Control = polygon_edit_scene.instance()
|
||||
|
||||
var slot_idx : int = add_slot(MMNodeUniversalProperty.SLOT_TYPE_NONE, MMNodeUniversalProperty.SLOT_TYPE_NONE, "", "", ge)
|
||||
|
||||
ge.set_value(_node)
|
||||
#ge.texture = _node.call(getter, _material, slot_idx)
|
||||
#properties[slot_idx].append(ge.texture)
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_curve() -> int:
|
||||
var ge : Control = curve_edit_scene.instance()
|
||||
|
||||
var slot_idx : int = add_slot(MMNodeUniversalProperty.SLOT_TYPE_NONE, MMNodeUniversalProperty.SLOT_TYPE_NONE, "", "", ge)
|
||||
|
||||
ge.set_value(_node)
|
||||
#ge.texture = _node.call(getter, _material, slot_idx)
|
||||
#properties[slot_idx].append(ge.texture)
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_color(getter : String, setter : String) -> int:
|
||||
var cp : ColorPickerButton = ColorPickerButton.new()
|
||||
|
||||
var slot_idx : int = add_slot(MMNodeUniversalProperty.SLOT_TYPE_NONE, MMNodeUniversalProperty.SLOT_TYPE_NONE, getter, setter, cp)
|
||||
|
||||
cp.color = _node.call(getter)
|
||||
|
||||
cp.connect("color_changed", _node, setter)
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_color_universal(property : MMNodeUniversalProperty) -> int:
|
||||
var cp : ColorPickerButton = ColorPickerButton.new()
|
||||
|
||||
var slot_idx : int = add_slot(property.input_slot_type, property.output_slot_type, "", "", cp)
|
||||
|
||||
cp.color = property.get_default_value()
|
||||
|
||||
properties[slot_idx].append(property)
|
||||
|
||||
cp.connect("color_changed", self, "on_universal_color_changed", [ slot_idx ])
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_label(getter : String, setter : String, slot_name : String) -> int:
|
||||
var l : Label = Label.new()
|
||||
|
||||
l.text = slot_name
|
||||
|
||||
return add_slot(MMNodeUniversalProperty.SLOT_TYPE_NONE, MMNodeUniversalProperty.SLOT_TYPE_NONE, getter, setter, l)
|
||||
|
||||
func add_slot_line_edit(getter : String, setter : String, slot_name : String, placeholder : String = "") -> int:
|
||||
var bc : VBoxContainer = VBoxContainer.new()
|
||||
|
||||
var l : Label = Label.new()
|
||||
l.text = slot_name
|
||||
bc.add_child(l)
|
||||
|
||||
var le : LineEdit = LineEdit.new()
|
||||
le.placeholder_text = placeholder
|
||||
bc.add_child(le)
|
||||
|
||||
var slot_idx : int = add_slot(MMNodeUniversalProperty.SLOT_TYPE_NONE, MMNodeUniversalProperty.SLOT_TYPE_NONE, getter, setter, bc)
|
||||
|
||||
le.text = _node.call(getter)
|
||||
|
||||
le.connect("text_entered", self, "on_slot_line_edit_text_entered", [ slot_idx ])
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_enum(getter : String, setter : String, slot_name : String, values : Array) -> int:
|
||||
var bc : VBoxContainer = VBoxContainer.new()
|
||||
|
||||
if slot_name:
|
||||
var l : Label = Label.new()
|
||||
l.text = slot_name
|
||||
bc.add_child(l)
|
||||
|
||||
var mb : OptionButton = OptionButton.new()
|
||||
|
||||
for v in values:
|
||||
mb.add_item(v)
|
||||
|
||||
bc.add_child(mb)
|
||||
|
||||
var slot_idx : int = add_slot(MMNodeUniversalProperty.SLOT_TYPE_NONE, MMNodeUniversalProperty.SLOT_TYPE_NONE, getter, setter, bc)
|
||||
|
||||
mb.selected = _node.call(getter)
|
||||
|
||||
mb.connect("item_selected", self, "on_slot_enum_item_selected", [ slot_idx ])
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_int(getter : String, setter : String, slot_name : String, prange : Vector2 = Vector2(-1000, 1000)) -> int:
|
||||
var bc : VBoxContainer = VBoxContainer.new()
|
||||
|
||||
var l : Label = Label.new()
|
||||
l.text = slot_name
|
||||
bc.add_child(l)
|
||||
|
||||
var sb : SpinBox = SpinBox.new()
|
||||
sb.rounded = true
|
||||
sb.min_value = prange.x
|
||||
sb.max_value = prange.y
|
||||
bc.add_child(sb)
|
||||
|
||||
var slot_idx : int = add_slot(MMNodeUniversalProperty.SLOT_TYPE_NONE, MMNodeUniversalProperty.SLOT_TYPE_NONE, getter, setter, bc)
|
||||
|
||||
sb.value = _node.call(getter)
|
||||
|
||||
sb.connect("value_changed", self, "on_int_spinbox_value_changed", [ slot_idx ])
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_bool(getter : String, setter : String, slot_name : String) -> int:
|
||||
var cb : CheckBox = CheckBox.new()
|
||||
cb.text = slot_name
|
||||
|
||||
var slot_idx : int = add_slot(MMNodeUniversalProperty.SLOT_TYPE_NONE, MMNodeUniversalProperty.SLOT_TYPE_NONE, getter, setter, cb)
|
||||
|
||||
cb.pressed = _node.call(getter)
|
||||
|
||||
cb.connect("toggled", _node, setter)
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_label_universal(property : MMNodeUniversalProperty) -> int:
|
||||
var l : Label = Label.new()
|
||||
l.text = property.slot_name
|
||||
|
||||
var slot_idx : int = add_slot(property.input_slot_type, property.output_slot_type, "", "", l)
|
||||
|
||||
properties[slot_idx].append(property)
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_int_universal(property : MMNodeUniversalProperty) -> int:
|
||||
var bc : VBoxContainer = VBoxContainer.new()
|
||||
|
||||
var l : Label = Label.new()
|
||||
l.text = property.slot_name
|
||||
bc.add_child(l)
|
||||
|
||||
var sb : SpinBox = SpinBox.new()
|
||||
sb.rounded = true
|
||||
sb.min_value = property.value_range.x
|
||||
sb.max_value = property.value_range.y
|
||||
bc.add_child(sb)
|
||||
|
||||
var slot_idx : int = add_slot(property.input_slot_type, property.output_slot_type, "", "", bc)
|
||||
|
||||
sb.value = property.get_default_value()
|
||||
|
||||
sb.connect("value_changed", self, "on_int_universal_spinbox_value_changed", [ slot_idx ])
|
||||
|
||||
properties[slot_idx].append(property)
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_float(getter : String, setter : String, slot_name : String, step : float = 0.1, prange : Vector2 = Vector2(-1000, 1000)) -> int:
|
||||
var bc : VBoxContainer = VBoxContainer.new()
|
||||
|
||||
var l : Label = Label.new()
|
||||
l.text = slot_name
|
||||
bc.add_child(l)
|
||||
|
||||
var sb : SpinBox = SpinBox.new()
|
||||
bc.add_child(sb)
|
||||
|
||||
var slot_idx : int = add_slot(MMNodeUniversalProperty.SLOT_TYPE_NONE, MMNodeUniversalProperty.SLOT_TYPE_NONE, getter, setter, bc)
|
||||
sb.rounded = false
|
||||
sb.step = step
|
||||
sb.min_value = prange.x
|
||||
sb.max_value = prange.y
|
||||
sb.value = _node.call(getter)
|
||||
|
||||
sb.connect("value_changed", self, "on_float_spinbox_value_changed", [ slot_idx ])
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_float_universal(property : MMNodeUniversalProperty) -> int:
|
||||
var bc : VBoxContainer = VBoxContainer.new()
|
||||
|
||||
var l : Label = Label.new()
|
||||
l.text = property.slot_name
|
||||
bc.add_child(l)
|
||||
|
||||
var sb : SpinBox = SpinBox.new()
|
||||
bc.add_child(sb)
|
||||
|
||||
var slot_idx : int = add_slot(property.input_slot_type, property.output_slot_type, "", "", bc)
|
||||
sb.rounded = false
|
||||
sb.step = property.value_step
|
||||
sb.min_value = property.value_range.x
|
||||
sb.max_value = property.value_range.y
|
||||
sb.value = property.get_default_value()
|
||||
|
||||
properties[slot_idx].append(property)
|
||||
|
||||
sb.connect("value_changed", self, "on_float_universal_spinbox_value_changed", [ slot_idx ])
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_vector2(getter : String, setter : String, slot_name : String, step : float = 0.1, prange : Vector2 = Vector2(-1000, 1000)) -> int:
|
||||
var bc : VBoxContainer = VBoxContainer.new()
|
||||
|
||||
var l : Label = Label.new()
|
||||
l.text = slot_name
|
||||
bc.add_child(l)
|
||||
|
||||
var sbx : SpinBox = SpinBox.new()
|
||||
bc.add_child(sbx)
|
||||
|
||||
var sby : SpinBox = SpinBox.new()
|
||||
bc.add_child(sby)
|
||||
|
||||
var slot_idx : int = add_slot(MMNodeUniversalProperty.SLOT_TYPE_NONE, MMNodeUniversalProperty.SLOT_TYPE_NONE, getter, setter, bc)
|
||||
sbx.rounded = false
|
||||
sby.rounded = false
|
||||
sbx.step = step
|
||||
sby.step = step
|
||||
sbx.min_value = prange.x
|
||||
sbx.max_value = prange.y
|
||||
sby.min_value = prange.x
|
||||
sby.max_value = prange.y
|
||||
|
||||
var val : Vector2 = _node.call(getter)
|
||||
|
||||
sbx.value = val.x
|
||||
sby.value = val.y
|
||||
|
||||
sbx.connect("value_changed", self, "on_vector2_spinbox_value_changed", [ slot_idx, sbx, sby ])
|
||||
sby.connect("value_changed", self, "on_vector2_spinbox_value_changed", [ slot_idx, sbx, sby ])
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_vector3(getter : String, setter : String, slot_name : String, step : float = 0.1, prange : Vector2 = Vector2(-1000, 1000)) -> int:
|
||||
var bc : VBoxContainer = VBoxContainer.new()
|
||||
|
||||
var l : Label = Label.new()
|
||||
l.text = slot_name
|
||||
bc.add_child(l)
|
||||
|
||||
var sbx : SpinBox = SpinBox.new()
|
||||
bc.add_child(sbx)
|
||||
|
||||
var sby : SpinBox = SpinBox.new()
|
||||
bc.add_child(sby)
|
||||
|
||||
var sbz : SpinBox = SpinBox.new()
|
||||
bc.add_child(sbz)
|
||||
|
||||
var slot_idx : int = add_slot(MMNodeUniversalProperty.SLOT_TYPE_NONE, MMNodeUniversalProperty.SLOT_TYPE_NONE, getter, setter, bc)
|
||||
sbx.rounded = false
|
||||
sby.rounded = false
|
||||
sbz.rounded = false
|
||||
sbx.step = step
|
||||
sby.step = step
|
||||
sbz.step = step
|
||||
sbx.min_value = prange.x
|
||||
sbx.max_value = prange.y
|
||||
sby.min_value = prange.x
|
||||
sby.max_value = prange.y
|
||||
sbz.min_value = prange.x
|
||||
sbz.max_value = prange.y
|
||||
|
||||
var val : Vector3 = _node.call(getter)
|
||||
|
||||
sbx.value = val.x
|
||||
sby.value = val.y
|
||||
sbz.value = val.z
|
||||
|
||||
sbx.connect("value_changed", self, "on_vector3_spinbox_value_changed", [ slot_idx, sbx, sby, sbz ])
|
||||
sby.connect("value_changed", self, "on_vector3_spinbox_value_changed", [ slot_idx, sbx, sby, sbz ])
|
||||
sbz.connect("value_changed", self, "on_vector3_spinbox_value_changed", [ slot_idx, sbx, sby, sbz ])
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_vector2_universal(property : MMNodeUniversalProperty) -> int:
|
||||
var bc : VBoxContainer = VBoxContainer.new()
|
||||
|
||||
var l : Label = Label.new()
|
||||
l.text = property.slot_name
|
||||
bc.add_child(l)
|
||||
|
||||
var sbx : SpinBox = SpinBox.new()
|
||||
bc.add_child(sbx)
|
||||
|
||||
var sby : SpinBox = SpinBox.new()
|
||||
bc.add_child(sby)
|
||||
|
||||
var slot_idx : int = add_slot(property.input_slot_type, property.output_slot_type, "", "", bc)
|
||||
sbx.rounded = false
|
||||
sby.rounded = false
|
||||
sbx.step = property.value_step
|
||||
sby.step = property.value_step
|
||||
sbx.min_value = property.value_range.x
|
||||
sbx.max_value = property.value_range.y
|
||||
sby.min_value = property.value_range.x
|
||||
sby.max_value = property.value_range.y
|
||||
|
||||
var val : Vector2 = property.get_default_value()
|
||||
|
||||
sbx.value = val.x
|
||||
sby.value = val.y
|
||||
|
||||
properties[slot_idx].append(property)
|
||||
|
||||
sbx.connect("value_changed", self, "on_vector2_universal_spinbox_value_changed", [ slot_idx, sbx, sby ])
|
||||
sby.connect("value_changed", self, "on_vector2_universal_spinbox_value_changed", [ slot_idx, sbx, sby ])
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot(input_type : int, output_type : int, getter : String, setter : String, control : Control) -> int:
|
||||
add_child(control)
|
||||
var slot_idx : int = get_child_count() - 1
|
||||
|
||||
var arr : Array = Array()
|
||||
|
||||
arr.append(slot_idx)
|
||||
arr.append(input_type)
|
||||
arr.append(output_type)
|
||||
arr.append(getter)
|
||||
arr.append(setter)
|
||||
arr.append(control)
|
||||
|
||||
properties.append(arr)
|
||||
|
||||
set_slot_enabled_left(slot_idx, input_type != -1)
|
||||
set_slot_enabled_right(slot_idx, output_type != -1)
|
||||
|
||||
if input_type != -1:
|
||||
set_slot_type_left(slot_idx, input_type)
|
||||
set_slot_color_left(slot_idx, get_slot_color(input_type))
|
||||
|
||||
if output_type != -1:
|
||||
set_slot_type_left(slot_idx, output_type)
|
||||
set_slot_color_right(slot_idx, get_slot_color(output_type))
|
||||
|
||||
return slot_idx
|
||||
|
||||
func connect_slot(slot_idx : int, to_node : Node, to_slot_idx : int) -> bool:
|
||||
var from_property_index : int = -1
|
||||
var to_property_index : int = -1
|
||||
|
||||
for i in range(properties.size()):
|
||||
if properties[i][2] != -1:
|
||||
from_property_index += 1
|
||||
|
||||
if from_property_index == slot_idx:
|
||||
from_property_index = i
|
||||
break
|
||||
|
||||
for i in range(to_node.properties.size()):
|
||||
if to_node.properties[i][1] != -1:
|
||||
to_property_index += 1
|
||||
|
||||
if to_property_index == to_slot_idx:
|
||||
to_property_index = i
|
||||
break
|
||||
|
||||
#to_node.properties[to_property_index][6].set_input_property(properties[from_property_index][6])
|
||||
|
||||
_undo_redo.create_action("MMGD: connect_slot")
|
||||
_undo_redo.add_do_method(to_node.properties[to_property_index][6], "set_input_property", properties[from_property_index][6])
|
||||
_undo_redo.add_undo_method(to_node.properties[to_property_index][6], "set_input_property", to_node.properties[to_property_index][6].input_property)
|
||||
_undo_redo.commit_action()
|
||||
|
||||
return true
|
||||
|
||||
func disconnect_slot(slot_idx : int, to_node : Node, to_slot_idx : int) -> bool:
|
||||
var from_property_index : int = -1
|
||||
var to_property_index : int = -1
|
||||
|
||||
for i in range(properties.size()):
|
||||
if properties[i][2] != -1:
|
||||
from_property_index += 1
|
||||
|
||||
if from_property_index == slot_idx:
|
||||
from_property_index = i
|
||||
break
|
||||
|
||||
for i in range(to_node.properties.size()):
|
||||
if to_node.properties[i][1] != -1:
|
||||
to_property_index += 1
|
||||
|
||||
if to_property_index == to_slot_idx:
|
||||
to_property_index = i
|
||||
break
|
||||
|
||||
#to_node.properties[to_property_index][6].set_input_property(null)
|
||||
|
||||
_undo_redo.create_action("MMGD: disconnect_slot")
|
||||
_undo_redo.add_do_method(to_node.properties[to_property_index][6], "unset_input_property")
|
||||
_undo_redo.add_undo_method(to_node.properties[to_property_index][6], "set_input_property", to_node.properties[to_property_index][6].input_property)
|
||||
_undo_redo.commit_action()
|
||||
|
||||
return true
|
||||
|
||||
func get_input_property_graph_node_slot_index(property) -> int:
|
||||
var property_index : int = -1
|
||||
|
||||
for i in range(properties.size()):
|
||||
if properties[i][1] != -1:
|
||||
property_index += 1
|
||||
|
||||
if properties[i][6] == property:
|
||||
break
|
||||
|
||||
return property_index
|
||||
|
||||
func get_output_property_graph_node_slot_index(property) -> int:
|
||||
var property_index : int = -1
|
||||
|
||||
for i in range(properties.size()):
|
||||
if properties[i][2] != -1:
|
||||
property_index += 1
|
||||
|
||||
if properties[i][6] == property:
|
||||
break
|
||||
|
||||
return property_index
|
||||
|
||||
func get_property_control(slot_idx : int) -> Node:
|
||||
return properties[slot_idx][5]
|
||||
|
||||
func set_node(material : MMMaterial, node : MMNode) -> void:
|
||||
_node = node
|
||||
_material = material
|
||||
|
||||
if !_node:
|
||||
return
|
||||
|
||||
title = _node.get_class()
|
||||
|
||||
if _node.get_script():
|
||||
title = _node.get_script().resource_path.get_file().get_basename()
|
||||
|
||||
_node.register_methods(self)
|
||||
|
||||
offset = _node.get_graph_position()
|
||||
|
||||
#_node.connect("changed", self, "on_node_changed")
|
||||
|
||||
func propagate_node_change() -> void:
|
||||
pass
|
||||
|
||||
func on_dragged(from : Vector2, to : Vector2):
|
||||
if _node:
|
||||
ignore_changes(true)
|
||||
#_node.set_graph_position(offset)
|
||||
|
||||
_undo_redo.create_action("MMGD: value changed")
|
||||
_undo_redo.add_do_method(_node, "set_graph_position", to)
|
||||
_undo_redo.add_undo_method(_node, "set_graph_position", from)
|
||||
_undo_redo.commit_action()
|
||||
|
||||
ignore_changes(false)
|
||||
|
||||
#func on_node_changed():
|
||||
# if _ignore_change_event:
|
||||
# return
|
||||
#
|
||||
# _ignore_change_event = true
|
||||
# propagate_node_change()
|
||||
# _ignore_change_event = false
|
||||
|
||||
func on_int_spinbox_value_changed(val : float, slot_idx) -> void:
|
||||
#_node.call(properties[slot_idx][4], int(val))
|
||||
|
||||
ignore_changes(true)
|
||||
_undo_redo.create_action("MMGD: value changed")
|
||||
_undo_redo.add_do_method(_node, properties[slot_idx][4], int(val))
|
||||
_undo_redo.add_undo_method(_node, properties[slot_idx][4], _node.call(properties[slot_idx][3]))
|
||||
_undo_redo.commit_action()
|
||||
ignore_changes(false)
|
||||
|
||||
func on_float_spinbox_value_changed(val : float, slot_idx) -> void:
|
||||
#_node.call(properties[slot_idx][4], val)
|
||||
|
||||
ignore_changes(true)
|
||||
_undo_redo.create_action("MMGD: value changed")
|
||||
_undo_redo.add_do_method(_node, properties[slot_idx][4], val)
|
||||
_undo_redo.add_undo_method(_node, properties[slot_idx][4], _node.call(properties[slot_idx][3]))
|
||||
_undo_redo.commit_action()
|
||||
ignore_changes(false)
|
||||
|
||||
func on_vector2_spinbox_value_changed(val : float, slot_idx, spinbox_x, spinbox_y) -> void:
|
||||
var vv : Vector2 = Vector2(spinbox_x.value, spinbox_y.value)
|
||||
|
||||
#_node.call(properties[slot_idx][4], vv)
|
||||
|
||||
ignore_changes(true)
|
||||
_undo_redo.create_action("MMGD: value changed")
|
||||
_undo_redo.add_do_method(_node, properties[slot_idx][4], vv)
|
||||
_undo_redo.add_undo_method(_node, properties[slot_idx][4], _node.call(properties[slot_idx][3]))
|
||||
_undo_redo.commit_action()
|
||||
ignore_changes(false)
|
||||
|
||||
func on_vector3_spinbox_value_changed(val : float, slot_idx, spinbox_x, spinbox_y, spinbox_z) -> void:
|
||||
var vv : Vector3 = Vector3(spinbox_x.value, spinbox_y.value, spinbox_z.value)
|
||||
|
||||
#_node.call(properties[slot_idx][4], vv)
|
||||
|
||||
ignore_changes(true)
|
||||
_undo_redo.create_action("MMGD: value changed")
|
||||
_undo_redo.add_do_method(_node, properties[slot_idx][4], vv)
|
||||
_undo_redo.add_undo_method(_node, properties[slot_idx][4], _node.call(properties[slot_idx][3]))
|
||||
_undo_redo.commit_action()
|
||||
ignore_changes(false)
|
||||
|
||||
func on_int_universal_spinbox_value_changed(val : float, slot_idx) -> void:
|
||||
#properties[slot_idx][6].set_default_value(int(val))
|
||||
|
||||
ignore_changes(true)
|
||||
_undo_redo.create_action("MMGD: value changed")
|
||||
_undo_redo.add_do_method(properties[slot_idx][6], "set_default_value", int(val))
|
||||
_undo_redo.add_undo_method(properties[slot_idx][6], "set_default_value", properties[slot_idx][6].get_default_value())
|
||||
_undo_redo.commit_action()
|
||||
ignore_changes(false)
|
||||
|
||||
func on_float_universal_spinbox_value_changed(val : float, slot_idx) -> void:
|
||||
#properties[slot_idx][6].set_default_value(val)
|
||||
|
||||
ignore_changes(true)
|
||||
_undo_redo.create_action("MMGD: value changed")
|
||||
_undo_redo.add_do_method(properties[slot_idx][6], "set_default_value", val)
|
||||
_undo_redo.add_undo_method(properties[slot_idx][6], "set_default_value", properties[slot_idx][6].get_default_value())
|
||||
_undo_redo.commit_action()
|
||||
ignore_changes(false)
|
||||
|
||||
func on_vector2_universal_spinbox_value_changed(val : float, slot_idx, spinbox_x, spinbox_y) -> void:
|
||||
var vv : Vector2 = Vector2(spinbox_x.value, spinbox_y.value)
|
||||
|
||||
#properties[slot_idx][6].set_default_value(vv)
|
||||
|
||||
ignore_changes(true)
|
||||
_undo_redo.create_action("MMGD: value changed")
|
||||
_undo_redo.add_do_method(properties[slot_idx][6], "set_default_value", vv)
|
||||
_undo_redo.add_undo_method(properties[slot_idx][6], "set_default_value", properties[slot_idx][6].get_default_value())
|
||||
_undo_redo.commit_action()
|
||||
ignore_changes(false)
|
||||
|
||||
func on_slot_enum_item_selected(val : int, slot_idx : int) -> void:
|
||||
#_node.call(properties[slot_idx][4], val)
|
||||
|
||||
ignore_changes(true)
|
||||
_undo_redo.create_action("MMGD: value changed")
|
||||
_undo_redo.add_do_method(_node, properties[slot_idx][4], val)
|
||||
_undo_redo.add_undo_method(_node, properties[slot_idx][4], _node.call(properties[slot_idx][3]))
|
||||
_undo_redo.commit_action()
|
||||
ignore_changes(false)
|
||||
|
||||
func on_universal_texture_changed(slot_idx : int) -> void:
|
||||
ignore_changes(true)
|
||||
|
||||
var img : Image = properties[slot_idx][6].get_active_image()
|
||||
|
||||
var tex : ImageTexture = properties[slot_idx][5].texture
|
||||
|
||||
if img:
|
||||
properties[slot_idx][5].texture.create_from_image(img, 0)
|
||||
else:
|
||||
properties[slot_idx][5].texture = ImageTexture.new()
|
||||
|
||||
ignore_changes(false)
|
||||
|
||||
func on_universal_texture_changed_image_picker(slot_idx : int) -> void:
|
||||
ignore_changes(true)
|
||||
|
||||
var img : Image = properties[slot_idx][6].get_active_image()
|
||||
|
||||
var tex : ImageTexture = properties[slot_idx][5].texture_normal
|
||||
|
||||
if img:
|
||||
properties[slot_idx][5].texture_normal.create_from_image(img, 0)
|
||||
else:
|
||||
properties[slot_idx][5].texture_normal = ImageTexture.new()
|
||||
|
||||
ignore_changes(false)
|
||||
|
||||
func on_slot_line_edit_text_entered(text : String, slot_idx : int) -> void:
|
||||
#_node.call(properties[slot_idx][4], text)
|
||||
|
||||
ignore_changes(true)
|
||||
_undo_redo.create_action("MMGD: value changed")
|
||||
_undo_redo.add_do_method(_node, properties[slot_idx][4], text)
|
||||
_undo_redo.add_undo_method(_node, properties[slot_idx][4], _node.call(properties[slot_idx][3]))
|
||||
_undo_redo.commit_action()
|
||||
ignore_changes(false)
|
||||
|
||||
func on_universal_color_changed(c : Color, slot_idx : int) -> void:
|
||||
#properties[slot_idx][6].set_default_value(c)
|
||||
|
||||
ignore_changes(true)
|
||||
_undo_redo.create_action("MMGD: value changed")
|
||||
_undo_redo.add_do_method(properties[slot_idx][6], "set_default_value", c)
|
||||
_undo_redo.add_undo_method(properties[slot_idx][6], "set_default_value", properties[slot_idx][6].get_default_value())
|
||||
_undo_redo.commit_action()
|
||||
ignore_changes(false)
|
||||
|
||||
func on_universal_image_path_changed(f : String, slot_idx : int) -> void:
|
||||
_node.call(properties[slot_idx][8], f)
|
||||
|
||||
ignore_changes(true)
|
||||
_undo_redo.create_action("MMGD: value changed")
|
||||
_undo_redo.add_do_method(properties[slot_idx][6], "set_default_value", f)
|
||||
_undo_redo.add_undo_method(properties[slot_idx][6], "set_default_value", properties[slot_idx][6].get_default_value())
|
||||
_undo_redo.commit_action()
|
||||
ignore_changes(false)
|
||||
|
||||
func get_material_node() -> MMNode:
|
||||
return _node
|
||||
|
||||
func on_close_request() -> void:
|
||||
var n : Node = get_parent()
|
||||
|
||||
while n:
|
||||
if n.has_method("on_graph_node_close_request"):
|
||||
n.call_deferred("on_graph_node_close_request", self)
|
||||
return
|
||||
|
||||
n = n.get_parent()
|
||||
|
||||
func get_slot_color(slot_type : int) -> Color:
|
||||
return _get_slot_color(slot_type)
|
||||
|
||||
func _get_slot_color(slot_type : int) -> Color:
|
||||
if slot_type == 0:
|
||||
return Color(0.91, 0.06, 0.06)
|
||||
elif slot_type == 1:
|
||||
return Color(0.43, 0.04, 0.04)
|
||||
elif slot_type == 2:
|
||||
return Color(0.83, 0.38, 0.38)
|
||||
elif slot_type == 3:
|
||||
return Color(0.04, 0.48, 0.43)
|
||||
elif slot_type == 4:
|
||||
return Color(0.35, 0.04, 0.34)
|
||||
elif slot_type == 5:
|
||||
return Color(0.04, 0.05, 1)
|
||||
elif slot_type == 6:
|
||||
return Color(0.37, 0.37, 0.37)
|
||||
|
||||
return Color(1, 1, 1, 1)
|
@ -1,118 +0,0 @@
|
||||
tool
|
||||
extends MMNode
|
||||
|
||||
class Point:
|
||||
var p : Vector2
|
||||
var ls : float
|
||||
var rs : float
|
||||
func _init(x : float, y : float, nls : float, nrs : float) -> void:
|
||||
p = Vector2(x, y)
|
||||
ls = nls
|
||||
rs = nrs
|
||||
|
||||
export(PoolRealArray) var points
|
||||
|
||||
func init_points_01():
|
||||
if points.size() == 0:
|
||||
points = [ 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0 ]
|
||||
|
||||
func init_points_11():
|
||||
if points.size() == 0:
|
||||
points = [ 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0 ]
|
||||
|
||||
func to_string() -> String:
|
||||
var rv = PoolStringArray()
|
||||
for p in points:
|
||||
rv.append("("+str(p.x)+","+str(p.y)+","+str(p.ls)+","+str(p.rs)+")")
|
||||
|
||||
return rv.join(",")
|
||||
|
||||
func clear() -> void:
|
||||
points.clear()
|
||||
curve_changed()
|
||||
|
||||
func add_point(x : float, y : float, ls : float = INF, rs : float = INF) -> void:
|
||||
var indx : int = points.size() / 4
|
||||
|
||||
for i in indx:
|
||||
var ii : int = i * 4
|
||||
if x < points[ii]:
|
||||
if ls == INF:
|
||||
ls == 0
|
||||
if rs == INF:
|
||||
rs == 0
|
||||
|
||||
points.insert(ii, x)
|
||||
points.insert(ii + 1, y)
|
||||
points.insert(ii + 2, ls)
|
||||
points.insert(ii + 3, rs)
|
||||
|
||||
curve_changed()
|
||||
return
|
||||
|
||||
points.append(x)
|
||||
points.append(y)
|
||||
points.append(ls)
|
||||
points.append(rs)
|
||||
|
||||
curve_changed()
|
||||
|
||||
func remove_point(i : int) -> bool:
|
||||
var index : int = i * 4
|
||||
|
||||
if index <= 0 or index >= points.size() - 1:
|
||||
return false
|
||||
else:
|
||||
points.remove(index)
|
||||
points.remove(index)
|
||||
points.remove(index)
|
||||
points.remove(index)
|
||||
|
||||
curve_changed()
|
||||
return true
|
||||
|
||||
func get_point_count() -> int:
|
||||
return points.size() / 4
|
||||
|
||||
func set_point(i : int, v : Point) -> void:
|
||||
var indx : int = i * 4
|
||||
|
||||
points[indx + 0] = v.p.x
|
||||
points[indx + 1] = v.p.y
|
||||
points[indx + 2] = v.ls
|
||||
points[indx + 3] = v.rs
|
||||
|
||||
curve_changed()
|
||||
|
||||
func get_point(i : int) -> Point:
|
||||
var indx : int = i * 4
|
||||
|
||||
return Point.new(points[indx + 0], points[indx + 1], points[indx + 2], points[indx + 3])
|
||||
|
||||
func get_points() -> Array:
|
||||
var arr : Array = Array()
|
||||
|
||||
var c : int = get_point_count()
|
||||
|
||||
for i in range(c):
|
||||
arr.append(get_point(i))
|
||||
|
||||
return arr
|
||||
|
||||
func set_points(arr : Array, notify : bool = true) -> void:
|
||||
points.resize(0)
|
||||
|
||||
for p in arr:
|
||||
points.append(p.p.x)
|
||||
points.append(p.p.y)
|
||||
points.append(p.ls)
|
||||
points.append(p.rs)
|
||||
|
||||
if notify:
|
||||
curve_changed()
|
||||
|
||||
func curve_changed() -> void:
|
||||
_curve_changed()
|
||||
|
||||
func _curve_changed() -> void:
|
||||
emit_changed()
|
@ -1,64 +0,0 @@
|
||||
tool
|
||||
extends MMNode
|
||||
|
||||
#var Gradients = preload("res://addons/mat_maker_gd/nodes/common/gradients.gd")
|
||||
|
||||
export(int) var interpolation_type : int = 1 setget set_interpolation_type, get_interpolation_type
|
||||
export(PoolRealArray) var points : PoolRealArray = PoolRealArray()
|
||||
|
||||
func get_gradient_color(x : float) -> Color:
|
||||
# if interpolation_type == 0:
|
||||
# return Gradients.gradient_type_1(x, points)
|
||||
# elif interpolation_type == 1:
|
||||
# return Gradients.gradient_type_2(x, points)
|
||||
# elif interpolation_type == 2:
|
||||
# return Gradients.gradient_type_3(x, points)
|
||||
# elif interpolation_type == 3:
|
||||
# return Gradients.gradient_type_4(x, points)
|
||||
|
||||
return Color(1, 1, 1, 1)
|
||||
|
||||
func get_interpolation_type() -> int:
|
||||
return interpolation_type
|
||||
|
||||
func set_interpolation_type(val : int) -> void:
|
||||
interpolation_type = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
func get_points() -> PoolRealArray:
|
||||
return points
|
||||
|
||||
func set_points(val : PoolRealArray) -> void:
|
||||
points = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
func get_point_value(index : int) -> float:
|
||||
return points[index * 5]
|
||||
|
||||
func get_point_color(index : int) -> Color:
|
||||
var indx : int = index * 5
|
||||
|
||||
return Color(points[indx + 1], points[indx + 2], points[indx + 3], points[indx + 4])
|
||||
|
||||
func add_point(val : float, color : Color) -> void:
|
||||
var s : int = points.size()
|
||||
points.resize(s + 5)
|
||||
|
||||
points[s] = val
|
||||
|
||||
points[s + 1] = color.r
|
||||
points[s + 2] = color.g
|
||||
points[s + 3] = color.b
|
||||
points[s + 4] = color.a
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
func get_point_count() -> int:
|
||||
return points.size() / 5
|
||||
|
||||
func clear() -> void:
|
||||
points.resize(0)
|
||||
|
||||
set_dirty(true)
|
@ -1,73 +0,0 @@
|
||||
tool
|
||||
extends MMNode
|
||||
|
||||
export(PoolVector2Array) var points : PoolVector2Array = [Vector2(0.2, 0.2), Vector2(0.7, 0.4), Vector2(0.4, 0.7)]
|
||||
|
||||
func clear() -> void:
|
||||
points.resize(0)
|
||||
|
||||
_polygon_changed()
|
||||
|
||||
func add_point(x : float, y : float, closed : bool = true) -> void:
|
||||
var p : Vector2 = Vector2(x, y)
|
||||
var points_count = points.size()
|
||||
|
||||
if points_count < 3:
|
||||
points.append(p)
|
||||
_polygon_changed()
|
||||
return
|
||||
|
||||
var min_length : float = (p-Geometry.get_closest_point_to_segment_2d(p, points[0], points[points_count-1])).length()
|
||||
var insert_point = 0
|
||||
|
||||
for i in points_count-1:
|
||||
var length = (p - Geometry.get_closest_point_to_segment_2d(p, points[i], points[i+1])).length()
|
||||
if length < min_length:
|
||||
min_length = length
|
||||
insert_point = i+1
|
||||
|
||||
if !closed and insert_point == 0 and (points[0]-p).length() > (points[points_count-1]-p).length():
|
||||
insert_point = points_count
|
||||
|
||||
points.insert(insert_point, p)
|
||||
|
||||
_polygon_changed()
|
||||
|
||||
func remove_point(index : int) -> bool:
|
||||
var s = points.size()
|
||||
if s < 4 or index < 0 or index >= s:
|
||||
return false
|
||||
else:
|
||||
points.remove(index)
|
||||
_polygon_changed()
|
||||
|
||||
return true
|
||||
|
||||
func get_point_count() -> int:
|
||||
return points.size()
|
||||
|
||||
func get_point(i : int) -> Vector2:
|
||||
return points[i]
|
||||
|
||||
func set_point(i : int, v : Vector2) -> void:
|
||||
points[i] = v
|
||||
|
||||
_polygon_changed()
|
||||
|
||||
func set_points(v : PoolVector2Array) -> void:
|
||||
points = v
|
||||
|
||||
_polygon_changed()
|
||||
|
||||
func polygon_changed() -> void:
|
||||
_polygon_changed()
|
||||
|
||||
func _polygon_changed() -> void:
|
||||
emit_changed()
|
||||
|
||||
func to_string() -> String:
|
||||
var rv = PoolStringArray()
|
||||
for p in points:
|
||||
rv.append("("+str(p.x)+","+str(p.y)+")")
|
||||
|
||||
return rv.join(",")
|
@ -1,16 +0,0 @@
|
||||
tool
|
||||
extends ColorPickerButton
|
||||
|
||||
func get_drag_data(_position):
|
||||
var preview = ColorRect.new()
|
||||
preview.color = color
|
||||
preview.rect_min_size = Vector2(32, 32)
|
||||
set_drag_preview(preview)
|
||||
return color
|
||||
|
||||
func can_drop_data(_position, data) -> bool:
|
||||
return typeof(data) == TYPE_COLOR
|
||||
|
||||
func drop_data(_position, data) -> void:
|
||||
color = data
|
||||
emit_signal("color_changed", color)
|
@ -1,14 +0,0 @@
|
||||
[gd_scene format=2]
|
||||
|
||||
[node name="ColorPickerPopup" type="PopupPanel"]
|
||||
margin_right = 316.0
|
||||
margin_bottom = 470.0
|
||||
|
||||
[node name="ColorPicker" type="ColorPicker" parent="."]
|
||||
margin_left = 4.0
|
||||
margin_top = 4.0
|
||||
margin_right = 312.0
|
||||
margin_bottom = 466.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
tool
|
||||
extends Control
|
||||
|
||||
var MMCurve = preload("res://addons/mat_maker_gd/nodes/bases/curve_base.gd")
|
||||
|
||||
var moving : bool = false
|
||||
|
||||
var min_x : float
|
||||
var max_x : float
|
||||
var min_y : float
|
||||
var max_y : float
|
||||
|
||||
const OFFSET : Vector2 = Vector2(3, 3)
|
||||
|
||||
signal moved(index)
|
||||
signal removed(index)
|
||||
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
func _draw():
|
||||
# var current_theme : Theme = get_node("/root/MainWindow").theme
|
||||
# var color : Color = current_theme.get_color("font_color", "Label")
|
||||
|
||||
var color : Color = Color(1, 1, 1, 1)
|
||||
for c in get_children():
|
||||
if c.visible:
|
||||
draw_line(OFFSET, c.rect_position+OFFSET, color)
|
||||
|
||||
draw_rect(Rect2(0, 0, 7, 7), color)
|
||||
|
||||
#p : MMCurve.Point
|
||||
func initialize(p) -> void:
|
||||
rect_position = get_parent().transform_point(p.p)-OFFSET
|
||||
if p.ls != INF:
|
||||
$LeftSlope.rect_position = $LeftSlope.distance*(get_parent().rect_size*Vector2(1.0, -p.ls)).normalized()
|
||||
if p.rs != INF:
|
||||
$RightSlope.rect_position = $RightSlope.distance*(get_parent().rect_size*Vector2(1.0, -p.rs)).normalized()
|
||||
|
||||
func set_constraint(x : float, X : float, y : float, Y : float) -> void:
|
||||
min_x = x
|
||||
max_x = X
|
||||
min_y = y
|
||||
max_y = Y
|
||||
|
||||
func _on_ControlPoint_gui_input(event):
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == BUTTON_LEFT:
|
||||
if event.pressed:
|
||||
moving = true
|
||||
else:
|
||||
moving = false
|
||||
get_parent().update_controls()
|
||||
elif event.button_index == BUTTON_RIGHT and event.pressed:
|
||||
emit_signal("removed", get_index())
|
||||
elif moving and event is InputEventMouseMotion:
|
||||
rect_position += event.relative
|
||||
if rect_position.x < min_x:
|
||||
rect_position.x = min_x
|
||||
elif rect_position.x > max_x:
|
||||
rect_position.x = max_x
|
||||
if rect_position.y < min_y:
|
||||
rect_position.y = min_y
|
||||
elif rect_position.y > max_y:
|
||||
rect_position.y = max_y
|
||||
emit_signal("moved", get_index())
|
||||
|
||||
func update_tangents() -> void:
|
||||
update()
|
||||
emit_signal("moved", get_index())
|
@ -1,39 +0,0 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/slope_point.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/control_point.gd" type="Script" id=2]
|
||||
|
||||
[node name="ControlPoint" type="Control"]
|
||||
margin_left = 56.9864
|
||||
margin_top = 33.8615
|
||||
margin_right = 63.9864
|
||||
margin_bottom = 40.8615
|
||||
rect_min_size = Vector2( 7, 7 )
|
||||
script = ExtResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="LeftSlope" type="Control" parent="."]
|
||||
margin_left = -18.5235
|
||||
margin_right = -11.5235
|
||||
margin_bottom = 7.0
|
||||
rect_min_size = Vector2( 7, 7 )
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
distance = -30.0
|
||||
|
||||
[node name="RightSlope" type="Control" parent="."]
|
||||
margin_left = 15.6919
|
||||
margin_right = 22.6919
|
||||
margin_bottom = 7.0
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
distance = 30.0
|
||||
[connection signal="gui_input" from="." to="." method="_on_ControlPoint_gui_input"]
|
||||
[connection signal="gui_input" from="LeftSlope" to="LeftSlope" method="_on_ControlPoint_gui_input"]
|
||||
[connection signal="gui_input" from="RightSlope" to="RightSlope" method="_on_ControlPoint_gui_input"]
|
@ -1,37 +0,0 @@
|
||||
tool
|
||||
extends WindowDialog
|
||||
|
||||
var MMCurve = preload("res://addons/mat_maker_gd/nodes/bases/curve_base.gd")
|
||||
|
||||
var previous_points : Array
|
||||
var curve
|
||||
|
||||
signal curve_changed(curve)
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
func _on_CurveDialog_popup_hide():
|
||||
queue_free()
|
||||
|
||||
func _on_OK_pressed():
|
||||
emit_signal("curve_changed", curve)
|
||||
curve.curve_changed()
|
||||
|
||||
queue_free()
|
||||
|
||||
func _on_Cancel_pressed():
|
||||
curve.set_points(previous_points)
|
||||
emit_signal("curve_changed", curve)
|
||||
|
||||
queue_free()
|
||||
|
||||
func edit_curve(c) -> void:
|
||||
curve = c
|
||||
previous_points = curve.get_points()
|
||||
$VBoxContainer/EditorContainer/CurveEditor.set_curve(curve)
|
||||
popup_centered()
|
||||
|
||||
func _on_CurveEditor_value_changed(value):
|
||||
emit_signal("curve_changed", value)
|
@ -1,81 +0,0 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/curve_editor.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/curve_dialog.gd" type="Script" id=2]
|
||||
|
||||
[node name="CurveDialog" type="WindowDialog"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = 307.0
|
||||
margin_top = 151.0
|
||||
margin_right = -347.0
|
||||
margin_bottom = -174.0
|
||||
window_title = "Edit curve"
|
||||
script = ExtResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = 5.0
|
||||
margin_top = 5.0
|
||||
margin_right = -5.0
|
||||
margin_bottom = -5.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="EditorContainer" type="MarginContainer" parent="VBoxContainer"]
|
||||
margin_right = 616.0
|
||||
margin_bottom = 353.0
|
||||
rect_clip_content = true
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
custom_constants/margin_right = 4
|
||||
custom_constants/margin_top = 4
|
||||
custom_constants/margin_left = 4
|
||||
custom_constants/margin_bottom = 4
|
||||
|
||||
[node name="CurveEditor" parent="VBoxContainer/EditorContainer" instance=ExtResource( 1 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 4.0
|
||||
margin_top = 4.0
|
||||
margin_right = 612.0
|
||||
margin_bottom = 349.0
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="HSeparator" type="HSeparator" parent="VBoxContainer"]
|
||||
margin_top = 357.0
|
||||
margin_right = 616.0
|
||||
margin_bottom = 361.0
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
margin_top = 365.0
|
||||
margin_right = 616.0
|
||||
margin_bottom = 385.0
|
||||
|
||||
[node name="Control" type="Control" parent="VBoxContainer/HBoxContainer"]
|
||||
margin_right = 488.0
|
||||
margin_bottom = 20.0
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="OK" type="Button" parent="VBoxContainer/HBoxContainer"]
|
||||
margin_left = 492.0
|
||||
margin_right = 552.0
|
||||
margin_bottom = 20.0
|
||||
rect_min_size = Vector2( 60, 0 )
|
||||
text = "OK"
|
||||
|
||||
[node name="Cancel" type="Button" parent="VBoxContainer/HBoxContainer"]
|
||||
margin_left = 556.0
|
||||
margin_right = 616.0
|
||||
margin_bottom = 20.0
|
||||
rect_min_size = Vector2( 60, 0 )
|
||||
text = "Cancel"
|
||||
[connection signal="popup_hide" from="." to="." method="_on_CurveDialog_popup_hide"]
|
||||
[connection signal="value_changed" from="VBoxContainer/EditorContainer/CurveEditor" to="." method="_on_CurveEditor_value_changed"]
|
||||
[connection signal="pressed" from="VBoxContainer/HBoxContainer/OK" to="." method="_on_OK_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Cancel" to="." method="_on_Cancel_pressed"]
|
@ -1,24 +0,0 @@
|
||||
tool
|
||||
extends Control
|
||||
|
||||
var MMCurve = preload("res://addons/mat_maker_gd/nodes/bases/curve_base.gd")
|
||||
|
||||
var value = null setget set_value
|
||||
|
||||
signal updated(curve)
|
||||
|
||||
func set_value(v) -> void:
|
||||
value = v
|
||||
$CurveView.set_curve(value)
|
||||
$CurveView.update()
|
||||
|
||||
func _on_CurveEdit_pressed():
|
||||
var dialog = preload("res://addons/mat_maker_gd/widgets/curve_edit/curve_dialog.tscn").instance()
|
||||
add_child(dialog)
|
||||
dialog.connect("curve_changed", self, "on_value_changed")
|
||||
dialog.edit_curve(value)
|
||||
|
||||
func on_value_changed(v) -> void:
|
||||
#set_value(v)
|
||||
emit_signal("updated", v)
|
||||
$CurveView.update()
|
@ -1,22 +0,0 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/curve_edit.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/curve_view.tscn" type="PackedScene" id=2]
|
||||
|
||||
[node name="CurveEdit" type="Button"]
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = -1280.0
|
||||
margin_right = -1220.0
|
||||
margin_bottom = -700.0
|
||||
rect_min_size = Vector2( 60, 20 )
|
||||
focus_mode = 1
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="CurveView" parent="." instance=ExtResource( 2 )]
|
||||
|
||||
[connection signal="pressed" from="." to="." method="_on_CurveEdit_pressed"]
|
@ -1,80 +0,0 @@
|
||||
tool
|
||||
extends "res://addons/mat_maker_gd/widgets/curve_edit/curve_view.gd"
|
||||
|
||||
signal value_changed(value)
|
||||
|
||||
func _ready():
|
||||
update_controls()
|
||||
|
||||
func set_curve(c) -> void:
|
||||
curve = c
|
||||
update()
|
||||
update_controls()
|
||||
|
||||
func update_controls() -> void:
|
||||
if !curve:
|
||||
return
|
||||
|
||||
for c in get_children():
|
||||
c.queue_free()
|
||||
|
||||
var points = curve.get_points()
|
||||
|
||||
for i in points.size():
|
||||
var p = points[i]
|
||||
var control_point = preload("res://addons/mat_maker_gd/widgets/curve_edit/control_point.tscn").instance()
|
||||
add_child(control_point)
|
||||
control_point.initialize(p)
|
||||
control_point.rect_position = transform_point(p.p)-control_point.OFFSET
|
||||
|
||||
if i == 0 or i == points.size()-1:
|
||||
control_point.set_constraint(control_point.rect_position.x, control_point.rect_position.x, -control_point.OFFSET.y, rect_size.y-control_point.OFFSET.y)
|
||||
if i == 0:
|
||||
control_point.get_child(0).visible = false
|
||||
else:
|
||||
control_point.get_child(1).visible = false
|
||||
else:
|
||||
var min_x = transform_point(points[i-1].p).x+1
|
||||
var max_x = transform_point(points[i+1].p).x-1
|
||||
control_point.set_constraint(min_x, max_x, -control_point.OFFSET.y, rect_size.y-control_point.OFFSET.y)
|
||||
|
||||
control_point.connect("moved", self, "_on_ControlPoint_moved")
|
||||
control_point.connect("removed", self, "_on_ControlPoint_removed")
|
||||
|
||||
emit_signal("value_changed", curve)
|
||||
|
||||
func _on_ControlPoint_moved(index):
|
||||
var points : Array = curve.get_points()
|
||||
|
||||
var control_point = get_child(index)
|
||||
points[index].p = reverse_transform_point(control_point.rect_position+control_point.OFFSET)
|
||||
|
||||
if control_point.has_node("LeftSlope"):
|
||||
var slope_vector = control_point.get_node("LeftSlope").rect_position/rect_size
|
||||
if slope_vector.x != 0:
|
||||
points[index].ls = -slope_vector.y / slope_vector.x
|
||||
|
||||
if control_point.has_node("RightSlope"):
|
||||
var slope_vector = control_point.get_node("RightSlope").rect_position/rect_size
|
||||
if slope_vector.x != 0:
|
||||
points[index].rs = -slope_vector.y / slope_vector.x
|
||||
|
||||
curve.set_points(points, false)
|
||||
update()
|
||||
emit_signal("value_changed", curve)
|
||||
|
||||
func _on_ControlPoint_removed(index):
|
||||
if curve.remove_point(index):
|
||||
update()
|
||||
update_controls()
|
||||
|
||||
func _on_CurveEditor_gui_input(event):
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == BUTTON_LEFT and event.doubleclick:
|
||||
var new_point_position = reverse_transform_point(get_local_mouse_position())
|
||||
curve.add_point(new_point_position.x, new_point_position.y, 0.0, 0.0)
|
||||
update_controls()
|
||||
|
||||
func _on_resize() -> void:
|
||||
._on_resize()
|
||||
update_controls()
|
@ -1,14 +0,0 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/curve_view.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/curve_editor.gd" type="Script" id=2]
|
||||
|
||||
[node name="CurveEditor" instance=ExtResource( 1 )]
|
||||
margin_left = 10.0
|
||||
margin_top = 10.0
|
||||
margin_right = -10.0
|
||||
margin_bottom = -10.0
|
||||
mouse_filter = 0
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[connection signal="gui_input" from="." to="." method="_on_CurveEditor_gui_input"]
|
@ -1,70 +0,0 @@
|
||||
tool
|
||||
extends Control
|
||||
|
||||
var MMCurve = preload("res://addons/mat_maker_gd/nodes/bases/curve_base.gd")
|
||||
|
||||
export var show_axes : bool = false
|
||||
|
||||
var curve #: MMCurve
|
||||
|
||||
func _ready() -> void:
|
||||
# curve = MMCurve.new()
|
||||
connect("resized", self, "_on_resize")
|
||||
update()
|
||||
|
||||
func set_curve(val) -> void:
|
||||
curve = val
|
||||
update()
|
||||
|
||||
func transform_point(p : Vector2) -> Vector2:
|
||||
return (Vector2(0.0, 1.0)+Vector2(1.0, -1.0)*p)*rect_size
|
||||
|
||||
func reverse_transform_point(p : Vector2) -> Vector2:
|
||||
return Vector2(0.0, 1.0)+Vector2(1.0, -1.0)*p/rect_size
|
||||
|
||||
func _draw():
|
||||
if !curve:
|
||||
return
|
||||
|
||||
# var current_theme : Theme = get_node("/root/MainWindow").theme
|
||||
#
|
||||
# var bg = current_theme.get_stylebox("panel", "Panel").bg_color
|
||||
# var fg = current_theme.get_color("font_color", "Label")
|
||||
#
|
||||
# var axes_color : Color = bg.linear_interpolate(fg, 0.25)
|
||||
# var curve_color : Color = bg.linear_interpolate(fg, 0.75)
|
||||
|
||||
var axes_color : Color = Color(0.9, 0.9, 0.9, 1)
|
||||
var curve_color : Color = Color(1, 1, 1, 1)
|
||||
|
||||
if show_axes:
|
||||
for i in range(5):
|
||||
var p = transform_point(0.25*Vector2(i, i))
|
||||
draw_line(Vector2(p.x, 0), Vector2(p.x, rect_size.y-1), axes_color)
|
||||
draw_line(Vector2(0, p.y), Vector2(rect_size.x-1, p.y), axes_color)
|
||||
|
||||
var points = curve.get_points()
|
||||
|
||||
for i in range(points.size() - 1):
|
||||
var p1 = points[i].p
|
||||
var p2 = points[i+1].p
|
||||
var d = (p2.x-p1.x)/3.0
|
||||
var yac = p1.y+d*points[i].rs
|
||||
var ybc = p2.y-d*points[i+1].ls
|
||||
var p = transform_point(p1)
|
||||
var count : int = max(1, int((transform_point(p2).x-p.x/5.0)))
|
||||
|
||||
for tt in range(count):
|
||||
var t = (tt+1.0)/count
|
||||
var omt = (1.0 - t)
|
||||
var omt2 = omt * omt
|
||||
var omt3 = omt2 * omt
|
||||
var t2 = t * t
|
||||
var t3 = t2 * t
|
||||
var x = p1.x+(p2.x-p1.x)*t
|
||||
var np = transform_point(Vector2(x, p1.y*omt3 + yac*omt2*t*3.0 + ybc*omt*t2*3.0 + p2.y*t3))
|
||||
draw_line(p, np, curve_color)
|
||||
p = np
|
||||
|
||||
func _on_resize() -> void:
|
||||
update()
|
@ -1,16 +0,0 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/curve_view.gd" type="Script" id=1]
|
||||
|
||||
[node name="CurveView" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = 4.0
|
||||
margin_top = 4.0
|
||||
margin_right = -4.0
|
||||
margin_bottom = -4.0
|
||||
mouse_filter = 2
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
tool
|
||||
extends Control
|
||||
|
||||
export var distance : float
|
||||
|
||||
var moving = false
|
||||
|
||||
const OFFSET = -Vector2(0, 0)
|
||||
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
func _draw():
|
||||
# var current_theme : Theme = get_node("/root/MainWindow").theme
|
||||
# var color : Color = current_theme.get_color("font_color", "Label")
|
||||
|
||||
var color : Color = Color(1, 1, 1, 1)
|
||||
|
||||
draw_circle(Vector2(3.0, 3.0), 3.0, color)
|
||||
|
||||
func _on_ControlPoint_gui_input(event):
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == BUTTON_LEFT:
|
||||
if event.pressed:
|
||||
if event.doubleclick:
|
||||
var parent = get_parent()
|
||||
var vector : Vector2
|
||||
if get_index() == 0:
|
||||
vector = parent.rect_position-parent.get_parent().get_child(parent.get_index()-1).rect_position
|
||||
else:
|
||||
vector = parent.get_parent().get_child(parent.get_index()+1).rect_position-parent.rect_position
|
||||
vector = distance*vector.normalized()
|
||||
rect_position = vector-OFFSET
|
||||
if event.control:
|
||||
get_parent().get_child(1-get_index()).rect_position = -vector-OFFSET
|
||||
get_parent().update_tangents()
|
||||
else:
|
||||
moving = true
|
||||
else:
|
||||
moving = false
|
||||
elif moving and event is InputEventMouseMotion:
|
||||
var vector = get_global_mouse_position()-get_parent().get_global_rect().position+OFFSET
|
||||
vector *= sign(vector.x)
|
||||
vector = distance*vector.normalized()
|
||||
rect_position = vector-OFFSET
|
||||
if event.control:
|
||||
get_parent().get_child(1-get_index()).rect_position = -vector-OFFSET
|
||||
|
||||
get_parent().update_tangents()
|
@ -1,139 +0,0 @@
|
||||
tool
|
||||
extends LineEdit
|
||||
|
||||
export var value : float = 0.5 setget set_value
|
||||
export var min_value : float = 0.0 setget set_min_value
|
||||
export var max_value : float = 1.0 setget set_max_value
|
||||
export var step : float = 0.0 setget set_step
|
||||
export var float_only : bool = false
|
||||
|
||||
var sliding : bool = false
|
||||
var start_position : float
|
||||
var last_position : float
|
||||
var start_value : float
|
||||
var modifiers : int
|
||||
var from_lower_bound : bool = false
|
||||
var from_upper_bound : bool = false
|
||||
|
||||
onready var slider = $Slider
|
||||
onready var cursor = $Slider/Cursor
|
||||
|
||||
signal value_changed(value)
|
||||
|
||||
func _ready() -> void:
|
||||
do_update()
|
||||
|
||||
func set_value(v) -> void:
|
||||
if v is float:
|
||||
value = v
|
||||
do_update()
|
||||
$Slider.visible = true
|
||||
elif v is String and !float_only:
|
||||
text = v
|
||||
$Slider.visible = false
|
||||
|
||||
func set_min_value(v : float) -> void:
|
||||
min_value = v
|
||||
do_update()
|
||||
|
||||
func set_max_value(v : float) -> void:
|
||||
max_value = v
|
||||
do_update()
|
||||
|
||||
func set_step(v : float) -> void:
|
||||
step = v
|
||||
do_update()
|
||||
|
||||
func do_update(update_text : bool = true) -> void:
|
||||
if update_text and $Slider.visible:
|
||||
text = str(value)
|
||||
if cursor != null:
|
||||
if max_value != min_value:
|
||||
cursor.rect_position.x = (clamp(value, min_value, max_value)-min_value)*(slider.rect_size.x-cursor.rect_size.x)/(max_value-min_value)
|
||||
else:
|
||||
cursor.rect_position.x = 0
|
||||
|
||||
func get_modifiers(event):
|
||||
var new_modifiers = 0
|
||||
if event.shift:
|
||||
new_modifiers |= 1
|
||||
if event.control:
|
||||
new_modifiers |= 2
|
||||
if event.alt:
|
||||
new_modifiers |= 4
|
||||
return new_modifiers
|
||||
|
||||
func _on_LineEdit_gui_input(event : InputEvent) -> void:
|
||||
if !$Slider.visible or !editable:
|
||||
return
|
||||
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
|
||||
if event.is_pressed():
|
||||
last_position = event.position.x
|
||||
start_position = last_position
|
||||
start_value = value
|
||||
sliding = true
|
||||
from_lower_bound = value <= min_value
|
||||
from_upper_bound = value >= max_value
|
||||
modifiers = get_modifiers(event)
|
||||
else:
|
||||
sliding = false
|
||||
elif sliding and event is InputEventMouseMotion and event.button_mask == BUTTON_MASK_LEFT:
|
||||
var new_modifiers = get_modifiers(event)
|
||||
if new_modifiers != modifiers:
|
||||
start_position = last_position
|
||||
start_value = value
|
||||
modifiers = new_modifiers
|
||||
else:
|
||||
last_position = event.position.x
|
||||
var delta : float = last_position-start_position
|
||||
var current_step = step
|
||||
if event.control:
|
||||
delta *= 0.2
|
||||
elif event.shift:
|
||||
delta *= 5.0
|
||||
if event.alt:
|
||||
current_step *= 0.01
|
||||
var v : float = start_value+sign(delta)*pow(abs(delta)*0.005, 2)*abs(max_value - min_value)
|
||||
if current_step != 0:
|
||||
v = min_value+floor((v - min_value)/current_step)*current_step
|
||||
if !from_lower_bound and v < min_value:
|
||||
v = min_value
|
||||
if !from_upper_bound and v > max_value:
|
||||
v = max_value
|
||||
set_value(v)
|
||||
select(0, 0)
|
||||
emit_signal("value_changed", value)
|
||||
release_focus()
|
||||
elif event is InputEventKey and !event.echo:
|
||||
match event.scancode:
|
||||
KEY_SHIFT, KEY_CONTROL, KEY_ALT:
|
||||
start_position = last_position
|
||||
start_value = value
|
||||
modifiers = get_modifiers(event)
|
||||
|
||||
func _on_LineEdit_text_changed(new_text : String) -> void:
|
||||
if new_text.is_valid_float():
|
||||
value = new_text.to_float()
|
||||
do_update(false)
|
||||
|
||||
func _on_LineEdit_text_entered(new_text : String, release = true) -> void:
|
||||
if new_text.is_valid_float():
|
||||
value = new_text.to_float()
|
||||
do_update()
|
||||
emit_signal("value_changed", value)
|
||||
$Slider.visible = true
|
||||
elif float_only:
|
||||
do_update()
|
||||
emit_signal("value_changed", value)
|
||||
$Slider.visible = true
|
||||
else:
|
||||
emit_signal("value_changed", new_text)
|
||||
$Slider.visible = false
|
||||
if release:
|
||||
release_focus()
|
||||
|
||||
func _on_FloatEdit_focus_entered():
|
||||
select_all()
|
||||
|
||||
func _on_LineEdit_focus_exited() -> void:
|
||||
_on_LineEdit_text_entered(text, false)
|
@ -1,46 +0,0 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/float_edit/float_edit.gd" type="Script" id=1]
|
||||
|
||||
[node name="FloatEdit" type="LineEdit"]
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = -1280.0
|
||||
margin_right = -1222.0
|
||||
margin_bottom = -696.0
|
||||
focus_mode = 1
|
||||
text = "0.5"
|
||||
max_length = 100
|
||||
context_menu_enabled = false
|
||||
caret_blink = true
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Slider" type="ColorRect" parent="."]
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = 2.0
|
||||
margin_top = -3.0
|
||||
margin_right = -2.0
|
||||
margin_bottom = -3.0
|
||||
rect_min_size = Vector2( 0, 2 )
|
||||
mouse_filter = 2
|
||||
color = Color( 0.501961, 0.501961, 0.501961, 1 )
|
||||
|
||||
[node name="Cursor" type="ColorRect" parent="Slider"]
|
||||
margin_right = 3.0
|
||||
margin_bottom = 1.0
|
||||
rect_min_size = Vector2( 3, 2 )
|
||||
mouse_filter = 2
|
||||
|
||||
[connection signal="focus_entered" from="." to="." method="_on_FloatEdit_focus_entered"]
|
||||
[connection signal="focus_exited" from="." to="." method="_on_LineEdit_focus_exited"]
|
||||
[connection signal="gui_input" from="." to="." method="_on_LineEdit_gui_input"]
|
||||
[connection signal="resized" from="." to="." method="do_update"]
|
||||
[connection signal="text_changed" from="." to="." method="_on_LineEdit_text_changed"]
|
||||
[connection signal="text_entered" from="." to="." method="_on_LineEdit_text_entered"]
|
||||
[connection signal="resized" from="Slider" to="." method="do_update"]
|
@ -1,288 +0,0 @@
|
||||
tool
|
||||
extends Control
|
||||
|
||||
class GradientCursor:
|
||||
extends Control
|
||||
|
||||
var color : Color
|
||||
var sliding : bool = false
|
||||
|
||||
onready var label : Label = get_parent().get_node("Value")
|
||||
|
||||
const WIDTH : int = 10
|
||||
|
||||
func _ready() -> void:
|
||||
rect_position = Vector2(0, 15)
|
||||
rect_size = Vector2(WIDTH, 15)
|
||||
|
||||
func _draw() -> void:
|
||||
# warning-ignore:integer_division
|
||||
var polygon : PoolVector2Array = PoolVector2Array([Vector2(0, 5), Vector2(WIDTH/2, 0), Vector2(WIDTH, 5), Vector2(WIDTH, 15), Vector2(0, 15), Vector2(0, 5)])
|
||||
var c = color
|
||||
c.a = 1.0
|
||||
draw_colored_polygon(polygon, c)
|
||||
draw_polyline(polygon, Color(0.0, 0.0, 0.0) if color.v > 0.5 else Color(1.0, 1.0, 1.0))
|
||||
|
||||
func _gui_input(ev) -> void:
|
||||
if ev is InputEventMouseButton:
|
||||
if ev.button_index == BUTTON_LEFT:
|
||||
if ev.doubleclick:
|
||||
get_parent().save_color_state()
|
||||
get_parent().select_color(self, ev.global_position)
|
||||
elif ev.pressed:
|
||||
get_parent().save_color_state()
|
||||
sliding = true
|
||||
label.visible = true
|
||||
label.text = "%.03f" % get_cursor_position()
|
||||
else:
|
||||
if sliding:
|
||||
get_parent().undo_redo_save_color_state()
|
||||
|
||||
sliding = false
|
||||
label.visible = false
|
||||
elif ev.button_index == BUTTON_RIGHT and get_parent().get_sorted_cursors().size() > 2:
|
||||
var parent = get_parent()
|
||||
parent.save_color_state()
|
||||
parent.remove_child(self)
|
||||
parent.update_value()
|
||||
parent.undo_redo_save_color_state()
|
||||
queue_free()
|
||||
elif ev is InputEventMouseMotion and (ev.button_mask & BUTTON_MASK_LEFT) != 0 and sliding:
|
||||
rect_position.x += get_local_mouse_position().x
|
||||
if ev.control:
|
||||
rect_position.x = round(get_cursor_position()*20.0)*0.05*(get_parent().rect_size.x - WIDTH)
|
||||
rect_position.x = min(max(0, rect_position.x), get_parent().rect_size.x-rect_size.x)
|
||||
get_parent().update_value()
|
||||
label.text = "%.03f" % get_cursor_position()
|
||||
|
||||
func get_cursor_position() -> float:
|
||||
return rect_position.x / (get_parent().rect_size.x - WIDTH)
|
||||
|
||||
func set_color(c) -> void:
|
||||
color = c
|
||||
get_parent().update_value()
|
||||
update()
|
||||
|
||||
static func sort(a, b) -> bool:
|
||||
return a.get_position() < b.get_position()
|
||||
|
||||
func can_drop_data(_position, data) -> bool:
|
||||
return typeof(data) == TYPE_COLOR
|
||||
|
||||
func drop_data(_position, data) -> void:
|
||||
set_color(data)
|
||||
|
||||
var graph_node = null
|
||||
var value = null setget set_value
|
||||
export var embedded : bool = true
|
||||
var _undo_redo : UndoRedo = null
|
||||
|
||||
signal updated(value)
|
||||
|
||||
var _saved_points : PoolRealArray = PoolRealArray()
|
||||
|
||||
func _init():
|
||||
connect("resized", self, "on_resized")
|
||||
|
||||
func ignore_changes(val):
|
||||
graph_node.ignore_changes(val)
|
||||
|
||||
func save_color_state():
|
||||
var p : PoolRealArray = value.points
|
||||
_saved_points.resize(0)
|
||||
|
||||
for v in p:
|
||||
_saved_points.push_back(v)
|
||||
|
||||
ignore_changes(true)
|
||||
|
||||
func undo_redo_save_color_state():
|
||||
var op : PoolRealArray
|
||||
var np : PoolRealArray
|
||||
|
||||
for v in _saved_points:
|
||||
op.push_back(v)
|
||||
|
||||
for v in value.get_points():
|
||||
np.push_back(v)
|
||||
|
||||
_undo_redo.create_action("MMGD: gradient colors changed")
|
||||
_undo_redo.add_do_method(value, "set_points", np)
|
||||
_undo_redo.add_undo_method(value, "set_points", op)
|
||||
_undo_redo.commit_action()
|
||||
|
||||
ignore_changes(false)
|
||||
|
||||
func set_undo_redo(ur : UndoRedo) -> void:
|
||||
_undo_redo = ur
|
||||
|
||||
#func get_gradient_from_data(data):
|
||||
# if typeof(data) == TYPE_ARRAY:
|
||||
# return data
|
||||
# elif typeof(data) == TYPE_DICTIONARY:
|
||||
# if data.has("parameters") and data.parameters.has("gradient"):
|
||||
# return data.parameters.gradient
|
||||
# if data.has("type") and data.type == "Gradient":
|
||||
# return data
|
||||
# return null
|
||||
|
||||
#func get_drag_data(_position : Vector2):
|
||||
# var data = 0#MMType.serialize_value(value)
|
||||
# var preview = ColorRect.new()
|
||||
# preview.rect_size = Vector2(64, 24)
|
||||
# preview.material = $Gradient.material
|
||||
# set_drag_preview(preview)
|
||||
# return data
|
||||
#
|
||||
#func can_drop_data(_position : Vector2, data) -> bool:
|
||||
# return get_gradient_from_data(data) != null
|
||||
#
|
||||
#func drop_data(_position : Vector2, data) -> void:
|
||||
# var gradient = get_gradient_from_data(data)
|
||||
# #if gradient != null:
|
||||
# #set_value(MMType.deserialize_value(gradient))
|
||||
|
||||
func set_value(v) -> void:
|
||||
value = v
|
||||
|
||||
update_preview()
|
||||
call_deferred("update_cursors")
|
||||
|
||||
func update_cursors() -> void:
|
||||
for c in get_children():
|
||||
if c is GradientCursor:
|
||||
remove_child(c)
|
||||
c.free()
|
||||
|
||||
var vs : int = value.get_point_count()
|
||||
|
||||
for i in range(vs):
|
||||
add_cursor(value.get_point_value(i) * (rect_size.x-GradientCursor.WIDTH), value.get_point_color(i))
|
||||
|
||||
$Interpolation.selected = value.interpolation_type
|
||||
|
||||
func update_value() -> void:
|
||||
value.clear()
|
||||
|
||||
var sc : Array = get_sorted_cursors()
|
||||
|
||||
var points : PoolRealArray = PoolRealArray()
|
||||
|
||||
for c in sc:
|
||||
|
||||
points.push_back(c.rect_position.x/(rect_size.x-GradientCursor.WIDTH))
|
||||
|
||||
var color : Color = c.color
|
||||
|
||||
points.push_back(color.r)
|
||||
points.push_back(color.g)
|
||||
points.push_back(color.b)
|
||||
points.push_back(color.a)
|
||||
|
||||
value.set_points(points)
|
||||
|
||||
update_preview()
|
||||
|
||||
func add_cursor(x, color) -> void:
|
||||
var cursor = GradientCursor.new()
|
||||
add_child(cursor)
|
||||
cursor.rect_position.x = x
|
||||
cursor.color = color
|
||||
|
||||
func _gui_input(ev) -> void:
|
||||
if ev is InputEventMouseButton and ev.button_index == 1 and ev.doubleclick:
|
||||
if ev.position.y > 15:
|
||||
var p = clamp(ev.position.x, 0, rect_size.x-GradientCursor.WIDTH)
|
||||
save_color_state()
|
||||
add_cursor(p, get_gradient_color(p))
|
||||
update_value()
|
||||
undo_redo_save_color_state()
|
||||
elif embedded:
|
||||
var popup = load("res://addons/mat_maker_gd/widgets/gradient_editor/gradient_popup.tscn").instance()
|
||||
add_child(popup)
|
||||
var popup_size = popup.rect_size
|
||||
popup.popup(Rect2(ev.global_position, Vector2(0, 0)))
|
||||
popup.set_global_position(ev.global_position-Vector2(popup_size.x / 2, popup_size.y))
|
||||
popup.init(value, graph_node, _undo_redo)
|
||||
popup.connect("updated", self, "set_value")
|
||||
popup.connect("popup_hide", popup, "queue_free")
|
||||
|
||||
# Showing a color picker popup to change a cursor's color
|
||||
|
||||
var active_cursor
|
||||
|
||||
func select_color(cursor, position) -> void:
|
||||
active_cursor = cursor
|
||||
var color_picker_popup = preload("res://addons/mat_maker_gd/widgets/color_picker_popup/color_picker_popup.tscn").instance()
|
||||
add_child(color_picker_popup)
|
||||
var color_picker = color_picker_popup.get_node("ColorPicker")
|
||||
color_picker.color = cursor.color
|
||||
color_picker.connect("color_changed", cursor, "set_color")
|
||||
color_picker_popup.rect_position = position
|
||||
color_picker_popup.connect("popup_hide", self, "undo_redo_save_color_state")
|
||||
color_picker_popup.connect("popup_hide", color_picker_popup, "queue_free")
|
||||
color_picker_popup.popup()
|
||||
|
||||
# Calculating a color from the gradient and generating the shader
|
||||
|
||||
func get_sorted_cursors() -> Array:
|
||||
var array = []
|
||||
for c in get_children():
|
||||
if c is GradientCursor:
|
||||
array.append(c)
|
||||
array.sort_custom(GradientCursor, "sort")
|
||||
return array
|
||||
|
||||
func generate_preview_image() -> void:
|
||||
var tex : ImageTexture = $Gradient.texture
|
||||
|
||||
if !tex:
|
||||
tex = ImageTexture.new()
|
||||
$Gradient.texture = tex
|
||||
|
||||
var img : Image = tex.get_data()
|
||||
|
||||
var w : float = $Gradient.rect_size.x
|
||||
var h : float = $Gradient.rect_size.y
|
||||
|
||||
if !img:
|
||||
img = Image.new()
|
||||
|
||||
if img.get_size().x != w || img.get_size().y != h:
|
||||
img.create(w, h, false, Image.FORMAT_RGBA8)
|
||||
|
||||
img.lock()
|
||||
|
||||
for i in range(w):
|
||||
var x : float = float(i) / float(w)
|
||||
var col : Color = value.get_gradient_color(x)
|
||||
|
||||
for j in range(h):
|
||||
img.set_pixel(i, j, col)
|
||||
|
||||
img.unlock()
|
||||
|
||||
tex.create_from_image(img, 0)
|
||||
|
||||
func get_gradient_color(x) -> Color:
|
||||
return value.get_gradient_color(x / (rect_size.x - GradientCursor.WIDTH))
|
||||
|
||||
func update_preview() -> void:
|
||||
call_deferred("generate_preview_image")
|
||||
|
||||
func _on_Interpolation_item_selected(ID) -> void:
|
||||
ignore_changes(true)
|
||||
|
||||
_undo_redo.create_action("MMGD: gradient interpolation_type changed")
|
||||
_undo_redo.add_do_method(value, "set_interpolation_type", ID)
|
||||
_undo_redo.add_undo_method(value, "set_interpolation_type", value.interpolation_type)
|
||||
_undo_redo.commit_action()
|
||||
|
||||
ignore_changes(false)
|
||||
|
||||
update_preview()
|
||||
|
||||
func on_resized() -> void:
|
||||
if value:
|
||||
update_preview()
|
||||
call_deferred("update_cursors")
|
@ -1,94 +0,0 @@
|
||||
[gd_scene load_steps=10 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/gradient_editor/gradient_editor.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/mat_maker_gd/icons/icons.tres" type="Texture" id=2]
|
||||
|
||||
[sub_resource type="Shader" id=1]
|
||||
code = "shader_type canvas_item;
|
||||
|
||||
void fragment() {
|
||||
COLOR = vec4(vec3(2.0*fract(0.5*(floor(0.12*FRAGCOORD.x)+floor(0.125*FRAGCOORD.y)))), 1.0);
|
||||
}"
|
||||
|
||||
[sub_resource type="ShaderMaterial" id=2]
|
||||
shader = SubResource( 1 )
|
||||
|
||||
[sub_resource type="Theme" id=5]
|
||||
|
||||
[sub_resource type="AtlasTexture" id=6]
|
||||
flags = 7
|
||||
atlas = ExtResource( 2 )
|
||||
region = Rect2( 96, 0, 32, 16 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=7]
|
||||
flags = 7
|
||||
atlas = ExtResource( 2 )
|
||||
region = Rect2( 64, 0, 32, 16 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=8]
|
||||
flags = 7
|
||||
atlas = ExtResource( 2 )
|
||||
region = Rect2( 64, 16, 32, 16 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=9]
|
||||
flags = 7
|
||||
atlas = ExtResource( 2 )
|
||||
region = Rect2( 96, 16, 32, 16 )
|
||||
|
||||
[node name="Control" type="Control"]
|
||||
margin_right = 120.0
|
||||
margin_bottom = 30.0
|
||||
rect_min_size = Vector2( 120, 32 )
|
||||
focus_mode = 1
|
||||
script = ExtResource( 1 )
|
||||
embedded = true
|
||||
|
||||
[node name="Background" type="ColorRect" parent="."]
|
||||
material = SubResource( 2 )
|
||||
anchor_right = 1.0
|
||||
margin_left = 4.0
|
||||
margin_right = -4.0
|
||||
margin_bottom = 15.0
|
||||
rect_min_size = Vector2( 112, 17 )
|
||||
mouse_filter = 2
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Gradient" type="TextureRect" parent="."]
|
||||
anchor_right = 1.0
|
||||
margin_left = 4.0
|
||||
margin_right = -4.0
|
||||
margin_bottom = 15.0
|
||||
rect_min_size = Vector2( 112, 17 )
|
||||
mouse_filter = 2
|
||||
theme = SubResource( 5 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Interpolation" type="OptionButton" parent="."]
|
||||
margin_left = 0.418457
|
||||
margin_top = -2.90374
|
||||
margin_right = 73.4185
|
||||
margin_bottom = 19.0963
|
||||
rect_scale = Vector2( 0.5, 0.5 )
|
||||
icon = SubResource( 6 )
|
||||
items = [ "", SubResource( 7 ), false, 0, null, "", SubResource( 6 ), false, 1, null, "", SubResource( 8 ), false, 2, null, "", SubResource( 9 ), false, 3, null ]
|
||||
selected = 1
|
||||
|
||||
[node name="Value" type="Label" parent="."]
|
||||
anchor_right = 1.0
|
||||
margin_top = -1.0
|
||||
margin_bottom = 14.0
|
||||
custom_colors/font_color = Color( 1, 1, 1, 1 )
|
||||
custom_colors/font_color_shadow = Color( 0, 0, 0, 1 )
|
||||
custom_constants/shadow_offset_x = 1
|
||||
custom_constants/shadow_offset_y = 1
|
||||
custom_constants/shadow_as_outline = 1
|
||||
align = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[connection signal="item_selected" from="Interpolation" to="." method="_on_Interpolation_item_selected"]
|
@ -1,15 +0,0 @@
|
||||
tool
|
||||
extends Popup
|
||||
|
||||
signal updated(value)
|
||||
|
||||
func init(value, graph_node, undo_redo) -> void:
|
||||
$Panel/Control.set_undo_redo(undo_redo)
|
||||
$Panel/Control.graph_node = graph_node
|
||||
$Panel/Control.set_value(value)
|
||||
|
||||
func _on_Control_updated(value) -> void:
|
||||
emit_signal("updated", value)
|
||||
|
||||
func _on_GradientPopup_popup_hide() -> void:
|
||||
queue_free()
|
@ -1,31 +0,0 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/gradient_editor/gradient_popup.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/gradient_editor/gradient_editor.tscn" type="PackedScene" id=2]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id=1]
|
||||
bg_color = Color( 0, 0, 0.25098, 0.752941 )
|
||||
|
||||
[node name="GradientPopup" type="Popup"]
|
||||
margin_right = 632.0
|
||||
margin_bottom = 49.0
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 0
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Panel" type="Panel" parent="."]
|
||||
margin_right = 632.0
|
||||
margin_bottom = 49.0
|
||||
custom_styles/panel = SubResource( 1 )
|
||||
|
||||
[node name="Control" parent="Panel" instance=ExtResource( 2 )]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = 10.0
|
||||
margin_top = 10.0
|
||||
margin_right = -10.0
|
||||
margin_bottom = -10.0
|
||||
embedded = false
|
||||
|
||||
[connection signal="popup_hide" from="." to="." method="_on_GradientPopup_popup_hide"]
|
||||
[connection signal="updated" from="Panel/Control" to="." method="_on_Control_updated"]
|
@ -1,46 +0,0 @@
|
||||
tool
|
||||
extends TextureButton
|
||||
|
||||
|
||||
var image_path = ""
|
||||
|
||||
|
||||
signal on_file_selected(f)
|
||||
|
||||
|
||||
func _ready():
|
||||
texture_normal = ImageTexture.new()
|
||||
|
||||
func do_set_image_path(path) -> void:
|
||||
if path == null:
|
||||
return
|
||||
image_path = path
|
||||
|
||||
texture_normal.load(image_path)
|
||||
|
||||
func set_image_path(path) -> void:
|
||||
do_set_image_path(path)
|
||||
emit_signal("on_file_selected", path)
|
||||
|
||||
func _on_ImagePicker_pressed():
|
||||
var dialog = preload("res://addons/mat_maker_gd/windows/file_dialog/file_dialog.tscn").instance()
|
||||
add_child(dialog)
|
||||
dialog.rect_min_size = Vector2(500, 500)
|
||||
dialog.access = FileDialog.ACCESS_FILESYSTEM
|
||||
dialog.mode = FileDialog.MODE_OPEN_FILE
|
||||
dialog.add_filter("*.bmp;BMP Image")
|
||||
dialog.add_filter("*.exr;EXR Image")
|
||||
dialog.add_filter("*.hdr;Radiance HDR Image")
|
||||
dialog.add_filter("*.jpg,*.jpeg;JPEG Image")
|
||||
dialog.add_filter("*.png;PNG Image")
|
||||
dialog.add_filter("*.svg;SVG Image")
|
||||
dialog.add_filter("*.tga;TGA Image")
|
||||
dialog.add_filter("*.webp;WebP Image")
|
||||
var files = dialog.select_files()
|
||||
while files is GDScriptFunctionState:
|
||||
files = yield(files, "completed")
|
||||
if files.size() > 0:
|
||||
set_image_path(files[0])
|
||||
|
||||
func on_drop_image_file(file_name : String) -> void:
|
||||
set_image_path(file_name)
|
@ -1,20 +0,0 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/image_picker_button/image_picker_button.gd" type="Script" id=2]
|
||||
|
||||
[sub_resource type="ImageTexture" id=1]
|
||||
|
||||
[node name="ImagePicker" type="TextureButton"]
|
||||
margin_right = 64.0
|
||||
margin_bottom = 64.0
|
||||
rect_min_size = Vector2( 64, 64 )
|
||||
rect_clip_content = true
|
||||
texture_normal = SubResource( 1 )
|
||||
expand = true
|
||||
stretch_mode = 5
|
||||
script = ExtResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[connection signal="pressed" from="." to="." method="_on_ImagePicker_pressed"]
|
@ -1,33 +0,0 @@
|
||||
tool
|
||||
extends Control
|
||||
|
||||
var moving : bool = false
|
||||
|
||||
const OFFSET : Vector2 = Vector2(3, 3)
|
||||
|
||||
signal moved(index)
|
||||
signal removed(index)
|
||||
|
||||
func _draw():
|
||||
# var current_theme : Theme = get_node("/root/MainWindow").theme
|
||||
# var color : Color = current_theme.get_color("font_color", "Label")
|
||||
|
||||
var color : Color = Color(1, 1, 1, 1)
|
||||
draw_rect(Rect2(0, 0, 7, 7), color)
|
||||
|
||||
func initialize(p : Vector2) -> void:
|
||||
rect_position = get_parent().transform_point(p) - OFFSET
|
||||
|
||||
func _on_ControlPoint_gui_input(event):
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == BUTTON_LEFT:
|
||||
if event.pressed:
|
||||
moving = true
|
||||
else:
|
||||
moving = false
|
||||
get_parent().update_controls()
|
||||
elif event.button_index == BUTTON_RIGHT and event.pressed:
|
||||
emit_signal("removed", get_index())
|
||||
elif moving and event is InputEventMouseMotion:
|
||||
rect_position += event.relative
|
||||
emit_signal("moved", get_index())
|
@ -1,15 +0,0 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/polygon_edit/control_point.gd" type="Script" id=1]
|
||||
|
||||
[node name="ControlPoint" type="Control"]
|
||||
margin_left = 56.9864
|
||||
margin_top = 33.8615
|
||||
margin_right = 63.9864
|
||||
margin_bottom = 40.8615
|
||||
rect_min_size = Vector2( 7, 7 )
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
[connection signal="gui_input" from="." to="." method="_on_ControlPoint_gui_input"]
|
@ -1,46 +0,0 @@
|
||||
tool
|
||||
extends WindowDialog
|
||||
|
||||
export var closed : bool = true setget set_closed
|
||||
var previous_points : PoolVector2Array
|
||||
var polygon
|
||||
|
||||
signal polygon_changed(polygon)
|
||||
|
||||
func set_closed(c : bool = true):
|
||||
closed = c
|
||||
window_title = "Edit polygon" if closed else "Edit polyline"
|
||||
$VBoxContainer/EditorContainer/PolygonEditor.set_closed(closed)
|
||||
|
||||
func _on_CurveDialog_popup_hide():
|
||||
# emit_signal("return_polygon", null)
|
||||
queue_free()
|
||||
pass
|
||||
|
||||
func _on_OK_pressed():
|
||||
emit_signal("polygon_changed", polygon)
|
||||
polygon.polygon_changed()
|
||||
|
||||
queue_free()
|
||||
|
||||
func _on_Cancel_pressed():
|
||||
polygon.set_points(previous_points)
|
||||
emit_signal("polygon_changed", polygon)
|
||||
|
||||
queue_free()
|
||||
|
||||
func edit_polygon(poly):
|
||||
polygon = poly
|
||||
previous_points = polygon.points
|
||||
|
||||
$VBoxContainer/EditorContainer/PolygonEditor.set_polygon(polygon)
|
||||
popup_centered()
|
||||
|
||||
#var result = yield(self, "return_polygon")
|
||||
|
||||
#queue_free()
|
||||
|
||||
#return result
|
||||
|
||||
func _on_PolygonEditor_value_changed(value):
|
||||
emit_signal("polygon_changed", value)
|
@ -1,81 +0,0 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/polygon_edit/polygon_editor.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/polygon_edit/polygon_dialog.gd" type="Script" id=2]
|
||||
|
||||
[node name="PolygonDialog" type="WindowDialog"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = 307.0
|
||||
margin_top = 151.0
|
||||
margin_right = -508.0
|
||||
margin_bottom = -70.0
|
||||
window_title = "Edit polygon"
|
||||
script = ExtResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = 5.0
|
||||
margin_top = 5.0
|
||||
margin_right = -5.0
|
||||
margin_bottom = -5.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="EditorContainer" type="MarginContainer" parent="VBoxContainer"]
|
||||
margin_right = 455.0
|
||||
margin_bottom = 457.0
|
||||
rect_clip_content = true
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
custom_constants/margin_right = 4
|
||||
custom_constants/margin_top = 4
|
||||
custom_constants/margin_left = 4
|
||||
custom_constants/margin_bottom = 4
|
||||
|
||||
[node name="PolygonEditor" parent="VBoxContainer/EditorContainer" instance=ExtResource( 1 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 4.0
|
||||
margin_top = 4.0
|
||||
margin_right = 451.0
|
||||
margin_bottom = 453.0
|
||||
|
||||
[node name="HSeparator" type="HSeparator" parent="VBoxContainer"]
|
||||
margin_top = 461.0
|
||||
margin_right = 455.0
|
||||
margin_bottom = 465.0
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
margin_top = 469.0
|
||||
margin_right = 455.0
|
||||
margin_bottom = 489.0
|
||||
|
||||
[node name="Control" type="Control" parent="VBoxContainer/HBoxContainer"]
|
||||
margin_right = 327.0
|
||||
margin_bottom = 20.0
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="OK" type="Button" parent="VBoxContainer/HBoxContainer"]
|
||||
margin_left = 331.0
|
||||
margin_right = 391.0
|
||||
margin_bottom = 20.0
|
||||
rect_min_size = Vector2( 60, 0 )
|
||||
text = "OK"
|
||||
|
||||
[node name="Cancel" type="Button" parent="VBoxContainer/HBoxContainer"]
|
||||
margin_left = 395.0
|
||||
margin_right = 455.0
|
||||
margin_bottom = 20.0
|
||||
rect_min_size = Vector2( 60, 0 )
|
||||
text = "Cancel"
|
||||
|
||||
[connection signal="popup_hide" from="." to="." method="_on_CurveDialog_popup_hide"]
|
||||
[connection signal="value_changed" from="VBoxContainer/EditorContainer/PolygonEditor" to="." method="_on_PolygonEditor_value_changed"]
|
||||
[connection signal="pressed" from="VBoxContainer/HBoxContainer/OK" to="." method="_on_OK_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Cancel" to="." method="_on_Cancel_pressed"]
|
@ -1,34 +0,0 @@
|
||||
tool
|
||||
extends Control
|
||||
|
||||
var MMPolygon = preload("res://addons/mat_maker_gd/nodes/bases/polygon_base.gd")
|
||||
|
||||
export var closed : bool = true setget set_closed
|
||||
var value = null setget set_value
|
||||
|
||||
signal updated(polygon)
|
||||
|
||||
func set_closed(c : bool = true):
|
||||
closed = c
|
||||
$PolygonView.set_closed(c)
|
||||
|
||||
func set_value(v) -> void:
|
||||
value = v
|
||||
$PolygonView.set_polygon(value)
|
||||
$PolygonView.update()
|
||||
|
||||
func _on_PolygonEdit_pressed():
|
||||
var dialog = preload("res://addons/mat_maker_gd/widgets/polygon_edit/polygon_dialog.tscn").instance()
|
||||
dialog.set_closed(closed)
|
||||
add_child(dialog)
|
||||
|
||||
dialog.connect("polygon_changed", self, "on_value_changed")
|
||||
|
||||
dialog.edit_polygon(value)
|
||||
|
||||
|
||||
|
||||
func on_value_changed(v) -> void:
|
||||
#set_value(v)
|
||||
emit_signal("updated", v)
|
||||
$PolygonView.update()
|
@ -1,26 +0,0 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/polygon_edit/polygon_edit.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/polygon_edit/polygon_view.tscn" type="PackedScene" id=2]
|
||||
|
||||
[node name="PolygonEdit" type="Button"]
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = -1280.0
|
||||
margin_right = -1248.0
|
||||
margin_bottom = -688.0
|
||||
rect_min_size = Vector2( 32, 32 )
|
||||
focus_mode = 1
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="PolygonView" parent="." instance=ExtResource( 2 )]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_right = 0.0
|
||||
margin_bottom = 0.0
|
||||
|
||||
[connection signal="pressed" from="." to="." method="_on_PolygonEdit_pressed"]
|
@ -1,57 +0,0 @@
|
||||
tool
|
||||
extends "res://addons/mat_maker_gd/widgets/polygon_edit/polygon_view.gd"
|
||||
|
||||
signal value_changed(value)
|
||||
|
||||
func _ready():
|
||||
update_controls()
|
||||
|
||||
func set_polygon(p) -> void:
|
||||
polygon = p
|
||||
update()
|
||||
update_controls()
|
||||
|
||||
func update_controls() -> void:
|
||||
for c in get_children():
|
||||
c.queue_free()
|
||||
|
||||
if !polygon:
|
||||
return
|
||||
|
||||
for i in polygon.points.size():
|
||||
var p = polygon.points[i]
|
||||
var control_point = preload("res://addons/mat_maker_gd/widgets/polygon_edit/control_point.tscn").instance()
|
||||
add_child(control_point)
|
||||
control_point.initialize(p)
|
||||
control_point.rect_position = transform_point(p)-control_point.OFFSET
|
||||
control_point.connect("moved", self, "_on_ControlPoint_moved")
|
||||
control_point.connect("removed", self, "_on_ControlPoint_removed")
|
||||
|
||||
emit_signal("value_changed", polygon)
|
||||
|
||||
func _on_ControlPoint_moved(index):
|
||||
var control_point = get_child(index)
|
||||
polygon.points[index] = reverse_transform_point(control_point.rect_position+control_point.OFFSET)
|
||||
|
||||
update()
|
||||
|
||||
emit_signal("value_changed", polygon)
|
||||
|
||||
func _on_ControlPoint_removed(index):
|
||||
if polygon.remove_point(index):
|
||||
update()
|
||||
update_controls()
|
||||
|
||||
func _on_PolygonEditor_gui_input(event):
|
||||
if !polygon:
|
||||
return
|
||||
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == BUTTON_LEFT and event.doubleclick:
|
||||
var new_point_position = reverse_transform_point(get_local_mouse_position())
|
||||
polygon.add_point(new_point_position.x, new_point_position.y, closed)
|
||||
update_controls()
|
||||
|
||||
func _on_resize() -> void:
|
||||
._on_resize()
|
||||
update_controls()
|
@ -1,14 +0,0 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/curve_view.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/polygon_edit/polygon_editor.gd" type="Script" id=2]
|
||||
|
||||
[node name="PolygonEditor" instance=ExtResource( 1 )]
|
||||
margin_left = 10.0
|
||||
margin_top = 10.0
|
||||
margin_right = -10.0
|
||||
margin_bottom = -10.0
|
||||
mouse_filter = 0
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[connection signal="gui_input" from="." to="." method="_on_PolygonEditor_gui_input"]
|
@ -1,58 +0,0 @@
|
||||
tool
|
||||
extends Control
|
||||
|
||||
var MMPolygon = preload("res://addons/mat_maker_gd/nodes/bases/polygon_base.gd")
|
||||
|
||||
#: MMPolygon
|
||||
var polygon
|
||||
|
||||
var draw_size : Vector2 = Vector2(1, 1)
|
||||
var draw_offset : Vector2 = Vector2(0, 0)
|
||||
var closed : bool = true
|
||||
|
||||
func set_closed(c : bool = true):
|
||||
closed = c
|
||||
update()
|
||||
|
||||
func _ready() -> void:
|
||||
# polygon = MMPolygon.new()
|
||||
connect("resized", self, "_on_resize")
|
||||
_on_resize()
|
||||
|
||||
func transform_point(p : Vector2) -> Vector2:
|
||||
return draw_offset+p*draw_size
|
||||
|
||||
func reverse_transform_point(p : Vector2) -> Vector2:
|
||||
return (p-draw_offset)/draw_size
|
||||
|
||||
func set_polygon(val):
|
||||
polygon = val
|
||||
|
||||
update()
|
||||
|
||||
func _draw():
|
||||
if !polygon:
|
||||
return
|
||||
|
||||
# var current_theme : Theme = get_node("/root/MainWindow").theme
|
||||
# var bg = current_theme.get_stylebox("panel", "Panel").bg_color
|
||||
# var fg = current_theme.get_color("font_color", "Label")
|
||||
# var axes_color : Color = bg.linear_interpolate(fg, 0.25)
|
||||
# var curve_color : Color = bg.linear_interpolate(fg, 0.75)
|
||||
|
||||
var axes_color : Color = Color(0.9, 0.9, 0.9, 1)
|
||||
var curve_color : Color = Color(1, 1, 1, 1)
|
||||
|
||||
draw_rect(Rect2(draw_offset, draw_size), axes_color, false)
|
||||
var tp : Vector2 = transform_point(polygon.points[polygon.points.size()-1 if closed else 0])
|
||||
|
||||
for p in polygon.points:
|
||||
var tnp = transform_point(p)
|
||||
draw_line(tp, tnp, curve_color)
|
||||
tp = tnp
|
||||
|
||||
func _on_resize() -> void:
|
||||
var ds : float = min(rect_size.x, rect_size.y)
|
||||
draw_size = Vector2(ds, ds)
|
||||
draw_offset = 0.5*(rect_size-draw_size)
|
||||
update()
|
@ -1,12 +0,0 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/widgets/polygon_edit/polygon_view.gd" type="Script" id=1]
|
||||
|
||||
[node name="PolygonView" type="Control"]
|
||||
margin_right = 64.0
|
||||
margin_bottom = 64.0
|
||||
mouse_filter = 2
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/icons/icons.svg" type="Texture" id=1]
|
||||
|
||||
[sub_resource type="AtlasTexture" id=1]
|
||||
flags = 4
|
||||
atlas = ExtResource( 1 )
|
||||
region = Rect2( 80, 80, 16, 16 )
|
||||
|
||||
[node name="FavButton" type="Button"]
|
||||
margin_right = 12.0
|
||||
margin_bottom = 20.0
|
||||
icon = SubResource( 1 )
|
||||
flat = true
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
tool
|
||||
extends FileDialog
|
||||
|
||||
|
||||
var left_panel = null
|
||||
var volume_option = null
|
||||
|
||||
|
||||
signal return_paths(path_list)
|
||||
|
||||
func _ready() -> void:
|
||||
var vbox = get_child(3)
|
||||
var hbox = HSplitContainer.new()
|
||||
add_child(hbox)
|
||||
remove_child(vbox)
|
||||
left_panel = preload("res://addons/mat_maker_gd/windows/file_dialog/left_panel.tscn").instance()
|
||||
hbox.add_child(left_panel)
|
||||
left_panel.connect("open_directory", self, "set_current_dir")
|
||||
hbox.add_child(vbox)
|
||||
vbox.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
var fav_button = preload("res://addons/mat_maker_gd/windows/file_dialog/fav_button.tscn").instance()
|
||||
vbox.get_child(0).add_child(fav_button)
|
||||
fav_button.connect("pressed", self, "add_favorite")
|
||||
if OS.get_name() == "Windows":
|
||||
volume_option = vbox.get_child(0).get_child(3)
|
||||
if ! volume_option is OptionButton:
|
||||
volume_option = null
|
||||
|
||||
|
||||
func get_full_current_dir() -> String:
|
||||
var prefix = ""
|
||||
if volume_option != null and volume_option.visible:
|
||||
prefix = volume_option.get_item_text(volume_option.selected)
|
||||
return prefix+get_current_dir()
|
||||
|
||||
func _on_FileDialog_file_selected(path) -> void:
|
||||
left_panel.add_recent(get_full_current_dir())
|
||||
emit_signal("return_paths", [ path ])
|
||||
|
||||
func _on_FileDialog_files_selected(paths) -> void:
|
||||
left_panel.add_recent(get_full_current_dir())
|
||||
emit_signal("return_paths", paths)
|
||||
|
||||
func _on_FileDialog_dir_selected(dir) -> void:
|
||||
emit_signal("return_paths", [ dir ])
|
||||
|
||||
func _on_FileDialog_popup_hide() -> void:
|
||||
emit_signal("return_paths", [ ])
|
||||
|
||||
func select_files() -> Array:
|
||||
popup_centered()
|
||||
var result = yield(self, "return_paths")
|
||||
queue_free()
|
||||
return result
|
||||
|
||||
func add_favorite():
|
||||
left_panel.add_favorite(get_full_current_dir())
|
@ -1,16 +0,0 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/windows/file_dialog/file_dialog.gd" type="Script" id=1]
|
||||
|
||||
[node name="FileDialog" type="FileDialog"]
|
||||
margin_right = 360.0
|
||||
margin_bottom = 130.0
|
||||
window_title = "Enregistrer un fichier"
|
||||
resizable = true
|
||||
show_hidden_files = true
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[connection signal="dir_selected" from="." to="." method="_on_FileDialog_dir_selected"]
|
||||
[connection signal="file_selected" from="." to="." method="_on_FileDialog_file_selected"]
|
||||
[connection signal="files_selected" from="." to="." method="_on_FileDialog_files_selected"]
|
||||
[connection signal="popup_hide" from="." to="." method="_on_FileDialog_popup_hide"]
|
@ -1,71 +0,0 @@
|
||||
tool
|
||||
extends VBoxContainer
|
||||
|
||||
var recents : Array = []
|
||||
var favorites : Array = []
|
||||
|
||||
signal open_directory(dirpath)
|
||||
|
||||
#func _ready():
|
||||
# if get_node("/root/MainWindow") != null:
|
||||
# var config_cache = get_node("/root/MainWindow").config_cache
|
||||
# if config_cache.has_section_key("file_dialog", "recents"):
|
||||
# var parse_result = JSON.parse(config_cache.get_value("file_dialog", "recents"))
|
||||
# if parse_result != null:
|
||||
# recents = parse_result.result
|
||||
# if config_cache.has_section_key("file_dialog", "favorites"):
|
||||
# var parse_result = JSON.parse(config_cache.get_value("file_dialog", "favorites"))
|
||||
# if parse_result != null:
|
||||
# favorites = parse_result.result
|
||||
# update_lists()
|
||||
|
||||
#func _exit_tree():
|
||||
# if get_node("/root/MainWindow") != null:
|
||||
# var config_cache = get_node("/root/MainWindow").config_cache
|
||||
# config_cache.set_value("file_dialog", "recents", JSON.print(recents))
|
||||
# config_cache.set_value("file_dialog", "favorites", JSON.print(favorites))
|
||||
|
||||
func add_recent(file_path : String):
|
||||
if recents.find(file_path) != -1:
|
||||
recents.erase(file_path)
|
||||
recents.push_front(file_path)
|
||||
update_lists()
|
||||
|
||||
func add_favorite(file_path : String):
|
||||
if favorites.find(file_path) == -1:
|
||||
favorites.push_back(file_path)
|
||||
update_lists()
|
||||
|
||||
func my_basename(s : String) -> String:
|
||||
var slash_pos : int = s.find_last("/")
|
||||
if slash_pos == -1 or slash_pos+1 == s.length():
|
||||
return s
|
||||
return s.right(slash_pos+1)
|
||||
|
||||
func update_lists():
|
||||
$FavList.clear()
|
||||
for d in favorites:
|
||||
$FavList.add_item(my_basename(d))
|
||||
$FavList.set_item_tooltip($FavList.get_item_count()-1, d)
|
||||
$RecentList.clear()
|
||||
for d in recents:
|
||||
$RecentList.add_item(my_basename(d))
|
||||
$RecentList.set_item_tooltip($RecentList.get_item_count()-1, d)
|
||||
|
||||
func _on_FavList_item_activated(index):
|
||||
emit_signal("open_directory", $FavList.get_item_tooltip(index))
|
||||
|
||||
func _on_RecentList_item_activated(index):
|
||||
emit_signal("open_directory", $RecentList.get_item_tooltip(index))
|
||||
|
||||
func _on_FavList_gui_input(event):
|
||||
if event is InputEventKey and event.pressed and event.scancode == KEY_DELETE:
|
||||
if ! $FavList.get_selected_items().empty():
|
||||
favorites.remove($FavList.get_selected_items()[0])
|
||||
update_lists()
|
||||
|
||||
func _on_RecentList_gui_input(event):
|
||||
if event is InputEventKey and event.pressed and event.scancode == KEY_DELETE:
|
||||
if ! $RecentList.get_selected_items().empty():
|
||||
recents.remove($RecentList.get_selected_items()[0])
|
||||
update_lists()
|
@ -1,48 +0,0 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/windows/file_dialog/left_panel.gd" type="Script" id=1]
|
||||
|
||||
[node name="LeftPanel" type="VBoxContainer"]
|
||||
margin_right = 40.0
|
||||
margin_bottom = 40.0
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="RecentLabel" type="Label" parent="."]
|
||||
margin_right = 100.0
|
||||
margin_bottom = 14.0
|
||||
text = "Recent"
|
||||
|
||||
[node name="RecentList" type="ItemList" parent="."]
|
||||
margin_top = 18.0
|
||||
margin_right = 100.0
|
||||
margin_bottom = 18.0
|
||||
rect_min_size = Vector2( 100, 0 )
|
||||
size_flags_vertical = 3
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="FavLabel" type="Label" parent="."]
|
||||
margin_top = 22.0
|
||||
margin_right = 100.0
|
||||
margin_bottom = 36.0
|
||||
text = "Favorite"
|
||||
|
||||
[node name="FavList" type="ItemList" parent="."]
|
||||
margin_top = 40.0
|
||||
margin_right = 100.0
|
||||
margin_bottom = 40.0
|
||||
rect_min_size = Vector2( 100, 0 )
|
||||
size_flags_vertical = 3
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[connection signal="gui_input" from="RecentList" to="." method="_on_RecentList_gui_input"]
|
||||
[connection signal="item_activated" from="RecentList" to="." method="_on_RecentList_item_activated"]
|
||||
[connection signal="gui_input" from="FavList" to="." method="_on_FavList_gui_input"]
|
||||
[connection signal="item_activated" from="FavList" to="." method="_on_FavList_item_activated"]
|
Loading…
Reference in New Issue
Block a user