Author Topic: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?  (Read 14839 times)

jarjin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Dynamic Fonts v2.6.1 UILabel \n Escape character failure?I cannot use \n. how can i do?

kicki2k

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
« Reply #1 on: May 06, 2013, 05:15:21 AM »
me too!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
« Reply #2 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.

aleraler

  • Guest
Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
« Reply #3 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
« Reply #4 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").

makeshiftwings

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
« Reply #5 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?
« Last Edit: May 08, 2013, 07:17:54 PM by makeshiftwings »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
« Reply #6 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.

makeshiftwings

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
« Reply #7 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?

realblues

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
« Reply #8 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 :)

Gibbie

  • Guest
Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
« Reply #9 on: June 04, 2013, 08:28:59 AM »
 :)

Oh thank you Real Blue!!

Seith

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 37
    • View Profile
    • SeithCG
Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
« Reply #10 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?
« Last Edit: June 22, 2013, 04:26:58 AM by Seith »
SeithCG.com

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
« Reply #11 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.

Seith

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 37
    • View Profile
    • SeithCG
Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
« Reply #12 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.
SeithCG.com

QiuLei

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Dynamic Fonts v2.6.1 UILabel \n Escape character failure?
« Reply #13 on: March 21, 2015, 06:06:09 AM »
I finally got the answer here,thank you all :)