Fix tooltip_node wrong references (#332)
* Created a signal room_ready in ESCMain to notify ESCTooltip that it is ready. Fixes #302 * docs: Automatic update of API docs Co-authored-by: StraToN <StraToN@users.noreply.github.com>
This commit is contained in:
@@ -1,46 +1,69 @@
|
||||
# A tooltip displaying <verb> <item1> [<item2>]
|
||||
|
||||
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
|
||||
|
||||
# Color of the label
|
||||
export(Color) var color setget set_color
|
||||
|
||||
# Vector2 defining the offset from the cursor
|
||||
export(Vector2) var offset_from_cursor = Vector2(10,0)
|
||||
|
||||
# Activates debug mode. If enabled, shows the label with a white background.
|
||||
export(bool) var debug_mode = false setget set_debug_mode
|
||||
|
||||
# Node containing the debug white background
|
||||
var debug_texturerect_node: TextureRect
|
||||
|
||||
# Maximum width of the label
|
||||
const MAX_WIDTH = 200
|
||||
|
||||
# Minimum height of the label
|
||||
const MIN_HEIGHT = 30
|
||||
|
||||
# Maximum height of the label
|
||||
const MAX_HEIGHT = 500
|
||||
|
||||
# Height of one line in the label
|
||||
const ONE_LINE_HEIGHT = 16
|
||||
|
||||
|
||||
|
||||
# Ready function
|
||||
func _ready():
|
||||
if escoria.main.current_scene:
|
||||
escoria.main.current_scene.game.tooltip_node = self
|
||||
escoria.action_manager.connect("action_changed", self, "on_action_selected")
|
||||
escoria.main.connect("room_ready", self, "_on_room_ready")
|
||||
escoria.action_manager.connect("action_changed", self, "_on_action_selected")
|
||||
|
||||
|
||||
|
||||
# Set the color of the label
|
||||
#
|
||||
# ## Parameters
|
||||
# - p_color: the color to set the label
|
||||
func set_color(p_color: Color):
|
||||
color = p_color
|
||||
update_tooltip_text()
|
||||
|
||||
|
||||
# Enable/disable debug mode of the label. If enabled, the label is displayed
|
||||
# with a white background.
|
||||
#
|
||||
# ## Parameters
|
||||
# - p_debug_mode: if true, enable debug mode. False to disable
|
||||
func set_debug_mode(p_debug_mode: bool):
|
||||
debug_mode = p_debug_mode
|
||||
if debug_mode:
|
||||
@@ -61,12 +84,18 @@ func set_debug_mode(p_debug_mode: bool):
|
||||
if debug_texturerect_node:
|
||||
remove_child(debug_texturerect_node)
|
||||
|
||||
|
||||
func on_action_selected() -> void:
|
||||
|
||||
# Called when an action is selected in Escoria
|
||||
func _on_action_selected() -> void:
|
||||
current_action = escoria.action_manager.current_action
|
||||
update_tooltip_text()
|
||||
|
||||
|
||||
# Set the first target of the label.
|
||||
#
|
||||
# ## Parameters
|
||||
# - target: String the target to add to the label
|
||||
# - needs_second_target: if true, the label will prepare for a second target
|
||||
func set_target(target: String, needs_second_target: bool = false) -> void:
|
||||
current_target = target
|
||||
if needs_second_target:
|
||||
@@ -74,12 +103,16 @@ func set_target(target: String, needs_second_target: bool = false) -> void:
|
||||
update_tooltip_text()
|
||||
|
||||
|
||||
# Set the second target of the label
|
||||
#
|
||||
# ## Parameters
|
||||
# - target2: String the second target to add to the label
|
||||
func set_target2(target2: String) -> void:
|
||||
current_target2 = target2
|
||||
update_tooltip_text()
|
||||
|
||||
|
||||
|
||||
# Update the tooltip text.
|
||||
func update_tooltip_text():
|
||||
"""
|
||||
Overriden method. Should not be called directly.
|
||||
@@ -87,7 +120,7 @@ func update_tooltip_text():
|
||||
pass
|
||||
|
||||
|
||||
|
||||
# Update the tooltip size according to the text.
|
||||
func update_size():
|
||||
## RECT_SIZE ##
|
||||
var rtl_width = rect_size.x
|
||||
@@ -132,7 +165,14 @@ func update_size():
|
||||
# printt("AFTER", "text_height", get_content_height(), "rtl_height", rect_size.y)
|
||||
|
||||
|
||||
func _offset(position):
|
||||
# Calculate the offset of the label depending on its position.
|
||||
#
|
||||
# ## Parameters
|
||||
# - position: the position to test
|
||||
#
|
||||
# **Return**
|
||||
# The calculated offset
|
||||
func _offset(position: Vector2) -> Vector2:
|
||||
var center_offset_x = rect_size.x / 2
|
||||
var offset_y = 5
|
||||
|
||||
@@ -142,19 +182,56 @@ func _offset(position):
|
||||
return position
|
||||
|
||||
|
||||
# Return the tooltip distance to top edge.
|
||||
#
|
||||
# ## Parameters
|
||||
# - position: the position to test
|
||||
#
|
||||
# **Return**
|
||||
# The distance to the edge.
|
||||
func tooltip_distance_to_edge_top(position: Vector2):
|
||||
return position.y
|
||||
|
||||
|
||||
# Return the tooltip distance to bottom edge.
|
||||
#
|
||||
# ## Parameters
|
||||
# - position: the position to test
|
||||
#
|
||||
# **Return**
|
||||
# The distance to the edge.
|
||||
func tooltip_distance_to_edge_bottom(position: Vector2):
|
||||
return escoria.game_size.y - position.y
|
||||
|
||||
|
||||
# Return the tooltip distance to left edge.
|
||||
#
|
||||
# ## Parameters
|
||||
# - position: the position to test
|
||||
#
|
||||
# **Return**
|
||||
# The distance to the edge.
|
||||
func tooltip_distance_to_edge_left(position: Vector2):
|
||||
return position.x
|
||||
|
||||
|
||||
# Return the tooltip distance to right edge.
|
||||
#
|
||||
# ## Parameters
|
||||
# - position: the position to test
|
||||
#
|
||||
# **Return**
|
||||
# The distance to the edge.
|
||||
func tooltip_distance_to_edge_right(position: Vector2):
|
||||
return escoria.game_size.x - position.x
|
||||
|
||||
|
||||
# Clear the tooltip targets texts
|
||||
func clear():
|
||||
set_target("")
|
||||
set_target2("")
|
||||
|
||||
|
||||
# Called when the room is loaded to setup the label.
|
||||
func _on_room_ready():
|
||||
escoria.main.current_scene.game.tooltip_node = self
|
||||
|
||||
Reference in New Issue
Block a user