From 0275c66a12cf4526ffbdee7276b17dac09551ba4 Mon Sep 17 00:00:00 2001 From: oier Date: Sat, 25 Feb 2023 06:56:42 +0100 Subject: [PATCH] tooltip rework --- .../cursors/rounded_mouse_left.png | Bin 0 -> 5636 bytes .../cursors/rounded_mouse_right.png | Bin 0 -> 5633 bytes .../esc_item_with_tooltip.gd | 45 +--------- .../esc_player_with_tooltip.gd | 1 + .../esc_rich_tooltip.gd | 82 ++++++++++++++++-- .../esc_rich_tooltip.tscn | 42 +++++++++ .../escoria-ui-return-monkey-island/game.gd | 59 ++++++++----- .../escoria-ui-return-monkey-island/game.tscn | 16 +++- .../theme.tres | 11 ++- .../trasera_cocina/esc/trasera_cocina.esc | 2 + .../rooms/trasera_cocina/trasera_cocina.tscn | 55 ++++++------ 11 files changed, 204 insertions(+), 109 deletions(-) create mode 100644 gymkhana/addons/escoria-ui-return-monkey-island/cursors/rounded_mouse_left.png create mode 100644 gymkhana/addons/escoria-ui-return-monkey-island/cursors/rounded_mouse_right.png create mode 100644 gymkhana/addons/escoria-ui-return-monkey-island/esc_rich_tooltip.tscn diff --git a/gymkhana/addons/escoria-ui-return-monkey-island/cursors/rounded_mouse_left.png b/gymkhana/addons/escoria-ui-return-monkey-island/cursors/rounded_mouse_left.png new file mode 100644 index 0000000000000000000000000000000000000000..e7832f8d38c37bf4bed2f840f71a7d98f1af071d GIT binary patch literal 5636 zcmeHLc~BH*7H<$7#UqG##3N2dTt#hWnC@YYFdSh<7+?@#BACOand!y>=3u6Q0r6I% zcoG$>H5y~YsJm!HjYlqx8Z~J}Hzq17Ymmbf7^2w}BwF;oZV<6HRa;hV_Ai@anD@Q+ ze((2w@9VGVUXh#>JIHU8AA%r*3~{;?_&XAQgZlM>&z(d3#vq7yTd^sfP9X}#PM3qS z=8|H%$VrMxkCj3YPwl;m8Pzw$1NGc2{iX~c^E^F5>qb;*kTZ zgXpOB&PN?}r<8&5!OM0x1%G(x{nKNx5d%wJNnobe)|YIPULB>a5v|Et6guHKj+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MGKpG-}7Vv-w zg^q!cP#>g)6~nSz1NruIEclLc{p6d(k>Yjd+RIDHapcwEy3H5NQRZvln$OeXD&R8# zG>iju3B-e%_*DEP{@*{yf(8DN)Wwk$pNy!koQJtVT=cP1)yRq={xPr^W{sI)M-ZSs~?Npyo*vitXqf&yK&Xy%U(}2217qY{DQ=S;-O0NF? zjm7A~Dc(NrlEL1ZGe>iB%V#W`_S-6K{HLKKR3BCqjgC;2OI;=-)V_~z{V@90+SKai zg=oRvxEqU$8iU$g))dVTitf3z=K EI|MFSssI20 literal 0 HcmV?d00001 diff --git a/gymkhana/addons/escoria-ui-return-monkey-island/esc_item_with_tooltip.gd b/gymkhana/addons/escoria-ui-return-monkey-island/esc_item_with_tooltip.gd index db261b36..f416afe9 100644 --- a/gymkhana/addons/escoria-ui-return-monkey-island/esc_item_with_tooltip.gd +++ b/gymkhana/addons/escoria-ui-return-monkey-island/esc_item_with_tooltip.gd @@ -6,47 +6,10 @@ class_name ESCItemWithTooltip, "res://addons/escoria-core/design/esc_item.svg" export(String) var action1_text = "" # Action 2 Label text export(String) var action2_text = "" - -# Action 1 X -export(int) var action1_x = 0 -# Action 1 Y -export(int) var action1_y = 0 +# Action 3 tooltip text in inventory +export(String) var action3_text = "" +# Action 3 tooltip text in inventory +export(String) var action4_text = "" # The text for the tooltip of action2 export(String) var tooltip2_name - -# Action1 tooltip text in inventory -export(String) var action3_text - -# Action2 tooltip text in inventory -export(String) var action4_text - - #$tooltips.visible = true; -var action1Tooltip: Object -var action2Tooltip: Object - -var tooltips = [] -func _ready(): - ._ready() - _detect_labels() - if(action1Tooltip != null): - action1Tooltip.set_text(action1_text) - if(action2Tooltip != null): - action2Tooltip.set_text(action2_text) - - - -func _detect_labels() -> void: - # Initialize collision variable. - for c in get_children(): - if c is Node2D: - if c.name == "action1": - action1Tooltip = c - if c.name =="action2": - action2Tooltip = c - if c.name == "action1" or c.name =="action2": - print("TOOL LOOP " + c.name) - #var node = c.get - #c.set_text("AAAAAAA") - tooltips.append(c) - #tooltipsLayer = c diff --git a/gymkhana/addons/escoria-ui-return-monkey-island/esc_player_with_tooltip.gd b/gymkhana/addons/escoria-ui-return-monkey-island/esc_player_with_tooltip.gd index 56b824ef..93f0dd38 100644 --- a/gymkhana/addons/escoria-ui-return-monkey-island/esc_player_with_tooltip.gd +++ b/gymkhana/addons/escoria-ui-return-monkey-island/esc_player_with_tooltip.gd @@ -18,3 +18,4 @@ func _ready(): ._ready() else: tooltip_name = "" + diff --git a/gymkhana/addons/escoria-ui-return-monkey-island/esc_rich_tooltip.gd b/gymkhana/addons/escoria-ui-return-monkey-island/esc_rich_tooltip.gd index ac37d8b8..5989a432 100644 --- a/gymkhana/addons/escoria-ui-return-monkey-island/esc_rich_tooltip.gd +++ b/gymkhana/addons/escoria-ui-return-monkey-island/esc_rich_tooltip.gd @@ -21,7 +21,9 @@ const ONE_LINE_HEIGHT = 16 export(Color) var color setget set_color # Vector2 defining the offset from the cursor -export(Vector2) var offset_from_cursor = Vector2(10,0) +export(Vector2) var offset_from_cursor_action1 = Vector2(5,5) + +export(Vector2) var offset_from_cursor_action2 = Vector2(5,-5) # Activates debug mode. If enabled, shows the label with a white background. export(bool) var debug_mode = false setget set_debug_mode @@ -33,12 +35,16 @@ var current_action: String # Target item/hotspot var current_target: String setget set_target +var current_target_object: Object = null setget set_target_object + # Preposition: on, with... var current_prep: String = "with" # Target 2 item/hotspot var current_target2: String +var current_size: Vector2 = Vector2(0,0) setget _set_current_size + # True if tooltip is waiting for a click on second target (use x with y) var waiting_for_target2 = false @@ -48,6 +54,7 @@ var debug_texturerect_node: TextureRect # Indicates whether the current room is loaded and ready var _room_is_ready: bool = false +signal tooltip_size_updated # Connect relevant functions func _ready(): @@ -80,7 +87,7 @@ func set_debug_mode(p_debug_mode: bool): debug_texturerect_node.expand = true debug_texturerect_node.stretch_mode = TextureRect.STRETCH_TILE #debug_texturerect_node.size_flags_horizontal = SIZE_EXPAND_FILL - debug_texturerect_node.size_flags_vertical = SIZE_EXPAND_FILL + #debug_texturerect_node.size_flags_vertical = SIZE_EXPAND_FILL debug_texturerect_node.show_behind_parent = true debug_texturerect_node.anchor_right = 1.0 debug_texturerect_node.anchor_bottom = 1.0 @@ -91,6 +98,16 @@ func set_debug_mode(p_debug_mode: bool): remove_child(debug_texturerect_node) debug_texturerect_node.queue_free() +func set_target_object(target: Object, needs_second_target: bool = false) -> void: + current_target_object = target + waiting_for_target2 = needs_second_target + if _room_is_ready: + update_tooltip_text() + if(target == null): + hide() + return + show() + # Set the first target of the label. # @@ -102,6 +119,10 @@ func set_target(target: String, needs_second_target: bool = false) -> void: waiting_for_target2 = needs_second_target if _room_is_ready: update_tooltip_text() + if(target == ""): + hide() + return + show() # Set the second target of the label @@ -112,14 +133,27 @@ func set_target2(target2: String) -> void: current_target2 = target2 if _room_is_ready: update_tooltip_text() + if(target2 == ""): + hide() + return + show() # Update the tooltip text. func update_tooltip_text(): - """ - Overriden method. Should not be called directly. - """ - pass + if(current_target_object == null): + return + hide() + if(current_target_object.action1_text != ""): + $tooltip1.visible = true; + + $tooltip1/label.text = current_target_object.action1_text + + if(current_target_object.action2_text != ""): + $tooltip1.visible = true; + + $tooltip2/label.text = current_target_object.action2_text + # Update the tooltip size according to the text. @@ -127,8 +161,20 @@ func update_size(): if not get_tree(): # We're not in the tree anymore. Return return - rect_size = get_font("normal_font").get_string_size(current_target) + current_size = $tooltip1/label.get_font("normal_font").get_string_size(current_target) +func get_tooltip1_size(): + if not get_tree(): + # We're not in the tree anymore. Return + return + escoria.logger.info(self, "get_string_size: " + String($tooltip1/label.get_font("normal_font").get_string_size(current_target))) + return $tooltip1/label.get_font("normal_font").get_string_size(current_target) + +func get_tooltip2_size(): + if not get_tree(): + # We're not in the tree anymore. Return + return + return $tooltip2/label.get_font("normal_font").get_string_size(current_target) # Calculate the offset of the label depending on its position. # @@ -138,7 +184,7 @@ func update_size(): # **Return** # The calculated offset func _offset(position: Vector2) -> Vector2: - var center_offset_x = rect_size.x / 2 + var center_offset_x = current_size.x / 2 var offset_y = 5 position.x -= center_offset_x @@ -190,6 +236,21 @@ func tooltip_distance_to_edge_left(position: Vector2): func tooltip_distance_to_edge_right(position: Vector2): return escoria.game_size.x - position.x +func show(): + if _room_is_ready: + $tooltip1.visible = true; + $tooltip2.visible = true; + #$icon.visible = true; + #$label.visible = true; + #$background.visible = true; + +func hide(): + if _room_is_ready: + $tooltip1.visible = false; + $tooltip2.visible = false; + #$icon.visible = false; + #$label.visible = false; + #$background.visible = false; # Clear the tooltip targets texts func clear(): @@ -197,7 +258,9 @@ func clear(): set_target("") set_target2("") - +func _set_current_size(size: Vector2): + current_size = size + # Called when the room is loaded to setup the label. func _on_room_ready(): escoria.main.current_scene.game.tooltip_node = self @@ -210,3 +273,4 @@ func _on_action_selected() -> void: if _room_is_ready: update_tooltip_text() + hide() diff --git a/gymkhana/addons/escoria-ui-return-monkey-island/esc_rich_tooltip.tscn b/gymkhana/addons/escoria-ui-return-monkey-island/esc_rich_tooltip.tscn new file mode 100644 index 00000000..2dc7c0ca --- /dev/null +++ b/gymkhana/addons/escoria-ui-return-monkey-island/esc_rich_tooltip.tscn @@ -0,0 +1,42 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://gymkhana/addons/escoria-ui-return-monkey-island/esc_rich_tooltip.gd" type="Script" id=1] +[ext_resource path="res://gymkhana/addons/escoria-ui-return-monkey-island/cursors/rounded_mouse_right.png" type="Texture" id=2] +[ext_resource path="res://gymkhana/addons/escoria-ui-return-monkey-island/cursors/rounded_mouse_left.png" type="Texture" id=3] +[ext_resource path="res://gymkhana/addons/escoria-ui-return-monkey-island/theme.tres" type="Theme" id=4] + +[node name="tooltipManager" type="Node2D"] +position = Vector2( -1, -10 ) +script = ExtResource( 1 ) + +[node name="tooltip1" type="Node2D" parent="."] +visible = false + +[node name="label" type="Label" parent="tooltip1"] +margin_left = 9.0 +margin_top = -6.0 +margin_right = 119.0 +margin_bottom = 8.0 +theme = ExtResource( 4 ) +text = "Text place holder" + +[node name="icon" type="Sprite" parent="tooltip1"] +position = Vector2( 1, 8 ) +scale = Vector2( 0.583333, 0.583333 ) +texture = ExtResource( 3 ) + +[node name="tooltip2" type="Node2D" parent="."] +visible = false + +[node name="label" type="Label" parent="tooltip2"] +margin_left = 9.0 +margin_top = 35.0 +margin_right = 144.0 +margin_bottom = 64.0 +theme = ExtResource( 4 ) +text = "Text place holder" + +[node name="icon" type="Sprite" parent="tooltip2"] +position = Vector2( 1, 49.5 ) +scale = Vector2( 0.583333, 0.583333 ) +texture = ExtResource( 2 ) diff --git a/gymkhana/addons/escoria-ui-return-monkey-island/game.gd b/gymkhana/addons/escoria-ui-return-monkey-island/game.gd index ccd85bf2..fce65f9a 100644 --- a/gymkhana/addons/escoria-ui-return-monkey-island/game.gd +++ b/gymkhana/addons/escoria-ui-return-monkey-island/game.gd @@ -84,8 +84,8 @@ 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") + #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(): @@ -227,11 +227,13 @@ func element_focused(element_id: String) -> void: var target_obj = escoria.object_manager.get_object(element_id).node if target_obj is ESCItem or ESCItemWithTooltip: $tooltip_layer/tooltip.set_target(target_obj.tooltip_name) - $tooltip_layer/tooltip2.set_target(target_obj.tooltip2_name) + $tooltip_layer/tooltip.set_target_object(target_obj) + #$tooltip_layer/tooltip2.set_target(target_obj.tooltip2_name) func element_unfocused() -> void: $tooltip_layer/tooltip.set_target("") - $tooltip_layer/tooltip2.set_target("") + $tooltip_layer/tooltip.set_target_object(null) + #$tooltip_layer/tooltip2.set_target("") ## ITEMS ## @@ -262,7 +264,7 @@ func click_on_item(item_global_id: String, event: InputEvent, action: String) -> if (action == ACTION1 && target_obj.tooltip_name != "") || (action == ACTION2 && target_obj is ESCItemWithTooltip && target_obj.tooltip2_name != ""): $tooltip_layer/tooltip.hide() - $tooltip_layer/tooltip2.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) @@ -305,7 +307,7 @@ func click_on_inventory_item(item_global_id: String, event: InputEvent, action: if (target_obj is ESCItemWithTooltip) && (action == ACTION3 && target_obj.action3_text != "") || (action == ACTION4 && target_obj.action4_text != ""): $tooltip_layer/tooltip.hide() - $tooltip_layer/tooltip2.hide() + #$tooltip_layer/tooltip2.hide() func left_click_on_inventory_item(inventory_item_global_id: String, event: InputEvent) -> void: var target_obj = escoria.object_manager.get_object(inventory_item_global_id).node @@ -323,7 +325,7 @@ func inventory_item_focused(inventory_item_global_id: String) -> void: var target_obj = escoria.object_manager.get_object(inventory_item_global_id).node if target_obj is ESCItemWithTooltip: $tooltip_layer/tooltip.set_target(target_obj.action3_text) - $tooltip_layer/tooltip2.set_target(target_obj.action4_text) + $tooltip_layer/tooltip.set_target_object(target_obj) func inventory_item_unfocused() -> void: @@ -391,33 +393,46 @@ func get_custom_data() -> Dictionary: # Update the tooltip position -func update_tooltip_following_mouse_position(tooltip: Object): +func update_tooltip_following_mouse_position(tooltip: ESCRichTooltip): if tooltip == null: return + set_tooltip_position("tooltip1", tooltip, tooltip.get_tooltip1_size(), tooltip.offset_from_cursor_action1) + set_tooltip_position("tooltip2", tooltip, tooltip.get_tooltip2_size(), tooltip.offset_from_cursor_action2) - var corrected_position = _current_mouse_pos \ - - Vector2( - tooltip.rect_size.x / 2, - tooltip.rect_size.y / 2 - ) + +func set_tooltip_position(nodeId: String, tooltip: ESCRichTooltip, size: Vector2, offset: Vector2): + var mouse_position = calculateMousePosition(size) + var corrected_position = correctPosition(tooltip, size, mouse_position, offset) + tooltip.get_node(nodeId).position = corrected_position + + +func calculateMousePosition(size: Vector2): + size.x / 2 + size.y / 2 + #escoria.logger.info(self, "_current_mouse_pos" + String(_current_mouse_pos.x) + " gameSize: " + escoria.game_size.x) + + return _current_mouse_pos - size + +func correctPosition(tooltip: ESCRichTooltip, size: Vector2, mouse_position: Vector2, offset: Vector2): # clamp TOP if tooltip.tooltip_distance_to_edge_top(_current_mouse_pos) <= mouse_tooltip_margin: - corrected_position.y = mouse_tooltip_margin + mouse_position.y = mouse_tooltip_margin # clamp BOTTOM - 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 + if tooltip.tooltip_distance_to_edge_bottom(_current_mouse_pos + size) <= mouse_tooltip_margin: + mouse_position.y = escoria.game_size.y - mouse_tooltip_margin - size.y # clamp LEFT - if tooltip.tooltip_distance_to_edge_left(_current_mouse_pos - tooltip.rect_size/2) <= mouse_tooltip_margin: - corrected_position.x = mouse_tooltip_margin + if tooltip.tooltip_distance_to_edge_left(_current_mouse_pos - size/2) <= mouse_tooltip_margin: + mouse_position.x = mouse_tooltip_margin # clamp RIGHT - 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 + if tooltip.tooltip_distance_to_edge_right(_current_mouse_pos + size/2) <= mouse_tooltip_margin: + mouse_position.x = escoria.game_size.x - mouse_tooltip_margin - size.x - tooltip.rect_position = corrected_position + tooltip.offset_from_cursor + + return mouse_position - offset func _on_event_done(return_code: int, _event_name: String): escoria.logger.info(self, "EVENT DONE! code=" + String(return_code)) @@ -425,7 +440,7 @@ func _on_event_done(return_code: int, _event_name: String): # escoria.action_manager.clear_current_action() # Show tooltips, they were hiddeen while performing action $tooltip_layer/tooltip.show() - $tooltip_layer/tooltip2.show() + #$tooltip_layer/tooltip2.show() # Reset mouse cursor to (perhaps we were using an inventory item) Input.set_custom_mouse_cursor(null) diff --git a/gymkhana/addons/escoria-ui-return-monkey-island/game.tscn b/gymkhana/addons/escoria-ui-return-monkey-island/game.tscn index c9030179..9990fe27 100644 --- a/gymkhana/addons/escoria-ui-return-monkey-island/game.tscn +++ b/gymkhana/addons/escoria-ui-return-monkey-island/game.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=10 format=2] +[gd_scene load_steps=11 format=2] [ext_resource path="res://gymkhana/addons/escoria-ui-return-monkey-island/inventory/inventory_ui.tscn" type="PackedScene" id=1] [ext_resource path="res://addons/escoria-core/game/scenes/dialogs/esc_dialog_player.gd" type="Script" id=2] [ext_resource path="res://addons/escoria-core/game/scenes/camera_player/camera.tscn" type="PackedScene" id=3] +[ext_resource path="res://gymkhana/addons/escoria-ui-return-monkey-island/esc_rich_tooltip.tscn" type="PackedScene" id=4] [ext_resource path="res://gymkhana/addons/escoria-ui-return-monkey-island/game.gd" type="Script" id=5] [ext_resource path="res://gymkhana/addons/escoria-ui-return-monkey-island/tooltip/target_tooltip.tscn" type="PackedScene" id=6] [ext_resource path="res://addons/escoria-core/ui_library/menus/main_menu/main_menu.tscn" type="PackedScene" id=7] @@ -76,16 +77,23 @@ visible = false [node name="tooltip_layer" type="CanvasLayer" parent="."] layer = 2 -[node name="tooltip" parent="tooltip_layer" instance=ExtResource( 6 )] +[node name="tooltipOld" parent="tooltip_layer" instance=ExtResource( 6 )] mouse_filter = 2 bbcode_text = "[center][color=#000000][/color][/center]" fit_content_height = true -offset_from_cursor = Vector2( -10, -50 ) +offset_from_cursor = Vector2( -5, -50 ) + [node name="tooltip2" parent="tooltip_layer" instance=ExtResource( 10 )] mouse_filter = 2 bbcode_text = "[center][color=#000000][/color][/center]" fit_content_height = true -offset_from_cursor = Vector2( -10, 50 ) +offset_from_cursor = Vector2( -5, 50 ) + +[node name="tooltip" parent="tooltip_layer" instance=ExtResource( 4 )] +z_index = 10 +color = Color( 1, 1, 1, 1 ) +offset_from_cursor_action1 = Vector2( 0, 50 ) +offset_from_cursor_action2 = Vector2( 0, -50 ) [connection signal="pressed" from="CanvasLayer/ui/HBoxContainer/VBoxContainer/MenuButton" to="." method="_on_MenuButton_pressed"] diff --git a/gymkhana/addons/escoria-ui-return-monkey-island/theme.tres b/gymkhana/addons/escoria-ui-return-monkey-island/theme.tres index 2982bf5f..204985b9 100644 --- a/gymkhana/addons/escoria-ui-return-monkey-island/theme.tres +++ b/gymkhana/addons/escoria-ui-return-monkey-island/theme.tres @@ -3,15 +3,14 @@ [ext_resource path="res://gymkhana/addons/escoria-ui-return-monkey-island/fonts/caslonantique.tres" type="DynamicFont" id=1] [sub_resource type="StyleBoxFlat" id=1] -content_margin_left = 28.0 -content_margin_right = 3.0 -content_margin_top = 6.0 -content_margin_bottom = 3.0 +content_margin_left = 4.0 +content_margin_right = 4.0 +content_margin_top = 4.0 +content_margin_bottom = 4.0 bg_color = Color( 0, 0, 0, 0.462745 ) -corner_radius_top_left = 5 corner_radius_top_right = 5 corner_radius_bottom_right = 5 -corner_radius_bottom_left = 5 +expand_margin_left = 19.0 [sub_resource type="StyleBoxFlat" id=2] bg_color = Color( 0, 0, 0, 0.509804 ) diff --git a/gymkhana/rooms/trasera_cocina/esc/trasera_cocina.esc b/gymkhana/rooms/trasera_cocina/esc/trasera_cocina.esc index e69de29b..d513f9cd 100644 --- a/gymkhana/rooms/trasera_cocina/esc/trasera_cocina.esc +++ b/gymkhana/rooms/trasera_cocina/esc/trasera_cocina.esc @@ -0,0 +1,2 @@ +:ready +camera_set_target 0 player \ No newline at end of file diff --git a/gymkhana/rooms/trasera_cocina/trasera_cocina.tscn b/gymkhana/rooms/trasera_cocina/trasera_cocina.tscn index 7661f708..95650278 100644 --- a/gymkhana/rooms/trasera_cocina/trasera_cocina.tscn +++ b/gymkhana/rooms/trasera_cocina/trasera_cocina.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=15 format=2] +[gd_scene load_steps=17 format=2] [ext_resource path="res://addons/escoria-core/game/core-scripts/esc_room.gd" type="Script" id=1] [ext_resource path="res://addons/escoria-core/game/core-scripts/esc_background.gd" type="Script" id=2] [ext_resource path="res://addons/escoria-core/game/core-scripts/esc_location.gd" type="Script" id=3] [ext_resource path="res://addons/escoria-core/game/core-scripts/esc_terrain.gd" type="Script" id=4] +[ext_resource path="res://addons/escoria-core/game/core-scripts/resources/esc_animationresource.gd" type="Script" id=5] [ext_resource path="res://gymkhana/rooms/trasera_cocina/assets/background trasera cocina-1500x577-noItems.jpg" type="Texture" id=6] [ext_resource path="res://gymkhana/characters/oier/oier.tscn" type="PackedScene" id=7] [ext_resource path="res://gymkhana/rooms/trasera_cocina/assets/columna.png" type="Texture" id=25] @@ -19,6 +20,13 @@ vertices = PoolVector2Array( 155, 425, 129, 383, 242, 376, 1511, 445, 1512, 574, polygons = [ PoolIntArray( 0, 1, 2 ), PoolIntArray( 3, 4, 5, 6 ), PoolIntArray( 5, 0, 2, 7, 8, 9 ), PoolIntArray( 9, 10, 11, 5 ), PoolIntArray( 5, 11, 12 ), PoolIntArray( 13, 14, 15, 16, 5 ), PoolIntArray( 17, 18, 19, 3 ), PoolIntArray( 13, 20, 14 ), PoolIntArray( 5, 12, 21 ), PoolIntArray( 22, 17, 3 ), PoolIntArray( 5, 21, 13 ), PoolIntArray( 6, 22, 3 ), PoolIntArray( 23, 6, 5 ), PoolIntArray( 5, 16, 23 ) ] outlines = [ PoolVector2Array( 263, 374, 359, 376, 385, 397, 442, 395, 464, 432, 506, 457, 584, 468, 725, 472, 749, 460, 794, 462, 846, 467, 864, 482, 981, 480, 1133, 474, 1249, 454, 1318, 435, 1367, 411, 1425, 417, 1511, 445, 1512, 574, 193, 574, 155, 425, 129, 383, 242, 376 ) ] +[sub_resource type="Resource" id=2] +script = ExtResource( 5 ) +dir_angles = [ ] +directions = [ ] +idles = [ ] +speaks = [ ] + [node name="ESCRoom" type="Node2D"] script = ExtResource( 1 ) global_id = "trasera_cocina" @@ -28,10 +36,8 @@ camera_limits = [ Rect2( 0, 0, 1500, 577 ) ] editor_debug_mode = 1 [node name="ESCBackground" type="TextureRect" parent="."] -margin_left = 17.0 -margin_top = 4.0 -margin_right = 1517.0 -margin_bottom = 581.0 +margin_right = 1500.0 +margin_bottom = 755.0 mouse_filter = 2 texture = ExtResource( 6 ) script = ExtResource( 2 ) @@ -45,7 +51,7 @@ scale_min = 0.5 navpoly = SubResource( 1 ) [node name="ESCLocation" type="Position2D" parent="."] -position = Vector2( 796, 480 ) +position = Vector2( 802, 470 ) script = ExtResource( 3 ) global_id = "trasera_cocina_start" is_start_location = true @@ -61,11 +67,13 @@ is_exit = true tooltip_name = "Esto es una puerta y tiene una descripcion mu larga" combine_when_selected_action_is_in = [ ] dialog_color = Color( 1, 1, 1, 1 ) +action1_text = "Esto es una puerta y tiene una descripcion mu larga" +action2_text = "Entrar! con descricion..." tooltip2_name = "Entrar! con descricion..." -animations = null +animations = SubResource( 2 ) [node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Hotspots/entrada_cocina"] -position = Vector2( 740.494, -123.8 ) +position = Vector2( 725, -125 ) scale = Vector2( 0.963362, 0.9875 ) polygon = PoolVector2Array( 21, 575, 22, 331, 135, 339, 137, 581 ) @@ -82,13 +90,15 @@ tooltip_name = "TT Mirar bombona" combine_when_selected_action_is_in = [ ] inventory_texture = ExtResource( 29 ) dialog_color = Color( 1, 1, 1, 1 ) -tooltip2_name = "TT2 Coger bombona" +action1_text = "TT Mirar bombona" +action2_text = "TT2 Coger bombona" action3_text = "¿Cómo ha entrado en mi bolsillo?" action4_text = "¿Por qué es una llave inglesa?" +tooltip2_name = "TT2 Coger bombona" animations = null [node name="bombona2" parent="Hotspots" instance=ExtResource( 27 )] -position = Vector2( 357, 408 ) +position = Vector2( 355, 409 ) script = ExtResource( 28 ) global_id = "i_bombona2" esc_script = "res://gymkhana/rooms/trasera_cocina/esc/i_bombona2.esc" @@ -97,30 +107,19 @@ combine_when_selected_action_is_in = [ "action1", "action3" ] use_from_inventory_only = true inventory_texture = ExtResource( 29 ) dialog_color = Color( 1, 1, 1, 1 ) -tooltip2_name = "TT2 Coger bombona" +action1_text = "TT Mirar bombona" +action2_text = "TT2 Coger bombona" action3_text = "Usar" action4_text = "¿Por qué es una llave inglesa?" +tooltip2_name = "TT Mirar bombona" animations = null [node name="Columna" type="Sprite" parent="."] -position = Vector2( 253.25, 294.5 ) +position = Vector2( 235, 294.5 ) scale = Vector2( 0.973684, 1.02358 ) z_index = 400 texture = ExtResource( 25 ) -[node name="TextureRect" type="TextureRect" parent="."] -margin_left = 598.0 -margin_top = 283.0 -margin_right = 692.0 -margin_bottom = 464.0 - -[node name="Area2D" type="Area2D" parent="."] -position = Vector2( 598, 283 ) - -[node name="TextureRect" type="TextureRect" parent="Area2D"] -margin_right = 40.0 -margin_bottom = 40.0 - [node name="EnekoSmoking" parent="." instance=ExtResource( 30 )] position = Vector2( 959, 413 ) tooltip_name = "Objervar sujeto" @@ -136,12 +135,14 @@ script = ExtResource( 3 ) global_id = "eneko_smoking" [node name="ESCItemWithTooltip" parent="." instance=ExtResource( 31 )] -position = Vector2( 728, 424 ) +position = Vector2( 707, 422 ) esc_script = "res://gymkhana/rooms/trasera_cocina/esc/i_caja_herramientas.esc" tooltip_name = "¿Que es esto?" -tooltip2_name = "Coger" +action1_text = "¿Que es esto?" +action2_text = "Coger" action3_text = "Mirar dentro" action4_text = "Usar" +tooltip2_name = "Coger" [node name="ESCLocation" type="Position2D" parent="ESCItemWithTooltip"] position = Vector2( -51, 69 )