コード例 #1
0
        public override void OnInspectorGUI()
        {
            EditorGUILayout.PropertyField(serializedObject.FindProperty("key"), new GUIContent("Key"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("displayErrorMessage"), new GUIContent("Display Error Message"));

            EditorScriptingUtils.HorizontalLine();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("useFallBackLanguage"), new GUIContent("Use Fallback Language"));
            if (serializedObject.FindProperty("useFallBackLanguage").boolValue)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("fallbackLanguage"), new GUIContent("Fallback Language"));
            }
            EditorScriptingUtils.HorizontalLine();

            EditorGUILayout.PropertyField(serializedObject.FindProperty("prefix"), new GUIContent("Prefix"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("suffix"), new GUIContent("Suffix"));

            serializedObject.ApplyModifiedProperties();
        }
コード例 #2
0
        private void OnGUI()
        {
            var languages = Localizator.GetAvailableLanguages();
            var localizationPercentages = Localizator.GetLocalizationPercentages();

            EditorScriptingUtils.BeginCenter();
            GUILayout.Label("Current Language(s)", EditorStyles.largeLabel);
            EditorScriptingUtils.EndCenter();

            EditorScriptingUtils.HorizontalLine(3);

            var languageButtonStyle = new GUIStyle(EditorStyles.miniButton)
            {
                fixedHeight = 30f,
                fixedWidth  = position.width * .3f,
                fontSize    = 12,
                padding     = new RectOffset(10, 10, 5, 5),
                alignment   = TextAnchor.MiddleCenter,
                richText    = true
            };

            scrollPos = GUILayout.BeginScrollView(scrollPos, false, true);
            foreach (var language in languages)
            {
                EditorScriptingUtils.BeginCenter();
                GUILayout.BeginHorizontal();
                var localizationPercentage = localizationPercentages[language];

                // Label
                GUILayout.Label($"<color={(localizationPercentage > 90f ? "green" : "red")}><b>{language.ToString()}</b>, {localizationPercentage}% Localized</color>",
                                languageButtonStyle);

                // Switch to the language
                if (GUILayout.Button($"Switch", languageButtonStyle))
                {
                    Localizator.UpdateLanguage(language);
                    Debug.Log($"Switched to the {language} language.");
                }

                // Remove the language
                if (GUILayout.Button($"Remove", languageButtonStyle))
                {
                    var dialogOutput = EditorUtility.DisplayDialog(
                        $"{language} language will be removed from the project permanently",
                        $"Are you sure you want to remove {language} language from your project?",
                        "Yes",
                        "No");

                    if (dialogOutput)
                    {
                        Localizator.RemoveLanguage(language);
                        ((KeyBrowser)GetWindow(typeof(KeyBrowser))).UpdateArrays();
                    }
                }

                GUILayout.EndHorizontal();
                EditorScriptingUtils.EndCenter();
            }

            GUILayout.EndScrollView();

            EditorScriptingUtils.HorizontalLine(3);

            // Language
            GUILayout.BeginHorizontal();
            GUILayout.Label("Language to add: ");
            languageToAdd = (SystemLanguage)EditorGUILayout.EnumPopup(languageToAdd, GUILayout.Width(200f));
            GUILayout.EndHorizontal();

            // File Name
            GUILayout.BeginHorizontal();
            GUILayout.Label("File Name: ");
            languageFileName = GUILayout.TextField(languageFileName, GUILayout.Width(200f));
            languageFileName = languageFileName.Replace(' ', '_').ToLower();
            GUILayout.EndHorizontal();

            // Language Name
            GUILayout.BeginHorizontal();
            GUILayout.Label("Language Name: ");
            languageName = GUILayout.TextField(languageName, GUILayout.Width(200f));
            GUILayout.EndHorizontal();

            // Localization Error Message
            GUILayout.BeginHorizontal();
            GUILayout.Label("Localization Error Message: ");
            localizationErrorMessage = GUILayout.TextField(localizationErrorMessage, GUILayout.Width(200f));
            GUILayout.EndHorizontal();

            bool canCreateLanguage = Array.IndexOf(Localizator.GetCurrentLanguageFiles(), languageFileName.Trim()) == -1 &&
                                     !string.IsNullOrWhiteSpace(languageFileName) &&
                                     Array.IndexOf(Localizator.GetAvailableLanguages(), languageToAdd) == -1;

            if (canCreateLanguage)
            {
                if (GUILayout.Button($"Add {languageToAdd} language"))
                {
                    var dialogOutput = EditorUtility.DisplayDialog(
                        $"{languageToAdd} language file will be created",
                        "Are you sure you want to add this language ?",
                        "Add",
                        "Cancel");

                    if (dialogOutput)
                    {
                        Localizator.CreateLanguage(languageToAdd, languageFileName.Replace('.', '_'), languageName,
                                                   localizationErrorMessage);
                        ((KeyBrowser)GetWindow(typeof(KeyBrowser))).UpdateArrays();
                    }
                }
            }
            else
            {
                EditorGUILayout.HelpBox("The file name entered or the desired language is invalid",
                                        MessageType.Warning);
            }
        }
コード例 #3
0
ファイル: KeyEditor.cs プロジェクト: AtaTrkgl/Unity-DartCore
        private void OnGUI()
        {
            var keySearchBarStyle = new GUIStyle(EditorStyles.textField)
            {
                fixedWidth  = position.width * .99f,
                fixedHeight = 23f,
                alignment   = TextAnchor.MiddleCenter,
                fontSize    = 12
            };

            key = GUILayout.TextField(key, keySearchBarStyle);
            key = Localizator.ConvertRawToKey(key);

            GUILayout.Space(10f);
            Localizator.UpdateKeyFile();

            if (key != keyLastValue || values.Length != Localizator.GetLanguageCount())
            {
                values = new string[Localizator.GetLanguageCount()];
            }

            if (Localizator.DoesContainKey(key))
            {
                scrollPos = GUILayout.BeginScrollView(scrollPos, false, true);
                for (var i = 0; i < values.Length; i++)
                {
                    if (values[i] == null)
                    {
                        values[i] = Localizator.GetString(key, Localizator.GetAvailableLanguages()[i], false);
                    }
                    GUILayout.BeginHorizontal();

                    var isSameAsTheSavedValue = values[i] == Localizator.GetString(key, Localizator.GetAvailableLanguages()[i], false);
                    GUI.color = isSameAsTheSavedValue ? Color.green : Color.red;
                    EditorGUILayout.LabelField($"{Localizator.GetAvailableLanguages()[i]}: ",
                                               GUILayout.MaxWidth(50));
                    GUI.color = Color.white;

                    var customTextAreaStyle = EditorStyles.textArea;
                    customTextAreaStyle.wordWrap      = true;
                    customTextAreaStyle.fixedHeight   = 0;
                    customTextAreaStyle.stretchHeight = true;

                    values[i] = EditorGUILayout.TextArea(
                        values[i], customTextAreaStyle);

                    GUILayout.EndHorizontal();
                }

                GUILayout.EndScrollView();

                if (GUILayout.Button("Update Values"))
                {
                    for (var i = 0; i < values.Length; i++)
                    {
                        Localizator.AddLocalizedValue(key, values[i], Localizator.GetAvailableLanguages()[i]);
                    }

                    Localizator.RefreshAll();
                    RefreshKeyBrowser();
                }

                if (GUILayout.Button("Remove Key"))
                {
                    var dialogOutput = EditorUtility.DisplayDialog(
                        $"{key} will be removed permanently",
                        "Are you sure you want to remove this key?",
                        "Remove",
                        "Cancel");
                    if (dialogOutput)
                    {
                        Localizator.RemoveKey(key);
                        Localizator.RefreshAll();

                        RefreshKeyBrowser();
                    }
                }

                // Renaming
                EditorScriptingUtils.BeginCenter();

                var canRename = !Localizator.DoesContainKey(newName.Trim()) &&
                                !string.IsNullOrWhiteSpace(newName.Trim());
                if (GUILayout.Button("Rename Key", GUILayout.Width(this.position.width * .5f)))
                {
                    if (canRename)
                    {
                        Localizator.AddKey(newName.Trim());
                        foreach (var language in Localizator.GetAvailableLanguages())
                        {
                            Localizator.AddLocalizedValue(newName.Trim(), Localizator.GetString(key, language, returnErrorString: false), language);
                        }

                        Localizator.RemoveKey(key);

                        key     = newName.Trim();
                        newName = "";
                        RefreshKeyBrowser();
                    }
                }

                newName = Localizator.ConvertRawToKey(GUILayout.TextField(newName, GUILayout.Width(this.position.width * .5f)));
                EditorScriptingUtils.EndCenter();
                if (Localizator.DoesContainKey(newName.Trim()))
                {
                    EditorGUILayout.HelpBox("The key name entered is already in use.",
                                            MessageType.Warning);
                }
            }
            else if (GUILayout.Button("Add New Key") && !string.IsNullOrEmpty(key) && !string.IsNullOrWhiteSpace(key))
            {
                Localizator.AddKey(key);
                RefreshKeyBrowser();
            }

            keyLastValue = key;
        }
コード例 #4
0
        private void OnGUI()
        {
            // Styles
            var languageDisplayerStyle = new GUIStyle
            {
                richText    = true,
                fixedHeight = ELEMENT_HEIGHT,
                fontStyle   = FontStyle.Bold,
                fontSize    = 12,
                padding     = new RectOffset(10, 10, 5, 5)
            };
            var keyButtonStyle = new GUIStyle(EditorStyles.miniButton)
            {
                fixedHeight = ELEMENT_HEIGHT,
                fixedWidth  = ELEMENT_WIDTH,
                fontSize    = 12,
                padding     = new RectOffset(10, 10, 5, 5)
            };
            var keyButtonStyleBold = new GUIStyle(GUI.skin.button)
            {
                fixedHeight = ELEMENT_HEIGHT,
                fixedWidth  = ELEMENT_WIDTH,
                fontSize    = 12,
                fontStyle   = FontStyle.BoldAndItalic,
                padding     = new RectOffset(10, 10, 5, 5)
            };

            if (GUILayout.Button("Refresh", GUILayout.Height(BUTTON_HEIGHT)) || !keysInit)
            {
                Refresh();
            }

            GUILayout.Space(10);

            var searchStyle = new GUIStyle(EditorStyles.textField)
            {
                fixedWidth  = position.width * .99f,
                fixedHeight = 23f,
                alignment   = TextAnchor.MiddleCenter,
                fontSize    = 12
            };

            search = GUILayout.TextField(search, searchStyle);
            search = search.Replace(' ', '_').ToLower();
            Search(search);

            // Search Options
            SetLocalizationStatus((LocalizationStatus)EditorGUILayout.EnumPopup(statusToDisplay));

            GUILayout.Space(10);
            EditorScriptingUtils.HorizontalLine(3);

            var rectPos  = EditorGUILayout.GetControlRect();
            var rectBox  = new Rect(rectPos.x, rectPos.y, rectPos.width, position.height - 110);
            var viewRect = new Rect(rectPos.x, rectPos.y,
                                    currentLanguages.Length * LANGUAGE_NAME_DISPLAYER_WIDTH + ELEMENT_WIDTH, searchedKeys.Count * ELEMENT_HEIGHT);

            scrollPos = GUI.BeginScrollView(rectBox, scrollPos, viewRect, false, true);

            var viewCount  = Mathf.FloorToInt((position.height - 110) / ELEMENT_HEIGHT);
            var firstIndex = Mathf.FloorToInt(scrollPos.y / ELEMENT_HEIGHT);

            var contentPos = new Rect(rectBox.x, firstIndex * ELEMENT_HEIGHT + 80f, rectBox.width, ELEMENT_HEIGHT);

            Localizator.UpdateKeyFile();

            for (var i = firstIndex; i < Mathf.Min(firstIndex + viewCount, searchedKeys.Count); i++)
            {
                contentPos.y += ELEMENT_HEIGHT;

                var localizationStatus = Localizator.GetLocalizationStatusOfKey(searchedKeys[i]);

                // Displaying
                EditorGUILayout.BeginHorizontal();

                var currentKey = searchedKeys[i];
                if (GUI.Button(contentPos, currentKey,
                               currentKey == "lng_name" || currentKey == "lng_error" ? keyButtonStyleBold : keyButtonStyle))
                {
                    KeyEditor.key = currentKey;

                    var window = (KeyEditor)GetWindow(typeof(KeyEditor), false, "Key Editor", true);
                    window.Show();
                    FocusWindowIfItsOpen(typeof(KeyEditor));
                }

                GUILayout.FlexibleSpace();
                for (var j = 0; j < currentLanguages.Length; j++)
                {
                    var language           = currentLanguages[j];
                    var xOffset            = ELEMENT_WIDTH + j * LANGUAGE_NAME_DISPLAYER_WIDTH;
                    var offsetedContentPos = new Rect(contentPos.x + xOffset, contentPos.y, contentPos.width, ELEMENT_HEIGHT);
                    GUI.Label(offsetedContentPos,
                              localizationStatus[j]
                            ? $"<color=green>{language.ToString()}</color>"
                            : $"<color=red>{language.ToString()}</color>",
                              languageDisplayerStyle);
                }

                EditorGUILayout.EndHorizontal();
            }

            GUI.EndScrollView();
        }