コード例 #1
0
        private void OnLanguageChange()
        {
            if (this.IgnoreEvents)
            {
                return;
            }
            string value = this.Language.value;

            this.BeginIgnoreEvents();
            UiTranslationDatabase.SetLanguage(value);
            this.EndIgnoreEvents();
        }
コード例 #2
0
 private void Awake()
 {
     if (this.Language)
     {
         this.Language.Clear();
         string[]  availableTranslations      = UiTranslationDatabase.GetAvailableTranslations();
         Texture[] availableTranslationsIcons = UiTranslationDatabase.GetAvailableTranslationsIcons();
         for (int i = 0; i < availableTranslations.Length; i++)
         {
             this.Language.AddItem(availableTranslations[i], availableTranslationsIcons[i], null);
         }
         EventDelegate.Add(this.Language.onChange, new EventDelegate.Callback(this.OnLanguageChange));
     }
     this.BeginIgnoreEvents();
 }
コード例 #3
0
 public static void RegisterLabel(Transform target, string translationKey, Color textColor, Color backgroundColor, NGUIText.Alignment alignment, UiTranslationOverlaySystem.CurrentViewOptions currentViewOption = UiTranslationOverlaySystem.CurrentViewOptions.AllowInWorld)
 {
     if (UiTranslationOverlaySystem.Instance && !UiTranslationOverlaySystem.Instance._activeLabels.ContainsKey(target) && UiTranslationDatabase.HasKey(translationKey))
     {
         string text = UiTranslationDatabase.TranslateKey(translationKey, string.Empty, false);
         if (!string.IsNullOrEmpty(text))
         {
             UiTranslationOverlayLabel uiTranslationOverlayLabel;
             if (UiTranslationOverlaySystem.Instance._labelPool.Count > 0)
             {
                 uiTranslationOverlayLabel = UiTranslationOverlaySystem.Instance._labelPool.Dequeue();
                 uiTranslationOverlayLabel.gameObject.SetActive(true);
                 UiTranslationOverlaySystem.Instance.SetIconHolderTr(uiTranslationOverlayLabel.transform, currentViewOption);
             }
             else
             {
                 uiTranslationOverlayLabel = UnityEngine.Object.Instantiate <UiTranslationOverlayLabel>(UiTranslationOverlaySystem.Instance._overlayLabelPrefab);
                 UiTranslationOverlaySystem.Instance.SetIconHolderTr(uiTranslationOverlayLabel.transform, currentViewOption);
                 uiTranslationOverlayLabel.transform.localScale = UiTranslationOverlaySystem.Instance._overlayLabelPrefab.transform.localScale;
             }
             uiTranslationOverlayLabel._label.text = text;
             bool flag = alignment != NGUIText.Alignment.Left;
             if (flag)
             {
                 if (uiTranslationOverlayLabel._label.pivot != UIWidget.Pivot.Center)
                 {
                     uiTranslationOverlayLabel._label.pivot = UIWidget.Pivot.Center;
                     uiTranslationOverlayLabel._label.transform.localPosition = Vector3.zero;
                     uiTranslationOverlayLabel._background.pivot = UIWidget.Pivot.Center;
                     uiTranslationOverlayLabel._background.transform.localPosition = new Vector3(0f, uiTranslationOverlayLabel._background.transform.localPosition.y, 0f);
                 }
             }
             else if (uiTranslationOverlayLabel._label.pivot != UIWidget.Pivot.Left)
             {
                 uiTranslationOverlayLabel._label.pivot = UIWidget.Pivot.Left;
                 uiTranslationOverlayLabel._label.transform.localPosition = Vector3.zero;
                 uiTranslationOverlayLabel._background.pivot = UIWidget.Pivot.Left;
                 uiTranslationOverlayLabel._background.transform.localPosition = new Vector3(-10f, uiTranslationOverlayLabel._background.transform.localPosition.y, 0f);
             }
             uiTranslationOverlayLabel._label.color         = textColor;
             uiTranslationOverlayLabel._background.color    = backgroundColor;
             uiTranslationOverlayLabel._follow._target      = target;
             uiTranslationOverlayLabel._follow._inBook      = (currentViewOption == UiTranslationOverlaySystem.CurrentViewOptions.AllowInBook);
             uiTranslationOverlayLabel._follow._inInventory = (currentViewOption == UiTranslationOverlaySystem.CurrentViewOptions.AllowInInventory);
             UiTranslationOverlaySystem.Instance._activeLabels.Add(target, uiTranslationOverlayLabel);
         }
     }
 }
コード例 #4
0
        public static string GetMappingFor(InputMappingIcons.Actions action)
        {
            if (TheForest.Utils.Input.IsGamePad)
            {
                return(InputMappingIcons.GamepadMappings[(int)action]);
            }
            string text = InputMappingIcons.KeyboardMappings[(int)action];

            if (text != null)
            {
                if (text == "Space")
                {
                    return(UiTranslationDatabase.TranslateKey("SPACE", "SPACE", true));
                }
            }
            return(InputMappingIcons.KeyboardMappings[(int)action]);
        }
コード例 #5
0
 public override void ApplyTranslation(string text)
 {
     if (this._translate && this._popup && this._popup.transform)
     {
         string[] array = text.Split(new char[]
         {
             '\n'
         });
         if (array.Length != this._popup.items.Count)
         {
             array = UiTranslationDatabase.EnglishValueForKey(this._key, text).Split(new char[]
             {
                 '\n'
             });
         }
         if (array.Length == this._popup.items.Count)
         {
             try
             {
                 int num = this._popup.items.IndexOf(this._popup.value);
                 if (this._popup.items == null)
                 {
                     this._popup.items = new List <string>();
                 }
                 else
                 {
                     this._popup.items.Clear();
                 }
                 foreach (string item in array)
                 {
                     this._popup.items.Add(item);
                 }
                 if (num >= 0 && num < this._popup.items.Count && this._popup.value != this._popup.items[num])
                 {
                     this._popup.value = this._popup.items[num];
                 }
             }
             catch (Exception exception)
             {
                 Debug.LogException(exception);
             }
         }
     }
 }
コード例 #6
0
ファイル: MpGameRow.cs プロジェクト: DevZhav/The-Forest
 public void RefreshName(List <Action <MpGameRow> > sortOptions)
 {
     if (this._previousPlayed)
     {
         this._continueButtonLabel.text = UiTranslationDatabase.TranslateKey("CONTINUE", "CONTINUE", false);
         if (!this._continueButtonLabel.transform.parent.gameObject.activeSelf)
         {
             this._continueButtonLabel.transform.parent.gameObject.SetActive(true);
         }
     }
     else if (this._continueButtonLabel.transform.parent.gameObject.activeSelf)
     {
         this._continueButtonLabel.transform.parent.gameObject.SetActive(false);
     }
     base.name = string.Empty;
     for (int i = 0; i < sortOptions.Count; i++)
     {
         sortOptions[i](this);
     }
     base.name += this._gameName.text;
 }
コード例 #7
0
ファイル: LoadSaveSlotInfo.cs プロジェクト: K07H/The-Forest
		private void LoadStats()
		{
			string localSlotPath = SaveSlotUtils.GetLocalSlotPath(this._slot);
			string path = localSlotPath + "info";
			if (!File.Exists(localSlotPath + "__RESUME__"))
			{
				this._labelSlot.text = UiTranslationDatabase.TranslateKey("SLOT_" + this._slotNum, "Slot " + this._slotNum, false);
				if (this._labelStat)
				{
					this._labelStat.gameObject.SetActive(false);
				}
				if (this._labelDateTime)
				{
					this._labelDateTime.gameObject.SetActive(false);
				}
				if (Application.loadedLevelName.Equals("TitleScene"))
				{
					base.transform.parent.GetComponent<Collider>().enabled = false;
				}
			}
			else
			{
				base.transform.parent.GetComponent<Collider>().enabled = true;
				try
				{
					if (File.Exists(path))
					{
						GameStats.Stats gameStats = GameStats.Stats.LoadFromBytes(File.ReadAllBytes(path));
						this._labelSlot.text = UiTranslationDatabase.TranslateKey("SLOT_" + this._slotNum, "Slot " + this._slotNum, false) + UiTranslationDatabase.TranslateKey("_DAY_", ": day ", false) + gameStats._day;
						if (this._labelStat)
						{
							FieldInfo[] array = (from f in gameStats.GetType().GetFields()
							where (int)f.GetValue(gameStats) > 0
							select f).ToArray<FieldInfo>();
							if (array != null && array.Length > 0)
							{
								int num = UnityEngine.Random.Range(0, array.Length);
								string name = array[num].Name;
								string text;
								switch (name)
								{
								case "_treeCutDown":
									text = "Trees Cut Down: ";
									goto IL_4BC;
								case "_enemiesKilled":
									text = "Enemies Killed: ";
									goto IL_4BC;
								case "_rabbitKilled":
									text = "Rabbits Killed: ";
									goto IL_4BC;
								case "_lizardKilled":
									text = "Lizards Killed: ";
									goto IL_4BC;
								case "_raccoonKilled":
									text = "Raccoons Killed: ";
									goto IL_4BC;
								case "_deerKilled":
									text = "Deer Killed: ";
									goto IL_4BC;
								case "_turtleKilled":
									text = "Turtles Killed: ";
									goto IL_4BC;
								case "_birdKilled":
									text = "Birds Killed: ";
									goto IL_4BC;
								case "_cookedFood":
									text = "Cooked Food: ";
									goto IL_4BC;
								case "_burntFood":
									text = "Burnt Food: ";
									goto IL_4BC;
								case "_cancelledStructures":
									text = "Cancelled Structures: ";
									goto IL_4BC;
								case "_builtStructures":
									text = "Built Structures: ";
									goto IL_4BC;
								case "_destroyedStructures":
									text = "Destroyed Structures: ";
									goto IL_4BC;
								case "_repairedStructures":
									text = "Repaired Structures: ";
									goto IL_4BC;
								case "_edibleItemsUsed":
									text = "Edible Items Used: ";
									goto IL_4BC;
								case "_itemsCrafted":
									text = "Items Crafted: ";
									goto IL_4BC;
								case "_upgradesAdded":
									text = "Upgrades Added: ";
									goto IL_4BC;
								case "_arrowsFired":
									text = "Arrows Fired: ";
									goto IL_4BC;
								case "_litArrows":
									text = "Lit Arrows: ";
									goto IL_4BC;
								case "_litWeapons":
									text = "Lit Weapons: ";
									goto IL_4BC;
								case "_burntEnemies":
									text = "Burnt Enemies: ";
									goto IL_4BC;
								case "_explodedEnemies":
									text = "Exploded Enemies: ";
									goto IL_4BC;
								}
								text = string.Empty;
								IL_4BC:
								if (string.IsNullOrEmpty(text))
								{
									this._labelStat.gameObject.SetActive(false);
								}
								else
								{
									this._labelStat.gameObject.SetActive(true);
									this._labelStat.text = text + array[num].GetValue(gameStats);
								}
							}
							else
							{
								this._labelStat.gameObject.SetActive(false);
							}
						}
					}
					else
					{
						this._labelSlot.text = "Slot " + this._slotNum;
					}
				}
				catch (Exception exception)
				{
					Debug.LogException(exception);
				}
				UILabel labelSlot = this._labelSlot;
				labelSlot.text += "\n";
				try
				{
					string path2 = localSlotPath + "difficulty";
					if (File.Exists(path2))
					{
						string text2 = File.ReadAllText(path2);
						if (text2 != null)
						{
							if (text2 == "Peaceful" || text2 == "Hard" || text2 == "HardSurvival" || text2 == "Creative" || text2 == "Normal")
							{
								string text3 = text2.ToUpper();
								UILabel labelSlot2 = this._labelSlot;
								labelSlot2.text += UiTranslationDatabase.TranslateKey(text3, text3, false);
							}
						}
					}
				}
				catch (Exception ex)
				{
				}
				if (this._labelDateTime)
				{
					this._labelDateTime.text = File.GetLastWriteTime(localSlotPath + "__RESUME__").ToString(CultureInfo.CurrentCulture.DateTimeFormat);
					this._labelDateTime.gameObject.SetActive(true);
				}
			}
		}
コード例 #8
0
 public static Texture[] GetAvailableTranslationsIcons()
 {
     UiTranslationDatabase.GetAvailableTranslations();
     return(UiTranslationDatabase.Instance._availableTranslationsIcons);
 }
コード例 #9
0
 public static void SetLanguage(string lang)
 {
     UiTranslationDatabase.GetAvailableTranslations();
     if (string.Equals(lang, "TRANSLATIONDEBUG", StringComparison.InvariantCultureIgnoreCase))
     {
         UiTranslationDatabase.Instance.Data = (from d in UiTranslationDatabase.Instance.DataEnglish
                                                where !string.IsNullOrEmpty(d.Value)
                                                select d).ToDictionary((KeyValuePair <string, string> i) => i.Key, (KeyValuePair <string, string> i) => "{" + i.Key + "}");
         UiTranslationDatabase.Instance.DataCaps = (from d in UiTranslationDatabase.Instance.DataEnglish
                                                    where !string.IsNullOrEmpty(d.Value)
                                                    select d).ToDictionary((KeyValuePair <string, string> i) => i.Key, (KeyValuePair <string, string> i) => "{{" + i.Key + "}}");
         EventRegistry.Game.Publish(TfEvent.LanguageSet, null);
         return;
     }
     if (!UiTranslationDatabase.Instance._availableTranslations.Contains(lang))
     {
         Debug.LogError("Unknown lang: " + lang + " fallback to English");
         lang = "English";
     }
     if (lang != UiTranslationDatabase.Instance._language || UiTranslationDatabase.Instance.Data == null)
     {
         string language = UiTranslationDatabase.Instance._language;
         UiTranslationDatabase.Instance._language = lang;
         try
         {
             string filename = UiTranslationDatabase.Instance.Filename;
             Dictionary <string, string> source;
             if (Path.IsPathRooted(filename))
             {
                 if (!File.Exists(filename))
                 {
                     Debug.LogError("Missing lang file: " + filename);
                     return;
                 }
                 source = JsonMapper.ToObject <Dictionary <string, string> >(File.ReadAllText(filename));
             }
             else
             {
                 string path = Application.dataPath + "/../" + UiTranslationDatabase.TranslationsPath;
                 if (!Directory.Exists(path))
                 {
                     Debug.LogError("Missing lang file: " + filename);
                     return;
                 }
                 source = JsonMapper.ToObject <Dictionary <string, string> >(File.ReadAllText(Application.dataPath + "/../" + filename));
             }
             UiTranslationDatabase.Instance.Data = (from d in source
                                                    where !string.IsNullOrEmpty(d.Value)
                                                    select d).ToDictionary((KeyValuePair <string, string> i) => i.Key, (KeyValuePair <string, string> i) => i.Value);
             UiTranslationDatabase.Instance.DataCaps = new Dictionary <string, string>();
             foreach (KeyValuePair <string, string> keyValuePair in UiTranslationDatabase.Instance.DataEnglish)
             {
                 if (!UiTranslationDatabase.Instance.Data.ContainsKey(keyValuePair.Key))
                 {
                     UiTranslationDatabase.Instance.Data.Add(keyValuePair.Key, keyValuePair.Value);
                 }
                 if (!UiTranslationDatabase.Instance.DataCaps.ContainsKey(keyValuePair.Key))
                 {
                     UiTranslationDatabase.Instance.DataCaps.Add(keyValuePair.Key, UiTranslationDatabase.Instance.Data[keyValuePair.Key].ToUpper());
                 }
             }
             PlayerPreferences.Language = lang;
             PlayerPreferences.Save();
         }
         catch (Exception exception)
         {
             Debug.LogException(exception);
             UiTranslationDatabase.Instance._language = language;
             return;
         }
         UiTranslationDatabase.OriginalVersion = (UiTranslationDatabase.Instance._language == "English");
         EventRegistry.Game.Publish(TfEvent.LanguageSet, null);
     }
 }