Пример #1
0
        void OnGUI_LanguageList()
        {
            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            GUILayout.FlexibleSpace();
            GUILayout.Label("Languages:", EditorStyles.miniLabel, GUILayout.ExpandWidth(false));
            GUILayout.FlexibleSpace();
            GUILayout.Label("Code:", EditorStyles.miniLabel, GUILayout.Width(76));
            GUILayout.EndHorizontal();

            //--[ Language List ]--------------------------

            int IndexLanguageToDelete = -1;
            int LanguageToMoveUp      = -1;
            int LanguageToMoveDown    = -1;

            mScrollPos_Languages = GUILayout.BeginScrollView(mScrollPos_Languages, EditorStyles.textArea, GUILayout.MinHeight(100), GUILayout.MaxHeight(Screen.height), GUILayout.ExpandHeight(false));

            List <string> codes = GoogleLanguages.GetAllInternationalCodes();

            codes.Sort();
            codes.Insert(0, string.Empty);

            for (int i = 0, imax = mProp_Languages.arraySize; i < imax; ++i)
            {
                SerializedProperty Prop_Lang     = mProp_Languages.GetArrayElementAtIndex(i);
                SerializedProperty Prop_LangName = Prop_Lang.FindPropertyRelative("Name");
                SerializedProperty Prop_LangCode = Prop_Lang.FindPropertyRelative("Code");
                SerializedProperty Prop_Flags    = Prop_Lang.FindPropertyRelative("Flags");
                bool isLanguageEnabled           = (Prop_Flags.intValue & (int)eLanguageDataFlags.DISABLED) == 0;

                GUI.color = isLanguageEnabled ? Color.white : new Color(1, 1, 1, 0.3f);
                GUILayout.BeginHorizontal();

                if (GUILayout.Button("X", "toolbarbutton", GUILayout.ExpandWidth(false)))
                {
                    IndexLanguageToDelete = i;
                }

                GUILayout.BeginHorizontal(EditorStyles.toolbar);

                GUI.changed = false;
                string LanName = EditorGUILayout.TextField(Prop_LangName.stringValue, GUILayout.ExpandWidth(true));
                if (GUI.changed && !string.IsNullOrEmpty(LanName))
                {
                    Prop_LangName.stringValue = LanName;
                    GUI.changed = false;
                }

                int Index = Mathf.Max(0, codes.IndexOf(Prop_LangCode.stringValue));
                GUI.changed = false;
                Index       = EditorGUILayout.Popup(Index, codes.ToArray(), EditorStyles.toolbarPopup, GUILayout.Width(60));
                if (GUI.changed && Index >= 0)
                {
                    Prop_LangCode.stringValue = codes[Index];
                }

                GUILayout.EndHorizontal();

                GUI.enabled = (i < imax - 1);
                if (GUILayout.Button("\u25BC", EditorStyles.toolbarButton, GUILayout.Width(18)))
                {
                    LanguageToMoveDown = i;
                }
                GUI.enabled = i > 0;
                if (GUILayout.Button("\u25B2", EditorStyles.toolbarButton, GUILayout.Width(18)))
                {
                    LanguageToMoveUp = i;
                }

                GUI.enabled = true;
                if (GUILayout.Button(new GUIContent("Show", "Preview all localizations into this language"), EditorStyles.toolbarButton, GUILayout.Width(35)))
                {
                    LocalizationManager.SetLanguageAndCode(LanName, Prop_LangCode.stringValue, false, true);
                }

                if (GUILayout.Button(new GUIContent("Translate", "Translate all empty terms"), EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
                {
                    TranslateAllToLanguage(LanName);
                }
                GUI.enabled = true;

                EditorGUI.BeginChangeCheck();
                isLanguageEnabled = EditorGUILayout.Toggle(isLanguageEnabled, GUILayout.Width(15));
                if (EditorGUI.EndChangeCheck())
                {
                    Prop_Flags.intValue = (Prop_Flags.intValue & ~(int)eLanguageDataFlags.DISABLED) | (isLanguageEnabled ? 0 : (int)eLanguageDataFlags.DISABLED);
                }

                GUILayout.EndHorizontal();
            }

            GUILayout.EndScrollView();

            OnGUI_AddLanguage(mProp_Languages);

            if (mConnection_WWW != null || mConnection_Text.Contains("Translating"))
            {
                // Connection Status Bar
                int    time    = (int)((Time.realtimeSinceStartup % 2) * 2.5);
                string Loading = mConnection_Text + ".....".Substring(0, time);
                GUI.color = Color.gray;
                GUILayout.BeginHorizontal(EditorStyles.textArea);
                GUILayout.Label(Loading, EditorStyles.miniLabel);
                GUI.color = Color.white;
                if (GUILayout.Button("Cancel", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
                {
                    EditorApplication.update -= DelayedStartTranslation;
                    StopConnectionWWW();
                }
                GUILayout.EndHorizontal();
                Repaint();
            }

            if (IndexLanguageToDelete >= 0)
            {
                mLanguageSource.RemoveLanguage(mLanguageSource.mLanguages[IndexLanguageToDelete].Name);
                serializedObject.Update();
                ParseTerms(true, false);
            }

            if (LanguageToMoveUp >= 0)
            {
                SwapLanguages(LanguageToMoveUp, LanguageToMoveUp - 1);
            }
            if (LanguageToMoveDown >= 0)
            {
                SwapLanguages(LanguageToMoveDown, LanguageToMoveDown + 1);
            }
        }
        void OnGUI_LanguageList()
        {
            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            GUILayout.FlexibleSpace();
            GUILayout.Label("Languages:", EditorStyles.miniLabel, GUILayout.ExpandWidth(false));
            GUILayout.FlexibleSpace();
            GUILayout.Label("Code:", EditorStyles.miniLabel, GUILayout.Width(76));
            GUILayout.EndHorizontal();

            //--[ Language List ]--------------------------

            int IndexLanguageToDelete = -1;
            int LanguageToMoveUp      = -1;
            int LanguageToMoveDown    = -1;

            mScrollPos_Languages = GUILayout.BeginScrollView(mScrollPos_Languages, "AS TextArea", GUILayout.MinHeight(100), GUILayout.MaxHeight(Screen.height), GUILayout.ExpandHeight(false));

            List <string> codes = GoogleLanguages.GetAllInternationalCodes();

            codes.Sort();
            codes.Insert(0, string.Empty);

            for (int i = 0, imax = mProp_Languages.arraySize; i < imax; ++i)
            {
                GUILayout.BeginHorizontal();

                SerializedProperty Prop_Lang     = mProp_Languages.GetArrayElementAtIndex(i);
                SerializedProperty Prop_LangName = Prop_Lang.FindPropertyRelative("Name");
                SerializedProperty Prop_LangCode = Prop_Lang.FindPropertyRelative("Code");

                if (GUILayout.Button("X", "toolbarbutton", GUILayout.ExpandWidth(false)))
                {
                    IndexLanguageToDelete = i;
                }

                GUILayout.BeginHorizontal(EditorStyles.toolbar);

                GUI.changed = false;
                string LanName = EditorGUILayout.TextField(Prop_LangName.stringValue, GUILayout.ExpandWidth(true));
                if (GUI.changed && !string.IsNullOrEmpty(LanName))
                {
                    Prop_LangName.stringValue = LanName;
                    GUI.changed = false;
                }

                int Index = Mathf.Max(0, codes.IndexOf(Prop_LangCode.stringValue));
                GUI.changed = false;
                Index       = EditorGUILayout.Popup(Index, codes.ToArray(), EditorStyles.toolbarPopup, GUILayout.Width(60));
                if (GUI.changed && Index >= 0)
                {
                    Prop_LangCode.stringValue = codes[Index];
                }

                GUILayout.EndHorizontal();

                GUI.enabled = (i < imax - 1);
                if (GUILayout.Button("\u25BC", EditorStyles.toolbarButton, GUILayout.Width(18)))
                {
                    LanguageToMoveDown = i;
                }
                GUI.enabled = i > 0;
                if (GUILayout.Button("\u25B2", EditorStyles.toolbarButton, GUILayout.Width(18)))
                {
                    LanguageToMoveUp = i;
                }
                GUI.enabled = true;

                if (GUILayout.Button(new GUIContent("Show", "Preview all localizations into this language"), EditorStyles.toolbarButton, GUILayout.Width(35)))
                {
                    LocalizationManager.SetLanguageAndCode(LanName, Prop_LangCode.stringValue, false, true);
                }

                GUILayout.EndHorizontal();
            }

            GUILayout.EndScrollView();

            OnGUI_AddLanguage(mProp_Languages);

            if (IndexLanguageToDelete >= 0)
            {
                mLanguageSource.RemoveLanguage(mLanguageSource.mLanguages[IndexLanguageToDelete].Name);
                serializedObject.Update();
                ParseTerms(true, false);
                mShouldDetectStoreIntegration = true;
            }

            if (LanguageToMoveUp >= 0)
            {
                SwapLanguages(LanguageToMoveUp, LanguageToMoveUp - 1);
            }
            if (LanguageToMoveDown >= 0)
            {
                SwapLanguages(LanguageToMoveDown, LanguageToMoveDown + 1);
            }
        }