Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: jarjin on May 06, 2013, 04:44:14 AM
-
Dynamic Fonts v2.6.1 UILabel \n Escape character failure?I cannot use \n. how can i do?
-
me too!
-
When filling via code, \n is one character (newline). When filling via a localization file, \n is translated to the newline character.
Two character sequence, '\' followed by 'n' is not interpreted as a new line anymore. So don't use it.
-
When filling via code, \n is one character (newline). When filling via a localization file, \n is translated to the newline character.
Two character sequence, '\' followed by 'n' is not interpreted as a new line anymore. So don't use it.
In our game, we read a string from .csv file, before 2.6.1 we used \n to start newline in this string.
How can we do it now?
Press Enter in .csv file will start newline(.csv file's, not the string) that not we expected.
-
You said you read the data from a CSV file. When you read each line, do string.Replace("\\n", "\n").
-
I'm using NData, and \n has stopped working in all the TextBindings. Do you know how to best fix this?
Edit: I've started adding string.Replace("\\n", "\n") to everywhere in my code where I pass a string to a label, but this is going to be a huge pain. Is there a reason that you removed the automatic conversion?
-
Because it was performing a string replace every single time you assigned the label's text. This is wrong. It should only happen when the data is loaded.
-
Doesn't it still do a string replace to deal with the NGUI custom format tags like color codes?
-
I Just Modified UI Label Code
From
public string text
{
get
{
return mText;
}
set
{
if (string.IsNullOrEmpty(value))
{
if (!string.IsNullOrEmpty(mText))
mText = "";
hasChanged = true;
}
else if (mText != value)
{
mText = value; <=== Here
hasChanged = true;
}
}
}
To
public string text
{
get
{
return mText;
}
set
{
if (string.IsNullOrEmpty(value))
{
if (!string.IsNullOrEmpty(mText))
mText = "";
hasChanged = true;
}
else if (mText != value)
{
mText = value.Replace("\\n", "\n"); <== Here
hasChanged = true;
}
}
}
I Didn't consider performance :)
-
:)
Oh thank you Real Blue!!
-
I didn't want to start a new topic since I've got the same problem: line breaks are not working anymore. I'm reading the text strings from an XML file where I use "\n" to create a line break. A couple of NGUI updates ago this stopped working. I thought it was a bug and would be fixed eventually but the problem's still there.
Reading this thread I see it mentions replacing all the "\\n" by "\n" but I'm already using "\n". I also tried unchecking the "Encoding" check-box but it doesn't seem to make any difference.
I would really like to keep on using NGUI for "Ghost of a Tale" but I need to be able to create line breaks. Does anyone have a solution, please?
UPDATE:
I implemented the change suggested by realblues and it works (thanks realblues!)... :)
@ArenMook: Do you think it would be possible to include that bugfix in NGUI so line-breaks become supported again out of the box, please?
-
It's not a bug fix. I removed it on purpose. I don't want it to string.Replace every time I assign text to a label! If you want that, do it outside the label.
-
Oh I see, sorry. I removed the string.Replace operation from the label code and applied it to my own script just before I update the label's text. It works fine. Thanks.
-
I finally got the answer here,thank you all :)