context menu added

player can find food and eat it
This commit is contained in:
Nikolai Fesenko
2025-08-20 16:45:03 +02:00
parent 9bab0ff0f3
commit a0efc6b9b8
11 changed files with 131 additions and 15 deletions

47
Scripts/ContextMenu.gd Normal file
View File

@@ -0,0 +1,47 @@
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)