From 761cb7fcb8a8afdaf5366c2703e027add0a0493c Mon Sep 17 00:00:00 2001 From: Eneko Nieto Date: Mon, 13 Feb 2023 13:40:53 +0100 Subject: [PATCH] MODIFIED addons/escoria-core/game/core-scripts/esc_game.gd Created tooltip2_target --- .../game/core-scripts/esc_game.gd | 5 ++- .../escoria-ui-return-monkey-island/game.gd | 38 +++++++++++++---- .../escoria-ui-return-monkey-island/game.tscn | 7 ++++ .../tooltip/target_tooltip.tscn | 2 +- .../tooltip/target_tooltip2.tscn | 11 +++++ .../tooltip/tooltip2_target.gd | 41 +++++++++++++++++++ .../tooltip/tooltip_target.gd | 13 ++++++ project.godot | 2 +- 8 files changed, 109 insertions(+), 10 deletions(-) create mode 100644 gymkhana/addons/escoria-ui-return-monkey-island/tooltip/target_tooltip2.tscn create mode 100644 gymkhana/addons/escoria-ui-return-monkey-island/tooltip/tooltip2_target.gd diff --git a/addons/escoria-core/game/core-scripts/esc_game.gd b/addons/escoria-core/game/core-scripts/esc_game.gd index dde467bc..64a93766 100644 --- a/addons/escoria-core/game/core-scripts/esc_game.gd +++ b/addons/escoria-core/game/core-scripts/esc_game.gd @@ -38,9 +38,12 @@ export(EDITOR_GAME_DEBUG_DISPLAY) var editor_debug_mode = \ # This should be a Control node and NOT a CanvasLayer (or any other type of) node. export(NodePath) var ui_parent_control_node -# A reference to the node handling tooltips +# A reference to the node handling tooltip1 var tooltip_node: Object +# A reference to the node handling tooltip2 +var tooltip2_node: Object + # Boolean indicating whether the game scene is ready to accept inputs # from the player. This enables using escoria.is_ready_for_inputs() in _input() # function of game.gd script. diff --git a/gymkhana/addons/escoria-ui-return-monkey-island/game.gd b/gymkhana/addons/escoria-ui-return-monkey-island/game.gd index 74dc7c7b..3818073a 100644 --- a/gymkhana/addons/escoria-ui-return-monkey-island/game.gd +++ b/gymkhana/addons/escoria-ui-return-monkey-island/game.gd @@ -73,6 +73,7 @@ var _current_mouse_pos = Vector2.ZERO 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") func _enter_tree(): @@ -110,6 +111,7 @@ func _input(event: InputEvent) -> void: if event is InputEventMouseMotion: _current_mouse_pos = get_global_mouse_position() update_tooltip_following_mouse_position() + update_tooltip2_following_mouse_position() # https://github.com/godotengine/godot-demo-projects/blob/3.4-585455e/misc/joypads/joypads.gd @@ -215,13 +217,9 @@ func left_double_click_on_bg(position: Vector2) -> void: ## ITEM/HOTSPOT FOCUS ## func element_focused(element_id: String) -> void: - escoria.logger.info( - self, - "monkey" - ) - var target_obj = escoria.object_manager.get_object(element_id).node - $tooltip_layer/tooltip.set_target(target_obj.tooltip_name + " " + target_obj.tooltip2_name) + $tooltip_layer/tooltip.set_target(target_obj.tooltip_name) + $tooltip_layer/tooltip2.set_target(target_obj.tooltip2_name) if escoria.action_manager.current_action != VERB_USE \ and escoria.action_manager.current_tool == null \ @@ -377,7 +375,7 @@ func get_custom_data() -> Dictionary: } -# Update the tooltip +# Update the tooltip1 func update_tooltip_following_mouse_position(): var corrected_position = _current_mouse_pos \ - Vector2( @@ -403,6 +401,32 @@ func update_tooltip_following_mouse_position(): 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 + func _on_action_finished(): $mouse_layer/verbs_menu.clear_tool_texture() diff --git a/gymkhana/addons/escoria-ui-return-monkey-island/game.tscn b/gymkhana/addons/escoria-ui-return-monkey-island/game.tscn index 99bc3238..71721122 100644 --- a/gymkhana/addons/escoria-ui-return-monkey-island/game.tscn +++ b/gymkhana/addons/escoria-ui-return-monkey-island/game.tscn @@ -9,6 +9,7 @@ [ext_resource path="res://addons/escoria-core/ui_library/menus/main_menu/main_menu.tscn" type="PackedScene" id=7] [ext_resource path="res://addons/escoria-core/ui_library/menus/pause_menu/pause_menu.tscn" type="PackedScene" id=8] [ext_resource path="res://gymkhana/addons/escoria-ui-return-monkey-island/theme.tres" type="Theme" id=9] +[ext_resource path="res://gymkhana/addons/escoria-ui-return-monkey-island/tooltip/target_tooltip2.tscn" type="PackedScene" id=10] [node name="game" type="Node2D"] script = ExtResource( 5 ) @@ -85,6 +86,12 @@ theme = ExtResource( 9 ) bbcode_text = "[center][color=#000000][/color][/center]" fit_content_height = true +[node name="tooltip2" parent="tooltip_layer" instance=ExtResource( 10 )] +mouse_filter = 2 +theme = ExtResource( 9 ) +bbcode_text = "[center][color=#000000][/color][/center]" +fit_content_height = true + [node name="mouse_layer" type="CanvasLayer" parent="."] layer = 2 diff --git a/gymkhana/addons/escoria-ui-return-monkey-island/tooltip/target_tooltip.tscn b/gymkhana/addons/escoria-ui-return-monkey-island/tooltip/target_tooltip.tscn index d7b70876..66384a85 100644 --- a/gymkhana/addons/escoria-ui-return-monkey-island/tooltip/target_tooltip.tscn +++ b/gymkhana/addons/escoria-ui-return-monkey-island/tooltip/target_tooltip.tscn @@ -8,4 +8,4 @@ bbcode_text = "[center][color=#ffffff][/color][/center]" scroll_active = false script = ExtResource( 2 ) color = Color( 1, 1, 1, 1 ) -offset_from_cursor = Vector2( 0, 0 ) +offset_from_cursor = Vector2( 0, -50 ) diff --git a/gymkhana/addons/escoria-ui-return-monkey-island/tooltip/target_tooltip2.tscn b/gymkhana/addons/escoria-ui-return-monkey-island/tooltip/target_tooltip2.tscn new file mode 100644 index 00000000..0e079bcf --- /dev/null +++ b/gymkhana/addons/escoria-ui-return-monkey-island/tooltip/target_tooltip2.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://gymkhana/addons/escoria-ui-return-monkey-island/tooltip/tooltip2_target.gd" type="Script" id=2] + +[node name="tooltip" type="RichTextLabel"] +bbcode_enabled = true +bbcode_text = "[center][color=#ffffff][/color][/center]" +scroll_active = false +script = ExtResource( 2 ) +color = Color( 1, 1, 1, 1 ) +offset_from_cursor = Vector2( 0, 50 ) diff --git a/gymkhana/addons/escoria-ui-return-monkey-island/tooltip/tooltip2_target.gd b/gymkhana/addons/escoria-ui-return-monkey-island/tooltip/tooltip2_target.gd new file mode 100644 index 00000000..eb35f207 --- /dev/null +++ b/gymkhana/addons/escoria-ui-return-monkey-island/tooltip/tooltip2_target.gd @@ -0,0 +1,41 @@ +extends ESCTooltip + +var id: int + +func _init(tooltip_id = 0): + id = tooltip_id + +signal tooltip2_size_updated + + +func update_tooltip_text(): + # Need to update size of bbcode rect before updating the text itself otherwise on the + # first frame the text is wider than the default of 0 and ends up being really tall + # and setting the wrong vertical margin for the tooltip + update_size() + + # We signal this here since the processing in this class happens AFTER input + # processing. We signal here to avoid "lagging" behind a frame since + # tooltips are presently dependent on the size of the bounding box around + # the rendered string. + emit_signal("tooltip2_size_updated") + + bbcode_text = "[center]" + bbcode_text += "[color=#" + color.to_html(false) + "]" + bbcode_text += current_target + bbcode_text += "[/color]" + bbcode_text += "[/center]" +# push_align(RichTextLabel.ALIGN_CENTER) +# push_color(color) +# append_bbcode(current_target) +# pop() +# pop() + + +func _on_room_ready(): + escoria.logger.warn( + self, + "ON ROOM READY TOOLTIP2 id=" + String(id) + ) + escoria.main.current_scene.game.tooltip2_node = self + _room_is_ready = true diff --git a/gymkhana/addons/escoria-ui-return-monkey-island/tooltip/tooltip_target.gd b/gymkhana/addons/escoria-ui-return-monkey-island/tooltip/tooltip_target.gd index 7874f8c6..420bf3a9 100644 --- a/gymkhana/addons/escoria-ui-return-monkey-island/tooltip/tooltip_target.gd +++ b/gymkhana/addons/escoria-ui-return-monkey-island/tooltip/tooltip_target.gd @@ -1,5 +1,9 @@ extends ESCTooltip +var id: int + +func _init(tooltip_id = 0): + id = tooltip_id signal tooltip_size_updated @@ -26,3 +30,12 @@ func update_tooltip_text(): # append_bbcode(current_target) # pop() # pop() + + +func _on_room_ready(): + escoria.logger.warn( + self, + "ON ROOM READY id=" + String(id) + ) + escoria.main.current_scene.game.tooltip_node = self + _room_is_ready = true diff --git a/project.godot b/project.godot index f1fd5912..c76f65e5 100644 --- a/project.godot +++ b/project.godot @@ -870,7 +870,7 @@ main/game_migration_path="" debug/terminate_on_warnings=false debug/terminate_on_errors=true debug/development_lang="en" -debug/log_level="TRACE" +debug/log_level="WARNING" debug/log_file_path="user://" debug/crash_message="We're sorry, but the game crashed. Please send us the following files: