Fix when ESCPlayer is not selectable or interactive manage click through

This commit is contained in:
Julian Murgia
2022-11-21 13:58:27 +01:00
parent 23b5de6ac2
commit a131efcfc2
21 changed files with 958 additions and 363 deletions

View File

@@ -100,7 +100,17 @@ func run(command_params: Array) -> int:
"[%s]: No dialog player was registered and the say command was encountered."
% get_command_name()
)
escoria.current_state = escoria.GAME_STATE.DEFAULT
return ESCExecution.RC_ERROR
if not escoria.main.current_scene.player:
escoria.logger.warn(
self,
"[%s]: No player item in the current scene was registered and the say command was encountered."
% get_command_name()
)
escoria.current_state = escoria.GAME_STATE.DEFAULT
return ESCExecution.RC_CANCEL
# Replace the names of any globals in "{ }" with their value
command_params[1] = escoria.globals_manager.replace_globals(command_params[1])

View File

@@ -748,13 +748,13 @@ func _is_object_actionable(obj: ESCObject) -> bool:
return false
if not obj.active:
escoria.logger.debug(
escoria.logger.trace(
self,
"Item %s is not active." % obj.global_id
)
object_is_actionable = false
elif not obj.interactive:
escoria.logger.debug(
escoria.logger.trace(
self,
"Item %s is not interactive." % obj.global_id
)

View File

@@ -89,7 +89,7 @@ func change_scene(room_path: String, enable_automatic_transitions: bool) -> void
if escoria.dialog_player:
escoria.dialog_player.interrupt()
escoria.inputs_manager.clear_stack()
escoria.inputs_manager.hover_stack_clear()
# Check if game scene was loaded
if not escoria.game_scene:

View File

@@ -97,6 +97,9 @@ func _get_interactive() -> bool:
func _set_interactive(value: bool):
if "is_interactive" in self.node:
self.node.is_interactive = value
if not value:
escoria.game_scene.clear_tooltip()
escoria.inputs_manager.on_item_non_interactive(self.node)
# Return the data of the object to be inserted in a savegame file.

View File

@@ -111,6 +111,12 @@ func _draw():
draw_rect(mouse_limits, ColorN("red"), false, 10.0)
# Clears the tooltip content (if an ESCTooltip node exists in UI)
func clear_tooltip():
if tooltip_node != null:
(tooltip_node as ESCTooltip).clear()
# Sets up and performs default walking action
#
# #### Parameters

View File

@@ -188,8 +188,8 @@ func _ready():
validate_animations(animations)
if not self.is_connected("mouse_entered", self, "_on_mouse_entered"):
connect("mouse_entered", self, "_on_mouse_entered")
if not self.is_connected("input_event", self, "_on_input_event"):
connect("input_event", self, "_on_input_event")
if not self.is_connected("mouse_exited", self, "_on_mouse_exited"):
connect("mouse_exited", self, "_on_mouse_exited")
@@ -294,6 +294,47 @@ func _ready():
_movable.last_scale = scale
_movable.update_terrain()
# Mouse exited happens on any item that mouse cursor exited, even those UNDER
# the top level of overlapping stack.
func _on_mouse_exited():
if escoria.inputs_manager.hover_stack.has(self):
escoria.inputs_manager.hover_stack_erase_item(self)
escoria.inputs_manager.unset_hovered_node(self)
class HoverStackSorter:
static func sort_ascending_z_index(a, b):
if a.z_index < b.z_index:
return true
return false
# Manage input events on the item
#
# #### Parameters
#
# - _viewport: the viewport node the event entered
# - event: the input event
# - _shape_idx is the child index of the clicked Shape2D.
func _on_input_event(_viewport: Object, event: InputEvent, _shape_idx: int):
if event is InputEventMouseMotion:
var physics2d_dss: Physics2DDirectSpaceState = get_world_2d().direct_space_state
var colliding: Array = physics2d_dss.intersect_point(event.global_position, 32, [], 0x7FFFFFFF, true, true)
var colliding_nodes = []
for c in colliding:
if c.collider.get("global_id") \
and escoria.action_manager.is_object_actionable(c.collider.global_id):
colliding_nodes.push_back(c.collider)
if colliding_nodes.empty():
return
colliding_nodes.sort_custom(HoverStackSorter, "sort_ascending_z_index")
escoria.inputs_manager.hover_stack_clear()
escoria.inputs_manager.hover_stack_add_items(colliding_nodes)
escoria.inputs_manager.set_hovered_node(colliding_nodes.back())
# Manage mouse button clicks on this item by sending out signals
#
# #### Parameters
@@ -334,7 +375,7 @@ func _unhandled_input(input_event: InputEvent) -> void:
)
return
var p = get_global_mouse_position()
if _is_in_shape(p):
if _is_in_shape(p) and escoria.action_manager.is_object_actionable(global_id):
if event.doubleclick and event.button_index == BUTTON_LEFT:
emit_signal("mouse_double_left_clicked_item", self, event)
get_tree().set_input_as_handled()
@@ -472,12 +513,13 @@ func get_interact_position() -> Vector2:
# React to the mouse entering the item by emitting the respective signal
func _on_mouse_entered():
emit_signal("mouse_entered_item", self)
func mouse_entered():
if escoria.action_manager.is_object_actionable(global_id):
emit_signal("mouse_entered_item", self)
# React to the mouse exiting the item by emitting the respective signal
func _on_mouse_exited():
func mouse_exited():
emit_signal("mouse_exited_item", self)

View File

@@ -22,5 +22,3 @@ func _ready():
._ready()
else:
tooltip_name = ""
if is_connected("input_event", self, "manage_input"):
disconnect("input_event", self, "manage_input")