Issue 320 (#396) - Mobile fixes

Co-authored-by: Dennis Ploeger <develop@dieploegers.de>
Co-authored-by: dploeger <dploeger@users.noreply.github.com>
This commit is contained in:
Dennis Ploeger
2021-09-23 08:32:08 +02:00
committed by GitHub
parent bb93dc1ef3
commit 60ea4d851b
82 changed files with 897 additions and 427 deletions

View File

@@ -59,6 +59,8 @@ func run(command_params: Array) -> int:
escoria.main.current_scene.global_id,
true
)
escoria.event_manager.interrupt_running_event()
if !command_params[1]:
escoria.main.scene_transition.transition_out()

View File

@@ -6,6 +6,9 @@ class_name ESCActionManager
# The current action was changed
signal action_changed
# Emitted, when an action has been completed
signal action_finished
# Current verb used
var current_action: String = "" setget set_current_action
@@ -109,6 +112,7 @@ func activate(
if event_returned[0] == ESCExecution.RC_OK:
escoria.action_manager\
.clear_current_action()
emit_signal("action_finished")
return event_returned[0]
else:
var errors = [
@@ -120,14 +124,14 @@ func activate(
]
if combine_with.node.combine_is_one_way:
errors.append(
"Reason: %s's item interaction " +\
"is one-way." % combine_with.global_id
("Reason: %s's item interaction " +\
"is one-way.") % combine_with.global_id
)
escoria.logger.report_warnings(
"ESCActionManager.activate: Invalid action",
errors
)
emit_signal("action_finished")
return ESCExecution.RC_ERROR
else:
escoria.logger.report_warnings(
@@ -140,13 +144,15 @@ func activate(
combine_with.global_id
]
]
)
)
emit_signal("action_finished")
return ESCExecution.RC_ERROR
else:
# We're missing a target here.
# Tell the Label to add a conjunction and wait for another
# click to add the target to p_param. Until then, return
current_tool = target
emit_signal("action_finished")
return ESCExecution.RC_OK
else:
escoria.logger.report_warnings(
@@ -175,6 +181,7 @@ func activate(
)
if event_returned[0] == ESCExecution.RC_OK:
escoria.action_manager.clear_current_action()
emit_signal("action_finished")
return event_returned[0]
else:
escoria.logger.report_warnings(
@@ -186,4 +193,5 @@ func activate(
]
]
)
emit_signal("action_finished")
return ESCExecution.RC_ERROR

View File

@@ -67,9 +67,6 @@ func _enter_tree():
shape.set_extents(size / 2)
area.shape_owner_add_shape(sid, shape)
# Handle inputs to the Area2D ourself
area.connect("input_event", self, "manage_input")
add_child(area)
# Disable mouse filter events and connect our own events to the ESC input
@@ -84,27 +81,30 @@ func _ready():
# Manage inputs reaching the Area2D and emit the events to the input manager
#
# #### Parameters
# - _viewport: (not used)
# - event: Event received
# - _shape_idx: (not used)
func manage_input(_viewport, event, _shape_idx) -> void:
func _input(event) -> void:
if not escoria.current_state == escoria.GAME_STATE.DEFAULT:
return
if event.is_action_pressed("switch_action_verb"):
if event.button_index == BUTTON_WHEEL_UP:
emit_signal("mouse_wheel_up")
elif event.button_index == BUTTON_WHEEL_DOWN:
emit_signal("mouse_wheel_down")
if event is InputEventMouseButton:
if event is InputEventMouseButton and event.is_pressed():
var p = get_global_mouse_position()
if event.doubleclick:
if event.button_index == BUTTON_LEFT:
emit_signal("double_left_click_on_bg", p)
var size
if get_texture():
size = get_texture().get_size()
else:
if event.is_pressed():
if event.button_index == BUTTON_LEFT:
emit_signal("left_click_on_bg", p)
if event.button_index == BUTTON_RIGHT:
emit_signal("right_click_on_bg", p)
size = rect_size
if Rect2(rect_position, size).has_point(p):
if event.doubleclick and event.button_index == BUTTON_LEFT:
emit_signal("double_left_click_on_bg", p)
elif event.button_index == BUTTON_LEFT:
emit_signal("left_click_on_bg", p)
elif event.button_index == BUTTON_RIGHT:
emit_signal("right_click_on_bg", p)
# Calculate the actual area taken by this background depending on its
# Texture or set size

View File

@@ -3,7 +3,6 @@
# "click on background" -> player walks to position
# "click on item" -> player walks to item then performs the action defined
# by current verb
class_name ESCController

View File

@@ -162,8 +162,6 @@ func _ready():
connect("mouse_entered", self, "_on_mouse_entered")
if not self.is_connected("mouse_exited", self, "_on_mouse_exited"):
connect("mouse_exited", self, "_on_mouse_exited")
if not self.is_connected("input_event", self, "manage_input"):
connect("input_event", self, "manage_input")
# Register and connect all elements to Escoria backoffice.
if not Engine.is_editor_hint():
@@ -265,6 +263,39 @@ func _ready():
_movable.last_scale = scale
_movable.update_terrain()
# Manage mouse button clicks on this item by sending out signals
#
# #### Parameters
#
# - event: Triggered event
func _input(event: InputEvent) -> void:
if not escoria.current_state == escoria.GAME_STATE.DEFAULT:
return
if event is InputEventMouseButton and event.is_pressed():
var p = get_global_mouse_position()
var mouse_in_shape: bool = false
var colliders = get_world_2d().direct_space_state.intersect_point(
p,
32,
[],
2147483647,
true,
true
)
for _owner in get_shape_owners():
for _shape_id in range(0, shape_owner_get_shape_count(_owner)):
for _collider in colliders:
if _collider.collider == self and\
_collider.shape == _shape_id:
mouse_in_shape = true
if mouse_in_shape:
if event.doubleclick and event.button_index == BUTTON_LEFT:
emit_signal("mouse_double_left_clicked_item", self, event)
elif event.button_index == BUTTON_LEFT:
emit_signal("mouse_left_clicked_item", self, event)
elif event.button_index == BUTTON_RIGHT:
emit_signal("mouse_right_clicked_item", self, event)
# Return the animation player node
func get_animation_player() -> Node:
@@ -291,9 +322,6 @@ func get_interact_position() -> Vector2:
var interact_position = null
for c in get_children():
if c is Position2D:
if c.get_owner() == self:
interact_position = global_position
continue
interact_position = c.global_position
if interact_position == null and collision != null:
@@ -302,31 +330,6 @@ func get_interact_position() -> Vector2:
return interact_position
# Manage mouse button clicks on this item by sending out signals
#
# #### Parameters
#
# - _viewport: not used
# - event: Triggered event
# - _shape_idx: not used
func manage_input(
_viewport: Viewport,
event: InputEvent,
_shape_idx: int
) -> void:
if event is InputEventMouseButton:
if event.doubleclick:
if event.button_index == BUTTON_LEFT:
emit_signal("mouse_double_left_clicked_item", self, event)
else:
if event.is_pressed():
if event.button_index == BUTTON_LEFT:
emit_signal("mouse_left_clicked_item", self, event)
elif event.button_index == BUTTON_RIGHT:
emit_signal("mouse_right_clicked_item", self, event)
# React to the mouse entering the item by emitting the respective signal
func _on_mouse_entered():
emit_signal("mouse_entered_item", self)