From e9ea621b93fbb58d9edfca8375918791637bbd52 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 30 Dec 2020 20:59:04 +0800 Subject: +init --- Client/Assembly-CSharp/LanguageUnit.cs | 79 ++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Client/Assembly-CSharp/LanguageUnit.cs (limited to 'Client/Assembly-CSharp/LanguageUnit.cs') diff --git a/Client/Assembly-CSharp/LanguageUnit.cs b/Client/Assembly-CSharp/LanguageUnit.cs new file mode 100644 index 0000000..62ae51e --- /dev/null +++ b/Client/Assembly-CSharp/LanguageUnit.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.IO; +using UnityEngine; + +public class LanguageUnit +{ + public bool IsEnglish; + + private Dictionary AllStrings = new Dictionary(); + + private Dictionary AllImages = new Dictionary(); + + public LanguageUnit(TextAsset data, ImageData[] images) + { + foreach (ImageData imageData in images) + { + this.AllImages.Add(imageData.Name, imageData.Sprite); + } + using (StringReader stringReader = new StringReader(data.text)) + { + for (string text = stringReader.ReadLine(); text != null; text = stringReader.ReadLine()) + { + if (text.Length != 0) + { + int num = text.IndexOf(','); + if (num < 0) + { + Debug.LogWarning("Couldn't parse: " + text); + } + else + { + string text2 = text.Substring(0, num); + StringNames key; + if (!Enum.TryParse(text2, out key)) + { + Debug.LogWarning("Couldn't parse: " + text2); + } + else + { + string value = LanguageUnit.UnescapeCodes(text.Substring(num + 1)); + this.AllStrings.Add(key, value); + } + } + } + } + } + } + + public static string UnescapeCodes(string src) + { + if (src.IndexOf("\\n") < 0) + { + return src; + } + return src.Replace("\\n", "\n"); + } + + public string GetString(StringNames stringId, params object[] parts) + { + string text; + if (!this.AllStrings.TryGetValue(stringId, out text)) + { + return "STRMISS"; + } + if (parts.Length != 0) + { + return string.Format(text, parts); + } + return text; + } + + public Sprite GetImage(ImageNames id) + { + Sprite result; + this.AllImages.TryGetValue(id, out result); + return result; + } +} -- cgit v1.1-26-g67d0