Author Topic: UILabel Dynamic Font Reference in NGUI 3.x  (Read 4728 times)

DarkMagicCK

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 20
    • View Profile
UILabel Dynamic Font Reference in NGUI 3.x
« on: November 20, 2013, 12:11:37 AM »
Recently we began to make an iOS game which we need multi resolution for retina and normal.

UISprite has no problem with atlas reference. The problem comes down on UIFont.(Version 3.0.5)
I made two Dynamic Font(eg. size 16 and size 32 for retina) prefab, and made a reference UIFont prefab which I control by myself in runtime to switch between 16 size and 32 size UIFont.

But the new schema seems to put ttf file into UILabel's inspector directly while using dynamic font, instead of a UIFont prefab.
And when font type is bitmap, I drag my reference UIFont into inspector and nothing happens.

I know I can add a script for each UILabel component to change its font size at runtime or change them all on scene start.
But is there a way to use dynamic font reference? I think this is the most effective way for font size switch. Thanks!

ps. Thanks for mention me in UIFont.cs, very happy when I saw my ID, lol.

DarkMagicCK

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: UILabel Dynamic Font Reference in NGUI 3.x
« Reply #1 on: November 20, 2013, 01:44:51 AM »
OK I've figured out by myself. Just need to add an additional check in UILabel.bitmapFont property' SET.
If it's a replacement UIFont, just let this UILabel use it, even if the source is not a bitmap font.

BTW do you think this is an issue? Will this be included in next release? Or give UILabel a new font type selection named "reference"?

  1. if (mFont != value)
  2. {
  3. #if DYNAMIC_FONT
  4.         if (value != null && value.dynamicFont != null && value.replacement == null)
  5.         {
  6.                 trueTypeFont = value.dynamicFont;
  7.                 return;
  8.         }
  9. #endif
  10.         if (trueTypeFont != null) trueTypeFont = null;
  11.         else RemoveFromPanel();
  12.  
  13.         mFont = value;
  14.         MarkAsChanged();
  15. }
  16.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel Dynamic Font Reference in NGUI 3.x
« Reply #2 on: November 20, 2013, 03:49:15 AM »
This isn't needed in 3.0.6 anymore as dynamic fonts have an option to keep their crispness even on non-pixel perfect UIs.

jeldrez

  • Sr. Member
  • ****
  • Thank You
  • -Given: 8
  • -Receive: 4
  • Posts: 352
    • View Profile
Re: UILabel Dynamic Font Reference in NGUI 3.x
« Reply #3 on: February 21, 2014, 02:31:18 PM »
What if I need to change the font for another Language?
I would need to change it using dynamicFont [set] ?

#edit
   Also is good to starts projects using placeholder font and changing later the reference to another one, besides changing all the UILabels references.
#end edit

Thanks
« Last Edit: February 21, 2014, 02:36:31 PM by jeldrez »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel Dynamic Font Reference in NGUI 3.x
« Reply #4 on: February 21, 2014, 02:41:21 PM »
You can use reference fonts for that. Set one UIFont as a Reference, pointing to another. Use this reference font on all your labels. In case of dynamic fonts you can even avoid this by simply creating a UIFont using a dynamic font. Use this UIFont on labels rather than the dynamic font directly, and you only have one place where you need to change the font -- UIFont's prefab.