Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: jarjin on May 06, 2013, 04:44:14 AM

Title: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
Post 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?
Title: Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
Post by: kicki2k on May 06, 2013, 05:15:21 AM
me too!
Title: Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
Post by: ArenMook on May 06, 2013, 04:37:57 PM
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.
Title: Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
Post by: aleraler on May 07, 2013, 09:27:15 PM
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.
Title: Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
Post by: ArenMook on May 08, 2013, 02:12:48 AM
You said you read the data from a CSV file. When you read each line, do string.Replace("\\n", "\n").
Title: Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
Post by: makeshiftwings on May 08, 2013, 07:03:50 PM
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?
Title: Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
Post by: ArenMook on May 08, 2013, 07:54:50 PM
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.
Title: Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
Post by: makeshiftwings on May 09, 2013, 05:32:51 PM
Doesn't it still do a string replace to deal with the NGUI custom format tags like color codes?
Title: Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
Post by: realblues on May 12, 2013, 08:43:41 PM
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 :)
Title: Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
Post by: Gibbie on June 04, 2013, 08:28:59 AM
 :)

Oh thank you Real Blue!!
Title: Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
Post by: Seith on June 21, 2013, 11:53:29 AM
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?
Title: Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
Post by: ArenMook on June 22, 2013, 06:04:05 AM
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.
Title: Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
Post by: Seith on June 23, 2013, 03:50:43 AM
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.
Title: Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
Post by: QiuLei on March 21, 2015, 06:06:09 AM
I finally got the answer here,thank you all :)