Author Topic: Dynamic tooltips with localization  (Read 2407 times)


  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Dynamic tooltips with localization
« on: August 01, 2012, 04:40:20 AM »
Hi, there might be a simple answer to this question, but I haven't been able to find a smooth solution yet.

In my game I'm having tooltips to display what my abilities does, including damage, cast time etc. I also have items and talents that affects how much damage the abilities does. I'm having trouble being able to dynamically change the damage value when using localized text. Here is an example to show the problem. When displaying the text in the tooltip I use a function which takes in the text, damage parameter, cast time parameter etc. If I only had it in english, I can simple do like this to have the damage text change depending on the damage variable.

ShowText("Fireball", "[" + NGUITools.EncodeColor( + "]Hurls a flaming ball of fire that deals [" + NGUITools.EncodeColor(Color.white) + "]" + mDamage.ToString() + "[" + NGUITools.EncodeColor( + "]damage. In addition the target will get [" + NGUITools.EncodeColor(Color.cyan) + "]stunned [" + NGUITools.EncodeColor( + "] for a short time.

Now the damage get changed automatically when the mDamage variable is changed. This won't work if I need the text localized in several languages.

The solution I would want is to be able to manually specify codes, similair to the codes used to specify colors; for example a [Damage] code so I simple can do something like this:

UILabel text = GetLocalizedText("Fireball");
text.SetParameter("Damage", mDamage);
ShowText(GetLocalizedHeader("Fireball"), text);

Is this something that is already build in or do I have to code something like this manually?



  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dynamic tooltips with localization
« Reply #1 on: August 01, 2012, 06:13:29 AM »
Look into string.Format(). It does exactly this, letting your string look like something like this:

"Double the amount of rigging on your ship, reducing the damage sails take by {0:0}% and maneuvering penalty caused by damage by {1:0}%."