diff options
author | Hop311 <Hop3114@gmail.com> | 2024-09-20 00:48:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-20 00:48:10 +0200 |
commit | 8f0538b74fd274721a3178bff9b1294a71af3431 (patch) | |
tree | 6dbafe4337ceb672a6e5972b0155333f73cbf262 /game/src/Game/GameSession | |
parent | 110a6ad29fb84e4507698897e97aab3f36b24242 (diff) | |
parent | c26247464feabe0fbb9d6a8527b242d667faa066 (diff) |
Merge pull request #270 from OpenVicProject/tall-tooltip
Allow tooltips to be as tall as the window + shift them to stay inside it
Diffstat (limited to 'game/src/Game/GameSession')
-rw-r--r-- | game/src/Game/GameSession/Tooltip.gd | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/game/src/Game/GameSession/Tooltip.gd b/game/src/Game/GameSession/Tooltip.gd index c110e2e..f079e4c 100644 --- a/game/src/Game/GameSession/Tooltip.gd +++ b/game/src/Game/GameSession/Tooltip.gd @@ -7,17 +7,48 @@ func _ready() -> void: _tooltip_label = get_gui_label_from_nodepath(^"./ToolTip") if _tooltip_label: + _update_tooltip_max_size() _tooltip_label.set_auto_adjust_to_content_size(true) MenuSingleton.update_tooltip.connect(update_tooltip) hide() +func _notification(what : int) -> void: + match what: + NOTIFICATION_RESIZED: + _update_tooltip_max_size() + +func _update_tooltip_max_size() -> void: + if _tooltip_label: + var max_size : Vector2 = _tooltip_label.get_base_max_size() + var window_size : Vector2 = get_size() + _tooltip_label.set_max_size(Vector2(min(max_size.x, window_size.x), window_size.y)) + func update_tooltip(text : String, substitution_dict : Dictionary, position : Vector2) -> void: - if text: + if text and _tooltip_label: _tooltip_label.set_text(text) _tooltip_label.set_substitution_dict(substitution_dict) + _tooltip_label.force_update_lines() + + var adjusted_rect : Rect2 = _tooltip_label.get_adjusted_rect() + + # Shift position so that the tooltip doesn't go past the bottom or right sides of the window + var bottom_right : Vector2 = position + adjusted_rect.position + adjusted_rect.size - get_size() + if bottom_right.x > 0: + position.x -= bottom_right.x + if bottom_right.y > 0: + position.y -= bottom_right.y + + # Shift position so that the tooltip doesn't go past the top or left sides of the window + var top_left : Vector2 = position + adjusted_rect.position + if top_left.x < 0: + position.x -= top_left.x + if top_left.y < 0: + position.y -= top_left.y + _tooltip_label.set_position(position) + show() else: hide() |