@@ -10,11 +10,6 @@ extends Control
1010const Constants = preload ("res://addons/block_code/ui/constants.gd" )
1111const BlockTreeUtil = preload ("res://addons/block_code/ui/block_tree_util.gd" )
1212
13- @onready var _icon_duplicate := EditorInterface .get_editor_theme ().get_icon ("Duplicate" , "EditorIcons" )
14- @onready var _icon_pin := EditorInterface .get_editor_theme ().get_icon ("Pin" , "EditorIcons" )
15- @onready var _icon_info := EditorInterface .get_editor_theme ().get_icon ("Info" , "EditorIcons" )
16- @onready var _icon_remove := EditorInterface .get_editor_theme ().get_icon ("Remove" , "EditorIcons" )
17-
1813signal drag_started (offset : Vector2 )
1914
2015## True to require that the mouse move outside of the component before
@@ -25,10 +20,6 @@ var _drag_start_position: Vector2 = Vector2.INF
2520var parent_block : Block
2621
2722
28- func _ready () -> void :
29- parent_block = BlockTreeUtil .get_parent_block (self )
30-
31-
3223func _gui_input (event : InputEvent ) -> void :
3324 # Watch for mouse clicks using _gui_input, so events are filtered based on
3425 # rules of the GUI system.
@@ -55,17 +46,20 @@ func _gui_input(event: InputEvent) -> void:
5546 # Accepts to avoid menu conflicts
5647 accept_event ()
5748
49+ if not parent_block :
50+ parent_block = BlockTreeUtil .get_parent_block (self )
51+
5852 # A new right-click menu with items
5953 var _context_menu := PopupMenu .new ()
60- _context_menu .add_icon_item (_icon_duplicate , "Duplicate" )
61- _context_menu .add_icon_item (_icon_info , "Summary" )
62- _context_menu .add_icon_item (_icon_pin , "Unpin" if parent_block .pinned else "Pin" )
54+ _context_menu .add_icon_item (EditorInterface . get_editor_theme (). get_icon ( "Duplicate" , "EditorIcons" ) , "Duplicate" )
55+ _context_menu .add_icon_item (EditorInterface . get_editor_theme (). get_icon ( "Info" , "EditorIcons" ) , "Summary" )
56+ _context_menu .add_icon_item (EditorInterface . get_editor_theme (). get_icon ( "Pin" , "EditorIcons" ) , "Unpin" if parent_block .pinned else "Pin" )
6357 _context_menu .add_separator ()
64- _context_menu .add_icon_item (_icon_remove , "Delete" )
58+ _context_menu .add_icon_item (EditorInterface . get_editor_theme (). get_icon ( "Remove" , "EditorIcons" ) , "Delete" )
6559 _context_menu .popup_hide .connect (_cleanup )
6660 _context_menu .id_pressed .connect (_menu_pressed .bind (_context_menu ))
6761
68- _context_menu .position = get_global_mouse_position ()
62+ _context_menu .position = DisplayServer . mouse_get_position ()
6963 add_child (_context_menu )
7064
7165 _context_menu .show ()
0 commit comments