Exemplo n.º 1
0
                private void RenderTitleBar()
                {
                    EditorGUILayout.BeginVertical();
                    {
                        //Load save
                        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                        {
                            if (GUILayout.Button("Save", EditorStyles.toolbarButton))
                            {
                                Localisation.SaveStrings();
                            }

                            if (GUILayout.Button("Reload", EditorStyles.toolbarButton))
                            {
                                Localisation.ReloadStrings();
                                UpdateKeys();
                            }

                            EditorGUILayout.Separator();

                            GUILayout.Button("Scale", EditorStyles.toolbarButton);

                            int fontSize = EditorGUILayout.IntSlider(_editorPrefs._tableFontSize, kMinFontSize, kMaxFontSize);

                            if (GUILayout.Button("Reset Scale", EditorStyles.toolbarButton))
                            {
                                fontSize = kDefaultFontSize;
                            }

                            if (_editorPrefs._tableFontSize != fontSize)
                            {
                                _editorPrefs._tableFontSize = fontSize;
                                _textStyle.fontSize         = _editorPrefs._tableFontSize;
                                _selectedTextStyle.fontSize = _editorPrefs._tableFontSize;
                                SaveEditorPrefs();
                            }

                            EditorGUILayout.Separator();

                            GUILayout.Button("Font", EditorStyles.toolbarButton);

                            Font currentFont = _editorPrefs._font.GetAsset();
                            Font font        = (Font)EditorGUILayout.ObjectField(currentFont, typeof(Font), false);

                            if (currentFont != font)
                            {
                                _editorPrefs._font = new EditorAssetRef <Font>(font);

                                if (font == null)
                                {
                                    _textStyle.font = _keyStyle.font;
                                }
                                else
                                {
                                    _textStyle.font = font;
                                }

                                SaveEditorPrefs();
                            }

                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();

                        //Filters
                        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                        {
                            GUILayout.Button("Filter", EditorStyles.toolbarButton);

                            EditorGUI.BeginChangeCheck();
                            _filter = EditorGUILayout.TextField(_filter, EditorStyles.toolbarSearchField);
                            if (EditorGUI.EndChangeCheck())
                            {
                                _needsRepaint = true;
                                UpdateKeys();
                            }

                            if (GUILayout.Button("Clear", EditorStyles.toolbarButton))
                            {
                                _filter = "";
                                UpdateKeys();
                                SelectKey(_editorPrefs._selectedKeys);
                            }

                            if (GUILayout.Button("Choose Localisation Folder", EditorStyles.toolbarButton))
                            {
                                string folder = LocalisationProjectSettings.Get()._localisationFolder;
                                folder = EditorUtility.OpenFolderPanel("Choose Localisation Folder", folder, "");

                                if (!string.IsNullOrEmpty(folder))
                                {
                                    LocalisationProjectSettings.Get()._localisationFolder = AssetUtils.GetAssetPath(folder);
                                    AssetDatabase.SaveAssets();
                                    Localisation.ReloadStrings(true);
                                    _needsRepaint = true;
                                }
                            }

                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();

                        //Headers
                        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                        {
                            float keyWidth           = _editorPrefs._keyWidth - (kResizerWidth * 0.5f);
                            float firstLanguageWidth = _editorPrefs._firstLanguageWidth - kResizerWidth;
                            float secondLangWidth    = position.width - _editorPrefs._keyWidth - _editorPrefs._firstLanguageWidth;

                            keyWidth -= _scrollPosition.x;

                            //Key
                            if (GUILayout.Button("Key", EditorStyles.toolbarButton, GUILayout.Width(Mathf.Max(keyWidth, 0f))))
                            {
                                _sortOrder = _sortOrder == eKeySortOrder.Desc ? eKeySortOrder.Asc : eKeySortOrder.Desc;
                            }

                            //Keys Resizer
                            RenderResizer(ref _keysResizerRect);

                            //Current Language
                            string label = "Current Language (" + Localisation.GetCurrentLanguage().ToString() + ")";
                            if (GUILayout.Button(label, EditorStyles.toolbarButton, GUILayout.Width(firstLanguageWidth)))
                            {
                                GenericMenu menu = new GenericMenu();

                                foreach (SystemLanguage lang in Enum.GetValues(typeof(SystemLanguage)))
                                {
                                    menu.AddItem(new GUIContent(lang.ToString()), false, OnChangeCurrentLanguage, lang);
                                }

                                menu.ShowAsContext();
                            }

                            //Language Resizer
                            RenderResizer(ref _languageResizerRect);

                            //Second Language
                            EditorGUI.BeginChangeCheck();
                            SystemLanguage language = (SystemLanguage)EditorGUILayout.EnumPopup(_editorPrefs._secondLanguage, EditorStyles.toolbarPopup, GUILayout.Width(secondLangWidth));
                            if (EditorGUI.EndChangeCheck())
                            {
                                //Unload the strings if second language is not current
                                if (_editorPrefs._secondLanguage != Localisation.GetCurrentLanguage())
                                {
                                    Localisation.UnloadStrings(_editorPrefs._secondLanguage);
                                }

                                _editorPrefs._secondLanguage = language;

                                //If new language isn't current load strings
                                if (language != Localisation.GetCurrentLanguage())
                                {
                                    Localisation.LoadStrings(language);
                                }
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.EndVertical();
                }
Exemplo n.º 2
0
                private void RenderTitleBar()
                {
                    EditorGUILayout.BeginVertical(GUILayout.Height(kToolBarHeight));
                    {
                        //Title
                        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                        {
                            string titleText = kWindowTitle + " - <b>Localisation.xml</b>";

                            if (Localisation.HasUnsavedChanges())
                            {
                                titleText += "<b>*</b>";
                            }

                            EditorGUILayout.LabelField(titleText, _titleStyle);
                        }
                        EditorGUILayout.EndHorizontal();

                        //Load save
                        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                        {
                            if (GUILayout.Button("Save", EditorStyles.toolbarButton))
                            {
                                Localisation.SaveStrings();
                            }

                            if (GUILayout.Button("Reload", EditorStyles.toolbarButton))
                            {
                                Localisation.LoadStrings();
                            }

                            EditorGUILayout.Separator();

                            GUILayout.Button("Scale", EditorStyles.toolbarButton);

                            int fontSize = EditorGUILayout.IntSlider(_editorPrefs._fontSize, 8, 16);

                            if (GUILayout.Button("Reset Scale", EditorStyles.toolbarButton))
                            {
                                fontSize = kDefaultFontSize;
                                EditorGUI.FocusTextInControl(string.Empty);
                            }

                            if (_editorPrefs._fontSize != fontSize)
                            {
                                _editorPrefs._fontSize = fontSize;
                                _keyStyle.fontSize     = _editorPrefs._fontSize;
                                _textStyle.fontSize    = _editorPrefs._fontSize;
                                SaveEditorPrefs();
                            }

                            EditorGUILayout.Separator();

                            GUILayout.Button("Font", EditorStyles.toolbarButton);

                            Font currentFont = _editorPrefs._font.GetAsset();
                            Font font        = (Font)EditorGUILayout.ObjectField(currentFont, typeof(Font), false);

                            if (currentFont != font)
                            {
                                _editorPrefs._font = new EditorAssetRef <Font>(font);

                                if (font == null)
                                {
                                    _textStyle.font = _keyStyle.font;
                                }
                                else
                                {
                                    _textStyle.font = font;
                                }

                                SaveEditorPrefs();
                            }

                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();

                        //Filters
                        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                        {
                            GUILayout.Button("Filter", EditorStyles.toolbarButton);

                            EditorGUI.BeginChangeCheck();
                            _filter = EditorGUILayout.TextField(_filter);
                            if (EditorGUI.EndChangeCheck())
                            {
                                _needsRepaint = true;
                            }

                            if (GUILayout.Button("Clear", EditorStyles.toolbarButton))
                            {
                                _filter = "";
                                EditorGUI.FocusTextInControl(string.Empty);
                            }

                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();

                        //Headers
                        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                        {
                            //Key
                            if (GUILayout.Button("Key", EditorStyles.toolbarButton, GUILayout.Width(_editorPrefs._keyWidth - 11)))
                            {
                                _sortOrder = _sortOrder == eKeySortOrder.Desc ? eKeySortOrder.Asc : eKeySortOrder.Desc;
                            }

                            EditorGUILayout.Separator();

                            //Resizer
                            RenderResizer();

                            //Text
                            EditorGUI.BeginChangeCheck();
                            SystemLanguage language = (SystemLanguage)EditorGUILayout.EnumPopup(Localisation.GetCurrentLanguage(), EditorStyles.toolbarButton);
                            if (EditorGUI.EndChangeCheck())
                            {
                                Localisation.SetLanguage(language);
                            }

                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.EndVertical();
                }
                private void RenderTitleBar()
                {
                    EditorGUILayout.BeginVertical(GUILayout.Height(kToolBarHeight));
                    {
                        //Title
                        EditorGUILayout.BeginHorizontal(_toolbarStyle);
                        {
                            string titleText = kWindowTitle + " - <b>Localisation.xml</b>";

                            if (Localisation.HasUnsavedChanges())
                            {
                                titleText += "<b>*</b>";
                            }

                            EditorGUILayout.LabelField(titleText, _titleStyle);
                        }
                        EditorGUILayout.EndHorizontal();

                        //Load save
                        EditorGUILayout.BeginHorizontal(_toolbarStyle);
                        {
                            if (GUILayout.Button("Save", EditorStyles.toolbarButton))
                            {
                                Localisation.SaveStrings();
                            }

                            if (GUILayout.Button("Reload", EditorStyles.toolbarButton))
                            {
                                Localisation.ReloadStrings();
                            }

                            EditorGUILayout.Separator();

                            GUILayout.Button("Scale", EditorStyles.toolbarButton);

                            int fontSize = EditorGUILayout.IntSlider(_editorPrefs._fontSize, 8, 16);

                            if (GUILayout.Button("Reset Scale", EditorStyles.toolbarButton))
                            {
                                fontSize = kDefaultFontSize;
                                EditorGUI.FocusTextInControl(string.Empty);
                            }

                            if (_editorPrefs._fontSize != fontSize)
                            {
                                _editorPrefs._fontSize = fontSize;
                                _keyStyle.fontSize     = _editorPrefs._fontSize;
                                _textStyle.fontSize    = _editorPrefs._fontSize;
                                SaveEditorPrefs();
                            }

                            EditorGUILayout.Separator();

                            GUILayout.Button("Font", EditorStyles.toolbarButton);

                            Font currentFont = _editorPrefs._font.GetAsset();
                            Font font        = (Font)EditorGUILayout.ObjectField(currentFont, typeof(Font), false);

                            if (currentFont != font)
                            {
                                _editorPrefs._font = new EditorAssetRef <Font>(font);

                                if (font == null)
                                {
                                    _textStyle.font = _keyStyle.font;
                                }
                                else
                                {
                                    _textStyle.font = font;
                                }

                                SaveEditorPrefs();
                            }

                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();

                        //Filters
                        EditorGUILayout.BeginHorizontal(_toolbarStyle);
                        {
                            GUILayout.Button("Filter", EditorStyles.toolbarButton);

                            EditorGUI.BeginChangeCheck();
                            _filter = EditorGUILayout.TextField(_filter);
                            if (EditorGUI.EndChangeCheck())
                            {
                                _needsRepaint = true;
                            }

                            if (GUILayout.Button("Clear", EditorStyles.toolbarButton))
                            {
                                _filter = "";
                                EditorGUI.FocusTextInControl(string.Empty);
                            }

                            if (GUILayout.Button("Choose Localisation Folder", EditorStyles.toolbarButton))
                            {
                                string folder = LocalisationProjectSettings.Get()._localisationFolder;
                                folder = EditorUtility.OpenFolderPanel("Choose Localisation Folder", folder, "");
                                LocalisationProjectSettings.Get()._localisationFolder = AssetUtils.GetAssetPath(folder);
                                AssetDatabase.SaveAssets();
                                Localisation.ReloadStrings(true);
                                _needsRepaint = true;
                            }

                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();

                        //Headers
                        EditorGUILayout.BeginHorizontal();
                        {
                            //Key
                            EditorGUILayout.BeginHorizontal(_toolbarStyle, GUILayout.Width(_editorPrefs._keyWidth - 3));
                            {
                                if (GUILayout.Button("Key", EditorStyles.toolbarButton, GUILayout.ExpandWidth(true)))
                                {
                                    _sortOrder = _sortOrder == eKeySortOrder.Desc ? eKeySortOrder.Asc : eKeySortOrder.Desc;
                                }
                            }
                            EditorGUILayout.EndHorizontal();

                            //Keys Resizer
                            RenderResizer(ref _keysResizerRect);

                            //Text
                            EditorGUILayout.BeginHorizontal(_toolbarStyle, GUILayout.Width(_editorPrefs._firstLanguageWidth - 3));
                            {
                                //First Language
                                GUILayout.Button(Localisation.GetCurrentLanguage().ToString(), EditorStyles.toolbarButton, GUILayout.ExpandWidth(true));
                            }
                            EditorGUILayout.EndHorizontal();

                            //Language Resizer
                            RenderResizer(ref _languageResizerRect);

                            //Second Language
                            float secondLangWidth = position.width - _editorPrefs._keyWidth - _editorPrefs._firstLanguageWidth;

                            EditorGUILayout.BeginHorizontal(_toolbarStyle, GUILayout.Width(secondLangWidth));
                            {
                                EditorGUI.BeginChangeCheck();
                                SystemLanguage language = (SystemLanguage)EditorGUILayout.EnumPopup(_editorPrefs._secondLanguage, EditorStyles.toolbarButton);
                                if (EditorGUI.EndChangeCheck())
                                {
                                    if (_editorPrefs._secondLanguage != Localisation.GetCurrentLanguage())
                                    {
                                        Localisation.UnloadStrings(_editorPrefs._secondLanguage);
                                    }

                                    _editorPrefs._secondLanguage = language;
                                }
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.EndVertical();
                }