Size CCS speech bubbles to content

This commit is contained in:
hz
2026-08-06 20:39:40 -05:00
parent dfc224660e
commit 6e039f00a7
3 changed files with 45 additions and 2 deletions
+17
View File
@@ -12,6 +12,9 @@ const CHOICE_CROP := Rect2(80.0, 200.0, 1610.0, 485.0)
const CHOICES_PER_PAGE := 4
const DIALOGUE_PAGE_MIN_CHARS := 32
const DIALOGUE_PAGE_MAX_CHARS := 82
const DIALOGUE_BUBBLE_MIN_HEIGHT := 150.0
const DIALOGUE_BUBBLE_MAX_HEIGHT := 240.0
const DIALOGUE_BUBBLE_VERTICAL_CHROME := 83.0
@onready var hour_hand: Node2D = $ClockMount/HourHand
@onready var minute_hand: Node2D = $ClockMount/MinuteHand
@@ -39,6 +42,7 @@ var dialogue_pages: Array[String] = []
var dialogue_page_index := 0
var dialogue_characters_per_second := 35.0
var dialogue_reveal_complete := false
var dialogue_layout_generation := 0
func _ready() -> void:
@@ -119,6 +123,17 @@ func _show_dialogue_page() -> void:
dialogue_continue_hint.visible = false
dialogue_bubble.visible = true
dialogue_bubble.grab_focus()
dialogue_layout_generation += 1
call_deferred("_prepare_dialogue_page", dialogue_layout_generation)
func _prepare_dialogue_page(generation: int) -> void:
if generation != dialogue_layout_generation or not dialogue_bubble.visible \
or dialogue_reveal_complete:
return
var measured_height := dialogue_text.get_content_height() + DIALOGUE_BUBBLE_VERTICAL_CHROME
dialogue_bubble.size.y = clampf(
measured_height, DIALOGUE_BUBBLE_MIN_HEIGHT, DIALOGUE_BUBBLE_MAX_HEIGHT)
var reveal_duration := float(dialogue_text.text.length()) / maxf(dialogue_characters_per_second, 1.0)
dialogue_tween = create_tween()
dialogue_tween.tween_property(dialogue_text, "visible_ratio", 1.0, reveal_duration)
@@ -128,6 +143,7 @@ func _show_dialogue_page() -> void:
func hide_patient_dialogue() -> void:
if dialogue_tween and dialogue_tween.is_valid():
dialogue_tween.kill()
dialogue_layout_generation += 1
dialogue_bubble.visible = false
dialogue_continue_hint.visible = false
dialogue_pages = []
@@ -166,6 +182,7 @@ func complete_dialogue_reveal() -> void:
return
if dialogue_tween and dialogue_tween.is_valid():
dialogue_tween.kill()
dialogue_layout_generation += 1
dialogue_text.visible_ratio = 1.0
_on_dialogue_reveal_finished()