static void OnGUI_TranslatingMessage()
 {
     if (GoogleTranslation.IsTranslating())
     {
         // Connection Status Bar
         int    time    = (int)((Time.realtimeSinceStartup % 2) * 2.5);
         string Loading = "Translating" + ".....".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)))
         {
             GoogleTranslation.CancelCurrentGoogleTranslations();
         }
         GUILayout.EndHorizontal();
         HandleUtility.Repaint();
     }
 }
Esempio n. 2
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.Space(170);
            GUILayout.EndHorizontal();

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

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

            GUI.backgroundColor  = Color.Lerp(GUITools.LightGray, Color.white, 0.5f);
            mScrollPos_Languages = GUILayout.BeginScrollView(mScrollPos_Languages, LocalizeInspector.GUIStyle_OldTextArea, GUILayout.MinHeight(200), /*GUILayout.MaxHeight(Screen.height),*/ GUILayout.ExpandHeight(false));
            GUI.backgroundColor  = Color.white;

            if (mLanguageCodePopupList == null || mLanguageCodePopupList.Count == 0)
            {
                mLanguageCodePopupList = GoogleLanguages.GetLanguagesForDropdown("", "");
                mLanguageCodePopupList.Sort();
                mLanguageCodePopupList.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);

                EditorGUI.BeginChangeCheck();
                string LanName = EditorGUILayout.TextField(Prop_LangName.stringValue, GUILayout.ExpandWidth(true));
                if (EditorGUI.EndChangeCheck() && !string.IsNullOrEmpty(LanName))
                {
                    Prop_LangName.stringValue = LanName;
                }

                var currentCode = "[" + Prop_LangCode.stringValue + "]";

                if (isLanguageEnabled)
                {
                    int Index = Mathf.Max(0, mLanguageCodePopupList.FindIndex(c => c.Contains(currentCode)));
                    EditorGUI.BeginChangeCheck();
                    Index = EditorGUILayout.Popup(Index, mLanguageCodePopupList.ToArray(), EditorStyles.toolbarPopup, GUILayout.Width(60));
                    if (EditorGUI.EndChangeCheck() && Index >= 0)
                    {
                        currentCode = mLanguageCodePopupList[Index];
                        int i0 = currentCode.IndexOf("[");
                        int i1 = currentCode.IndexOf("]");
                        if (i0 >= 0 && i1 > i0)
                        {
                            Prop_LangCode.stringValue = currentCode.Substring(i0 + 1, i1 - i0 - 1);
                        }
                        else
                        {
                            Prop_LangCode.stringValue = string.Empty;
                        }
                    }
                    var rect = GUILayoutUtility.GetLastRect();
                    GUI.Label(rect, Prop_LangCode.stringValue, EditorStyles.toolbarPopup);
                }
                else
                {
                    GUILayout.Label(Prop_LangCode.stringValue, EditorStyles.toolbarPopup, GUILayout.Width(60));
                }

                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 (TestButtonArg(eTest_ActionType.Button_Languages_TranslateAll, i, new GUIContent("Translate", "Translate all empty terms"), EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
                {
                    GUITools.DelayedCall(() => TranslateAllToLanguage(LanName));
                }
                GUI.enabled = true;
                GUI.color   = Color.white;

                EditorGUI.BeginChangeCheck();
                isLanguageEnabled = EditorGUILayout.Toggle(isLanguageEnabled, GUILayout.Width(15));

                var r = GUILayoutUtility.GetLastRect();
                GUI.Label(r, new GUIContent("", "Enable/Disable the language.\nDisabled languages can be used to store data values or to avoid showing Languages that are stil under development"));

                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(LocalizeInspector.GUIStyle_OldTextArea);
                GUILayout.Label(Loading, EditorStyles.miniLabel);
                GUI.color = Color.white;
                if (GUILayout.Button("Cancel", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
                {
                    GoogleTranslation.CancelCurrentGoogleTranslations();
                    StopConnectionWWW();
                }
                GUILayout.EndHorizontal();
                Repaint();
            }

            if (IndexLanguageToDelete >= 0)
            {
                if (EditorUtility.DisplayDialog("Confirm delete", "Are you sure you want to delete the selected language", "Yes", "Cancel"))
                {
                    mLanguageSource.RemoveLanguage(mLanguageSource.mLanguages [IndexLanguageToDelete].Name);
                    serializedObject.Update();
                    ParseTerms(true, false, false);
                }
            }

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