48 lines
1006 B
GDScript
48 lines
1006 B
GDScript
extends Panel
|
|
|
|
|
|
signal show_context_menu
|
|
signal hide_context_menu
|
|
|
|
|
|
func _ready() -> void:
|
|
Global.show_context_menu.connect(_on_show_menu)
|
|
Global.hide_context_menu.connect(_on_hide_menu)
|
|
|
|
func _on_show_menu():
|
|
if self.visible != true:
|
|
show_menu()
|
|
else:
|
|
Global.hide_context_menu.emit()
|
|
func _on_hide_menu():
|
|
hide_menu()
|
|
|
|
|
|
func show_menu():
|
|
Global.is_context_menu_active = true
|
|
self.position = get_viewport().get_mouse_position()
|
|
get_context_actions()
|
|
self.visible = true
|
|
func hide_menu():
|
|
Global.is_context_menu_active = false
|
|
self.visible = false
|
|
|
|
|
|
func get_context_actions():
|
|
var container = $ScrollContainer/VBoxContainer
|
|
remove_children(container)
|
|
var newButtons
|
|
print(Global.object_selected.name)
|
|
if Global.object_selected.name == "Person":
|
|
newButtons = PersonAction.get_context_buttons()
|
|
|
|
for button in newButtons:
|
|
container.add_child(button)
|
|
|
|
|
|
func remove_children(object: Node):
|
|
var children = object.get_children()
|
|
|
|
for child in children:
|
|
object.remove_child(child)
|