Skip to content

Commit

Permalink
fix: adds proper player selectable checking in click events; also pro…
Browse files Browse the repository at this point in the history
…perly orders hover_stack in ascending z_index order
  • Loading branch information
BHSDuncan committed Sep 13, 2022
1 parent 169a5b5 commit 7201f02
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
4 changes: 2 additions & 2 deletions addons/escoria-core/game/core-scripts/esc/commands/say.gd
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ func run(command_params: Array) -> int:
# Replace the names of any globals in "{ }" with their value
command_params[1] = escoria.globals_manager.replace_globals(command_params[1])

var player_character_global_id = escoria.main.current_scene.player.global_id \
var speaking_character_global_id = escoria.main.current_scene.player.global_id \
if command_params[0].to_upper() == CURRENT_PLAYER_KEYWORD \
else command_params[0]

escoria.dialog_player.say(
player_character_global_id,
speaking_character_global_id,
command_params[2],
command_params[1]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func _get_event_to_queue(
else:
escoria.logger.warn(
self,
"Invalid action on item" +
"Invalid action on item: " +
"Trying to run action %s on object %s, " %
[
action,
Expand Down
59 changes: 52 additions & 7 deletions addons/escoria-core/game/esc_inputs_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ func _on_mouse_exited_inventory_item() -> void:
#
# - item: The Escoria item hovered
func _on_mouse_entered_item(item: ESCItem) -> void:
if item as ESCPlayer and not (item as ESCPlayer).selectable:
escoria.logger.debug(
self,
"Ignoring mouse entering player %s: Player not selectable." % [item.global_id]
)
return

if not escoria.action_manager.is_object_actionable(item.global_id):
escoria.logger.debug(
self,
Expand All @@ -308,13 +315,8 @@ func _on_mouse_entered_item(item: ESCItem) -> void:
)
_clean_hover_stack()

if not hover_stack.empty():
if item.z_index < hover_stack.back().z_index:
hover_stack.insert(hover_stack.size() - 1, item)
else:
hover_stack.push_back(item)
else:
hover_stack.push_back(item)
hover_stack.push_back(item)
hover_stack.sort_custom(HoverStackSorter, "sort_ascending_z_index")

hotspot_focused = hover_stack.back().global_id
escoria.main.current_scene.game.element_focused(hotspot_focused)
Expand Down Expand Up @@ -347,6 +349,18 @@ 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 item as ESCPlayer and not (item as ESCPlayer).selectable:
escoria.logger.debug(
self,
"Ignoring left click on player %s: Player not selectable." % [item.global_id]
)

if not hover_stack.empty():
var next_item = hover_stack.pop_back()
_on_mouse_left_clicked_item(next_item, event)

return

if not escoria.action_manager.is_object_actionable(item.global_id):
escoria.logger.debug(
self,
Expand Down Expand Up @@ -381,6 +395,18 @@ func _on_mouse_left_double_clicked_item(
event: InputEvent
) -> void:
if input_mode == INPUT_ALL:
if item as ESCPlayer and not (item as ESCPlayer).selectable:
escoria.logger.debug(
self,
"Ignoring double-left click on player %s: Player not selectable." % [item.global_id]
)

if not hover_stack.empty():
var next_item = hover_stack.pop_back()
_on_mouse_left_double_clicked_item(next_item, event)

return

if not escoria.action_manager.is_object_actionable(item.global_id):
escoria.logger.debug(
self,
Expand Down Expand Up @@ -411,6 +437,18 @@ 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 item as ESCPlayer and not (item as ESCPlayer).selectable:
escoria.logger.debug(
self,
"Ignoring right click on player %s: Player not selectable." % [item.global_id]
)

if not hover_stack.empty():
var next_item = hover_stack.pop_back()
_on_mouse_right_clicked_item(next_item, event)

return

if not escoria.action_manager.is_object_actionable(item.global_id):
escoria.logger.debug(
self,
Expand Down Expand Up @@ -460,3 +498,10 @@ func _clean_hover_stack():
# - item: the item to remove from the hover stack
func _hover_stack_erase_item(item):
hover_stack.erase(item)


class HoverStackSorter:
static func sort_ascending_z_index(a, b):
if a.z_index < b.z_index:
return true
return false

0 comments on commit 7201f02

Please sign in to comment.