Skip to content

Commit

Permalink
Merge pull request #484 from BlacRyu/Node_preview_fixes
Browse files Browse the repository at this point in the history
Fixes issues where node preview does not toggle correctly
  • Loading branch information
RodZill4 authored Jul 12, 2022
2 parents a43416b + aef8483 commit 6cb376c
Showing 1 changed file with 47 additions and 5 deletions.
52 changes: 47 additions & 5 deletions material_maker/nodes/generic/generic.gd
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
extends MMGraphNodeBase
class_name MMGraphNodeGeneric


var controls = {}
var ignore_parameter_change = ""
var output_count = 0

var preview : ColorRect
var preview_timer : Timer = Timer.new()


func _ready() -> void:
add_to_group("updated_from_locale")

Expand Down Expand Up @@ -258,6 +260,7 @@ func restore_preview_widget() -> void:
func update_preview() -> void:
if generator == null or generator.preview == -1:
return
preview_disconnect()
preview_timer.start(0.2)

func do_update_preview() -> void:
Expand All @@ -271,6 +274,7 @@ func do_update_preview() -> void:
parent = parent.get_parent()
preview.rect_position = Vector2(18, 24)-pos
preview.rect_size = rect_size-Vector2(38, 28)
preview_connect()
preview.visible = true

func update_rendering_time(t : int) -> void:
Expand Down Expand Up @@ -512,24 +516,62 @@ func on_clicked_output(index : int, with_shift : bool) -> bool:
if ! with_shift:
if generator.preview == index:
generator.preview = -1
disconnect("mouse_entered", self, "on_mouse_entered")
disconnect("mouse_exited", self, "on_mouse_exited")
preview_disconnect()
else:
generator.preview = index
connect("mouse_entered", self, "on_mouse_entered")
connect("mouse_exited", self, "on_mouse_exited")
update_preview()
restore_preview_widget()
update()
return true
return false

func preview_connect_node(node : Control) -> void:
if node is Control and !node.is_connected("mouse_entered", self, "on_mouse_entered"):
if node is Popup:
node.connect("mouse_entered", self, "on_mouse_entered")
node.connect("popup_hide", self, "on_mouse_exited")
else:
node.connect("mouse_entered", self, "on_mouse_entered")
node.connect("mouse_exited", self, "on_mouse_exited")
for child in node.get_children():
preview_connect_node(child)

func preview_disconnect_node(node : Control) -> void:
if node is Control and node.is_connected("mouse_entered", self, "on_mouse_entered"):
if node is Popup:
node.disconnect("mouse_entered", self, "on_mouse_entered")
node.disconnect("popup_hide", self, "on_mouse_exited")
else:
node.disconnect("mouse_entered", self, "on_mouse_entered")
node.disconnect("mouse_exited", self, "on_mouse_exited")
for child in node.get_children():
preview_disconnect_node(child)

func preview_connect() -> void:
if !get_tree().is_connected("node_added", self, "on_node_added"):
get_tree().connect("node_added", self, "on_node_added")
preview_connect_node(self)

func preview_disconnect() -> void:
if get_tree().is_connected("node_added", self, "on_node_added"):
get_tree().disconnect("node_added", self, "on_node_added")
preview_disconnect_node(self)

func on_node_added(n : Node):
#print("Adding "+str(n)+", parent = "+str(n.get_parent()))
if n is Control and is_a_parent_of(n):
preview_connect_node(n)

func on_mouse_entered():
if !generator.minimized:
preview.visible = false

func on_mouse_exited():
if !generator.minimized and !get_global_rect().has_point(get_global_mouse_position()):
if !generator.minimized:
var preview_parent = preview.get_parent()
# Fake move of preview in hierarchy, so it's shown in front of whatever
# control that has been created recently
preview_parent.move_child(preview, preview_parent.get_child_count()-1)
preview.visible = true

func update_from_locale() -> void:
Expand Down

0 comments on commit 6cb376c

Please sign in to comment.