public TableCreator()
        {
            var asset = Resources.GetTemplateAsset(nameof(TableCreator));

            asset.CloneTree(this);

            var locales = LocalizationEditorSettings.GetLocales();

            m_LocalesList = this.Q <ScrollView>("locales-list");
            foreach (var locale in locales)
            {
                AddLocaleElement(locale);
            }

            m_CreateStringTablesButton = this.Q <Button>("create-string-tables-button");
            m_CreateStringTablesButton.clickable.clicked += () => CreateCollection(LocalizationEditorSettings.CreateStringTableCollection);

            m_CreateAssetTablesButton = this.Q <Button>("create-asset-tables-button");
            m_CreateAssetTablesButton.clickable.clicked += () => CreateCollection(LocalizationEditorSettings.CreateAssetTableCollection);

            UpdateCreateButtonState();

            this.Q <Button>("select-all-button").clickable.clicked       += () => SelectAllLocales(true);
            this.Q <Button>("select-none-button").clickable.clicked      += () => SelectAllLocales(false);
            this.Q <Button>("locale-generator-button").clickable.clicked += () => LocaleGeneratorWindow.ShowWindow();

            m_TableCollectionName = this.Q <TextField>("new-table-name-field");

            LocalizationEditorSettings.EditorEvents.LocaleAdded   += OnLocaleAdded;
            LocalizationEditorSettings.EditorEvents.LocaleRemoved += OnLocaleRemoved;
        }
        void DrawToolbar(Rect rect)
        {
            var commandName = Event.current.commandName;
            var controlId   = GUIUtility.GetControlID(FocusType.Passive);

            var fieldPos  = EditorGUI.PrefixLabel(rect, GUIContent.none);
            var selection = (ToolBarChoices)GUI.Toolbar(fieldPos, -1, Styles.toolbarButtons);

            switch (selection)
            {
            case ToolBarChoices.LocaleGeneratorWindow:
                LocaleGeneratorWindow.ShowWindow();
                break;

            case ToolBarChoices.RemoveSelected:
            {
                var selectedLocales = ListView.GetSelection();
                for (int i = selectedLocales.Count - 1; i >= 0; --i)
                {
                    var item = ListView.GetRows()[selectedLocales[i]] as SerializedLocaleItem;
                    LocalizationEditorSettings.RemoveLocale(item.SerializedObject.targetObject as Locale, true);
                }
                ListView.SetSelection(new int[0]);
                ListView.Reload();
            }
            break;

            case ToolBarChoices.AddAsset:
                EditorGUIUtility.ShowObjectPicker <Locale>(null, false, string.Empty, controlId);
                break;

            case ToolBarChoices.AddAllAssets:
            {
                var assets = AssetDatabase.FindAssets("t:Locale");
                for (int i = 0; i < assets.Length; ++i)
                {
                    LocalizationEditorSettings.AddLocale(AssetDatabase.LoadAssetAtPath <Locale>(AssetDatabase.GUIDToAssetPath(assets[i])), true);
                }
                ListView.Reload();
            }
            break;
            }

            if (commandName == "ObjectSelectorClosed" && EditorGUIUtility.GetObjectPickerControlID() == controlId && EditorGUIUtility.GetObjectPickerObject() != null)
            {
                LocalizationEditorSettings.AddLocale(EditorGUIUtility.GetObjectPickerObject() as Locale, true);
                ListView.Reload();
            }
        }
        public TableCreator()
        {
            var asset = Resources.GetTemplateAsset(nameof(TableCreator));

            asset.CloneTree(this);

            var locales = LocalizationEditorSettings.GetLocales();

            m_LocalesList = this.Q <ScrollView>("locales-list");
            foreach (var locale in locales)
            {
                AddLocaleElement(locale);
            }
            m_LocaleHelpBoxContainer = this.Q("locale-help-box-container");

            var items = new List <Type> {
                typeof(StringTableCollection), typeof(AssetTableCollection)
            };

            m_CollectionTypeContainer = this.Q <VisualElement>("table-collection-type-container");
            m_CollectionTypePopup     = new PopupField <Type>("Type", items, 0)
            {
                formatListItemCallback      = type => ObjectNames.NicifyVariableName(type.Name),
                formatSelectedValueCallback = type => ObjectNames.NicifyVariableName(type.Name)
            };
            m_CollectionTypePopup.RegisterValueChangedCallback(it => UpdateCreateButtonState());
            m_CollectionTypeContainer.Add(m_CollectionTypePopup);

            m_CreateTableCollectionButton = this.Q <Button>("create-table-collection-button");
            m_CreateTableCollectionButton.clickable.clicked += CreateCollection;

            this.Q <Button>("select-all-button").clickable.clicked       += () => SelectAllLocales(true);
            this.Q <Button>("select-none-button").clickable.clicked      += () => SelectAllLocales(false);
            this.Q <Button>("locale-generator-button").clickable.clicked += () => LocaleGeneratorWindow.ShowWindow();

            m_TableCollectionName = this.Q <TextField>("new-table-name-field");
            m_TableCollectionName.RegisterValueChangedCallback(it => UpdateCreateButtonState());
            InitializeTableName();

            m_TableNameHelpBoxContainer = this.Q("table-name-help-box-container");

            LocalizationEditorSettings.EditorEvents.LocaleAdded   += OnLocaleAdded;
            LocalizationEditorSettings.EditorEvents.LocaleRemoved += OnLocaleRemoved;
        }
Ejemplo n.º 4
0
        void DrawTableDetails(Rect position, Rect rowPosition, SerializedProperty property)
        {
            if (!property.isExpanded)
            {
                return;
            }

            EditorGUI.indentLevel++;

            // Table selection
            var tableSelectionPos = m_Property.SelectedTableIndex != 0 ? new Rect(rowPosition.x, rowPosition.y, rowPosition.width - k_OpenTableEditorButtonWidth, rowPosition.height) : rowPosition;

            EditorGUI.BeginChangeCheck();
            var selectedTableIndex = EditorGUI.Popup(tableSelectionPos, Styles.selectedTable, m_Property.SelectedTableIndex, ProjectTableLabels);

            if (EditorGUI.EndChangeCheck())
            {
                m_Property.SelectedTableIndex = selectedTableIndex;
            }

            if (m_Property.SelectedTableIndex != 0)
            {
                var openTableEditorPos = new Rect(tableSelectionPos.xMax, tableSelectionPos.y, k_OpenTableEditorButtonWidth, tableSelectionPos.height);
                if (GUI.Button(openTableEditorPos, EditorIcons.StringTable))
                {
                    LocalizationTablesWindow.ShowWindow(m_Property.SelectedTableCollection);
                }
            }

            rowPosition.y += rowPosition.height;
            var buttonPos = new Rect(rowPosition.x + EditorGUIUtility.labelWidth, rowPosition.y, rowPosition.width - EditorGUIUtility.labelWidth, rowPosition.height);

            if (selectedTableIndex == 0)
            {
                if (GUI.Button(buttonPos, Styles.addTableCollection, EditorStyles.miniButton))
                {
                    LocalizationTablesWindow.ShowTableCreator();
                }
            }
            else
            {
                if (GUI.Button(buttonPos, Styles.addTableEntry, EditorStyles.miniButton))
                {
                    // Attempt to create a new key with a set default name
                    var keys = m_Property.SelectedTableCollection.SharedData;

                    const string newKeyName = "New Entry";
                    var          keyToTry   = newKeyName;
                    SharedTableData.SharedTableEntry entry = null;
                    int counter = 1;
                    while (entry == null)
                    {
                        if (keys.Contains(keyToTry))
                        {
                            keyToTry = $"{newKeyName} {counter++}";
                        }
                        else
                        {
                            Undo.RecordObject(keys, "Add entry.");
                            entry = keys.AddKey(keyToTry);
                            EditorUtility.SetDirty(keys);
                        }
                    }
                    m_Property.SelectedTableEntry = entry;
                    LocalizationEditorSettings.EditorEvents.RaiseTableEntryAdded(m_Property.SelectedTableCollection, entry);
                }
            }

            rowPosition.y += rowPosition.height;
            buttonPos.y    = rowPosition.y;
            if (GUI.Button(buttonPos, Styles.addLocale))
            {
                LocaleGeneratorWindow.ShowWindow();
            }
            rowPosition.y += rowPosition.height + EditorGUIUtility.standardVerticalSpacing;

            if (m_Property.SelectedTableEntry != null)
            {
                DrawTableEntryDetails(ref rowPosition, position);
            }
            EditorGUI.indentLevel--;
        }
Ejemplo n.º 5
0
        void DrawTableDetails(Rect position, Rect rowPosition, Data data, SerializedProperty property)
        {
            if (!property.isExpanded)
            {
                return;
            }

            EditorGUI.indentLevel++;

            // Table selection
            var tableSelectionPos = data.SelectedTableIndex != 0 ? new Rect(rowPosition.x, rowPosition.y, rowPosition.width - k_OpenTableEditorButtonWidth, rowPosition.height) : rowPosition;

            EditorGUI.BeginChangeCheck();
            var selectedTableIndex = EditorGUI.Popup(tableSelectionPos, Styles.selectedTable, data.SelectedTableIndex, ProjectTableLabels);

            if (EditorGUI.EndChangeCheck())
            {
                data.SelectedTableIndex = selectedTableIndex;
            }

            if (data.SelectedTableIndex != 0)
            {
                var openTableEditorPos = new Rect(tableSelectionPos.xMax, tableSelectionPos.y, k_OpenTableEditorButtonWidth, tableSelectionPos.height);
                if (GUI.Button(openTableEditorPos, EditorIcons.StringTable))
                {
                    LocalizationTablesWindow.ShowWindow(data.SelectedTableCollection);
                }
            }

            rowPosition.y += rowPosition.height;
            var buttonPos = new Rect(rowPosition.x + EditorGUIUtility.labelWidth, rowPosition.y, rowPosition.width - EditorGUIUtility.labelWidth, rowPosition.height);

            if (selectedTableIndex == 0)
            {
                if (GUI.Button(buttonPos, Styles.addTableCollection, EditorStyles.miniButton))
                {
                    LocalizationTablesWindow.ShowTableCreator();
                }
            }
            else
            {
                if (GUI.Button(buttonPos, Styles.addTableEntry, EditorStyles.miniButton))
                {
                    // Attempt to create a new key with a set default name
                    var keys = data.SelectedTableCollection.SharedData;

                    Undo.RecordObject(keys, "Add entry.");
                    var entry = keys.AddKey();
                    EditorUtility.SetDirty(keys);

                    data.SelectedTableEntry = entry;
                    LocalizationEditorSettings.EditorEvents.RaiseTableEntryAdded(data.SelectedTableCollection, entry);
                }
            }

            rowPosition.y += rowPosition.height;
            buttonPos.y    = rowPosition.y;
            if (GUI.Button(buttonPos, Styles.addLocale))
            {
                LocaleGeneratorWindow.ShowWindow();
            }
            rowPosition.MoveToNextLine();

            if (data.SelectedTableEntry != null)
            {
                DrawTableEntryDetails(ref rowPosition, data, position);
            }
            EditorGUI.indentLevel--;
        }