123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- namespace I2.Loc
- {
- public class LocalizeTarget_NGUI_Label : LocalizeTarget<UILabel>
- {
- static LocalizeTarget_NGUI_Label()
- {
- LocalizeTarget_NGUI_Label.AutoRegister();
- }
- [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
- private static void AutoRegister()
- {
- LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type<UILabel, LocalizeTarget_NGUI_Label>
- {
- Name = "NGUI Label",
- Priority = 100
- });
- }
- public override eTermType GetPrimaryTermType(Localize cmp)
- {
- return eTermType.Text;
- }
- public override eTermType GetSecondaryTermType(Localize cmp)
- {
- return eTermType.UIFont;
- }
- public override bool CanUseSecondaryTerm()
- {
- return true;
- }
- public override bool AllowMainTermToBeRTL()
- {
- return true;
- }
- public override bool AllowSecondTermToBeRTL()
- {
- return false;
- }
- public override void GetFinalTerms(Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm)
- {
- primaryTerm = ((!this.mTarget) ? null : this.mTarget.text);
- secondaryTerm = ((!(this.mTarget.ambigiousFont != null)) ? string.Empty : this.mTarget.ambigiousFont.name);
- }
- public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
- {
- Font secondaryTranslatedObj = cmp.GetSecondaryTranslatedObj<Font>(ref mainTranslation, ref secondaryTranslation);
- if (secondaryTranslatedObj != null)
- {
- if (secondaryTranslatedObj != this.mTarget.ambigiousFont)
- {
- this.mTarget.ambigiousFont = secondaryTranslatedObj;
- }
- }
- else
- {
- UIFont secondaryTranslatedObj2 = cmp.GetSecondaryTranslatedObj<UIFont>(ref mainTranslation, ref secondaryTranslation);
- if (secondaryTranslatedObj2 != null && this.mTarget.ambigiousFont != secondaryTranslatedObj2)
- {
- this.mTarget.ambigiousFont = secondaryTranslatedObj2;
- }
- }
- if (this.mInitializeAlignment)
- {
- this.mInitializeAlignment = false;
- this.mAlignment_LTR = (this.mAlignment_RTL = this.mTarget.alignment);
- if (LocalizationManager.IsRight2Left && this.mAlignment_RTL == NGUIText.Alignment.Right)
- {
- this.mAlignment_LTR = NGUIText.Alignment.Left;
- }
- if (!LocalizationManager.IsRight2Left && this.mAlignment_LTR == NGUIText.Alignment.Left)
- {
- this.mAlignment_RTL = NGUIText.Alignment.Right;
- }
- }
- UIInput uiinput = NGUITools.FindInParents<UIInput>(this.mTarget.gameObject);
- if (uiinput != null && uiinput.label == this.mTarget)
- {
- if (mainTranslation != null && uiinput.defaultText != mainTranslation)
- {
- if (cmp.CorrectAlignmentForRTL && (uiinput.label.alignment == NGUIText.Alignment.Left || uiinput.label.alignment == NGUIText.Alignment.Right))
- {
- uiinput.label.alignment = ((!LocalizationManager.IsRight2Left) ? this.mAlignment_LTR : this.mAlignment_RTL);
- }
- uiinput.defaultText = mainTranslation;
- }
- }
- else if (mainTranslation != null && this.mTarget.text != mainTranslation)
- {
- if (cmp.CorrectAlignmentForRTL && (this.mTarget.alignment == NGUIText.Alignment.Left || this.mTarget.alignment == NGUIText.Alignment.Right))
- {
- this.mTarget.alignment = ((!LocalizationManager.IsRight2Left) ? this.mAlignment_LTR : this.mAlignment_RTL);
- }
- if (((!this.mTarget.useFloatSpacing && (this.mTarget.spacingX != 0 || this.mTarget.spacingY != 0)) || (this.mTarget.useFloatSpacing && (this.mTarget.floatSpacingX != 0f || this.mTarget.floatSpacingY != 0f))) && cmp.gameObject.GetComponent<NGUILabelLocalizeSupport>() == null)
- {
- NGUILabelLocalizeSupport nguilabelLocalizeSupport = cmp.gameObject.AddComponent<NGUILabelLocalizeSupport>();
- if (!cmp.ForceOverFlowShrink)
- {
- nguilabelLocalizeSupport.overRidePropertys.overFlow.enabled = false;
- }
- }
- if (cmp.ForceOverFlowShrink && cmp.gameObject.GetComponent<NGUILabelLocalizeSupport>() == null)
- {
- cmp.gameObject.AddComponent<NGUILabelLocalizeSupport>();
- }
- if (!string.IsNullOrEmpty(mainTranslation) && cmp.mTermArgs != null && 0 < cmp.mTermArgs.Length)
- {
- List<string> list = new List<string>();
- for (int i = 0; i < cmp.mTermArgs.Length; i++)
- {
- string text = cmp.mTermArgs[i].text;
- if (!cmp.mTermArgs[i].isTerm)
- {
- if (text.IndexOf('{') != -1 && text.IndexOf('}') != -1)
- {
- mainTranslation += text;
- }
- else
- {
- list.Add(text);
- }
- }
- else
- {
- list.Add((text == null) ? string.Empty : LocalizationManager.GetTranslation(text, false, 0, true, false, null, null));
- }
- }
- mainTranslation = string.Format(mainTranslation, list.ToArray());
- }
- this.mTarget.text = mainTranslation;
- }
- }
- private NGUIText.Alignment mAlignment_RTL = NGUIText.Alignment.Right;
- private NGUIText.Alignment mAlignment_LTR = NGUIText.Alignment.Left;
- private bool mAlignmentWasRTL;
- private bool mInitializeAlignment = true;
- }
- }
|