Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue_360 Fix dialog_caption size #361

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,41 @@ extends PopochiuDialogText


#region Private ####################################################################################
func _modify_size(msg: String, _target_position: Vector2) -> void:
func _modify_size(msg: String, target_position: Vector2) -> void:
var _size := await _calculate_size(msg)

# Define size and position (before calculating overflow)
rich_text_label.size.x = _size.x
rich_text_label.size.y = _size.y
rich_text_label.position.x = (get_viewport_rect().size.x/2) - (_size.x /2)
Comment on lines +9 to +11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the ideal approach in this case is not to modify the width (size.x) and X position of the RichTextLabel. Considering how this Control is configured in Godot, what we should do is ensure that the value defined in the wrap_width property is assigned to the size.x property of the RichTextLabel in the _ready() function. To control the Y position of the component, Godot's anchors can be used.

rich_text_label.position.y = get_meta(DFLT_POSITION).y - (_size.y - get_meta(DFLT_SIZE).y)


## Appends text for the dialog caption
## Ensures that where a printing a word would see it wrap to the next line that the newline
## is forced into the text. Without this the tween in dialog_text.gd would print part of the word
## until it runs out of space, then erase the part word and put it onto the next line which looks
## messy.
func _append_text(msg: String, props: Dictionary) -> void:
rich_text_label.text = "[center][color=%s]%s[/color][/center]" % [props.color.to_html(), msg]
rich_text_label.text = msg
var number_of_lines_of_text = rich_text_label.get_line_count()
balloonpopper marked this conversation as resolved.
Show resolved Hide resolved
if number_of_lines_of_text > 1:
var current_line_number = 0
balloonpopper marked this conversation as resolved.
Show resolved Hide resolved
for current_character in range(0, rich_text_label.text.length()):

var ThisChar = rich_text_label.text[current_character]
var ThisLine = rich_text_label.get_character_line(current_character)
balloonpopper marked this conversation as resolved.
Show resolved Hide resolved
if rich_text_label.get_character_line(current_character) > current_line_number:
current_line_number += 1
if rich_text_label.text[current_character-1] == " ":
rich_text_label.text[current_character-1] = "\n"
elif rich_text_label.text[current_character-1] != "\n":
rich_text_label.text = rich_text_label.text.left(current_character) + "\n" + rich_text_label.text.right(-current_character)
balloonpopper marked this conversation as resolved.
Show resolved Hide resolved

if current_line_number == number_of_lines_of_text - 1:
break

msg = rich_text_label.text
rich_text_label.text = "[center][color=%s]%s[/color][/center]" % [props.color.to_html(), msg]

#endregion
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func play_text(props: Dictionary) -> void:
await _modify_size(msg, props.position)

# Assign the text and align mode
msg = "[color=%s]%s[/color]" % [props.color.to_html(), msg]
balloonpopper marked this conversation as resolved.
Show resolved Hide resolved
_append_text(msg, props)

if _secs_per_character > 0.0:
Expand Down