Files
project-thor/Scripts/ContextMenu.gd
Nikolai Fesenko a0efc6b9b8 context menu added
player can find food and eat it
2025-08-20 16:45:03 +02:00

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)