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

Conversation

balloonpopper
Copy link
Contributor

Fixes #360

Copy link
Collaborator

@mapedorr mapedorr left a comment

Choose a reason for hiding this comment

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

I'm asking for a couple of changes. I still have to devote some time to test the behavior of the component.

@balloonpopper
Copy link
Contributor Author

The changes to the _calculate_size function were because the existing code would split the text from this command onto 2 lines for a 100px text box, when the text was only about 60px wide when tested with (from memory) dialog_overhead.

await C.get_OfficerBlonde().say("It's free.")

Copy link
Collaborator

@mapedorr mapedorr left a comment

Choose a reason for hiding this comment

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

I request some changes before merging this to develop.

Comment on lines +9 to +11
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)
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.

Comment on lines +25 to +41
func _correct_line_breaks(msg: String) -> String:
rich_text_label.text = msg
var number_of_lines_of_text := rich_text_label.get_line_count()
if number_of_lines_of_text > 1:
var current_line_number := 0
for current_character in range(0, rich_text_label.text.length()):
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)

if current_line_number == number_of_lines_of_text - 1:
break
return rich_text_label.text
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like what this code does, but it shouldn't be duplicated in the 3 DialogText components. You should move this to the dialog_text.gd script so any DialogText component can make use of it.

Comment on lines +46 to +69
## 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 rewrite it on the next line which looks
## messy.
func _correct_line_breaks(msg: String) -> String:
rich_text_label.text = msg
var number_of_lines_of_text := rich_text_label.get_line_count()
if number_of_lines_of_text > 1:
var current_line_number := 0
for current_character in range(0, rich_text_label.text.length()):
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)

if current_line_number == number_of_lines_of_text - 1:
break
return rich_text_label.text


Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this after moving this function to the dialog_text.gd script.

Comment on lines +29 to +30
msg = _correct_line_breaks(msg)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Assign the [color][/color] to the msg in the same way you did for the dialog_caption.gd:17 and the dialog_portrait.gd:47.

Comment on lines +50 to +72
## 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 rewrite it on the next line which looks
## messy.
func _correct_line_breaks(msg: String) -> String:
rich_text_label.text = msg
var number_of_lines_of_text := rich_text_label.get_line_count()
if number_of_lines_of_text > 1:
var current_line_number := 0
for current_character in range(0, rich_text_label.text.length()):
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)

if current_line_number == number_of_lines_of_text - 1:
break
return rich_text_label.text

Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this after moving this function to the dialog_text.gd script.

# Call the virtual method that modifies the size of the RichTextLabel in case the dialog style
# requires it.
await _modify_size(msg, props.position)

rich_text_label.push_color(props.color)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We removed this in #357 because it was causing issues when centering text. Please remove it again since each DialogText component should assign the color itself using BBCode ([color][/color]).

Comment on lines +84 to +87
if PopochiuConfig.should_talk_gibberish():
_append_text(D.create_gibberish(msg), props)
else:
_append_text(msg, props)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be just this since the gibberish text replacement was already done in line 75.

Suggested change
if PopochiuConfig.should_talk_gibberish():
_append_text(D.create_gibberish(msg), props)
else:
_append_text(msg, props)
_append_text(msg, props)

lbl.text = rt.get_parsed_text()
lbl.size = lbl.get_minimum_size()
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 this is not necessary since the custom_minimum_size of the component at this point will be Vector2.ZERO.

Comment on lines 175 to +177
## Creates a RichTextLabel to calculate the resulting size of this node once the whole text is shown.
## Uses a RichTextLabel to provide the "get_parsed_text" function, and a label within it to work out
## the minimum size. Calculating the size from just the RichTextLabel does not work.
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you want to replace the description of the function, please remove the previous one. Also, I suggest a small change to make it clear what the function really does.

Suggested change
## Creates a RichTextLabel to calculate the resulting size of this node once the whole text is shown.
## Uses a RichTextLabel to provide the "get_parsed_text" function, and a label within it to work out
## the minimum size. Calculating the size from just the RichTextLabel does not work.
## Uses a [RichTextLabel] and a [Label] to work out the minimum size since calculating it from just
## the [RichTextLabel] does not work.

@mapedorr
Copy link
Collaborator

I think the _correct_line_breaks() function you created to modify the text so the line breaks are displayed properly works fine, and it actually improves the behavior of the tween, but I suggest making that calculation before trying to calculate the size of each DialogText component.

About the Overhead dialog

The idea of this component is to take into account the dialog_pos property of each PopochiuCharacter to make the bottom of the component to render above that line. In many cases, your implementation makes the text to render below that line, which can cause reading issues on long texts.

👇 Your implementation 👇

dialog_overhead_wrong_behavior.mp4

👇 The current (an expected) behavior 👇

dialog_overhead_expected_behavior.mp4

About the Portrait dialog

Due to how this scene is structured, the size of the RichTextLabel adjusts to the available space within the PanelContainer component where it is contained. Perhaps what should happen with this component is that the value of the wrap_width property defines the size that the PanelContainer should have. In any case, modifying the text using your _correct_line_breaks() function can help the make the tween look better.

About the Caption dialog

As I mentioned in one of the comments, I think the ideal approach for this component is that the value of the wrap_width property defines the X size of the RichTextLabel component on its _ready() function. The width of this component will remain fixed regardless of the amount of content to render. I think modifying only the height based on the content is fine (as it is in the current implementation (in develop)), but we could use the _correct_line_breaks() function to ensure the final size adjusts better based on the final text content.

To summarize

I think the right approach to make use of the code you made for calculating the line breaks should be used before calling _modify_size() (line 79 in your code) in the DialogText class. That way, the calculation of the size of the RichTextLabel component will use the text with the line breaks fixes.

## 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 rewrite it on the next line which looks
## messy.
func _correct_line_breaks(msg: String) -> String:
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 _fix_line_breaks is a better name for this function. "Correct" sounds weird.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The dialog resize function does not work in the 2 button interface
2 participants