context menu added
player can find food and eat it
This commit is contained in:
47
Scripts/ContextMenu.gd
Normal file
47
Scripts/ContextMenu.gd
Normal 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)
|
||||
1
Scripts/ContextMenu.gd.uid
Normal file
1
Scripts/ContextMenu.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://di0njko68ahky
|
||||
@@ -36,7 +36,7 @@ func _process(delta: float) -> void:
|
||||
#print(self.position.dot(ownRigidBody.position))
|
||||
|
||||
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"):
|
||||
#self.position = self.position.lerp(Vector3.ZERO,global_delta * 5.0)
|
||||
zoom_pos += global_delta * 45.0
|
||||
|
||||
@@ -11,6 +11,9 @@ signal object_unselected_signal
|
||||
signal object_over_mouse_selected_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_over_mouse
|
||||
@@ -27,27 +30,29 @@ func _ready() -> 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:
|
||||
object_selected_signal.emit(object_over_mouse)
|
||||
if event.is_action_released("right_mouse_click"):
|
||||
if object_selected != object_over_mouse:
|
||||
else:
|
||||
object_unselected_signal.emit()
|
||||
if event.is_action_released("right_mouse_click"):
|
||||
show_context_menu.emit()
|
||||
|
||||
func _on_interact(person, object):
|
||||
object.start_action(person, object)
|
||||
|
||||
|
||||
func _on_object_selected(object):
|
||||
if object_selected != null:
|
||||
if object_selected != null and object != object_selected:
|
||||
object_unselected_signal.emit()
|
||||
object_selected = object
|
||||
object_selected.is_selected = true
|
||||
print(object_selected)
|
||||
func _on_object_unselected():
|
||||
object_selected.is_selected = false
|
||||
object_selected.disable_outline()
|
||||
object_selected = null
|
||||
if object_selected != null:
|
||||
object_selected.is_selected = false
|
||||
object_selected.disable_outline()
|
||||
object_selected = null
|
||||
|
||||
func _on_mouse_object_selected(object):
|
||||
object_over_mouse = object
|
||||
|
||||
@@ -11,6 +11,9 @@ func set_person_target_item(person,item_name):
|
||||
result.is_being_used = true
|
||||
person.target_item = result
|
||||
person.set_target(result.shelf_owner)
|
||||
return true
|
||||
else:
|
||||
return null
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ func _ready() -> void:
|
||||
|
||||
|
||||
func start_action(person, object):
|
||||
if person.target_action == "take":
|
||||
if person.target_action == "take" or person.target_action == "eat":
|
||||
give_out(person)
|
||||
|
||||
|
||||
|
||||
@@ -112,12 +112,11 @@ func drop_item():
|
||||
|
||||
func _on_item_received():
|
||||
if holdingItem != null:
|
||||
pass
|
||||
#holdingItem.use()
|
||||
if target_action == "eat" and holdingItem.name == "food":
|
||||
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:
|
||||
|
||||
@@ -1,6 +1,27 @@
|
||||
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):
|
||||
person.action = action
|
||||
person.timer.wait_time = 2.0
|
||||
|
||||
Reference in New Issue
Block a user