Skip to content

Commit

Permalink
feat: Several fixes and optimizations
Browse files Browse the repository at this point in the history
This fixes another error message of godot-escoria/escoria-issues#64
This optimizes how UI and dialog managers register themselves with Escoria
This fixes another "character is at position, but action still isn't carried out"
This fixes click bubbling down to multiple items triggering different actions
This removes the "tooltip follows focus" setting because it solemly was a simplemouse feature
This optimizes the registering of settings
  • Loading branch information
dploeger committed Nov 26, 2021
1 parent 09446c7 commit bcfc5e7
Show file tree
Hide file tree
Showing 12 changed files with 377 additions and 292 deletions.
4 changes: 2 additions & 2 deletions addons/escoria-core/game/core-scripts/esc_animation_player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ func stop():
# - name: The animation name to play
# - backwards: Play backwards
func play(name: String, backwards: bool = false):
if _is_animation_player:
if _is_animation_player and _animation_player.current_animation != "":
_animation_player.seek(0)
else:
elif not _is_animation_player:
_animated_sprite.frame = 0
_current_animation = name
if backwards and _is_animation_player:
Expand Down
2 changes: 1 addition & 1 deletion addons/escoria-core/game/core-scripts/esc_controller.gd
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func perform_inputevent_on_object(
var player_global_pos = escoria.main.current_scene.player.global_position
var clicked_position = event.position

if not player_global_pos == destination_position:
if not player_global_pos.is_equal_approx(destination_position):
dont_interact = true

# If no interaction should happen after player has arrived, leave
Expand Down
28 changes: 0 additions & 28 deletions addons/escoria-core/game/core-scripts/esc_game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -256,34 +256,6 @@ func show_ui():
pass


# Function is called if Project setting escoria/ui/tooltip_follows_mouse = true
#
# #### Parameters
#
# - p_position: Position of the mouse
func update_tooltip_following_mouse_position(p_position: Vector2):
var corrected_position = p_position

# clamp TOP
if tooltip_node.tooltip_distance_to_edge_top(p_position) <= mouse_tooltip_margin:
corrected_position.y = mouse_tooltip_margin

# clamp BOTTOM
if tooltip_node.tooltip_distance_to_edge_bottom(p_position + tooltip_node.rect_size) <= mouse_tooltip_margin:
corrected_position.y = escoria.game_size.y - mouse_tooltip_margin - tooltip_node.rect_size.y

# clamp LEFT
if tooltip_node.tooltip_distance_to_edge_left(p_position - tooltip_node.rect_size/2) <= mouse_tooltip_margin:
corrected_position.x = mouse_tooltip_margin

# clamp RIGHT
if tooltip_node.tooltip_distance_to_edge_right(p_position + tooltip_node.rect_size/2) <= mouse_tooltip_margin:
corrected_position.x = escoria.game_size.x - mouse_tooltip_margin - tooltip_node.rect_size.x

tooltip_node.anchor_right = 0.2
tooltip_node.rect_position = corrected_position + tooltip_node.offset_from_cursor


# Set the Editor debug mode
func _set_editor_debug_mode(p_editor_debug_mode: int) -> void:
editor_debug_mode = p_editor_debug_mode
Expand Down
3 changes: 3 additions & 0 deletions addons/escoria-core/game/core-scripts/esc_item.gd
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,13 @@ func _unhandled_input(event: InputEvent) -> void:
if mouse_in_shape:
if event.doubleclick and event.button_index == BUTTON_LEFT:
emit_signal("mouse_double_left_clicked_item", self, event)
get_tree().set_input_as_handled()
elif event.button_index == BUTTON_LEFT:
emit_signal("mouse_left_clicked_item", self, event)
get_tree().set_input_as_handled()
elif event.button_index == BUTTON_RIGHT:
emit_signal("mouse_right_clicked_item", self, event)
get_tree().set_input_as_handled()


# Return the animation player node
Expand Down
111 changes: 105 additions & 6 deletions addons/escoria-core/game/escoria.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# The escoria main script
tool
extends Node

# Signal sent when pause menu has to be displayed
Expand Down Expand Up @@ -310,12 +311,6 @@ func _input(event):
if event.is_action_pressed("ui_cancel"):
emit_signal("request_pause_menu")

if ProjectSettings.get_setting("escoria/ui/tooltip_follows_mouse"):
if escoria.main.current_scene and escoria.main.current_scene.game:
if event is InputEventMouseMotion:
escoria.main.current_scene.game. \
update_tooltip_following_mouse_position(event.position)


# Pauses or unpause the game
#
Expand Down Expand Up @@ -349,6 +344,110 @@ func run_event_from_script(script: ESCScript, event_name: String):
[]
)
return


# Register a new project setting if it hasn't been defined already
#
# #### Parameters
#
# - name: Name of the project setting
# - default: Default value
# - info: Property info for the setting
func register_setting(name: String, default, info: Dictionary):
if not ProjectSettings.has_setting(name):
ProjectSettings.set_setting(
name,
default
)
info.name = name
ProjectSettings.add_property_info(info)


# Register a user interface. This should be called in a deferred way
# from the addon's _enter_tree.
#
# #### Parameters
# - game_scene: Path to the game scene extending ESCGame
func register_ui(game_scene: String):
if not ProjectSettings.get_setting("escoria/ui/game_scene") in [
"",
game_scene
]:
logger.report_errors(
"escoria.gd:register_ui()",
[
"Can't register user interface because %s is registered" % \
ProjectSettings.get_setting("escoria/ui/game_scene")
]
)
ProjectSettings.set_setting(
"escoria/ui/game_scene",
game_scene
)


# Deregister a user interface
#
# #### Parameters
# - game_scene: Path to the game scene extending ESCGame
func deregister_ui(game_scene: String):
if ProjectSettings.get_setting("escoria/ui/game_scene") != game_scene:
logger.report_errors(
"escoria.gd:deregister_ui()",
[
(
"Can't deregister user interface %s because it " +
"is not registered."
) % ProjectSettings.get_setting("escoria/ui/game_scene")
]
)
ProjectSettings.set_setting(
"escoria/ui/game_scene",
""
)


# Register a dialog manager addon. This should be called in a deferred way
# from the addon's _enter_tree.
#
# #### Parameters
# - manager_class: Path to the manager class script
func register_dialog_manager(manager_class: String):
var dialog_managers: Array = ProjectSettings.get_setting(
"escoria/ui/dialog_managers"
)
if manager_class in dialog_managers:
return
dialog_managers.push_back(manager_class)
ProjectSettings.set_setting(
"escoria/ui/dialog_managers",
dialog_managers
)


# Deregister a dialog manager addon
#
# #### Parameters
# - manager_class: Path to the manager class script
func deregister_dialog_manager(manager_class: String):
var dialog_managers: Array = ProjectSettings.get_setting(
"escoria/ui/dialog_managers"
)
if not manager_class in dialog_managers:
logger.report_warnings(
"escoria.gd:deregister_dialog_manager()",
[
"Dialog manager %s is not registered" % manager_class
]
)
return

dialog_managers.erase(manager_class)

ProjectSettings.set_setting(
"escoria/ui/dialog_managers",
dialog_managers
)


# Function called to quit the game.
Expand Down
Loading

0 comments on commit bcfc5e7

Please sign in to comment.