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

View File

@@ -52,10 +52,12 @@ size = Vector3(5.62061, 2.52063, 2.12427)
[sub_resource type="SphereShape3D" id="SphereShape3D_c1046"] [sub_resource type="SphereShape3D" id="SphereShape3D_c1046"]
radius = 0.870929 radius = 0.870929
[node name="DoubleBeds" type="Node3D" node_paths=PackedStringArray("meshInstance")] [node name="DoubleBeds" type="Node3D" node_paths=PackedStringArray("meshInstance", "ActionNode", "static_body")]
script = ExtResource("1_nn5da") script = ExtResource("1_nn5da")
meshInstance = NodePath("DoubleBeds") meshInstance = NodePath("DoubleBeds")
preview_shader = SubResource("ShaderMaterial_dn7et") preview_shader = SubResource("ShaderMaterial_dn7et")
ActionNode = NodePath("ActionNode")
static_body = NodePath("StaticBody3D")
[node name="DoubleBeds" type="MeshInstance3D" parent="."] [node name="DoubleBeds" type="MeshInstance3D" parent="."]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, -1.83435, -0.42751, 0) transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, -1.83435, -0.42751, 0)

View File

@@ -13,6 +13,7 @@ script = ExtResource("2_cemcp")
mesh = NodePath("Cube") mesh = NodePath("Cube")
[node name="StaticBody3D" type="StaticBody3D" parent="." index="0"] [node name="StaticBody3D" type="StaticBody3D" parent="." index="0"]
process_mode = 4
transform = Transform3D(1, -1.44862e-12, -1.09139e-11, -1.56369e-12, 1, 1.81899e-12, 7.27596e-12, 0, 1, 0, 0, 0) transform = Transform3D(1, -1.44862e-12, -1.09139e-11, -1.56369e-12, 1, 1.81899e-12, 7.27596e-12, 0, 1, 0, 0, 0)
[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" index="0"] [node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" index="0"]

View File

@@ -1,7 +1,8 @@
[gd_scene load_steps=3 format=3 uid="uid://cyaesj3qjb5um"] [gd_scene load_steps=4 format=3 uid="uid://cyaesj3qjb5um"]
[ext_resource type="Script" uid="uid://bqh6f4f4sc4ba" path="res://Scripts/ui/panel_build_select.gd" id="1_dew6i"] [ext_resource type="Script" uid="uid://bqh6f4f4sc4ba" path="res://Scripts/ui/panel_build_select.gd" id="1_dew6i"]
[ext_resource type="Script" uid="uid://3bsllk6udire" path="res://Scripts/button_select_build.gd" id="1_yp16r"] [ext_resource type="Script" uid="uid://3bsllk6udire" path="res://Scripts/button_select_build.gd" id="1_yp16r"]
[ext_resource type="Script" uid="uid://di0njko68ahky" path="res://Scripts/ContextMenu.gd" id="3_yve02"]
[node name="MainGameUi" type="Control"] [node name="MainGameUi" type="Control"]
layout_mode = 3 layout_mode = 3
@@ -83,6 +84,42 @@ text = "Shelf"
script = ExtResource("1_yp16r") script = ExtResource("1_yp16r")
id = 3 id = 3
[node name="Panel3" type="Panel" parent="."]
visible = false
clip_contents = true
layout_mode = 0
offset_right = 119.0
offset_bottom = 92.0
script = ExtResource("3_yve02")
[node name="ScrollContainer" type="ScrollContainer" parent="Panel3"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="VBoxContainer" type="VBoxContainer" parent="Panel3/ScrollContainer"]
layout_mode = 2
size_flags_horizontal = 3
[node name="Button" type="Button" parent="Panel3/ScrollContainer/VBoxContainer"]
layout_mode = 2
text = "Action #1"
[node name="Button2" type="Button" parent="Panel3/ScrollContainer/VBoxContainer"]
layout_mode = 2
text = "Action #2"
[node name="Button3" type="Button" parent="Panel3/ScrollContainer/VBoxContainer"]
layout_mode = 2
text = "Action #1"
[node name="Button4" type="Button" parent="Panel3/ScrollContainer/VBoxContainer"]
layout_mode = 2
text = "Action #1"
[connection signal="pressed" from="Panel2/HBoxContainer/ButtonCreateBed" to="Panel2/HBoxContainer/ButtonCreateBed" method="_on_pressed"] [connection signal="pressed" from="Panel2/HBoxContainer/ButtonCreateBed" to="Panel2/HBoxContainer/ButtonCreateBed" method="_on_pressed"]
[connection signal="pressed" from="Panel2/HBoxContainer/ButtonCreatePot" to="Panel2/HBoxContainer/ButtonCreatePot" method="_on_pressed"] [connection signal="pressed" from="Panel2/HBoxContainer/ButtonCreatePot" to="Panel2/HBoxContainer/ButtonCreatePot" method="_on_pressed"]
[connection signal="pressed" from="Panel2/HBoxContainer/ButtonCreatePot2" to="Panel2/HBoxContainer/ButtonCreatePot2" method="_on_pressed"] [connection signal="pressed" from="Panel2/HBoxContainer/ButtonCreatePot2" to="Panel2/HBoxContainer/ButtonCreatePot2" method="_on_pressed"]

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)

View File

@@ -0,0 +1 @@
uid://di0njko68ahky

View File

@@ -36,7 +36,7 @@ func _process(delta: float) -> void:
#print(self.position.dot(ownRigidBody.position)) #print(self.position.dot(ownRigidBody.position))
func _input(event: InputEvent) -> void: # zoom control func _input(event: InputEvent) -> void: # zoom control
if(event.is_action("camera_zoom")): if(event.is_action("camera_zoom") and !Global.is_context_menu_active):
if (event.as_text() == "Mouse Wheel Up"): if (event.as_text() == "Mouse Wheel Up"):
#self.position = self.position.lerp(Vector3.ZERO,global_delta * 5.0) #self.position = self.position.lerp(Vector3.ZERO,global_delta * 5.0)
zoom_pos += global_delta * 45.0 zoom_pos += global_delta * 45.0

View File

@@ -11,6 +11,9 @@ signal object_unselected_signal
signal object_over_mouse_selected_signal(object) signal object_over_mouse_selected_signal(object)
signal object_over_mouse_unselected_signal(object) signal object_over_mouse_unselected_signal(object)
signal show_context_menu
signal hide_context_menu
var is_context_menu_active: bool = false
var object_selected var object_selected
var object_over_mouse var object_over_mouse
@@ -27,27 +30,29 @@ func _ready() -> void:
func _input(event: InputEvent) -> void: func _input(event: InputEvent) -> void:
if event.is_action_released("mouse_click"): if event.is_action_released("mouse_click") and !is_context_menu_active:
if object_over_mouse != null: if object_over_mouse != null:
object_selected_signal.emit(object_over_mouse) object_selected_signal.emit(object_over_mouse)
if event.is_action_released("right_mouse_click"): else:
if object_selected != object_over_mouse:
object_unselected_signal.emit() object_unselected_signal.emit()
if event.is_action_released("right_mouse_click"):
show_context_menu.emit()
func _on_interact(person, object): func _on_interact(person, object):
object.start_action(person, object) object.start_action(person, object)
func _on_object_selected(object): func _on_object_selected(object):
if object_selected != null: if object_selected != null and object != object_selected:
object_unselected_signal.emit() object_unselected_signal.emit()
object_selected = object object_selected = object
object_selected.is_selected = true object_selected.is_selected = true
print(object_selected) print(object_selected)
func _on_object_unselected(): func _on_object_unselected():
object_selected.is_selected = false if object_selected != null:
object_selected.disable_outline() object_selected.is_selected = false
object_selected = null object_selected.disable_outline()
object_selected = null
func _on_mouse_object_selected(object): func _on_mouse_object_selected(object):
object_over_mouse = object object_over_mouse = object

View File

@@ -11,6 +11,9 @@ func set_person_target_item(person,item_name):
result.is_being_used = true result.is_being_used = true
person.target_item = result person.target_item = result
person.set_target(result.shelf_owner) person.set_target(result.shelf_owner)
return true
else:
return null

View File

@@ -18,7 +18,7 @@ func _ready() -> void:
func start_action(person, object): func start_action(person, object):
if person.target_action == "take": if person.target_action == "take" or person.target_action == "eat":
give_out(person) give_out(person)

View File

@@ -112,12 +112,11 @@ func drop_item():
func _on_item_received(): func _on_item_received():
if holdingItem != null: if holdingItem != null:
pass if target_action == "eat" and holdingItem.name == "food":
#holdingItem.use() holdingItem.use()
print("I ate it")
func _on_input_event(camera: Node, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) -> void:
pass
func _on_mouse_entered() -> void: func _on_mouse_entered() -> void:

View File

@@ -1,5 +1,26 @@
extends Node extends Node
func get_context_buttons():
var buttons = Array()
# go eat
var go_eat_button = Button.new()
go_eat_button.text = "Go Eat"
go_eat_button.pressed.connect(go_eat)
buttons.append(go_eat_button)
return buttons
func go_eat():
print("I will go eat")
print(Global.object_selected)
var selected_person = Global.object_selected
selected_person.target_action = "eat"
var result = ItemManager.set_person_target_item(selected_person, "food")
if result == null:
print("I cant find food")
else:
print("I found food")
Global.hide_context_menu.emit()
func sleep(person, object, action): func sleep(person, object, action):
person.action = action person.action = action