2019-10-21 23:58:14 +02:00
|
|
|
extends GraphNode
|
|
|
|
class_name MMGraphNodeBase
|
|
|
|
|
|
|
|
var generator : MMGenBase = null setget set_generator
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
connect("offset_changed", self, "_on_offset_changed")
|
2020-02-15 11:17:41 +01:00
|
|
|
connect("gui_input", self, "_on_gui_input")
|
2019-10-21 23:58:14 +02:00
|
|
|
|
2019-12-27 22:30:49 +01:00
|
|
|
func _exit_tree() -> void:
|
|
|
|
get_parent().call_deferred("check_last_selected")
|
|
|
|
|
2019-11-06 23:49:26 +01:00
|
|
|
func _draw() -> void:
|
2019-11-04 07:58:17 +01:00
|
|
|
if generator != null and generator.has_randomness():
|
2020-01-25 15:20:08 +01:00
|
|
|
var icon = preload("res://material_maker/icons/randomness_locked.tres") if generator.is_seed_locked() else preload("res://material_maker/icons/randomness_unlocked.tres")
|
2019-11-03 10:04:23 +01:00
|
|
|
draw_texture_rect(icon, Rect2(rect_size.x-48, 4, 16, 16), false)
|
|
|
|
|
2019-10-21 23:58:14 +02:00
|
|
|
func set_generator(g) -> void:
|
|
|
|
generator = g
|
|
|
|
|
|
|
|
func _on_offset_changed() -> void:
|
|
|
|
generator.set_position(offset)
|
2019-11-03 10:04:23 +01:00
|
|
|
|
2020-02-15 11:17:41 +01:00
|
|
|
func _input(event) -> void:
|
|
|
|
_on_gui_input(event)
|
|
|
|
|
2019-11-06 23:49:26 +01:00
|
|
|
func _on_gui_input(event) -> void:
|
2019-11-03 10:04:23 +01:00
|
|
|
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):
|
2019-11-04 07:58:17 +01:00
|
|
|
generator.toggle_lock_seed()
|
2019-11-03 10:04:23 +01:00
|
|
|
update()
|
2020-02-03 20:55:32 +01:00
|
|
|
get_parent().send_changed_signal()
|
2020-02-15 11:17:41 +01:00
|
|
|
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 ""
|