Hi all, I just started learning Godot. And I am trying to make a dialogue manager in a 2d shop game for the customers but I can’t figure out how to design the speech bubble.
Since the customer approaches the counter at the same place every time I want the speech bubble to be static as well. But if there is more text the bubble should expand sidewards until a max width and then upwards.
As to not mess with the art I am using a NinePatchRect node for my speech bubble sprite, but I can’t figure out a way to map the bubble to expand with the text.
Currently the NinePatchRect controls the RichText , is there a way that it can be the opposite, like a script could spawn the text based on whatever character approaches the counter and the speech bubble configures to border the text.
You would have to design some system to get the necessary text box size according to its content, but after that it should just be as straight-forward as setting PromptLabel’s anchors_preset to “Full rect” and setting MarginContainer’s size to whatever is necessary to fit the text, plus the margin.
@onready var bubble_frame: NinePatchRect = $".." # path to BubbleFrame
@onready var text_margin_container: MarginContainer = $".." # path to MarginContainer
@onready var prompt_label: RichTextLabel = $".." # path to PromptLabel
func get_bounding_box(label: RichTextLabel) -> Rect2:
return Rect2() # however you want to determine the box
func _on_prompt_label_text_changed() -> void:
var size := get_bounding_box(prompt_label).size
var margin_left: int = text_margin_container.get_theme_constant(&"margin_left")
var margin_right: int = text_margin_container.get_theme_constant(&"margin_right")
var margin_top: int = text_margin_container.get_theme_constant(&"margin_top")
var margin_bottom: int = text_margin_container.get_theme_constant(&"margin_bottom")
var margin_size := size + Vector2(margin_left + margin_right, margin_top + margin_bottom)
bubble_frame.size = margin_size
text_margin_container.size = margin_size