From 62b8b35f1cafda62bb69b9bfce09b997b9fe2fed Mon Sep 17 00:00:00 2001 From: Eneko Nieto Date: Wed, 15 Feb 2023 17:26:23 +0100 Subject: [PATCH] Revert "Deleted tooltip2" This reverts commit f1f9bf7a6908c226f15b94ebb511f28512c100f5. --- .../escoria-ui-return-monkey-island/game.gd | 13 ++++- .../escoria-ui-return-monkey-island/game.tscn | 7 +++ .../tooltip/target_tooltip2.tscn | 11 ++++ .../tooltip/tooltip2_target.gd | 57 +++++++++++++++++++ gymkhana/rooms/home/home.tscn | 1 + .../rooms/trasera_cocina/trasera_cocina.tscn | 1 + project.godot | 6 -- 7 files changed, 89 insertions(+), 7 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/gymkhana/addons/escoria-ui-return-monkey-island/game.gd b/gymkhana/addons/escoria-ui-return-monkey-island/game.gd index 3b9c3847..b1773170 100644 --- a/gymkhana/addons/escoria-ui-return-monkey-island/game.gd +++ b/gymkhana/addons/escoria-ui-return-monkey-island/game.gd @@ -72,9 +72,14 @@ var _is_gamepad_connected = false # Tracks the mouse's current position onscreen. var _current_mouse_pos = Vector2.ZERO +# A reference to the node handling tooltip2 +var tooltip2_node: Object + func _ready(): if $tooltip_layer/tooltip.connect("tooltip_size_updated", self, "update_tooltip_following_mouse_position", [tooltip_node]) != 0: escoria.logger.error(self, "Error connecting tooltip_size_updated") + if $tooltip_layer/tooltip2.connect("tooltip2_size_updated", self, "update_tooltip_following_mouse_position", [tooltip2_node]) != 0: + escoria.logger.error(self, "Error connecting tooltip2_size_updated") func _enter_tree(): @@ -113,6 +118,7 @@ func _input(event: InputEvent) -> void: if event is InputEventMouseMotion: _current_mouse_pos = get_global_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 @@ -214,9 +220,11 @@ func left_double_click_on_bg(position: Vector2) -> void: func element_focused(element_id: String) -> void: var target_obj = escoria.object_manager.get_object(element_id).node $tooltip_layer/tooltip.set_target(target_obj.tooltip_name) + $tooltip_layer/tooltip2.set_target(target_obj.tooltip2_name) func element_unfocused() -> void: $tooltip_layer/tooltip.set_target("") + $tooltip_layer/tooltip2.set_target("") ## ITEMS ## @@ -231,8 +239,9 @@ func click_on_item(item_global_id: String, event: InputEvent, action: String) -> true ) - if (action == ACTION1 && target_obj.tooltip_name != ""): + if (action == ACTION1 && target_obj.tooltip_name != "") || (action == ACTION2 && target_obj.tooltip2_name != ""): $tooltip_layer/tooltip.hide() + $tooltip_layer/tooltip2.hide() func left_click_on_item(item_global_id: String, event: InputEvent) -> void: click_on_item(item_global_id, event, ACTION1) @@ -266,6 +275,7 @@ func inventory_item_focused(inventory_item_global_id: String) -> void: func inventory_item_unfocused() -> void: $tooltip_layer/tooltip.set_target("") + $tooltip_layer/tooltip2.set_target("") func open_inventory(): $CanvasLayer/ui/HBoxContainer/inventory_ui.show_inventory() @@ -361,6 +371,7 @@ func _on_event_done(return_code: int, _event_name: String): if return_code == ESCExecution.RC_OK: escoria.action_manager.clear_current_action() $tooltip_layer/tooltip.show() + $tooltip_layer/tooltip2.show() func _on_MenuButton_pressed() -> void: diff --git a/gymkhana/addons/escoria-ui-return-monkey-island/game.tscn b/gymkhana/addons/escoria-ui-return-monkey-island/game.tscn index bf861be0..b17a023f 100644 --- a/gymkhana/addons/escoria-ui-return-monkey-island/game.tscn +++ b/gymkhana/addons/escoria-ui-return-monkey-island/game.tscn @@ -8,6 +8,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 ) @@ -84,4 +85,10 @@ 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 + [connection signal="pressed" from="CanvasLayer/ui/HBoxContainer/VBoxContainer/MenuButton" to="." method="_on_MenuButton_pressed"] 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..26fc7d68 --- /dev/null +++ b/gymkhana/addons/escoria-ui-return-monkey-island/tooltip/tooltip2_target.gd @@ -0,0 +1,57 @@ +extends ESCTooltip + +var id: int + + +export(Texture) var iconTexture: Texture = null \ + setget ,_get_icon_texture + +func _init(tooltip_id = 0): + id = tooltip_id + + #$icon.texture = iconTexture + + + + +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() + #var texturePath = get_constant() + var texturePath = null + # 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]" + #if(texturePath != null): + bbcode_text += "[img]" + "res://gymkhana/addons/escoria-ui-return-monkey-island/cursors/mouse_right.png" + "[/img]" + 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.main.current_scene.game.tooltip2_node = self + _room_is_ready = true + +func _get_icon_texture() -> Texture: + if iconTexture == null: + for c in get_children(): + if c is TextureRect or c is Sprite: + return c.texture + return null + else: + return iconTexture diff --git a/gymkhana/rooms/home/home.tscn b/gymkhana/rooms/home/home.tscn index 35e499c0..3eb1253b 100644 --- a/gymkhana/rooms/home/home.tscn +++ b/gymkhana/rooms/home/home.tscn @@ -109,6 +109,7 @@ tooltip_name = "This is action1" combine_when_selected_action_is_in = [ ] inventory_texture = ExtResource( 10 ) dialog_color = Color( 1, 1, 1, 1 ) +tooltip2_name = "This is action2" [node name="Art1" type="Sprite" parent="Hotspots/artwork1"] position = Vector2( 470, 140 ) diff --git a/gymkhana/rooms/trasera_cocina/trasera_cocina.tscn b/gymkhana/rooms/trasera_cocina/trasera_cocina.tscn index a2aff137..f6ee8485 100644 --- a/gymkhana/rooms/trasera_cocina/trasera_cocina.tscn +++ b/gymkhana/rooms/trasera_cocina/trasera_cocina.tscn @@ -99,6 +99,7 @@ global_id = "l_exit" esc_script = "res://gymkhana/rooms/trasera_cocina/esc/entrada_cocina.esc" is_exit = true tooltip_name = "Esto es una puerta" +tooltip2_name = "Entrar!" default_action = "action2" combine_when_selected_action_is_in = [ ] dialog_color = Color( 1, 1, 1, 1 ) diff --git a/project.godot b/project.godot index 2a7195ed..4fb4cd49 100644 --- a/project.godot +++ b/project.godot @@ -319,11 +319,6 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/escoria-core/game/core-scripts/esc_item.gd" }, { -"base": "ESCItem", -"class": "ESCItemWithTooltip", -"language": "GDScript", -"path": "res://gymkhana/addons/escoria-ui-return-monkey-island/item.gd" -}, { "base": "Position2D", "class": "ESCLocation", "language": "GDScript", @@ -752,7 +747,6 @@ _global_script_class_icons={ "ESCInventoryItem": "", "ESCInventoryManager": "", "ESCItem": "res://addons/escoria-core/design/esc_item.svg", -"ESCItemWithTooltip": "res://addons/escoria-core/design/esc_item.svg", "ESCLocation": "res://addons/escoria-core/design/esc_location.svg", "ESCMain": "", "ESCMigration": "",