Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Wumpee on April 15, 2014, 09:04:57 PM

Title: Only rendering N characters in a Label?
Post by: Wumpee on April 15, 2014, 09:04:57 PM
Hi,

Is there a way to tell a UILabel to only render a certain number of characters? I'm wanting to set up a typewriter effect for cut-scene text which is right justified, and slowly growing the text parameter just doesn't cut it.

Even with left justified text it would be ideal to just be able to just render N characters so you don't get weird pops when a word wraps.
Title: Re: Only rendering N characters in a Label?
Post by: ArenMook on April 16, 2014, 10:32:45 AM
Weird pops? Not sure what you mean. TypeWriterEffect script wraps everything beforehand.
Title: Re: Only rendering N characters in a Label?
Post by: Wumpee on April 16, 2014, 05:36:13 PM
I'm referring to when you keep adding characters to a UILabel and the last word wraps when it goes past the right hand border of the label.

The problem with the TypeWriterEffect script when it comes to right justified text is that the text grows out from the right hand side rather than having each character revealed in-place, which would be preferable in my case.
Title: Re: Only rendering N characters in a Label?
Post by: ArenMook on April 17, 2014, 11:02:54 AM
The typewriter effect pre-wraps everything before typing, so no, it doesn't behave like you're describing. In NGUI 2 it used to. In NGUI 3 it doesn't. What version are you using?
Title: Re: Only rendering N characters in a Label?
Post by: Wumpee on April 17, 2014, 05:09:33 PM
I just grabbed the one from the examples folder after reimporting NGUI 3.5.7.
Title: Re: Only rendering N characters in a Label?
Post by: ArenMook on April 18, 2014, 04:05:19 PM
Then I don't understand what you mean. The current typewriter effect wraps everything first, and only then continues to print text. Make sure the label isn't set to "shrink to fit" btw.
Title: Re: Only rendering N characters in a Label?
Post by: Wumpee on April 18, 2014, 07:00:37 PM
So if you create a right aligned label and add the typewriter effect, do the characters scroll in from the right side of the label toward the left side of the label, or do the characters appear "in place" rather than scrolling in?
Title: Re: Only rendering N characters in a Label?
Post by: ArenMook on April 19, 2014, 05:42:28 PM
They get added to the right side, extending the already printed text toward the left.
Title: Re: Only rendering N characters in a Label?
Post by: Wumpee on April 20, 2014, 03:41:23 PM
Ok, so that is what I'm experiencing also. What I want though is for the text of a right justified label to start appearing from the left, which is why I asked in the first place whether it was possible to get a label to draw N characters so I could manually increment the number of characters it draws to make the text appear.
Title: Re: Only rendering N characters in a Label?
Post by: ArenMook on April 20, 2014, 05:18:39 PM
That's custom behaviour. You will need to write a custom script for that.
Title: Re: Only rendering N characters in a Label?
Post by: Wumpee on April 20, 2014, 06:22:51 PM
So I initially ask "Is there a way to tell a UILabel to only render a certain number of characters?", which I think is a pretty straight forward question, and it takes 6 days to get to the point where you're telling me that I need to write a custom script for it.

Lesson learnt... I should have just looked into it myself instead of wasting time asking a question.

Any way, thanks for replying at least.
Title: Re: Only rendering N characters in a Label?
Post by: Wumpee on April 29, 2014, 09:03:41 PM
Hi,

Even if I try restricting the drawing of characters in UILabel.OnFill, it doesn't help... the characters still grow out from the right side of the label.

Can you please give me an example of how you would do a right justified typewriter effect which starts drawing characters from the left side and grows toward the right?
Title: Re: Only rendering N characters in a Label?
Post by: ENAY on April 30, 2014, 04:13:26 AM
I think it would help immensely if you posted some code so we can at least see what your problem is. Or a picture at the very least.
Title: Re: Only rendering N characters in a Label?
Post by: Wumpee on April 30, 2014, 04:32:24 AM
I think it would help immensely if you posted some code so we can at least see what your problem is. Or a picture at the very least.

Based on ArenMook's last reply, I think he understands the issue.

There is no code to post in relation to this issue... it's related to the TypewriterEffect example that comes with NGUI and the fact that it doesn't handle right justified text the way I would expect - our designer also commented that he thinks the text would look better if it came in the same way that left justified text does.

To be more clear - Left justified labels with a TypewriterEffect script attached start drawing characters from the left, and move across the screen to the right one character at a time. Right justified labels grow from the right side of the label toward the left side of the label.

e.g.
|         ABCD| will draw / reveal as follows, one character at a time:

|            A|
|           AB|
|          ABC|
|         ABCD|


It would be ideal if it revealed the label like so instead (i.e. revealing the characters "in place", instead of growing them in from the right side of the label)

|         A   |
|         AB  |
|         ABC |
|         ABCD|

Title: Re: Only rendering N characters in a Label?
Post by: ENAY on April 30, 2014, 04:43:32 AM
I think I see what you are saying now, you want the text to pop out as it does now, as if it were left assigned, except you want the full length of the word to be right aligned when it has finished?
Well what I would do is keep the UILabel left aligned, but adjust its transform in the X direction to the right side. First position the UILabel at the right side of where you want it and then use the UILabels 'printedSize' and subtract that from that position. In other words, you make a script which moves the UILabel according to the words text size.

I am still not 100% sure if that is what you are trying to achieve, but I hope this helps.
Title: Re: Only rendering N characters in a Label?
Post by: Wumpee on April 30, 2014, 05:22:03 AM
I think I see what you are saying now, you want the text to pop out as it does now, as if it were left assigned, except you want the full length of the word to be right aligned when it has finished?
Well what I would do is keep the UILabel left aligned, but adjust its transform in the X direction to the right side. First position the UILabel at the right side of where you want it and then use the UILabels 'printedSize' and subtract that from that position. In other words, you make a script which moves the UILabel according to the words text size.

I am still not 100% sure if that is what you are trying to achieve, but I hope this helps.

Thanks for the feedback Enay,

I guess I should have mentioned that this needs to work with multi-line labels too, so left justifying and adjusting the label position wouldn't work in our case =/

I tried modifying the UILabel.OnFill method to get it to only draw a maximum number of characters so that I could reveal the label slowly, but even that isn't working - it exhibits the same issue of growing out from the right side of the label.
Title: Re: Only rendering N characters in a Label?
Post by: ArenMook on April 30, 2014, 05:24:16 PM
Instead of filling characters slowly, simply adjust the alpha of the characters in your OnFill function. This way the characters will already be there, positioned properly. You will simply be "revealing" them gradually.
Title: Re: Only rendering N characters in a Label?
Post by: Wumpee on April 30, 2014, 05:44:25 PM
Instead of filling characters slowly, simply adjust the alpha of the characters in your OnFill function. This way the characters will already be there, positioned properly. You will simply be "revealing" them gradually.

Thanks ArenMook.

Will this need to be done in the OnFill or the NGUIText.Print method which is called from OnFill? If I modify the tint in NGUIText.Print, it seems to work, but only for certain labels.

I'd really appreciate a more direct example if you have a minute to spare.

Title: Re: Only rendering N characters in a Label?
Post by: ArenMook on April 30, 2014, 06:12:04 PM
You would do it in your custom version of UILabel.OnFill. Just derive from UILabel and override that function. Call base.OnFill, then modify the alpha of the color array as needed. Note that you will also need to mark the widget as changing via MarkAsChanged() frequently, or OnFill will not be called again.