Example #1
0
        private bool SelectLanguage(String lang)
        {
            _languageIndex = -1;
            if (_dictionary.Count == 0)
            {
                return(false);
            }

            int index = 0;

            for (int length = _languages.Length; index < length; ++index)
            {
                if (_languages[index] != lang)
                {
                    continue;
                }

                _oldDictionary.Clear();
                _languageIndex = index;
                _language      = lang;
                PlayerPrefs.SetString("Language", _language);
                Localization.onLocalize?.Invoke();
                UIRoot.Broadcast("OnLocalize");
                return(true);
            }

            return(false);
        }
Example #2
0
    /// <summary>
    /// Select the specified language from the previously loaded CSV file.
    /// </summary>

    static bool SelectLanguage(string language)
    {
        mLanguageIndex = -1;

        if (mDictionary.Count == 0)
        {
            return(false);
        }

        for (int i = 0, imax = mLanguages.Length; i < imax; ++i)
        {
            if (mLanguages[i] == language)
            {
                mOldDictionary.Clear();
                mLanguageIndex = i;
                mLanguage      = language;
                PlayerPrefs.SetString("Language", mLanguage);
                if (onLocalize != null)
                {
                    onLocalize();
                }
                UIRoot.Broadcast("OnLocalize");
                return(true);
            }
        }
        return(false);
    }
    /// <summary>
    /// Select the specified language from the previously loaded CSV file.
    /// </summary>

    static bool SelectLanguage(string language)
    {
        mLanguageIndex = -1;

        if (mDictionary.Count == 0)
        {
            return(false);
        }

        string[] keys;

        if (mDictionary.TryGetValue("KEY", out keys))
        {
            for (int i = 0; i < keys.Length; ++i)
            {
                if (keys[i] == language)
                {
                    mOldDictionary.Clear();
                    mLanguageIndex = i;
                    mLanguage      = language;
                    PlayerPrefs.SetString("Language", mLanguage);
                    UIRoot.Broadcast("OnLocalize");
                    return(true);
                }
            }
        }
        return(false);
    }
Example #4
0
    static int Broadcast(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1 && TypeChecker.CheckTypes(L, 1, typeof(string)))
            {
                string arg0 = ToLua.ToString(L, 1);
                UIRoot.Broadcast(arg0);
                return(0);
            }
            else if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(string), typeof(object)))
            {
                string arg0 = ToLua.ToString(L, 1);
                object arg1 = ToLua.ToVarObject(L, 2);
                UIRoot.Broadcast(arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UIRoot.Broadcast"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #5
0
 private void Load(TextAsset asset)
 {
     this.mLanguage = asset.name;
     PlayerPrefs.SetString("Language", this.mLanguage);
     this.mDictionary = new ByteReader(asset).ReadDictionary();
     UIRoot.Broadcast("OnLocalize", this);
 }
Example #6
0
 private static bool SelectLanguage(string language)
 {
     Localization.mLanguageIndex = -1;
     if (Localization.mDictionary.Count == 0)
     {
         return(false);
     }
     string[] array;
     if (Localization.mDictionary.TryGetValue("KEY", out array))
     {
         for (int i = 0; i < array.Length; i++)
         {
             if (array[i] == language)
             {
                 Localization.mOldDictionary.Clear();
                 Localization.mLanguageIndex = i;
                 Localization.mLanguage      = language;
                 PlayerPrefs.SetString("Language", Localization.mLanguage);
                 UIRoot.Broadcast("OnLocalize");
                 return(true);
             }
         }
     }
     return(false);
 }
Example #7
0
 static public int Broadcast_s(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 1)
         {
             System.String a1;
             checkType(l, 1, out a1);
             UIRoot.Broadcast(a1);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 2)
         {
             System.String a1;
             checkType(l, 1, out a1);
             System.Object a2;
             checkType(l, 2, out a2);
             UIRoot.Broadcast(a1, a2);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #8
0
    private static bool SelectLanguage(string language)
    {
        Localization.mLanguageIndex = -1;
        if (Localization.mDictionary.Count == 0)
        {
            return(false);
        }
        int i   = 0;
        int num = Localization.mLanguages.Length;

        while (i < num)
        {
            if (Localization.mLanguages[i] == language)
            {
                Localization.mOldDictionary.Clear();
                Localization.mLanguageIndex = i;
                Localization.mLanguage      = language;
                PlayerPrefs.SetString("Language", Localization.mLanguage);
                if (Localization.onLocalize != null)
                {
                    Localization.onLocalize();
                }
                UIRoot.Broadcast("OnLocalize");
                return(true);
            }
            i++;
        }
        return(false);
    }
Example #9
0
 private void Update()
 {
     if (m_ScreenWidth != Screen.width || m_ScreenHeight != Screen.height)
     {
         m_ScreenWidth  = Screen.width;
         m_ScreenHeight = Screen.height;
         UIRoot.Broadcast("OnResolutionChange");
     }
 }
    /// <summary>
    /// Load the specified asset and activate the localization.
    /// </summary>

    void Load(TextAsset asset)
    {
        mLanguage = asset.name;
        PlayerPrefs.SetString("Language", mLanguage);
        ByteReader reader = new ByteReader(asset);

        mDictionary = reader.ReadDictionary();
        UIRoot.Broadcast("OnLocalize", this);
    }
    /// <summary>
    /// Load the specified asset and activate the localization.
    /// </summary>

    static public void Set(string languageName, Dictionary <string, string> dictionary)
    {
        mLanguage = languageName;
        PlayerPrefs.SetString("Language", mLanguage);
        mOldDictionary         = dictionary;
        localizationHasBeenSet = false;
        mLanguageIndex         = -1;
        mLanguages             = new string[] { languageName };
        UIRoot.Broadcast("OnLocalize");
    }
Example #12
0
    /// <summary>
    /// Load the specified asset and activate the localization.
    /// </summary>

    public void Set(string languageName, Dictionary <string, string> dictionary)
    {
#if SHOW_REPORT
        mUsed.Clear();
#endif
        mLanguage = languageName;
        PlayerPrefs.SetString("Language", mLanguage);
        mDictionary = dictionary;
        UIRoot.Broadcast("OnLocalize", this);
    }
    /// <summary>
    /// Load the specified asset and activate the localization.
    /// </summary>

    void Load(TextAsset asset)
    {
        mLanguage = asset.name;
        PlayerPrefs.SetString("Language", mLanguage);
        ByteReader reader = new ByteReader(asset);

        mDictionary = reader.ReadDictionary();
        UIRoot.Broadcast("OnLocalize", this);
        YuanUnityPhoton.GetYuanUnityPhotonInstantiate().dicLanguage = mDictionary;
    }
Example #14
0
    /// <summary>
    /// Load the specified asset and activate the localization.
    /// </summary>

    void Load(string lenName)
    {
        mLanguage = lenName;
        PlayerPrefs.SetString("Language", mLanguage);

        //Set up the fonts
        LoadFont("fontSimple", mLanguage);
        LoadFont("fontOutlined", mLanguage);

        UIRoot.Broadcast("OnLocalize", this);
    }
Example #15
0
    /// <summary>
    /// Load the specified asset and activate the localization.
    /// </summary>

    static public void Set(string languageName, Dictionary <string, string> dictionary)
    {
#if SHOW_REPORT
        mUsed.Clear();
#endif
        mLanguage = languageName;
        PlayerPrefs.SetString("Language", mLanguage);
        mOldDictionary         = dictionary;
        localizationHasBeenSet = false;
        mLanguageIndex         = -1;
        knownLanguages         = new string[] { languageName };
        UIRoot.Broadcast("OnLocalize");
    }
Example #16
0
 static public void Append(string languageName, Dictionary <string, string> dictionarys)
 {
     mLanguage = languageName;
     PlayerPrefs.SetString("Language", mLanguage);
     foreach (KeyValuePair <string, string> kv in dictionarys)
     {
         mOldDictionary[kv.Key] = kv.Value;
     }
     localizationHasBeenSet = false;
     mLanguageIndex         = -1;
     mLanguages             = new string[] { languageName };
     UIRoot.Broadcast("OnLocalize");
 }
Example #17
0
 public static bool Reload()
 {
     Localization.localizationHasBeenSet = false;
     if (!Localization.LoadDictionary(Localization.mLanguage, true))
     {
         return(false);
     }
     if (Localization.onLocalize != null)
     {
         Localization.onLocalize();
     }
     UIRoot.Broadcast("OnLocalize");
     return(true);
 }
Example #18
0
        public void Set(String languageName, Dictionary <String, String> dic)
        {
            lock (_lock)
            {
                _language = languageName;
                PlayerPrefs.SetString("Language", _language);

                _oldDictionary = dic;
                Localization.localizationHasBeenSet = true;

                _languageIndex = -1;
                _languages     = new[] { languageName };

                Localization.onLocalize?.Invoke();
                UIRoot.Broadcast("OnLocalize");
            }
        }
Example #19
0
 public static void Set(string languageName, Dictionary <string, string> dictionary)
 {
     Localization.mLanguage = languageName;
     PlayerPrefs.SetString("Language", Localization.mLanguage);
     Localization.mOldDictionary         = dictionary;
     Localization.localizationHasBeenSet = true;
     Localization.mLanguageIndex         = -1;
     Localization.mLanguages             = new string[]
     {
         languageName
     };
     if (Localization.onLocalize != null)
     {
         Localization.onLocalize();
     }
     UIRoot.Broadcast("OnLocalize");
 }
Example #20
0
 public void SelectLanguage(String language)
 {
     if (_languages.TryGetValue(language, out var languageDic))
     {
         _current          = languageDic;
         _currentLanguage  = language;
         LanguagePrefs.Key = language;
     }
     else
     {
         _current          = _failback;
         _currentLanguage  = _failbackLanguage;
         LanguagePrefs.Key = null;
         Log.Error($"[LocalizationDictionary] Cannot find localisation data for the language [{language}].");
     }
     _currentSymbol = Get(SymbolKey);
     UIRoot.Broadcast("OnLocalize");
 }
Example #21
0
    // 인터페이스 : 언어설정
    public void SetLocalization()
    {
        var pByte = LoadLocalization();

        if (0 == pByte.Count)
        {
            return;
        }

        Localization.localizationHasBeenSet = false;
        Localization.LoadCSV(pByte.ToArray());
        if (null != Localization.onLocalize)
        {
            Localization.onLocalize();
        }

        UIRoot.Broadcast("OnLocalize");
        Localization.language = GetLanguage().ToString();
    }
Example #22
0
    private void LateUpdate()
    {
        if (!handlesEvents)
        {
            return;
        }
        int width  = Screen.width;
        int height = Screen.height;

        if (width != mWidth || height != mHeight)
        {
            mWidth  = width;
            mHeight = height;
            UIRoot.Broadcast("UpdateAnchors");
            if (onScreenResize != null)
            {
                onScreenResize();
            }
        }
    }
Example #23
0
	/// <summary>
	/// Keep an eye on screen size changes.
	/// </summary>

	void LateUpdate ()
	{
#if UNITY_EDITOR
		if (!Application.isPlaying || !handlesEvents) return;
#else
		if (!handlesEvents) return;
#endif
		int w = Screen.width;
		int h = Screen.height;

		if (w != mWidth || h != mHeight)
		{
			mWidth = w;
			mHeight = h;

			UIRoot.Broadcast("UpdateAnchors");

			if (onScreenResize != null)
				onScreenResize();
		}
	}
Example #24
0
    public static int Broadcast_s(IntPtr l)
    {
        int result;

        try
        {
            int num = LuaDLL.pua_gettop(l);
            if (num == 1)
            {
                string funcName;
                LuaObject.checkType(l, 1, out funcName);
                UIRoot.Broadcast(funcName);
                LuaObject.pushValue(l, true);
                result = 1;
            }
            else if (num == 2)
            {
                string funcName2;
                LuaObject.checkType(l, 1, out funcName2);
                object param;
                LuaObject.checkType <object>(l, 2, out param);
                UIRoot.Broadcast(funcName2, param);
                LuaObject.pushValue(l, true);
                result = 1;
            }
            else
            {
                LuaObject.pushValue(l, false);
                LuaDLL.pua_pushstring(l, "No matched override function to call");
                result = 2;
            }
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Example #25
0
 private static bool SelectLanguage(string language)
 {
     mLanguageIndex = -1;
     if (mDictionary.Count == 0)
     {
         return(false);
     }
     if (mDictionary.TryGetValue("KEY", out var value))
     {
         for (int i = 0; i < value.Length; i++)
         {
             if (value[i] == language)
             {
                 mOldDictionary.Clear();
                 mLanguageIndex = i;
                 mLanguage      = language;
                 PlayerPrefs.SetString("Language", mLanguage);
                 UIRoot.Broadcast("OnLocalize");
                 return(true);
             }
         }
     }
     return(false);
 }
Example #26
0
    static int Broadcast(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 1)
        {
            string arg0 = LuaScriptMgr.GetLuaString(L, 1);
            UIRoot.Broadcast(arg0);
            return(0);
        }
        else if (count == 2)
        {
            string arg0 = LuaScriptMgr.GetLuaString(L, 1);
            object arg1 = LuaScriptMgr.GetVarObject(L, 2);
            UIRoot.Broadcast(arg0, arg1);
            return(0);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: UIRoot.Broadcast");
        }

        return(0);
    }
Example #27
0
 public unsafe static long $Invoke1(long instance, long *args)
 {
     UIRoot.Broadcast(Marshal.PtrToStringUni(*(IntPtr *)args));
     return(-1L);
 }
Example #28
0
 public unsafe static long $Invoke2(long instance, long *args)
 {
     UIRoot.Broadcast(Marshal.PtrToStringUni(*(IntPtr *)args), GCHandledObjects.GCHandleToObject(args[1]));
     return(-1L);
 }
Example #29
0
    /// <summary>
    /// Load the specified CSV file.
    /// </summary>

    static bool LoadCSV(byte[] bytes, TextAsset asset, bool merge = false)
    {
        if (bytes == null)
        {
            return(false);
        }
        ByteReader reader = new ByteReader(bytes);

        // The first line should contain "KEY", followed by languages.
        var header = reader.ReadCSV();

        // There must be at least two columns in a valid CSV file
        if (header.size < 2)
        {
            return(false);
        }
        header.RemoveAt(0);

        string[] languagesToAdd = null;
        if (string.IsNullOrEmpty(mLanguage))
        {
            localizationHasBeenSet = false;
        }

        // Clear the dictionary
        if (!localizationHasBeenSet || (!merge && !mMerging) || mLanguages == null || mLanguages.Length == 0)
        {
            mDictionary.Clear();
            mLanguages = new string[header.size];

            if (!localizationHasBeenSet)
            {
                mLanguage = PlayerPrefs.GetString("Language", header.buffer[0]);
                localizationHasBeenSet = true;
            }

            for (int i = 0; i < header.size; ++i)
            {
                mLanguages[i] = header.buffer[i];
                if (mLanguages[i] == mLanguage)
                {
                    mLanguageIndex = i;
                }
            }
        }
        else
        {
            languagesToAdd = new string[header.size];
            for (int i = 0; i < header.size; ++i)
            {
                languagesToAdd[i] = header.buffer[i];
            }

            // Automatically resize the existing languages and add the new language to the mix
            for (int i = 0; i < header.size; ++i)
            {
                if (!HasLanguage(header.buffer[i]))
                {
                    int newSize = mLanguages.Length + 1;
#if UNITY_FLASH
                    var temp = new string[newSize];
                    for (int b = 0, bmax = arr.Length; b < bmax; ++b)
                    {
                        temp[b] = mLanguages[b];
                    }
                    mLanguages = temp;
#else
                    System.Array.Resize(ref mLanguages, newSize);
#endif
                    mLanguages[newSize - 1] = header.buffer[i];

                    var newDict = new Dictionary <string, string[]>();

                    foreach (var pair in mDictionary)
                    {
                        var arr = pair.Value;
#if UNITY_FLASH
                        temp = new string[newSize];
                        for (int b = 0, bmax = arr.Length; b < bmax; ++b)
                        {
                            temp[b] = arr[b];
                        }
                        arr = temp;
#else
                        System.Array.Resize(ref arr, newSize);
#endif
                        arr[newSize - 1] = arr[0];
                        newDict.Add(pair.Key, arr);
                    }
                    mDictionary = newDict;
                }
            }
        }

        var languageIndices = new Dictionary <string, int>();
        for (int i = 0; i < mLanguages.Length; ++i)
        {
            languageIndices.Add(mLanguages[i], i);
        }

        // Read the entire CSV file into memory
        for (;;)
        {
            var temp = reader.ReadCSV();
            if (temp == null || temp.size == 0)
            {
                break;
            }
            if (string.IsNullOrEmpty(temp.buffer[0]))
            {
                continue;
            }
            AddCSV(temp, languagesToAdd, languageIndices);
        }

        if (!mMerging && onLocalize != null)
        {
            mMerging = true;
            OnLocalizeNotification note = onLocalize;
            onLocalize = null;
            note();
            onLocalize = note;
            mMerging   = false;
        }

        if (merge)
        {
            if (onLocalize != null)
            {
                onLocalize();
            }
            UIRoot.Broadcast("OnLocalize");
        }
        return(true);
    }
Example #30
0
    private static bool LoadCSV(byte[] bytes, TextAsset asset, bool merge = false)
    {
        if (bytes == null)
        {
            return(false);
        }
        ByteReader          byteReader = new ByteReader(bytes);
        BetterList <string> betterList = byteReader.ReadCSV();

        if (betterList.size < 2)
        {
            return(false);
        }
        betterList.RemoveAt(0);
        string[] array = null;
        if (string.IsNullOrEmpty(Localization.mLanguage))
        {
            Localization.localizationHasBeenSet = false;
        }
        if (!Localization.localizationHasBeenSet || (!merge && !Localization.mMerging) || Localization.mLanguages == null || Localization.mLanguages.Length == 0)
        {
            Localization.mDictionary.Clear();
            Localization.mLanguages = new string[betterList.size];
            if (!Localization.localizationHasBeenSet)
            {
                Localization.mLanguage = PlayerPrefs.GetString("Language", betterList[0]);
                Localization.localizationHasBeenSet = true;
            }
            for (int i = 0; i < betterList.size; i++)
            {
                Localization.mLanguages[i] = betterList[i];
                if (Localization.mLanguages[i] == Localization.mLanguage)
                {
                    Localization.mLanguageIndex = i;
                }
            }
        }
        else
        {
            array = new string[betterList.size];
            for (int j = 0; j < betterList.size; j++)
            {
                array[j] = betterList[j];
            }
            for (int k = 0; k < betterList.size; k++)
            {
                if (!Localization.HasLanguage(betterList[k]))
                {
                    int num = Localization.mLanguages.Length + 1;
                    Array.Resize <string>(ref Localization.mLanguages, num);
                    Localization.mLanguages[num - 1] = betterList[k];
                    Dictionary <string, string[]> dictionary = new Dictionary <string, string[]>();
                    foreach (KeyValuePair <string, string[]> current in Localization.mDictionary)
                    {
                        string[] value = current.Value;
                        Array.Resize <string>(ref value, num);
                        value[num - 1] = value[0];
                        dictionary.Add(current.Key, value);
                    }
                    Localization.mDictionary = dictionary;
                }
            }
        }
        Dictionary <string, int> dictionary2 = new Dictionary <string, int>();

        for (int l = 0; l < Localization.mLanguages.Length; l++)
        {
            dictionary2.Add(Localization.mLanguages[l], l);
        }
        while (true)
        {
            BetterList <string> betterList2 = byteReader.ReadCSV();
            if (betterList2 == null || betterList2.size == 0)
            {
                break;
            }
            if (!string.IsNullOrEmpty(betterList2[0]))
            {
                Localization.AddCSV(betterList2, array, dictionary2);
            }
        }
        if (!Localization.mMerging && Localization.onLocalize != null)
        {
            Localization.mMerging = true;
            Localization.OnLocalizeNotification onLocalizeNotification = Localization.onLocalize;
            Localization.onLocalize = null;
            onLocalizeNotification();
            Localization.onLocalize = onLocalizeNotification;
            Localization.mMerging   = false;
        }
        if (merge)
        {
            if (Localization.onLocalize != null)
            {
                Localization.onLocalize();
            }
            UIRoot.Broadcast("OnLocalize");
        }
        return(true);
    }