Skip to content

Commit

Permalink
Fix sizing in example balloon when dialogue spans multiple lines
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanhoad committed Feb 6, 2022
1 parent ad6dac4 commit 8d44afc
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 11 deletions.
20 changes: 17 additions & 3 deletions addons/dialogue_manager/example_balloon/example_balloon.gd
Expand Up @@ -11,6 +11,7 @@ const MenuItem = preload("res://addons/dialogue_manager/example_balloon/menu_ite
onready var balloon := $Balloon
onready var margin := $Balloon/Margin
onready var character_label := $Balloon/Margin/VBox/Character
onready var size_check_label := $SizeCheck
onready var dialogue_label := $Balloon/Margin/VBox/Dialogue
onready var responses_menu := $Balloon/Margin/VBox/Responses/Menu

Expand All @@ -20,6 +21,7 @@ var dialogue: Line

func _ready() -> void:
balloon.visible = false
size_check_label.modulate.a = 0

if not dialogue:
queue_free()
Expand All @@ -30,9 +32,18 @@ func _ready() -> void:
character_label.bbcode_text = dialogue.character
else:
character_label.visible = false

dialogue_label.dialogue = dialogue

# For some reason, RichTextLabels within containers
# don't resize properly when their content changes
size_check_label.bbcode_text = dialogue.dialogue
# Give the size check a chance to resize
yield(get_tree(), "idle_frame")

# Resize our dialogue label with the new size hint
dialogue_label.rect_min_size = Vector2(size_check_label.rect_size.x, size_check_label.get_content_height())
dialogue_label.rect_size = Vector2(0, 0)

# Show any responses we have
responses_menu.is_active = false
for item in responses_menu.get_children():
Expand All @@ -46,11 +57,13 @@ func _ready() -> void:

# Make sure our responses get included in the height reset
responses_menu.visible = true
margin.rect_size = Vector2(0, 0)

yield(get_tree(), "idle_frame")

balloon.rect_min_size = margin.rect_size
balloon.rect_size = Vector2(0, -1)
balloon.rect_global_position = Vector2(0, balloon.get_viewport_rect().size.y - balloon.rect_size.y)
balloon.rect_size = Vector2(0, 0)
balloon.rect_global_position = Vector2(0, balloon.get_viewport().size.y - balloon.rect_size.y)

# Ok, we can hide it now. It will come back later if we have any responses
responses_menu.visible = false
Expand All @@ -66,6 +79,7 @@ func _ready() -> void:
if dialogue.responses.size() > 1:
responses_menu.is_active = true
responses_menu.visible = true
responses_menu.index = 0
var response = yield(responses_menu, "actioned")
next_id = dialogue.responses[response[0]].next_id
else:
Expand Down
43 changes: 36 additions & 7 deletions addons/dialogue_manager/example_balloon/example_balloon.tscn
@@ -1,4 +1,4 @@
[gd_scene load_steps=12 format=2]
[gd_scene load_steps=15 format=2]

[ext_resource path="res://addons/dialogue_manager/example_balloon/example_balloon.gd" type="Script" id=1]
[ext_resource path="res://addons/dialogue_manager/example_balloon/menu.tscn" type="PackedScene" id=2]
Expand All @@ -24,13 +24,24 @@ font_data = ExtResource( 5 )
size = 25
font_data = ExtResource( 4 )

[sub_resource type="DynamicFont" id=8]
size = 25
font_data = ExtResource( 6 )

[sub_resource type="DynamicFont" id=9]
size = 25
font_data = ExtResource( 5 )

[sub_resource type="DynamicFont" id=10]
size = 25
font_data = ExtResource( 4 )

[node name="ExampleBalloon" type="CanvasLayer"]
layer = 128
script = ExtResource( 1 )

[node name="Balloon" type="Control" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
Expand All @@ -44,6 +55,7 @@ __meta__ = {

[node name="Margin" type="MarginContainer" parent="Balloon"]
anchor_right = 1.0
anchor_bottom = 1.0
custom_constants/margin_right = 40
custom_constants/margin_top = 10
custom_constants/margin_left = 40
Expand All @@ -55,12 +67,12 @@ __meta__ = {
[node name="VBox" type="VBoxContainer" parent="Balloon/Margin"]
margin_left = 40.0
margin_top = 10.0
margin_right = 1880.0
margin_right = 984.0
margin_bottom = 84.0

[node name="Character" type="RichTextLabel" parent="Balloon/Margin/VBox"]
modulate = Color( 1, 1, 1, 0.470588 )
margin_right = 1840.0
margin_right = 944.0
margin_bottom = 30.0
rect_min_size = Vector2( 0, 30 )
custom_colors/default_color = Color( 0, 0, 0, 1 )
Expand All @@ -70,8 +82,9 @@ scroll_active = false

[node name="Dialogue" parent="Balloon/Margin/VBox" instance=ExtResource( 7 )]
margin_top = 34.0
margin_right = 1840.0
margin_right = 944.0
margin_bottom = 70.0
rect_clip_content = false
custom_colors/default_color = Color( 0, 0, 0, 1 )
custom_fonts/italics_font = SubResource( 5 )
custom_fonts/bold_font = SubResource( 6 )
Expand All @@ -81,15 +94,14 @@ text = "This is a bunch of dialogue!"

[node name="Responses" type="MarginContainer" parent="Balloon/Margin/VBox"]
margin_top = 74.0
margin_right = 1840.0
margin_right = 944.0
margin_bottom = 74.0
custom_constants/margin_left = 40
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Menu" parent="Balloon/Margin/VBox/Responses" instance=ExtResource( 2 )]
margin_right = 1840.0
margin_bottom = 0.0
_pointer = NodePath("../Pointer")

Expand All @@ -98,3 +110,20 @@ position = Vector2( 29.6, 13 )
texture = ExtResource( 3 )
centered = false
offset = Vector2( -20, -10 )

[node name="SizeCheck" type="RichTextLabel" parent="."]
margin_top = 649.0
margin_right = 944.0
margin_bottom = 689.0
custom_fonts/italics_font = SubResource( 8 )
custom_fonts/bold_font = SubResource( 9 )
custom_fonts/normal_font = SubResource( 10 )
bbcode_enabled = true
bbcode_text = "This is used for sizing."
meta_underlined = false
text = "This is used for sizing."
fit_content_height = true
scroll_active = false
__meta__ = {
"_edit_use_anchors_": false
}
2 changes: 1 addition & 1 deletion addons/dialogue_manager/views/main_view.gd
Expand Up @@ -345,7 +345,7 @@ func _on_NewButton_pressed():
func _on_NewDialogueDialog_file_selected(path):
var resource = DialogueResource.new()
resource.take_over_path(path)
resource.raw_text = "~ this_is_a_node_title\n\nNathan: This is some dialogue.\nNathan: Here are some choices.\n- First one\n\tNathan: You picked the first one.\n- Second one\n\tNathan You picked the second one.\n- Start again => this_is_a_node_title\n- End the conversation => END\nNathan: For more information about conditional dialogue, mutations, and all the fun stuff, see the online documentation."
resource.raw_text = "~ this_is_a_node_title\n\nNathan: This is some dialogue.\nNathan: Here are some choices.\n- First one\n\tNathan: You picked the first one.\n- Second one\n\tNathan: You picked the second one.\n- Start again => this_is_a_node_title\n- End the conversation => END\nNathan: For more information about conditional dialogue, mutations, and all the fun stuff, see the online documentation."
resource.syntax_version = Constants.SYNTAX_VERSION
ResourceSaver.save(path, resource)
open_resource(resource)
Expand Down

0 comments on commit 8d44afc

Please sign in to comment.