-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
addons/popochiu/engine/objects/gui/components/dialog_text/dialog_text.gd
Show resolved
Hide resolved
addons/popochiu/engine/objects/gui/components/dialog_text/dialog_caption/dialog_caption.gd
Outdated
Show resolved
Hide resolved
addons/popochiu/engine/objects/gui/components/dialog_text/dialog_caption/dialog_caption.gd
Outdated
Show resolved
Hide resolved
addons/popochiu/engine/objects/gui/components/dialog_text/dialog_caption/dialog_caption.gd
Outdated
Show resolved
Hide resolved
addons/popochiu/engine/objects/gui/components/dialog_text/dialog_caption/dialog_caption.gd
Outdated
Show resolved
Hide resolved
…og_caption/dialog_caption.gd Co-authored-by: Carenalga <[email protected]>
…og_caption/dialog_caption.gd Co-authored-by: Carenalga <[email protected]>
…tion ends up wrong
…serted between lines
8170932
to
bf1d6f5
Compare
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.
|
There was a problem hiding this 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
.
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) |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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.
## 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 | ||
|
||
|
There was a problem hiding this comment.
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.
msg = _correct_line_breaks(msg) | ||
|
There was a problem hiding this comment.
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
.
## 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 | ||
|
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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]
).
if PopochiuConfig.should_talk_gibberish(): | ||
_append_text(D.create_gibberish(msg), props) | ||
else: | ||
_append_text(msg, props) |
There was a problem hiding this comment.
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.
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() |
There was a problem hiding this comment.
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.
## 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. |
There was a problem hiding this comment.
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.
## 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. |
I think the About the Overhead dialogThe idea of this component is to take into account the 👇 Your implementation 👇 dialog_overhead_wrong_behavior.mp4👇 The current (an expected) behavior 👇 dialog_overhead_expected_behavior.mp4About the Portrait dialogDue 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 About the Caption dialogAs I mentioned in one of the comments, I think the ideal approach for this component is that the value of the To summarizeI think the right approach to make use of the code you made for calculating the line breaks should be used before calling |
## 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: |
There was a problem hiding this comment.
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.
Fixes #360