Beispiel #1
0
        protected override void OnDrawGUI()
        {
            _currentLanguageData.Language.Name = EditorGUILayout.TextField("Language Name:", _currentLanguageData.Language.Name);

            DrawCultures();

            EditorWindowHelper.DrawUILine(Color.grey);

            DrawTranslations();

            EditorWindowHelper.DrawUILine(Color.grey);

            if (GUILayout.Button("Save"))
            {
                if (IsFileValid() && AreCulturesValid())
                {
                    if (_isNew)
                    {
                        CreateAsset();
                    }
                    else
                    {
                        SaveAssetAndClose();
                    }
                }
            }

            if (!string.IsNullOrEmpty(_errors))
            {
                EditorGUILayout.HelpBox(_errors, MessageType.Error);
            }
        }
     private void DrawDebug()
     {
 #if SIMPLEI18NDEBUG
         _showDebug = EditorGUILayout.Toggle("Show Debug? ", _showDebug);
         if (_showDebug)
         {
             EditorWindowHelper.DebugShowWindowBounds(position);
         }
 #endif
     }
        private void DrawNoKeysDetected()
        {
            EditorGUILayout.HelpBox(string.Format("No keys found in path {0}\n\n You want to create one?", KeysFilePath), MessageType.Info);

            EditorWindowHelper.HorizontalLayout(() =>
            {
                if (GUILayout.Button("Create Keys file"))
                {
                    var newFile = ScriptableObject.CreateInstance <SimpleLanguageKeys>();
                    AssetDatabase.CreateAsset(newFile, KeysFilePath);
                    EditorUtility.SetDirty(newFile);
                    AssetDatabase.SaveAssets();
                }
            });
        }
        private void DrawNoConfigDetected()
        {
            EditorGUILayout.HelpBox(string.Format("No config found in path {0}\n\n You want to create one?", ConfigFilePath), MessageType.Info);

            EditorWindowHelper.HorizontalLayout(() =>
            {
                if (GUILayout.Button("Create Config"))
                {
                    AssetDatabase.CreateFolder("Assets/Resources", "Localization");
                    var newConfig = ScriptableObject.CreateInstance <SimpleLanguageConfig>();
                    AssetDatabase.CreateAsset(newConfig, ConfigFilePath);
                    EditorUtility.SetDirty(newConfig);
                    AssetDatabase.SaveAssets();
                }
            });
        }
        protected override void OnDrawGUI()
        {
            if (CurrentConfig == null)
            {
                DrawNoConfigDetected();
                return;
            }

            if (CurrentKeys == null)
            {
                DrawNoKeysDetected();
                return;
            }

            if (!CurrentConfig.Languages.Any())
            {
                EditorWindowHelper.HorizontalLayout(() =>
                {
                    EditorGUILayout.HelpBox("No languages detected!", MessageType.Info);
                });
            }

            EditorGUILayout.LabelField("Basic Configuration");

            EditorGUI.BeginChangeCheck();

            CurrentConfig.AutodetectLanguage =
                EditorGUILayout.Toggle("Autodetect Language: ", CurrentConfig.AutodetectLanguage);

            if (GUI.changed)
            {
                EditorUtility.SetDirty(CurrentConfig);
                AssetDatabase.SaveAssets();
            }

            EditorGUI.EndChangeCheck();

            DrawLanguages();

            EditorWindowHelper.HorizontalLayout(() =>
            {
                if (GUILayout.Button("Create Language!"))
                {
                    EditOrCreateLanguage();
                }
            });
        }
Beispiel #6
0
        private void DrawCultures()
        {
            EditorGUILayout.LabelField("Selected Cultures:");

            if (!_currentLanguageData.Language.Cultures.Any())
            {
                EditorGUILayout.HelpBox("Add at least one culture", MessageType.Info);
            }

            for (int i = _currentLanguageData.Language.Cultures.Count - 1; i >= 0; i--)
            {
                var culture = _currentLanguageData.Language.Cultures[i];

                EditorWindowHelper.HorizontalLayout(() =>
                {
                    EditorGUILayout.LabelField(culture);
                    var rect = GUILayoutUtility.GetLastRect();
                    if (GUI.Button(new Rect(rect.x + 100, rect.y, 25, rect.height), "-"))
                    {
                        _currentLanguageData.Language.Cultures.Remove(culture);
                    }
                });
            }

            EditorGUI.BeginChangeCheck();
            _selectedCulture = EditorGUILayout.Popup("Add Culture:", _selectedCulture, Cultures);

            if (GUI.changed)
            {
                IsCultureAddValid();
            }

            EditorGUI.EndChangeCheck();

            if (!string.IsNullOrEmpty(_cultureErrors))
            {
                EditorGUILayout.HelpBox(_cultureErrors, MessageType.Error);
            }

            if (GUILayout.Button("Add Culture") && IsCultureAddValid())
            {
                _currentLanguageData.Language.Cultures.Add(Cultures[_selectedCulture]);
            }
        }
Beispiel #7
0
        private void DrawCustomInspector()
        {
            if (SimpleLocalizationWindow.CurrentKeys != null)
            {
                _selectedKeyIndex = EditorGUILayout.Popup("Key", _selectedKeyIndex, _availableKeys);

                if (GUI.changed)
                {
                    _localizationKey.stringValue = _availableKeys[_selectedKeyIndex];
                }

                if (GUILayout.Button("Edit Keys file"))
                {
                    Selection.activeObject = SimpleLocalizationWindow.CurrentKeys;
                }

                if (!SimpleLocalizationWindow.CurrentKeys.Keys.Contains(_localizationKey.stringValue))
                {
                    _errorText = "Key not found or empty";
                    EditorGUILayout.HelpBox(string.Format("Key '{0}' not found in Keys file.\nCheck your Keys files in '{1}'", _localizationKey.stringValue, SimpleLocalizationWindow.KeysFilePath), MessageType.Warning);
                }
                else
                {
                    _errorText = string.Empty;
                }
            }
            else
            {
                EditorGUILayout.PropertyField(_localizationKey);

                if (GUI.changed)
                {
                    _localizationKey.stringValue = _localizationKey.stringValue.Trim();
                }
                _errorText = "Keys file not found";
                EditorGUILayout.HelpBox("Warning, keys file not found. Key validation is disabled.", MessageType.Warning);
            }

            EditorWindowHelper.DrawUILine(Color.grey);
        }
Beispiel #8
0
        public override void OnInspectorGUI()
        {
            EditorGUILayout.LabelField("Simple localization Configuration");

            if (_config.AutodetectLanguage)
            {
                EditorGUILayout.HelpBox("Autodetect language is enabled.", MessageType.Info);
            }
            else
            {
                EditorGUILayout.HelpBox("Autodetect language is disabled.\nThis will use the default language unless you change it in runtime.", MessageType.Warning);
            }

            if (_config.DefaultLanguage != null)
            {
                EditorGUILayout.HelpBox(string.Format("Default language is {0}", _config.DefaultLanguage.Language.Name), MessageType.Info);
            }
            else
            {
                EditorGUILayout.HelpBox("Setup a default language to prevent errors at runtime.", MessageType.Warning);
            }

            EditorGUILayout.HelpBox(string.Format("You have {0} languages configured", _config.Languages.Count), MessageType.Info);

            EditorWindowHelper.DrawUILine(Color.grey);

            if (SimpleLocalizationWindow.CurrentConfig != _config)
            {
                EditorGUILayout.HelpBox("This config isn't the Default config. You're unable to edit external configurations.", MessageType.Warning);
                return;
            }

            if (GUILayout.Button("Open Config Editor"))
            {
                SimpleLocalizationConfigWindow.DisplayWindow();
            }
        }
        public override void OnInspectorGUI()
        {
            EditorGUILayout.LabelField("Localization Keys");

            _keyFilter = EditorGUILayout.TextField("Search: ", _keyFilter);

            EditorWindowHelper.DrawUILine(Color.gray);

            var hRect = EditorGUILayout.BeginHorizontal();

            _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos, false, false, GUILayout.Width(hRect.width), GUILayout.MaxHeight(300));

            for (int i = _keys.Keys.Count - 1; i >= 0; i--)
            {
                int realIndex = _keys.Keys.Count - 1 - i;

                if (!_keys.Keys[realIndex].Contains(_keyFilter))
                {
                    continue;
                }

                EditorGUILayout.LabelField("");
                Rect rect = GUILayoutUtility.GetLastRect();
                _keys.Keys[realIndex] = GUI.TextField(new Rect(rect.x, rect.y, rect.width - 45, 20), _keys.Keys[realIndex]);

                if (GUI.Button(new Rect(rect.width - 40, rect.y, 35, 20), "-"))
                {
                    Undo.RecordObject(_keys, string.Format("Removed key ({0})", _keys.Keys[realIndex]));
                    _keys.Keys.RemoveAt(realIndex);
                    EditorUtility.SetDirty(_keys);
                    AssetDatabase.SaveAssets();
                }
            }

            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndHorizontal();

            EditorWindowHelper.DrawUILine(Color.gray);

            EditorGUI.BeginChangeCheck();
            _keyToAdd = EditorGUILayout.TextField("Key To Add: ", _keyToAdd);

            if (GUI.changed)
            {
                _errors = string.Empty;
            }

            EditorGUI.EndChangeCheck();

            if (GUILayout.Button("Add") || EditorWindowHelper.DetectKey(KeyCode.Return) || EditorWindowHelper.DetectKey(KeyCode.KeypadEnter))
            {
                string cleanKey = _keyToAdd.Trim();

                if (!string.IsNullOrWhiteSpace(cleanKey))
                {
                    if (!_keys.Keys.Contains(cleanKey))
                    {
                        Undo.RecordObject(_keys, string.Format("Added key ({0})", cleanKey));
                        _keys.Keys.Add(cleanKey);
                        _keyToAdd = string.Empty;
                        EditorUtility.SetDirty(_keys);
                        AssetDatabase.SaveAssets();
                    }
                    else
                    {
                        _errors = string.Format("Key '{0}' already exist in dictionary", cleanKey);
                    }
                }
                else
                {
                    _errors = "Key cannot be empty";
                }
            }

            if (!string.IsNullOrEmpty(_errors))
            {
                EditorGUILayout.HelpBox(_errors, MessageType.Error);
            }
        }