mirror of
https://github.com/Relintai/material-maker.git
synced 2025-01-25 18:59:18 +01:00
Prepared tooltips everywhere and minor fixes & optimizations
This commit is contained in:
parent
8d4eb23483
commit
fb3b9c88d6
@ -3,10 +3,13 @@ extends Node
|
|||||||
|
|
||||||
const STD_GENDEF_PATH = "res://addons/material_maker/nodes"
|
const STD_GENDEF_PATH = "res://addons/material_maker/nodes"
|
||||||
|
|
||||||
var generators = {}
|
var predefined_generators = {}
|
||||||
|
|
||||||
func _ready()-> void:
|
func _ready()-> void:
|
||||||
var gen_count = 0
|
update_predefined_generators()
|
||||||
|
|
||||||
|
func update_predefined_generators()-> void:
|
||||||
|
predefined_generators = {}
|
||||||
for path in [ STD_GENDEF_PATH, OS.get_executable_path().get_base_dir()+"/generators" ]:
|
for path in [ STD_GENDEF_PATH, OS.get_executable_path().get_base_dir()+"/generators" ]:
|
||||||
var dir = Directory.new()
|
var dir = Directory.new()
|
||||||
if dir.open(path) == OK:
|
if dir.open(path) == OK:
|
||||||
@ -16,14 +19,9 @@ func _ready()-> void:
|
|||||||
if !dir.current_is_dir() and file_name.get_extension() == "mmg":
|
if !dir.current_is_dir() and file_name.get_extension() == "mmg":
|
||||||
var file : File = File.new()
|
var file : File = File.new()
|
||||||
if file.open(path+"/"+file_name, File.READ) == OK:
|
if file.open(path+"/"+file_name, File.READ) == OK:
|
||||||
if !generators.has(file_name.get_basename()):
|
predefined_generators[file_name.get_basename()] = parse_json(file.get_as_text())
|
||||||
gen_count += 1
|
|
||||||
generators[file_name.get_basename()] = parse_json(file.get_as_text())
|
|
||||||
file.close()
|
file.close()
|
||||||
file_name = dir.get_next()
|
file_name = dir.get_next()
|
||||||
else:
|
|
||||||
print("An error occurred when trying to access the path.")
|
|
||||||
print(gen_count)
|
|
||||||
|
|
||||||
func generator_name_from_path(path : String) -> String:
|
func generator_name_from_path(path : String) -> String:
|
||||||
for p in [ STD_GENDEF_PATH, OS.get_executable_path().get_base_dir()+"/generators" ]:
|
for p in [ STD_GENDEF_PATH, OS.get_executable_path().get_base_dir()+"/generators" ]:
|
||||||
@ -85,9 +83,11 @@ func create_gen(data) -> MMGenBase:
|
|||||||
if types.has(data.type):
|
if types.has(data.type):
|
||||||
generator = types[data.type].new()
|
generator = types[data.type].new()
|
||||||
else:
|
else:
|
||||||
generator = create_gen(generators[data.type])
|
generator = create_gen(predefined_generators[data.type])
|
||||||
if generator == null:
|
if generator == null:
|
||||||
print("Cannot find description for "+data.type)
|
print("Cannot find description for "+data.type)
|
||||||
|
else:
|
||||||
|
generator.model = data.type
|
||||||
if generator != null:
|
if generator != null:
|
||||||
generator.name = data.type
|
generator.name = data.type
|
||||||
if generator == null:
|
if generator == null:
|
||||||
|
@ -32,8 +32,13 @@ func _ready() -> void:
|
|||||||
func _gui_input(event) -> void:
|
func _gui_input(event) -> void:
|
||||||
if event is InputEventKey and event.pressed:
|
if event is InputEventKey and event.pressed:
|
||||||
var scancode_with_modifiers = event.get_scancode_with_modifiers()
|
var scancode_with_modifiers = event.get_scancode_with_modifiers()
|
||||||
if scancode_with_modifiers == KEY_DELETE || scancode_with_modifiers == KEY_BACKSPACE:
|
if scancode_with_modifiers == KEY_DELETE or scancode_with_modifiers == KEY_BACKSPACE:
|
||||||
remove_selection()
|
remove_selection()
|
||||||
|
return
|
||||||
|
if event is InputEventMouseMotion and event.button_mask == 0:
|
||||||
|
for c in get_children():
|
||||||
|
if c is GraphNode and Rect2(c.rect_global_position, c.rect_size*c.get_global_transform().get_scale()).has_point(event.global_position):
|
||||||
|
hint_tooltip = c.get_slot_tooltip(c.get_global_transform().xform_inv(event.global_position))
|
||||||
|
|
||||||
# Misc. useful functions
|
# Misc. useful functions
|
||||||
func get_source(node, port) -> Dictionary:
|
func get_source(node, port) -> Dictionary:
|
||||||
|
@ -524,7 +524,10 @@ func update_preview_3d(previews : Array) -> void:
|
|||||||
for p in previews:
|
for p in previews:
|
||||||
gen_material.update_materials(p.get_materials())
|
gen_material.update_materials(p.get_materials())
|
||||||
|
|
||||||
|
var selected_node = null
|
||||||
func on_selected_node_change(node) -> void:
|
func on_selected_node_change(node) -> void:
|
||||||
|
if node != selected_node:
|
||||||
|
selected_node = node
|
||||||
preview_2d.setup_controls(node.generator if node != null else null)
|
preview_2d.setup_controls(node.generator if node != null else null)
|
||||||
update_preview_2d(node)
|
update_preview_2d(node)
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ var generator : MMGenBase = null setget set_generator
|
|||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
connect("offset_changed", self, "_on_offset_changed")
|
connect("offset_changed", self, "_on_offset_changed")
|
||||||
|
connect("gui_input", self, "_on_gui_input")
|
||||||
|
|
||||||
func _exit_tree() -> void:
|
func _exit_tree() -> void:
|
||||||
get_parent().call_deferred("check_last_selected")
|
get_parent().call_deferred("check_last_selected")
|
||||||
@ -13,11 +14,6 @@ func _draw() -> void:
|
|||||||
if generator != null and generator.has_randomness():
|
if generator != null and generator.has_randomness():
|
||||||
var icon = preload("res://material_maker/icons/randomness_locked.tres") if generator.is_seed_locked() else preload("res://material_maker/icons/randomness_unlocked.tres")
|
var icon = preload("res://material_maker/icons/randomness_locked.tres") if generator.is_seed_locked() else preload("res://material_maker/icons/randomness_unlocked.tres")
|
||||||
draw_texture_rect(icon, Rect2(rect_size.x-48, 4, 16, 16), false)
|
draw_texture_rect(icon, Rect2(rect_size.x-48, 4, 16, 16), false)
|
||||||
if !is_connected("gui_input", self, "_on_gui_input"):
|
|
||||||
connect("gui_input", self, "_on_gui_input")
|
|
||||||
else:
|
|
||||||
if is_connected("gui_input", self, "_on_gui_input"):
|
|
||||||
disconnect("gui_input", self, "_on_gui_input")
|
|
||||||
|
|
||||||
func set_generator(g) -> void:
|
func set_generator(g) -> void:
|
||||||
generator = g
|
generator = g
|
||||||
@ -25,8 +21,33 @@ func set_generator(g) -> void:
|
|||||||
func _on_offset_changed() -> void:
|
func _on_offset_changed() -> void:
|
||||||
generator.set_position(offset)
|
generator.set_position(offset)
|
||||||
|
|
||||||
|
func _input(event) -> void:
|
||||||
|
_on_gui_input(event)
|
||||||
|
|
||||||
func _on_gui_input(event) -> void:
|
func _on_gui_input(event) -> void:
|
||||||
if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_LEFT and Rect2(rect_size.x-48, 4, 16, 16).has_point(event.position):
|
if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_LEFT and Rect2(rect_size.x-48, 4, 16, 16).has_point(event.position):
|
||||||
generator.toggle_lock_seed()
|
generator.toggle_lock_seed()
|
||||||
update()
|
update()
|
||||||
get_parent().send_changed_signal()
|
get_parent().send_changed_signal()
|
||||||
|
elif event is InputEventMouseMotion:
|
||||||
|
var epos = event.position
|
||||||
|
if Rect2(0, 0, 16, 16).has_point(epos):
|
||||||
|
if generator.model != null:
|
||||||
|
hint_tooltip = generator.model
|
||||||
|
return
|
||||||
|
elif Rect2(rect_size.x-48, 4, 16, 16).has_point(epos) and generator.has_randomness():
|
||||||
|
if generator.is_seed_locked():
|
||||||
|
hint_tooltip = "Unlock the random seed, so it can be modified by moving the node"
|
||||||
|
else:
|
||||||
|
hint_tooltip = "Lock the random seed to its current value"
|
||||||
|
return
|
||||||
|
hint_tooltip = ""
|
||||||
|
|
||||||
|
func get_slot_tooltip(pos : Vector2):
|
||||||
|
for i in range(get_connection_input_count()):
|
||||||
|
if is_slot_enabled_left(i) and (get_connection_input_position(i)-pos).length() < 5:
|
||||||
|
return "input "+str(i)
|
||||||
|
for i in range(get_connection_output_count()):
|
||||||
|
if is_slot_enabled_right(i) and (get_connection_output_position(i)-pos).length() < 5:
|
||||||
|
return "output "+str(i)
|
||||||
|
return ""
|
||||||
|
@ -309,7 +309,7 @@ func load_generator() -> void:
|
|||||||
dialog.rect_min_size = Vector2(500, 500)
|
dialog.rect_min_size = Vector2(500, 500)
|
||||||
dialog.access = FileDialog.ACCESS_FILESYSTEM
|
dialog.access = FileDialog.ACCESS_FILESYSTEM
|
||||||
dialog.mode = FileDialog.MODE_OPEN_FILE
|
dialog.mode = FileDialog.MODE_OPEN_FILE
|
||||||
dialog.add_filter("*.mmg,*.mmn;Material Maker Generator")
|
dialog.add_filter("*.mmg;Material Maker Generator")
|
||||||
dialog.connect("file_selected", self, "do_load_generator")
|
dialog.connect("file_selected", self, "do_load_generator")
|
||||||
dialog.popup_centered()
|
dialog.popup_centered()
|
||||||
|
|
||||||
@ -350,6 +350,7 @@ func do_save_generator(file_name : String) -> void:
|
|||||||
data.node_position = { x=0, y=0 }
|
data.node_position = { x=0, y=0 }
|
||||||
file.store_string(JSON.print(data, "\t", true))
|
file.store_string(JSON.print(data, "\t", true))
|
||||||
file.close()
|
file.close()
|
||||||
|
mm_loader.update_predefined_generators()
|
||||||
|
|
||||||
func update_preview_buttons(index : int) -> void:
|
func update_preview_buttons(index : int) -> void:
|
||||||
for i in range(output_count):
|
for i in range(output_count):
|
||||||
|
@ -41,7 +41,7 @@ func find_control(gp) -> Dictionary:
|
|||||||
if c.get("controls") != null:
|
if c.get("controls") != null:
|
||||||
for w in c.controls:
|
for w in c.controls:
|
||||||
var widget = c.controls[w]
|
var widget = c.controls[w]
|
||||||
if widget != null and Rect2(widget.rect_global_position, widget.rect_size*widget.get_global_transform().get_scale()).has_point(gp):
|
if is_instance_valid(widget) and Rect2(widget.rect_global_position, widget.rect_size*widget.get_global_transform().get_scale()).has_point(gp):
|
||||||
return { node=c, widget=widget }
|
return { node=c, widget=widget }
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user