diff --git a/addons/escoria-core/testing/white.png b/addons/escoria-core/game/assets/images/white.png similarity index 100% rename from addons/escoria-core/testing/white.png rename to addons/escoria-core/game/assets/images/white.png diff --git a/addons/escoria-core/game/core-scripts/escgame.gd b/addons/escoria-core/game/core-scripts/escgame.gd index a0fa339e..fbdd8274 100644 --- a/addons/escoria-core/game/core-scripts/escgame.gd +++ b/addons/escoria-core/game/core-scripts/escgame.gd @@ -7,6 +7,7 @@ func get_class(): export(float) var mouse_tooltip_margin = 50.0 +var tooltip_node : Object ### EDITOR TOOLS ### enum EDITOR_GAME_DEBUG_DISPLAY { @@ -16,6 +17,9 @@ enum EDITOR_GAME_DEBUG_DISPLAY { export(EDITOR_GAME_DEBUG_DISPLAY) var editor_debug_mode = EDITOR_GAME_DEBUG_DISPLAY.NONE setget set_editor_debug_mode +func _ready(): + escoria.esc_runner.connect("event_done", self, "_on_event_done") + func set_editor_debug_mode(p_editor_debug_mode : int) -> void: editor_debug_mode = p_editor_debug_mode @@ -104,5 +108,29 @@ func show_ui(): func _on_event_done(event_name: String): pass -func _on_tooltip_position_update_required(p_position : Vector2): - pass + +## FUNCTIONS BELOW THIS POINT DON'T NEED TO BE REIMPLEMENTED BY USER +## (Although they can be, if required) + +# This function is called if Project setting escoria/ui/tooltip_follows_mouse = true +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 diff --git a/addons/escoria-core/game/core-scripts/esctooltip.gd b/addons/escoria-core/game/core-scripts/esctooltip.gd new file mode 100644 index 00000000..98148fbf --- /dev/null +++ b/addons/escoria-core/game/core-scripts/esctooltip.gd @@ -0,0 +1,153 @@ +tool +extends RichTextLabel +class_name ESCTooltip + +func get_class(): + return "ESCTooltip" + + +# Infinitive verb +var current_action : String +# Target item/hotspot +var current_target : String setget set_target +# Preposition: on, with... +var current_prep : String = "with" +# Target 2 item/hotspot +var current_target2 : String +# True if tooltip is waiting for a click on second target (use x with y) +var waiting_for_target2 = false + +export(Color) var color setget set_color +export(Vector2) var offset_from_cursor = Vector2(10,0) + +export(bool) var debug_mode = false setget set_debug_mode +var debug_texturerect_node : TextureRect + +const MAX_WIDTH = 200 +const MIN_HEIGHT = 30 +const MAX_HEIGHT = 500 +const ONE_LINE_HEIGHT = 16 + + + +func _ready(): + escoria.call_deferred("register_object", self) + escoria.esc_runner.connect("action_changed", self, "on_action_selected") + + +func set_color(p_color : Color): + color = p_color + update_tooltip_text() + + +func set_debug_mode(p_debug_mode : bool): + debug_mode = p_debug_mode + if debug_mode: + # Add a white TextureRect behind the RTL to see its actual size + debug_texturerect_node = TextureRect.new() + add_child(debug_texturerect_node) + debug_texturerect_node.texture = load("res://addons/escoria-core/game/assets/images/white.png") + 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.show_behind_parent = true + debug_texturerect_node.anchor_right = 1.0 + debug_texturerect_node.anchor_bottom = 1.0 + debug_texturerect_node.mouse_filter = Control.MOUSE_FILTER_IGNORE + move_child(debug_texturerect_node, 2) + else: + remove_child(debug_texturerect_node) + + +func on_action_selected() -> void: + current_action = escoria.esc_runner.current_action + update_tooltip_text() + + +func set_target(target : String, needs_second_target : bool = false) -> void: + current_target = target + if needs_second_target: + waiting_for_target2 = true + update_tooltip_text() + + +func set_target2(target2 : String) -> void: + current_target2 = target2 + update_tooltip_text() + + + +func update_tooltip_text(): + """ + Overriden method. Should not be called. + """ + pass + + + +func update_size(): + ## RECT_SIZE ## + var rtl_width = rect_size.x + var rtl_height = rect_size.y + var content_height = get_content_height() + var nb_visible_characters = visible_characters + var nb_visible_lines = get_visible_line_count() + + printt("BEFORE", "text_height", content_height, "rtl_height", rect_size.y) + + # if text is too long and is wrapped +# var nblines = float(get_content_height()) / float(ONE_LINE_HEIGHT) + var nblines = nb_visible_lines + if nblines >= 1: + + yield(get_tree(), "idle_frame") + yield(get_tree(), "idle_frame") + var text_height = get_content_height() + if text_height > MAX_HEIGHT: + text_height = MAX_HEIGHT + if text_height <= MIN_HEIGHT: + text_height = MIN_HEIGHT + + var parent_width = rect_size.x + + # first, try to increase width until it goes above max_width + while parent_width < MAX_WIDTH && float(text_height) / float(ONE_LINE_HEIGHT) > 1.0: + rect_size.x += 1 + parent_width = rect_size.x + + + rect_size.y = text_height + + if rect_size.x >= MAX_WIDTH: + rect_size.x = MAX_WIDTH + + ## END RECT_SIZE ## + anchor_top = 0.0 + anchor_right = 0.0 + anchor_bottom = 0.0 + anchor_left = 0.0 + printt("AFTER", "text_height", get_content_height(), "rtl_height", rect_size.y) + + +func _offset(position): + var center_offset_x = rect_size.x / 2 + var offset_y = 5 + + position.x -= center_offset_x + position.y += offset_y + + return position + + +func tooltip_distance_to_edge_top(position : Vector2): + return position.y + +func tooltip_distance_to_edge_bottom(position: Vector2): + return escoria.game_size.y - position.y + +func tooltip_distance_to_edge_left(position : Vector2): + return position.x + +func tooltip_distance_to_edge_right(position : Vector2): + return escoria.game_size.x - position.x diff --git a/addons/escoria-core/game/core-scripts/inventory_item.gd b/addons/escoria-core/game/core-scripts/inventory_item.gd index 7a53a26a..b1790578 100644 --- a/addons/escoria-core/game/core-scripts/inventory_item.gd +++ b/addons/escoria-core/game/core-scripts/inventory_item.gd @@ -20,6 +20,11 @@ func _ready(): connect("mouse_exited", self, "_on_inventory_item_mouse_exit") func _on_inventory_item_gui_input(event : InputEvent): + if event.is_action_pressed("switch_action_verb"): + if event.button_index == BUTTON_WHEEL_UP: + escoria.inputs_manager._on_mousewheel_action(-1) + elif event.button_index == BUTTON_WHEEL_DOWN: + escoria.inputs_manager._on_mousewheel_action(1) if event is InputEventMouseButton: # var p = get_global_mouse_position() if event.doubleclick: diff --git a/addons/escoria-core/game/escoria.gd b/addons/escoria-core/game/escoria.gd index a0dca14f..393198c4 100644 --- a/addons/escoria-core/game/escoria.gd +++ b/addons/escoria-core/game/escoria.gd @@ -79,6 +79,10 @@ func register_object(object : Object): if object is ESCInventory: inventory = object + if object is ESCTooltip: + if main.current_scene: + main.current_scene.game.tooltip_node = object + """ diff --git a/addons/escoria-core/game/inputs_manager.gd b/addons/escoria-core/game/inputs_manager.gd index e843ca31..d1a92bcf 100644 --- a/addons/escoria-core/game/inputs_manager.gd +++ b/addons/escoria-core/game/inputs_manager.gd @@ -16,7 +16,7 @@ func _input(event): if ProjectSettings.get_setting("escoria/ui/tooltip_follows_mouse"): if !hotspot_focused.empty(): if event is InputEventMouseMotion: - escoria.main.current_scene.game.update_tooltip_position(event.position) + escoria.main.current_scene.game.update_tooltip_following_mouse_position(event.position) ################################################################################### diff --git a/addons/escoria-core/testing/rtl_screen_offset_testing.gd b/addons/escoria-core/testing/rtl_screen_offset_testing.gd index e1001da0..ee9578be 100644 --- a/addons/escoria-core/testing/rtl_screen_offset_testing.gd +++ b/addons/escoria-core/testing/rtl_screen_offset_testing.gd @@ -20,7 +20,7 @@ func _ready(): # Add a white TextureRect behind the RTL to see its actual size var texturerect_node = TextureRect.new() get_node(path_to_richtextlabel).add_child(texturerect_node) - texturerect_node.texture = load("res://addons/escoria-core/testing/white.png") + texturerect_node.texture = load("res://addons/escoria-core/game/assets/images/white.png") texturerect_node.expand = true texturerect_node.stretch_mode = TextureRect.STRETCH_TILE texturerect_node.size_flags_horizontal = SIZE_EXPAND_FILL @@ -64,17 +64,17 @@ func _on_new_text_pressed(): emit_signal("text_selected", pressed_button.text) -func tooltip_distance_to_edge_top(position_y): - return position_y +func tooltip_distance_to_edge_top(position : Vector2): + return position.y -func tooltip_distance_to_edge_bottom(position_y): - return screen_height - position_y +func tooltip_distance_to_edge_bottom(position: Vector2): + return screen_height - position.y -func tooltip_distance_to_edge_left(position_x): - return position_x +func tooltip_distance_to_edge_left(position : Vector2): + return position.x -func tooltip_distance_to_edge_right(position_x): - return screen_width - position_x +func tooltip_distance_to_edge_right(position : Vector2): + return screen_width - position.x func _on_Control_mouse_moved(mouse_pos): # printt("mousepos", mouse_pos) @@ -84,19 +84,19 @@ func _on_Control_mouse_moved(mouse_pos): var corrected_position = mouse_pos # clamp TOP - if tooltip_distance_to_edge_top(mouse_pos.y) <= global_distance_to_clamp: + if tooltip_distance_to_edge_top(mouse_pos) <= global_distance_to_clamp: corrected_position.y = global_distance_to_clamp # clamp BOTTOM - if tooltip_distance_to_edge_bottom(mouse_pos.y + get_node(path_to_richtextlabel).rect_size.y) <= global_distance_to_clamp: + if tooltip_distance_to_edge_bottom(mouse_pos + get_node(path_to_richtextlabel).rect_size) <= global_distance_to_clamp: corrected_position.y = screen_height - global_distance_to_clamp - get_node(path_to_richtextlabel).rect_size.y # clamp LEFT - if tooltip_distance_to_edge_left(mouse_pos.x - get_node(path_to_richtextlabel).rect_size.x/2) <= global_distance_to_clamp: + if tooltip_distance_to_edge_left(mouse_pos - get_node(path_to_richtextlabel).rect_size/2) <= global_distance_to_clamp: corrected_position.x = global_distance_to_clamp # clamp RIGHT - if tooltip_distance_to_edge_right(mouse_pos.x + get_node(path_to_richtextlabel).rect_size.x/2) <= global_distance_to_clamp: + if tooltip_distance_to_edge_right(mouse_pos + get_node(path_to_richtextlabel).rect_size/2) <= global_distance_to_clamp: corrected_position.x = screen_width - global_distance_to_clamp - get_node(path_to_richtextlabel).rect_size.x get_node(path_to_richtextlabel).anchor_right = 0.2 @@ -111,11 +111,6 @@ func _on_clamp_distance_text_changed(new_text): global_distance_to_clamp = int(new_text) update_line2d() -func _on_rtl_sizex_text_changed(text): - pass - get_node(path_to_richtextlabel).rect_size.x = float(text) - update_size() - func _offset(position): var center_offset_x = rect_size.x / 2 diff --git a/addons/escoria-core/testing/rtl_screen_offset_testing.tscn b/addons/escoria-core/testing/rtl_screen_offset_testing.tscn index 927807d3..282814a0 100644 --- a/addons/escoria-core/testing/rtl_screen_offset_testing.tscn +++ b/addons/escoria-core/testing/rtl_screen_offset_testing.tscn @@ -54,7 +54,7 @@ margin_right = 470.0 margin_bottom = 380.0 [node name="foo" type="CheckBox" parent="HBoxContainer2"] -margin_right = 624.0 +margin_right = 588.0 margin_bottom = 24.0 pressed = true group = SubResource( 1 ) @@ -62,14 +62,14 @@ text = "Foo" [node name="foobar" type="CheckBox" parent="HBoxContainer2"] margin_top = 28.0 -margin_right = 624.0 +margin_right = 588.0 margin_bottom = 52.0 group = SubResource( 1 ) text = "Foo bar" [node name="whatisit" type="CheckBox" parent="HBoxContainer2"] margin_top = 56.0 -margin_right = 624.0 +margin_right = 588.0 margin_bottom = 80.0 group = SubResource( 1 ) text = "A super extremely long sentence to test
the behaviour of that RichTextLabel node..." @@ -80,8 +80,8 @@ margin_top = 131.18 margin_right = 638.815 margin_bottom = 231.18 rect_min_size = Vector2( 400, 0 ) -bbcode_text = "Tooltip content" -text = "Tooltip content" +bbcode_text = "[center][color=#200606][/color][/center]" +text = "[center][color=#200606][/color][/center]" [connection signal="mouse_moved" from="." to="." method="_on_Control_mouse_moved"] [connection signal="text_selected" from="." to="." method="_on_Control_text_selected"] diff --git a/addons/escoria-core/testing/white.png.import b/addons/escoria-core/testing/white.png.import deleted file mode 100644 index 1b5c931c..00000000 --- a/addons/escoria-core/testing/white.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/white.png-e746adb12fed1043fc3bcc319345fecb.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://addons/escoria-core/testing/white.png" -dest_files=[ "res://.import/white.png-e746adb12fed1043fc3bcc319345fecb.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/game/items/escitems/bottle_escitem.tscn b/game/items/escitems/bottle_escitem.tscn index 2bfa1148..f1b4ed40 100644 --- a/game/items/escitems/bottle_escitem.tscn +++ b/game/items/escitems/bottle_escitem.tscn @@ -18,10 +18,10 @@ use_from_inventory_only = true inventory_item_scene_file = ExtResource( 3 ) dialog_color = Color( 1, 1, 1, 1 ) interact_positions = { -"default": Vector2( 59.3937, 58.8658 ) +"default": Vector2( 0, 0 ) } -[node name="Sprite" type="Sprite" parent="."] +[node name="sprite" type="Sprite" parent="."] texture = ExtResource( 2 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] diff --git a/game/items/escitems/pen_escitem.tscn b/game/items/escitems/pen_escitem.tscn index ecee8f78..ea460390 100644 --- a/game/items/escitems/pen_escitem.tscn +++ b/game/items/escitems/pen_escitem.tscn @@ -16,11 +16,12 @@ default_action = "look" combine_if_action_used_among = PoolStringArray( "use", "give" ) use_from_inventory_only = true inventory_item_scene_file = ExtResource( 3 ) +dialog_color = Color( 1, 1, 1, 1 ) interact_positions = { -"default": null +"default": Vector2( 0, 0 ) } -[node name="pen" type="Sprite" parent="."] +[node name="sprite" type="Sprite" parent="."] texture = ExtResource( 2 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] diff --git a/game/rooms/room2/room2.tscn b/game/rooms/room2/room2.tscn index 839f552c..2c730f09 100644 --- a/game/rooms/room2/room2.tscn +++ b/game/rooms/room2/room2.tscn @@ -16,8 +16,18 @@ player_scene = ExtResource( 4 ) camera_limits = [ Rect2( 0, 0, 1289, 555 ) ] [node name="walkable_area" parent="." instance=ExtResource( 1 )] +scales = null +bitmaps_scale = Vector2( 1, 1 ) +lightmap = null +player_speed_multiplier = 1.0 +player_doubleclick_speed_multiplier = 1.5 +lightmap_modulate = Color( 1, 1, 1, 1 ) +debug_mode = 1 +scale_min = 0.3 +scale_max = 1.0 [node name="background" parent="." instance=ExtResource( 2 )] +esc_script = "" [node name="room_label" type="Label" parent="background"] margin_right = 40.0 @@ -34,13 +44,26 @@ __meta__ = { script = ExtResource( 7 ) global_id = "r2_right_platform" esc_script = "res://game/rooms/room2/esc/right_platform.esc" +is_exit = false +is_trigger = false +trigger_in_verb = "trigger_in" +trigger_out_verb = "trigger_out" +is_interactive = true +player_orients_on_arrival = true interaction_direction = 3 tooltip_name = "Right platform" default_action = "look" +combine_if_action_used_among = PoolStringArray( ) +combine_is_one_way = false +use_from_inventory_only = false +inventory_item_scene_file = null dialog_color = Color( 1, 1, 1, 1 ) interact_positions = { "default": Vector2( 430.893, 451.052 ) } +animations = null +speed = 300 +v_speed_damp = 1.0 [node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Hotspots/r_platform"] polygon = PoolVector2Array( 870.974, 538.342, 827.536, 353.995, 1181.4, 357.174, 1287.34, 413.325, 1289.46, 545.758 ) @@ -53,12 +76,25 @@ script = ExtResource( 7 ) global_id = "r2_r_exit" esc_script = "res://game/rooms/room2/esc/right_exit.esc" is_exit = true +is_trigger = false +trigger_in_verb = "trigger_in" +trigger_out_verb = "trigger_out" +is_interactive = true +player_orients_on_arrival = true +interaction_direction = 0 tooltip_name = "Right exit" default_action = "walk" +combine_if_action_used_among = PoolStringArray( ) +combine_is_one_way = false +use_from_inventory_only = false +inventory_item_scene_file = null dialog_color = Color( 1, 1, 1, 1 ) interact_positions = { "default": Vector2( 1225.47, 353.99 ) } +animations = null +speed = 300 +v_speed_damp = 1.0 [node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Hotspots/r_door"] polygon = PoolVector2Array( 1177.94, 348.61, 1175.95, 45.3759, 1276.06, 92.0953, 1277.95, 399.407 ) @@ -71,12 +107,25 @@ script = ExtResource( 7 ) global_id = "r2_l_exit" esc_script = "res://game/rooms/room2/esc/left_exit.esc" is_exit = true +is_trigger = false +trigger_in_verb = "trigger_in" +trigger_out_verb = "trigger_out" +is_interactive = true +player_orients_on_arrival = true +interaction_direction = 0 tooltip_name = "Left exit" default_action = "walk" +combine_if_action_used_among = PoolStringArray( ) +combine_is_one_way = false +use_from_inventory_only = false +inventory_item_scene_file = null dialog_color = Color( 1, 1, 1, 1 ) interact_positions = { "default": Vector2( 52.1462, 384.691 ) } +animations = null +speed = 300 +v_speed_damp = 1.0 [node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Hotspots/l_door"] polygon = PoolVector2Array( -1.37926, 443.158, 7.96461, 122.796, 84.0504, 77.4118, 88.055, 377.751 ) @@ -88,10 +137,24 @@ position = Vector2( 52.1462, 384.691 ) position = Vector2( 958.107, 176.401 ) global_id = "r2_button_right" esc_script = "res://game/rooms/room2/esc/button.esc" +is_exit = false +is_trigger = false +trigger_in_verb = "trigger_in" +trigger_out_verb = "trigger_out" +is_interactive = true +player_orients_on_arrival = true +interaction_direction = 0 +combine_if_action_used_among = PoolStringArray( ) +combine_is_one_way = false +use_from_inventory_only = false +inventory_item_scene_file = null dialog_color = Color( 0, 1, 0.109804, 1 ) interact_positions = { "default": Vector2( 987.537, 371.812 ) } +animations = null +speed = 300 +v_speed_damp = 1.0 [node name="Position2D" type="Position2D" parent="Hotspots/button_right"] position = Vector2( 29.4302, 195.411 ) @@ -103,10 +166,24 @@ __meta__ = { position = Vector2( 288.82, 171.439 ) global_id = "r2_button" esc_script = "res://game/rooms/room2/esc/button.esc" +is_exit = false +is_trigger = false +trigger_in_verb = "trigger_in" +trigger_out_verb = "trigger_out" +is_interactive = true +player_orients_on_arrival = true +interaction_direction = 0 +combine_if_action_used_among = PoolStringArray( ) +combine_is_one_way = false +use_from_inventory_only = false +inventory_item_scene_file = null dialog_color = Color( 0, 1, 0.109804, 1 ) interact_positions = { "default": Vector2( 313.488, 368.437 ) } +animations = null +speed = 300 +v_speed_damp = 1.0 [node name="Position2D" type="Position2D" parent="Hotspots/button_left"] position = Vector2( 24.6681, 196.998 ) diff --git a/game/rooms/room5/room5.tscn b/game/rooms/room5/room5.tscn index d224b2e9..50c02e34 100644 --- a/game/rooms/room5/room5.tscn +++ b/game/rooms/room5/room5.tscn @@ -77,6 +77,15 @@ text = "ROOM 5" [node name="walkable_area" type="Navigation2D" parent="."] script = ExtResource( 1 ) +scales = null +bitmaps_scale = Vector2( 1, 1 ) +lightmap = null +player_speed_multiplier = 1.0 +player_doubleclick_speed_multiplier = 1.5 +lightmap_modulate = Color( 1, 1, 1, 1 ) +debug_mode = 1 +scale_min = 0.3 +scale_max = 1.0 [node name="platform" type="NavigationPolygonInstance" parent="walkable_area"] position = Vector2( 6.73163, -264.779 ) @@ -150,7 +159,6 @@ position = Vector2( -77.4207, 0 ) [node name="pen" parent="Hotspots" instance=ExtResource( 10 )] position = Vector2( 909.908, 443.451 ) -dialog_color = Color( 1, 1, 1, 1 ) interact_positions = { "default": Vector2( 909.908, 443.451 ) } diff --git a/game/ui/ui_9verbs/game.gd b/game/ui/ui_9verbs/game.gd index e414731c..a66785d1 100644 --- a/game/ui/ui_9verbs/game.gd +++ b/game/ui/ui_9verbs/game.gd @@ -31,9 +31,6 @@ Implement methods to react to inputs. - _on_event_done(event_name: String) """ -func _ready(): - escoria.esc_runner.connect("event_done", self, "_on_event_done") - func _input(event): if event.is_action_pressed("switch_action_verb"): diff --git a/game/ui/ui_9verbs/game.tscn b/game/ui/ui_9verbs/game.tscn index ec4a3b51..a6644e5f 100644 --- a/game/ui/ui_9verbs/game.tscn +++ b/game/ui/ui_9verbs/game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=2] +[gd_scene load_steps=10 format=2] [ext_resource path="res://game/ui/ui_9verbs/tooltip/action_target_tooltip.tscn" type="PackedScene" id=1] [ext_resource path="res://game/ui/ui_9verbs/inventory/inventory_ui.tscn" type="PackedScene" id=2] @@ -7,6 +7,7 @@ [ext_resource path="res://game/ui/ui_9verbs/game.gd" type="Script" id=5] [ext_resource path="res://addons/escoria-core/game/scenes/camera_player/camera.tscn" type="PackedScene" id=6] [ext_resource path="res://game/ui/commons/room_select.tscn" type="PackedScene" id=7] +[ext_resource path="res://game/ui/ui_9verbs/tooltip/tooltip_action_target.gd" type="Script" id=8] [sub_resource type="StyleBoxFlat" id=1] bg_color = Color( 0.6, 0.6, 0.6, 0.5 ) @@ -54,14 +55,15 @@ margin_bottom = 615.331 layer = 2 [node name="tooltip" parent="ui/tooltip_layer" instance=ExtResource( 1 )] -anchor_left = 0.208 -anchor_top = 0.722 -anchor_right = 0.734 -anchor_bottom = 0.77 -margin_left = 0.383453 -margin_top = 0.364075 -margin_right = 0.103394 -margin_bottom = -0.0359497 +anchor_left = 0.132 +anchor_top = 0.719 +anchor_right = 0.832 +anchor_bottom = 0.767 +margin_left = 0.0272522 +margin_top = 0.320557 +margin_right = -0.252686 +margin_bottom = -0.0794678 +script = ExtResource( 8 ) [node name="dialog_layer" type="CanvasLayer" parent="ui"] layer = 3 diff --git a/game/ui/ui_9verbs/tooltip/action_target_tooltip.gd b/game/ui/ui_9verbs/tooltip/action_target_tooltip.gd deleted file mode 100644 index 6e13da73..00000000 --- a/game/ui/ui_9verbs/tooltip/action_target_tooltip.gd +++ /dev/null @@ -1,55 +0,0 @@ -extends RichTextLabel - -# Infinitive verb -var current_action : String -# Target item/hotspot -var current_target : String -# Preposition: on, with... -var current_prep : String = "with" -# Target 2 item/hotspot -var current_target2 : String - -var waiting_for_target2 = false - -func _ready(): - escoria.esc_runner.connect("action_changed", self, "on_action_selected") - - -func on_action_selected() -> void: - current_action = escoria.esc_runner.current_action - update_tooltip_text() - - -func set_target(target : String, needs_second_target : bool = false) -> void: - current_target = target - if needs_second_target: - waiting_for_target2 = true - - update_tooltip_text() - - -func set_target2(target2 : String) -> void: - current_target2 = target2 - update_tooltip_text() - - -func update_tooltip_text(): - bbcode_text = "[center]" - - if !current_action.empty(): - bbcode_text += current_action - bbcode_text += "\t" - - bbcode_text += current_target - - if waiting_for_target2 and current_target2.empty(): - bbcode_text += "\t" - bbcode_text += current_prep - - if !current_target2.empty(): - bbcode_text += "\t" - bbcode_text += current_prep - bbcode_text += "\t" - bbcode_text += current_target2 - - bbcode_text += "[/center]" diff --git a/game/ui/ui_9verbs/tooltip/action_target_tooltip.tscn b/game/ui/ui_9verbs/tooltip/action_target_tooltip.tscn index fad2b5fb..63850ad1 100644 --- a/game/ui/ui_9verbs/tooltip/action_target_tooltip.tscn +++ b/game/ui/ui_9verbs/tooltip/action_target_tooltip.tscn @@ -1,7 +1,6 @@ [gd_scene load_steps=5 format=2] [ext_resource path="res://addons/escoria-core/game/assets/fonts/onesize/ONESIZE_.TTF" type="DynamicFontData" id=1] -[ext_resource path="res://game/ui/ui_9verbs/tooltip/action_target_tooltip.gd" type="Script" id=2] [sub_resource type="DynamicFont" id=1] size = 30 @@ -11,16 +10,44 @@ font_data = ExtResource( 1 ) size = 30 font_data = ExtResource( 1 ) +[sub_resource type="GDScript" id=3] +script/source = "extends ESCTooltip + + +func update_tooltip_text(): + bbcode_text = \"[center]\" + + if !current_action.empty(): + bbcode_text += current_action + bbcode_text += \"\\t\" + + bbcode_text += current_target + + if waiting_for_target2 and current_target2.empty(): + bbcode_text += \"\\t\" + bbcode_text += current_prep + + if !current_target2.empty(): + bbcode_text += \"\\t\" + bbcode_text += current_prep + bbcode_text += \"\\t\" + bbcode_text += current_target2 + + bbcode_text += \"[/center]\" +" + [node name="tooltip" type="RichTextLabel"] -anchor_right = 0.526 +anchor_right = 0.7 anchor_bottom = 0.06 -margin_right = -0.280029 +margin_left = 1.49829 +margin_right = 1.21826 margin_bottom = -10.0 custom_fonts/mono_font = SubResource( 1 ) custom_fonts/normal_font = SubResource( 2 ) bbcode_enabled = true +bbcode_text = "[center][/center]" scroll_active = false -script = ExtResource( 2 ) +script = SubResource( 3 ) __meta__ = { "_edit_use_anchors_": false } diff --git a/game/ui/ui_9verbs/tooltip/tooltip_action_target.gd b/game/ui/ui_9verbs/tooltip/tooltip_action_target.gd new file mode 100644 index 00000000..8f16906a --- /dev/null +++ b/game/ui/ui_9verbs/tooltip/tooltip_action_target.gd @@ -0,0 +1,17 @@ +extends ESCTooltip + +func update_tooltip_text(): + push_align(RichTextLabel.ALIGN_CENTER) + + if !current_action.empty(): + add_text(current_action + "\t") + + add_text(current_target) + + if waiting_for_target2 and current_target2.empty(): + add_text("\t" + current_prep) + + if !current_target2.empty(): + add_text("\t" + current_prep + "\t" + current_target2) + + pop() diff --git a/game/ui/ui_mouse_icons/game.gd b/game/ui/ui_mouse_icons/game.gd index fc7f238b..393bc6cc 100644 --- a/game/ui/ui_mouse_icons/game.gd +++ b/game/ui/ui_mouse_icons/game.gd @@ -11,17 +11,15 @@ Implement methods to react to inputs. - element_focused(element_id : String) - element_unfocused() -- left_click_on_hotspot(hotspot_global_id : String, event : InputEvent) -- right_click_on_hotspot(hotspot_global_id : String, event : InputEvent) -- left_double_click_on_hotspot(hotspot_global_id : String, event : InputEvent) - - left_click_on_item(item_global_id : String, event : InputEvent) - right_click_on_item(item_global_id : String, event : InputEvent) - left_double_click_on_item(item_global_id : String, event : InputEvent) -- inventory_item_focused(inventory_item_global_id : String) -> void -- inventory_item_unfocused() -> void - +- left_click_on_inventory_item(inventory_item_global_id : String, event : InputEvent) +- right_click_on_inventory_item(inventory_item_global_id : String, event : InputEvent) +- left_double_click_on_inventory_item(inventory_item_global_id : String, event : InputEvent) +- inventory_item_focused(inventory_item_global_id : String) +- inventory_item_unfocused() - open_inventory() - close_inventory() @@ -31,7 +29,6 @@ Implement methods to react to inputs. - show_ui() - _on_event_done(event_name: String) -- update_tooltip_position(p_position : Vector2) """ @@ -40,27 +37,32 @@ Implement methods to react to inputs. func left_click_on_bg(position : Vector2) -> void: escoria.do("walk", ["player", position]) $ui/verbs_layer/verbs_menu.set_by_name("walk") + $ui/verbs_layer/verbs_menu.clear_tool_texture() func right_click_on_bg(position : Vector2) -> void: escoria.do("walk", ["player", position]) $ui/verbs_layer/verbs_menu.set_by_name("walk") + $ui/verbs_layer/verbs_menu.clear_tool_texture() func left_double_click_on_bg(position : Vector2) -> void: escoria.do("walk", ["player", position, true]) $ui/verbs_layer/verbs_menu.set_by_name("walk") + $ui/verbs_layer/verbs_menu.clear_tool_texture() ## ITEM/HOTSPOT FOCUS ## func element_focused(element_id : String) -> void: var target_obj = escoria.esc_runner.get_object(element_id) - $ui/tooltip_layer/tooltip.text = target_obj.tooltip_name - + $ui/tooltip_layer/tooltip.set_target(target_obj.tooltip_name) + $ui/tooltip_layer/tooltip.show() + if escoria.esc_runner.current_action != "use" && escoria.esc_runner.current_tool == null: if target_obj is ESCItem: $ui/verbs_layer/verbs_menu.set_by_name(target_obj.default_action) func element_unfocused() -> void: - $ui/tooltip_layer/tooltip.text = "" + $ui/tooltip_layer/tooltip.set_target("") + $ui/tooltip_layer/tooltip.hide() ## ITEMS ## @@ -80,8 +82,8 @@ func left_click_on_inventory_item(inventory_item_global_id : String, event : Inp escoria.do("item_left_click", [inventory_item_global_id, event]) if escoria.esc_runner.current_action == "use": var item = escoria.esc_runner.get_object(inventory_item_global_id) - if item.texture: - $ui/verbs_layer/verbs_menu.set_tool_texture(item.texture) + if item.get_node("sprite").texture: + $ui/verbs_layer/verbs_menu.set_tool_texture(item.get_node("sprite").texture) elif item.inventory_item_scene_file.instance().texture_normal: $ui/verbs_layer/verbs_menu.set_tool_texture(item.inventory_item_scene_file.instance().texture_normal) @@ -117,8 +119,4 @@ func show_ui(): func _on_event_done(event_name: String): escoria.esc_runner.clear_current_action() - - -func update_tooltip_position(p_position : Vector2): -# + Vector2(-200,-50) - $ui/tooltip_layer/tooltip.global_position = p_position + $ui/verbs_layer/verbs_menu.clear_tool_texture() diff --git a/game/ui/ui_mouse_icons/game.tscn b/game/ui/ui_mouse_icons/game.tscn index 8bdc5eee..b4a6aa79 100644 --- a/game/ui/ui_mouse_icons/game.tscn +++ b/game/ui/ui_mouse_icons/game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=8 format=2] [ext_resource path="res://game/ui/ui_mouse_icons/inventory/inventory_ui.tscn" type="PackedScene" id=1] [ext_resource path="res://addons/escoria-core/game/scenes/dialogs/dialog_player.tscn" type="PackedScene" id=2] @@ -6,9 +6,11 @@ [ext_resource path="res://game/ui/ui_mouse_icons/verbs_mouseicons.tscn" type="PackedScene" id=4] [ext_resource path="res://game/ui/ui_mouse_icons/game.gd" type="Script" id=5] [ext_resource path="res://game/ui/ui_mouse_icons/tooltip/target_tooltip.tscn" type="PackedScene" id=6] +[ext_resource path="res://game/ui/commons/room_select.tscn" type="PackedScene" id=7] [node name="game" type="Node2D"] script = ExtResource( 5 ) +editor_debug_mode = 1 [node name="ui" type="CanvasLayer" parent="."] @@ -35,10 +37,20 @@ layer = 2 [node name="tooltip" parent="ui/tooltip_layer" instance=ExtResource( 6 )] mouse_filter = 2 +bbcode_text = "[center][color=#000000][/color][/center]" +color = Color( 0, 0, 0, 1 ) +offset_from_cursor = Vector2( 75, 10 ) +debug_mode = true [node name="dialog_layer" type="CanvasLayer" parent="ui"] layer = 3 [node name="dialog_player" parent="ui/dialog_layer" instance=ExtResource( 2 )] +[node name="room_select" parent="ui" instance=ExtResource( 7 )] +margin_left = 75.5099 +margin_top = 751.323 +margin_right = 138.51 +margin_bottom = 791.324 + [node name="camera" parent="." instance=ExtResource( 3 )] diff --git a/game/ui/ui_mouse_icons/tooltip/target_tooltip.gd b/game/ui/ui_mouse_icons/tooltip/target_tooltip.gd deleted file mode 100644 index 759c09ac..00000000 --- a/game/ui/ui_mouse_icons/tooltip/target_tooltip.gd +++ /dev/null @@ -1,10 +0,0 @@ -extends RichTextLabel - -var current_target : String - -func set_target(target : String) -> void: - current_target = target - update_tooltip_text() - -func update_tooltip_text(): - bbcode_text = current_target diff --git a/game/ui/ui_mouse_icons/tooltip/target_tooltip.tscn b/game/ui/ui_mouse_icons/tooltip/target_tooltip.tscn index 8ede150e..5baa1922 100644 --- a/game/ui/ui_mouse_icons/tooltip/target_tooltip.tscn +++ b/game/ui/ui_mouse_icons/tooltip/target_tooltip.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=5 format=2] [ext_resource path="res://addons/escoria-core/game/assets/fonts/onesize/ONESIZE_.TTF" type="DynamicFontData" id=1] -[ext_resource path="res://game/ui/ui_mouse_icons/tooltip/target_tooltip.gd" type="Script" id=2] +[ext_resource path="res://game/ui/ui_mouse_icons/tooltip/tooltip_target.gd" type="Script" id=2] [sub_resource type="DynamicFont" id=1] size = 30 @@ -12,17 +12,17 @@ size = 30 font_data = ExtResource( 1 ) [node name="tooltip" type="RichTextLabel"] -anchor_right = 0.7 -anchor_bottom = 0.06 -margin_left = 1.49829 -margin_right = 1.21826 -margin_bottom = -10.0 +margin_right = 200.0 +margin_bottom = 32.0 +rect_min_size = Vector2( 200, 32 ) custom_fonts/mono_font = SubResource( 1 ) custom_fonts/normal_font = SubResource( 2 ) bbcode_enabled = true -bbcode_text = "[center][/center]" +bbcode_text = "[center][color=#ffffff][/color][/center]" scroll_active = false script = ExtResource( 2 ) __meta__ = { "_edit_use_anchors_": false } +color = Color( 1, 1, 1, 1 ) +offset_from_cursor = Vector2( 100, 10 ) diff --git a/game/ui/ui_mouse_icons/tooltip/tooltip_target.gd b/game/ui/ui_mouse_icons/tooltip/tooltip_target.gd new file mode 100644 index 00000000..e7b0a5d7 --- /dev/null +++ b/game/ui/ui_mouse_icons/tooltip/tooltip_target.gd @@ -0,0 +1,16 @@ +tool +extends ESCTooltip + +func update_tooltip_text(): + print("new color " + str(color)) + 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() + update_size() diff --git a/project.godot b/project.godot index 97421767..1ccdf3f6 100644 --- a/project.godot +++ b/project.godot @@ -64,6 +64,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/escoria-core/game/core-scripts/escterrain.gd" }, { +"base": "RichTextLabel", +"class": "ESCTooltip", +"language": "GDScript", +"path": "res://addons/escoria-core/game/core-scripts/esctooltip.gd" +}, { "base": "Node", "class": "Movable", "language": "GDScript", @@ -81,6 +86,7 @@ _global_script_class_icons={ "ESCPlayer": "", "ESCRoom": "", "ESCTerrain": "", +"ESCTooltip": "", "Movable": "" } @@ -119,11 +125,11 @@ main/force_quit=true debug/terminate_on_warnings=false debug/terminate_on_errors=true debug/development_lang="en" -ui/tooltip_follows_mouse=false +ui/tooltip_follows_mouse=true ui/dialogs_folder="res://game/ui/commons/dialogs" ui/default_dialog_scene="res://game/ui/commons/dialogs/dialog_label.tscn" ui/main_menu_scene="res://game/ui/commons/main_menu.tscn" -ui/game_scene="res://game/ui/ui_9verbs/game.tscn" +ui/game_scene="res://game/ui/ui_mouse_icons/game.tscn" internals/save_data="" [input]