diff --git a/gymkhana/addons/escoria-ui-return-monkey-island/game.gd b/gymkhana/addons/escoria-ui-return-monkey-island/game.gd index 9edcd843..5a94f842 100644 --- a/gymkhana/addons/escoria-ui-return-monkey-island/game.gd +++ b/gymkhana/addons/escoria-ui-return-monkey-island/game.gd @@ -76,8 +76,8 @@ var _current_mouse_pos = Vector2.ZERO var tooltip2_node: Object func _ready(): - $tooltip_layer/tooltip.connect("tooltip_size_updated", self, "update_tooltip_following_mouse_position") - $tooltip_layer/tooltip.connect("tooltip2_size_updated", self, "update_tooltip2_following_mouse_position") + $tooltip_layer/tooltip.connect("tooltip_size_updated", self, "update_tooltip_following_mouse_position", [tooltip_node]) + $tooltip_layer/tooltip.connect("tooltip2_size_updated", self, "update_tooltip_following_mouse_position", [tooltip2_node]) func _enter_tree(): @@ -114,8 +114,8 @@ func _input(event: InputEvent) -> void: if escoria.get_escoria().is_ready_for_inputs(): if event is InputEventMouseMotion: _current_mouse_pos = get_global_mouse_position() - update_tooltip_following_mouse_position() - update_tooltip2_following_mouse_position() + update_tooltip_following_mouse_position(tooltip_node) + update_tooltip_following_mouse_position(tooltip2_node) # https://github.com/godotengine/godot-demo-projects/blob/3.4-585455e/misc/joypads/joypads.gd @@ -337,57 +337,34 @@ func get_custom_data() -> Dictionary: } -# Update the tooltip1 -func update_tooltip_following_mouse_position(): +# Update the tooltip position +func update_tooltip_following_mouse_position(tooltip: Object): + if tooltip == null: + return + var corrected_position = _current_mouse_pos \ - Vector2( - tooltip_node.rect_size.x / 2, - tooltip_node.rect_size.y / 2 + tooltip.rect_size.x / 2, + tooltip.rect_size.y / 2 ) # clamp TOP - if tooltip_node.tooltip_distance_to_edge_top(_current_mouse_pos) <= mouse_tooltip_margin: + if tooltip.tooltip_distance_to_edge_top(_current_mouse_pos) <= mouse_tooltip_margin: corrected_position.y = mouse_tooltip_margin # clamp BOTTOM - if tooltip_node.tooltip_distance_to_edge_bottom(_current_mouse_pos + tooltip_node.rect_size) <= mouse_tooltip_margin: - corrected_position.y = escoria.game_size.y - mouse_tooltip_margin - tooltip_node.rect_size.y + if tooltip.tooltip_distance_to_edge_bottom(_current_mouse_pos + tooltip.rect_size) <= mouse_tooltip_margin: + corrected_position.y = escoria.game_size.y - mouse_tooltip_margin - tooltip.rect_size.y # clamp LEFT - if tooltip_node.tooltip_distance_to_edge_left(_current_mouse_pos - tooltip_node.rect_size/2) <= mouse_tooltip_margin: + if tooltip.tooltip_distance_to_edge_left(_current_mouse_pos - tooltip.rect_size/2) <= mouse_tooltip_margin: corrected_position.x = mouse_tooltip_margin # clamp RIGHT - if tooltip_node.tooltip_distance_to_edge_right(_current_mouse_pos + tooltip_node.rect_size/2) <= mouse_tooltip_margin: - corrected_position.x = escoria.game_size.x - mouse_tooltip_margin - tooltip_node.rect_size.x + if tooltip.tooltip_distance_to_edge_right(_current_mouse_pos + tooltip.rect_size/2) <= mouse_tooltip_margin: + corrected_position.x = escoria.game_size.x - mouse_tooltip_margin - tooltip.rect_size.x - tooltip_node.rect_position = corrected_position + tooltip_node.offset_from_cursor - -# Update the tooltip2 -func update_tooltip2_following_mouse_position(): - var corrected_position = _current_mouse_pos \ - - Vector2( - tooltip2_node.rect_size.x / 2, - tooltip2_node.rect_size.y / 2 - ) - - # clamp TOP - if tooltip2_node.tooltip_distance_to_edge_top(_current_mouse_pos) <= mouse_tooltip_margin: - corrected_position.y = mouse_tooltip_margin - - # clamp BOTTOM - if tooltip2_node.tooltip_distance_to_edge_bottom(_current_mouse_pos + tooltip2_node.rect_size) <= mouse_tooltip_margin: - corrected_position.y = escoria.game_size.y - mouse_tooltip_margin - tooltip2_node.rect_size.y - - # clamp LEFT - if tooltip2_node.tooltip_distance_to_edge_left(_current_mouse_pos - tooltip2_node.rect_size/2) <= mouse_tooltip_margin: - corrected_position.x = mouse_tooltip_margin - - # clamp RIGHT - if tooltip2_node.tooltip_distance_to_edge_right(_current_mouse_pos + tooltip2_node.rect_size/2) <= mouse_tooltip_margin: - corrected_position.x = escoria.game_size.x - mouse_tooltip_margin - tooltip2_node.rect_size.x - - tooltip2_node.rect_position = corrected_position + tooltip2_node.offset_from_cursor + tooltip.rect_position = corrected_position + tooltip.offset_from_cursor func _on_event_done(return_code: int, _event_name: String): if return_code == ESCExecution.RC_OK: