コード例 #1
0
                private void RenderTable()
                {
                    Vector2 scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, false, false);

                    {
                        if (_scrollPosition != scrollPosition)
                        {
                            _scrollPosition = scrollPosition;
                            EditorGUI.FocusTextInControl(string.Empty);
                        }

                        //On layout, check what part of table is currently being viewed
                        if (Event.current.type == EventType.Layout)
                        {
                            _keys = GetKeys();
                            GetViewableRange(_scrollPosition.y, GetTableAreaHeight(), out _viewStartIndex, out _viewEndIndex, out _contentStart, out _contentHeight);
                        }

                        EditorGUILayout.BeginVertical(GUILayout.Height(_contentHeight));
                        {
                            GUILayout.Label(GUIContent.none, GUILayout.Height(_contentStart));

                            for (int i = _viewStartIndex; i < _viewEndIndex; i++)
                            {
                                bool selected = _keys[i] == _editorPrefs._selectedKey;

                                Color origBackgroundColor = GUI.backgroundColor;
                                GUI.backgroundColor = selected ? kSelectedTextLineBackgroundColor : i % 2 == 0 ? kTextLineBackgroundColorA : kTextLineBackgroundColorB;

                                EditorGUILayout.BeginHorizontal(EditorUtils.ColoredRoundedBoxStyle);
                                {
                                    GUI.backgroundColor = kKeyBackgroundColor;

                                    if (selected && _editingKeyName)
                                    {
                                        EditorGUI.BeginChangeCheck();
                                        GUI.SetNextControlName(kEditKeyId);
                                        string key = EditorGUILayout.DelayedTextField(_keys[i], _keyEditStyle, GUILayout.Width(_editorPrefs._keyWidth), GUILayout.ExpandHeight(true));
                                        if (EditorGUI.EndChangeCheck())
                                        {
                                            _editingKeyName = false;
                                            Localisation.ChangeKey(_keys[i], key);
                                        }

                                        if (!_wasEditingKeyName)
                                        {
                                            EditorGUI.FocusTextInControl(kEditKeyId);
                                        }

                                        _wasEditingKeyName = true;
                                    }
                                    else
                                    {
                                        if (GUILayout.Button(_keys[i], _keyStyle, GUILayout.Width(_editorPrefs._keyWidth), GUILayout.ExpandHeight(true)))
                                        {
                                            _editorPrefs._selectedKey = _keys[i];
                                            _editingKeyName           = false;
                                            EditorGUI.FocusTextInControl(string.Empty);
                                        }
                                    }

                                    GUI.backgroundColor = i % 2 == 0 ? kTextBackgroundColorA : kTextBackgroundColorB;
                                    EditorGUI.BeginChangeCheck();

                                    string text = Localisation.GetRawString(_keys[i]);
                                    text = EditorGUILayout.TextArea(text, _textStyle, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                                    if (EditorGUI.EndChangeCheck())
                                    {
                                        Localisation.Set(_keys[i], Localisation.GetCurrentLanguage(), text);
                                    }
                                }
                                EditorGUILayout.EndHorizontal();

                                if (selected)
                                {
                                    GUI.backgroundColor = kSelectedButtonsBackgroundColor;
                                    EditorGUILayout.BeginHorizontal(EditorUtils.ColoredRoundedBoxStyle);
                                    {
                                        GUI.backgroundColor = origBackgroundColor;

                                        if (GUILayout.Button("Edit Key", EditorStyles.toolbarButton))
                                        {
                                            _editingKeyName    = true;
                                            _wasEditingKeyName = false;
                                        }

                                        if (GUILayout.Button("Delete", EditorStyles.toolbarButton))
                                        {
                                            DeleteSelected();
                                        }

                                        if (GUILayout.Button("Duplicate", EditorStyles.toolbarButton))
                                        {
                                            DuplicateSelected();
                                        }

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

                                GUI.backgroundColor = origBackgroundColor;
                            }
                        }
                        EditorGUILayout.EndVertical();
                    }
                    EditorGUILayout.EndScrollView();
                }
コード例 #2
0
                private void RenderTable()
                {
                    _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, false, false);
                    {
                        float          defaultItemHeight = GetItemHeight();
                        SystemLanguage currentLanguage   = Localisation.GetCurrentLanguage();
                        float          secondLangWidth   = position.width - _editorPrefs._keyWidth - _editorPrefs._firstLanguageWidth;

                        //On layout, check what part of table is currently being viewed
                        if (Event.current.type == EventType.Layout || _keysDirty)
                        {
                            GetViewableRange(_scrollPosition.y, GetTableAreaHeight(), defaultItemHeight, out _viewStartIndex, out _viewEndIndex, out _contentStart, out _contentHeight);
                        }

                        EditorGUILayout.BeginVertical(GUILayout.Height(_contentHeight));
                        {
                            //Blank space until start of content
                            GUILayout.Label(GUIContent.none, GUILayout.Height(_contentStart));

                            //Then render viewable range
                            for (int i = _viewStartIndex; i < _viewEndIndex; i++)
                            {
                                bool selected = IsSelected(_keys[i]);

                                Color origBackgroundColor = GUI.backgroundColor;
                                Color origContentColor    = GUI.contentColor;

                                //Work out item height
                                float itemHeight;
                                {
                                    if (selected)
                                    {
                                        //Work out highest text size
                                        string textA       = Localisation.GetRawString(_keys[i], Localisation.GetCurrentLanguage());
                                        float  textAHeight = _selectedTextStyle.CalcHeight(new GUIContent(textA), _editorPrefs._firstLanguageWidth);

                                        string textB       = Localisation.GetRawString(_keys[i], _editorPrefs._secondLanguage);
                                        float  textBHeight = _selectedTextStyle.CalcHeight(new GUIContent(textB), secondLangWidth);

                                        float textHeight = Mathf.Max(textAHeight, textBHeight);

                                        itemHeight = Mathf.Max(defaultItemHeight, textHeight);
                                    }
                                    else
                                    {
                                        itemHeight = defaultItemHeight;
                                    }
                                }

                                //Render item
                                GUI.backgroundColor = selected ? kSelectedTextLineBackgroundColor : i % 2 == 0 ? kTextLineBackgroundColorA : kTextLineBackgroundColorB;
                                EditorGUILayout.BeginHorizontal(_tableStyle, GUILayout.Height(itemHeight));
                                {
                                    GUI.backgroundColor = origBackgroundColor;
                                    GUI.contentColor    = selected ? kSelectedTextColor : Color.white;

                                    //Render Key
                                    EditorGUILayout.BeginVertical();
                                    {
                                        if (_editingKeyName == _keys[i])
                                        {
                                            EditorGUI.BeginChangeCheck();
                                            string key = EditorGUILayout.DelayedTextField(_keys[i], _editKeyStyle, GUILayout.Width(_editorPrefs._keyWidth), GUILayout.Height(itemHeight));
                                            if (EditorGUI.EndChangeCheck())
                                            {
                                                _editingKeyName = null;
                                                Localisation.ChangeKey(_keys[i], key);
                                                UpdateKeys();
                                            }
                                        }
                                        else
                                        {
                                            if (GUILayout.Button(_keys[i], selected ? _selectedKeyStyle : _keyStyle, GUILayout.Width(_editorPrefs._keyWidth), GUILayout.Height(itemHeight)))
                                            {
                                                OnClickItem(i, SystemLanguage.Unknown);
                                            }
                                        }
                                    }
                                    EditorGUILayout.EndVertical();

                                    //Render Text
                                    {
                                        GUI.backgroundColor = i % 2 == 0 ? kTextBackgroundColorA : kTextBackgroundColorB;

                                        //Render First Language
                                        string text = Localisation.GetRawString(_keys[i], currentLanguage);

                                        if (GUILayout.Button(selected ? text : StringUtils.GetFirstLine(text), selected ? _selectedTextStyle : _textStyle, GUILayout.Width(_editorPrefs._firstLanguageWidth), GUILayout.Height(itemHeight)))
                                        {
                                            OnClickItem(i, currentLanguage);
                                        }

                                        //Render Second Language
                                        EditorGUILayout.BeginVertical(GUILayout.Width(secondLangWidth));
                                        {
                                            string stext = Localisation.GetRawString(_keys[i], _editorPrefs._secondLanguage);

                                            if (GUILayout.Button(selected ? stext : StringUtils.GetFirstLine(stext), selected ? _selectedTextStyle : _textStyle, GUILayout.Width(secondLangWidth), GUILayout.Height(itemHeight)))
                                            {
                                                OnClickItem(i, _editorPrefs._secondLanguage);
                                            }
                                        }
                                        EditorGUILayout.EndVertical();
                                    }
                                }
                                EditorGUILayout.EndHorizontal();

                                GUI.backgroundColor = origBackgroundColor;
                                GUI.contentColor    = origContentColor;
                            }
                        }
                        EditorGUILayout.EndVertical();
                    }
                    EditorGUILayout.EndScrollView();
                }