Added the image picker button from Material Maker. Also added image node.

This commit is contained in:
Relintai 2021-10-18 12:33:31 +02:00
parent e036935e4b
commit e04f17dac2
12 changed files with 427 additions and 17 deletions

View File

@ -43,6 +43,24 @@ func add_slot_texture_universal(property : MMNodeUniversalProperty) -> int:
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()
@ -443,7 +461,6 @@ func on_vector2_universal_spinbox_value_changed(val : float, slot_idx, spinbox_x
func on_slot_enum_item_selected(val : int, slot_idx : int) -> void:
_node.call(properties[slot_idx][4], val)
func on_universal_texture_changed(slot_idx : int) -> void:
var img : Image = properties[slot_idx][6].get_active_image()
@ -454,11 +471,24 @@ func on_universal_texture_changed(slot_idx : int) -> void:
else:
properties[slot_idx][5].texture = ImageTexture.new()
func on_universal_texture_changed_image_picker(slot_idx : int) -> void:
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()
func on_slot_line_edit_text_entered(text : String, slot_idx : int) -> void:
_node.call(properties[slot_idx][4], text)
func on_universal_color_changed(c : Color, slot_idx : int) -> void:
properties[slot_idx][6].set_default_value(c)
func on_universal_image_path_changed(f : String, slot_idx : int) -> void:
_node.call(properties[slot_idx][8], f)
func get_material_node() -> MMNode:
return _node

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/new_resource-test.png-cc7641e40ff847e5aad9a8930b582cdc.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/mat_maker_gd/new_resource-test.png"
dest_files=[ "res://.import/new_resource-test.png-cc7641e40ff847e5aad9a8930b582cdc.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=1
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=false
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

View File

@ -1,4 +1,4 @@
[gd_resource type="Resource" load_steps=25 format=2]
[gd_resource type="Resource" load_steps=31 format=2]
[ext_resource path="res://addons/mat_maker_gd/nodes/mm_material.gd" type="Script" id=1]
[ext_resource path="res://addons/mat_maker_gd/nodes/noise/perlin.gd" type="Script" id=2]
@ -8,6 +8,8 @@
[ext_resource path="res://addons/mat_maker_gd/nodes/other/output_image.gd" type="Script" id=6]
[ext_resource path="res://addons/mat_maker_gd/nodes/gradient/gradient.gd" type="Script" id=7]
[ext_resource path="res://addons/mat_maker_gd/nodes/gradient/radial_gradient.gd" type="Script" id=8]
[ext_resource path="res://addons/mat_maker_gd/nodes/uniform/uniform.gd" type="Script" id=9]
[ext_resource path="res://addons/mat_maker_gd/nodes/simple/image.gd" type="Script" id=10]
[sub_resource type="Resource" id=1]
script = ExtResource( 2 )
@ -41,15 +43,6 @@ default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=10]
script = ExtResource( 5 )
default_type = 5
default_int = 0
default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=4]
script = ExtResource( 5 )
default_type = 1
@ -58,7 +51,6 @@ default_float = 0.65
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
input_property = SubResource( 10 )
[sub_resource type="Resource" id=5]
script = ExtResource( 4 )
@ -69,7 +61,7 @@ sides = 11
radius = SubResource( 4 )
edge = SubResource( 3 )
[sub_resource type="Resource" id=16]
[sub_resource type="Resource" id=25]
script = ExtResource( 5 )
default_type = 5
default_int = 0
@ -80,8 +72,8 @@ default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=6]
script = ExtResource( 6 )
graph_position = Vector2( -20, -320 )
image = SubResource( 16 )
graph_position = Vector2( 100, -320 )
image = SubResource( 25 )
postfix = "-test"
[sub_resource type="Resource" id=9]
@ -93,6 +85,15 @@ default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=10]
script = ExtResource( 5 )
default_type = 5
default_int = 0
default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=11]
script = ExtResource( 5 )
default_type = 1
@ -123,7 +124,7 @@ default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=15]
script = ExtResource( 7 )
graph_position = Vector2( -300, 120 )
interpolation_type = 2
interpolation_type = 3
points = PoolRealArray( 0, 0.376471, 0.239216, 0.713726, 1, 0.254237, 0.484375, 0.198669, 0.198669, 1, 0.762712, 1, 1, 1, 1, 1, 0.263715, 0.585938, 0.100708, 1 )
image = SubResource( 14 )
repeat = 1.0
@ -146,7 +147,36 @@ points = PoolRealArray( 0, 0.121124, 0.574219, 0.19192, 1, 0.262712, 0.976562, 0
image = SubResource( 17 )
repeat = 1.0
[sub_resource type="Resource" id=20]
script = ExtResource( 5 )
default_type = 4
default_int = 0
default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0.443137, 0.74902, 0.4, 1 )
[sub_resource type="Resource" id=21]
script = ExtResource( 9 )
graph_position = Vector2( -100, -100 )
uniform = SubResource( 20 )
[sub_resource type="Resource" id=23]
script = ExtResource( 5 )
default_type = 5
default_int = 0
default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=24]
script = ExtResource( 10 )
graph_position = Vector2( -140, -220 )
image = SubResource( 23 )
image_path = "/home/relintai/Projects/broken_seals/game/icon.png"
[resource]
script = ExtResource( 1 )
image_size = Vector2( 128, 128 )
nodes = [ SubResource( 1 ), SubResource( 2 ), SubResource( 5 ), SubResource( 6 ), SubResource( 12 ), SubResource( 15 ), SubResource( 18 ) ]
nodes = [ SubResource( 1 ), SubResource( 2 ), SubResource( 5 ), SubResource( 6 ), SubResource( 12 ), SubResource( 15 ), SubResource( 18 ), SubResource( 21 ), SubResource( 24 ) ]

View File

@ -0,0 +1,41 @@
tool
extends MMNode
export(Resource) var image : Resource
export(String) var image_path : String
func _init_properties():
if !image:
image = MMNodeUniversalProperty.new()
image.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE
image.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE
register_output_property(image)
func _register_methods(mm_graph_node) -> void:
mm_graph_node.add_slot_image_path_universal(image, "get_image_path", "set_image_path")
#func _render(material) -> void:
# var img : Image = render_image(material)
#
# image.set_value(img)
func get_value_for(uv : Vector2, pseed : int) -> Color:
return image.get_value(uv)
func get_image_path() -> String:
return image_path
func set_image_path(val : String) -> void:
image_path = val
var img : Image = Image.new()
if image_path && image_path != "":
img.load(image_path)
image.set_value(img)
set_dirty(true)

View File

@ -0,0 +1,46 @@
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)

View File

@ -0,0 +1,20 @@
[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"]

View File

@ -0,0 +1,17 @@
[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
}

View File

@ -0,0 +1,57 @@
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())

View File

@ -0,0 +1,15 @@
[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
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"]

View File

@ -0,0 +1,71 @@
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()

View File

@ -0,0 +1,48 @@
[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"]