fix: blocks actions on inputs for non-interactive and/or non-active items/objects
This commit is contained in:
@@ -126,6 +126,7 @@ func do(action: int, params: Array = [], can_interrupt: bool = false) -> void:
|
||||
escoria.event_manager.interrupt()
|
||||
|
||||
var item = escoria.object_manager.get_object(params[0])
|
||||
|
||||
self.perform_inputevent_on_object(item, params[1])
|
||||
|
||||
ACTION.ITEM_RIGHT_CLICK:
|
||||
@@ -139,6 +140,7 @@ func do(action: int, params: Array = [], can_interrupt: bool = false) -> void:
|
||||
escoria.event_manager.interrupt()
|
||||
|
||||
var item = escoria.object_manager.get_object(params[0])
|
||||
|
||||
self.perform_inputevent_on_object(item, params[1], true)
|
||||
|
||||
ACTION.TRIGGER_IN:
|
||||
@@ -476,7 +478,7 @@ func perform_inputevent_on_object(
|
||||
|
||||
escoria.logger.info(
|
||||
self,
|
||||
"%s left-clicked with event %s." % [obj.global_id, event]
|
||||
"%s to perform event %s." % [obj.global_id, event]
|
||||
)
|
||||
|
||||
var event_flags = 0
|
||||
@@ -584,6 +586,19 @@ func perform_inputevent_on_object(
|
||||
)
|
||||
|
||||
|
||||
# Determines whether the object in question can be acted upon.
|
||||
#
|
||||
# #### Parameters
|
||||
#
|
||||
# - global_id: the global ID of the item to examine
|
||||
#
|
||||
# *Returns* True iff the item represented by global_id can be acted upon.
|
||||
func is_object_actionable(global_id: String) -> bool:
|
||||
var obj: ESCObject = escoria.object_manager.get_object(global_id) as ESCObject
|
||||
|
||||
return _is_object_actionable(obj)
|
||||
|
||||
|
||||
# Prepare the "obj" object for current_action: if required, set the object as
|
||||
# current tool.
|
||||
#
|
||||
@@ -698,3 +713,32 @@ func _walk_towards_object(
|
||||
walk_context.dont_interact_on_arrival = true
|
||||
|
||||
return context
|
||||
|
||||
|
||||
# Determines whether the object in question can be acted upon.
|
||||
#
|
||||
# #### Parameters
|
||||
#
|
||||
# - obj: the ESCObject to examine
|
||||
#
|
||||
# *Returns* True iff 'obj' can be acted upon.
|
||||
func _is_object_actionable(obj: ESCObject) -> bool:
|
||||
var object_is_actionable: bool = true
|
||||
|
||||
if not obj:
|
||||
return false
|
||||
|
||||
if not obj.active:
|
||||
escoria.logger.debug(
|
||||
self,
|
||||
"Item %s is not active." % obj.global_id
|
||||
)
|
||||
object_is_actionable = false
|
||||
elif not obj.interactive:
|
||||
escoria.logger.debug(
|
||||
self,
|
||||
"Item %s is not interactive." % obj.global_id
|
||||
)
|
||||
object_is_actionable = false
|
||||
|
||||
return object_is_actionable
|
||||
|
||||
@@ -339,6 +339,13 @@ func _on_mouse_exited_item(item: ESCItem) -> void:
|
||||
# - event: The input event from the click
|
||||
func _on_mouse_left_clicked_item(item: ESCItem, event: InputEvent) -> void:
|
||||
if input_mode == INPUT_ALL:
|
||||
if not escoria.action_manager.is_object_actionable(item.global_id):
|
||||
escoria.logger.debug(
|
||||
self,
|
||||
"Ignoring left click on %s with event %s." % [item.global_id, event]
|
||||
)
|
||||
return
|
||||
|
||||
if hover_stack.empty() or hover_stack.back() == item:
|
||||
escoria.logger.info(
|
||||
self,
|
||||
@@ -362,6 +369,13 @@ func _on_mouse_left_double_clicked_item(
|
||||
event: InputEvent
|
||||
) -> void:
|
||||
if input_mode == INPUT_ALL:
|
||||
if not escoria.action_manager.is_object_actionable(item.global_id):
|
||||
escoria.logger.debug(
|
||||
self,
|
||||
"Ignoring double-left click on %s with event %s." % [item.global_id, event]
|
||||
)
|
||||
return
|
||||
|
||||
escoria.logger.info(
|
||||
self,
|
||||
"Item %s left double clicked with event %s." % [item.global_id, event]
|
||||
@@ -381,6 +395,13 @@ func _on_mouse_left_double_clicked_item(
|
||||
# - event: The input event from the click
|
||||
func _on_mouse_right_clicked_item(item: ESCItem, event: InputEvent) -> void:
|
||||
if input_mode == INPUT_ALL:
|
||||
if not escoria.action_manager.is_object_actionable(item.global_id):
|
||||
escoria.logger.debug(
|
||||
self,
|
||||
"Ignoring right click on %s with event %s." % [item.global_id, event]
|
||||
)
|
||||
return
|
||||
|
||||
escoria.logger.info(
|
||||
self,
|
||||
"Item %s right clicked with event %s." % [item.global_id, event]
|
||||
|
||||
Reference in New Issue
Block a user