private void CreateGUI() { AcquireProperties(); LoadStylesheets(); rootElement.AddGet <VisualElement>("Header").Do(selfHeader => { selfHeader.AddGet <VisualElement>(null, "logo"); var title = selfHeader.AddGet <Label>(null, "text"); title.text = "Unity Localization"; }); activeSettingsWarning = rootElement.AddGet <VisualElement>("ActiveSettingsWarning").Do(self => { self.AddGet <VisualElement>("WarningContainer").Do(self2 => { self2.AddGet <VisualElement>(null, "icon"); self2.AddGet <Label>(null, "text").text = "There is no active Localization Settings selected."; }); self.AddGet(new Button(OpenSettingsWindow) { text = "Open Settings", name = "OpenSettingsButton" }); }); rootSettingsContainer = rootElement.AddGet <VisualElement>("SettingsContainer"); var settings = localizedString.Settings; if (settings != null) { CreateSettingsGUI(settings); } UpdateWarningVisibility(); UpdateKeyVisibility(); }
private void CreateGUI() { if (!stylesheetsLoaded) { InitializeWindow(this); } if (settings == null) { Close(); return; } if (deferStylesheetLoading) { var utilityStylesheet = Resources.Load <StyleSheet>("Stylesheets/Utility"); var stylesheet = Resources.Load <StyleSheet>("Stylesheets/TableEditorWindow"); this.AddStylesheet(utilityStylesheet); this.AddStylesheet(stylesheet); deferStylesheetLoading = false; stylesheetsLoaded = true; } var tables = settings.Tables; var anyTable = tables.Count > 0; if (!anyTable) { tabContents = new VisualElement { name = "TabContents" }; tabContents.AddToClassList("no-tables"); tabContents.AddGet <Label>("NoTablesLabel").Do(label => label.text = "No tables"); tabContents.AddGet <Button>("NoTablesButton", "large").Do(button => { button.clicked += CreateTable; button.text = "Create Table"; }); rootVisualElement.Add(tabContents); return; } tabs = new List <Tab>(); tabContents = new VisualElement { name = "TabContents" }; topContainer = new VisualElement { name = "TopContainer" }; tabContainer = new ScrollView(ScrollViewMode.Horizontal) { name = "TabContainer" }; foreach (var table in tables) { tabs.Add(tabContainer.AddGet(new Tab(table.TableName)).Do(tab => { tab.Clicked += () => TabClicked(tab); tab.DeleteClicked += () => DeleteTable(tab.userData as LocalizationTable); tab.userData = table; })); } if (activeTabIndex >= 0 && activeTabIndex < tabs.Count) { tabs[activeTabIndex].AddToClassList("active"); LoadTabContent(tabs[activeTabIndex]); } else { activeTabIndex = 0; tabs[activeTabIndex].AddToClassList("active"); LoadTabContent(tabs[activeTabIndex]); } var createTableButton = new Button(CreateTable) { name = "CreateTableButton", tooltip = "Create table" }; createTableButton.AddGet <VisualElement>("CreateTableButton-Image"); topContainer.Add(tabContainer); topContainer.Add(createTableButton); rootVisualElement.Add(topContainer); rootVisualElement.Add(tabContents); }
private void LoadTabContent(Tab tab) { tabContents.Clear(); if (settings == null) { return; } var table = tab.userData as LocalizationTable; var entries = table !.Entries; var scrollView = new ScrollView(ScrollViewMode.VerticalAndHorizontal); keyColumn = Factory.Create <VisualElement>(null, "table-col"); keyColumn.AddGet(new TableCell("key", false)).AddToClassList("header"); for (var i = 0; i < entries.Count; i++) { keyColumn.Add(MakeKeyCell(table, entries[i].Key, i)); } createEntry = new TableCell("Add...", true) { name = "CreateEntryCell" }; createEntry.OnValueChanged += CreateEntry; createEntry.OnBeginEdit += field => { field.value = ""; }; createEntry.OnCancelEdit += field => { createEntry.Text = "Add..."; }; createEntry.OnNextCellSelected += () => Schedule(0, () => GetCell(keyColumn.childCount - 3, 1)?.BeginEdit()); createEntry.OnPreviousCellSelected += () => Schedule(0, () => GetCell(keyColumn.childCount - 3, localeColumns.Count)?.BeginEdit()); createEntry.OnNextRowSelected += () => Schedule(0, () => createEntry.BeginEdit()); createEntry.OnPreviousRowSelected += () => Schedule(0, () => GetCell(keyColumn.childCount - 3, 0)?.BeginEdit()); keyColumn.Add(createEntry); var locales = settings.Locales; localeColumns = new List <VisualElement>(locales.Count); for (var i = 0; i < locales.Count; i++) { var col = i; var locale = locales[i]; var isDefaultLocale = locale.Equals(settings.DefaultLocale); var localeColumn = Factory.Create <VisualElement>(null, "table-col"); localeColumn.Add(new TableCell($"{locale.EnglishName}{(isDefaultLocale ? " - Default" : "")}", false).Do(cell => { cell.AddToClassList("header"); if (isDefaultLocale) { cell.AddToClassList("bold"); } })); for (var j = 0; j < entries.Count; j++) { var row = j; localeColumn.Add(MakeCell(entries[row].Values[col], row, col, table)); } // Add empty cell for Add entry cell localeColumn.Add(new TableCell("", false)); localeColumns.Add(localeColumn); } var tableElement = new VisualElement { name = "Table" }; tableElement.AddToClassList("table"); tableElement.Add(keyColumn); foreach (var column in localeColumns) { tableElement.Add(column); } tableElement.Add(scrollView); scrollView.Add(tableElement); tabContents.Add(scrollView); }
private void CreateSettingsGUI(LocalizationSettings settings) { var tableChoices = settings.TableGuids.Prepend(Guid.Empty.ToString()).ToList(); var defaultIndex = settings.GuidToTableIndex(localizedString.TableGuid) + 1; var tableDropdown = new PopupField <string>("Table", tableChoices, defaultIndex, guid => settings.GuidToTableName(guid, "None"), guid => settings.GuidToTableName(guid, "None")); tableDropdown.name = "TableDropdown"; tableDropdown.RegisterValueChangedCallback(evt => { var table = settings.GuidToTable(evt.newValue); localizedString.TableGuid = evt.newValue; localizedString.Table = table; localizedString.Key = null; localizedString.KeyGuid = null; EditorUtility.SetDirty(localizedString); UpdateKeyVisibility(); }); rootSettingsContainer.Add(tableDropdown); rootSettingsContainer.Add(localizationSettingsContainer = new VisualElement { name = "LocalizationSettingsContainer" }); localizationSettingsContainer.AddGet <VisualElement>("KeyContainer").Do(keyContainer => { keyContainer.AddGet(new TextField("Key") { name = "LocalizationKey", isReadOnly = true }).Do(self => { self.SetEnabled(false); self.BindProperty(keyProperty); }); keyContainer.AddGet(new Button(OnSelectKey) { text = "Select Key", name = "SelectKeyButton" }); }); localizationSettingsContainer.Add(new PropertyField(setterProperty).Do(field => { field.RegisterValueChangeCallback(evt => { var count = localizedString.Setter.GetPersistentEventCount(); for (var i = 0; i < count; i++) { localizedString.Setter.SetPersistentListenerState(i, UnityEventCallState.EditorAndRuntime); } }); })); // Preview section if (localizedString.PreviewLocaleIndex == -1) { localizedString.PreviewLocaleIndex = settings.DefaultLocaleIndex(); } var previewContainer = localizationSettingsContainer.AddGet <VisualElement>("PreviewContainer"); previewContainer.AddGet(previewToggleButton = new Button(TogglePreview) { name = "TogglePreviewButton", text = "Preview" }) .SetClass(localizedString.IsPreviewActive, "active"); previewButtons = new List <Button>(); previewSettings = previewContainer.AddGet <VisualElement>("PreviewSettings").SetClass(!localizedString.IsPreviewActive, "hidden"); previewSettings.AddGet(new ScrollView(ScrollViewMode.Horizontal) { name = "PreviewLocalesContainer" }).Do(container => { for (var i = 0; i < settings.Locales.Count; i++) { var locale = settings.Locales[i]; var localeIndex = i; previewButtons.Add(container.AddGet( new Button(() => SetPreviewLocale(localeIndex)) { text = $"{locale.LocaleCode}" } .SetClass(localeIndex == localizedString.PreviewLocaleIndex, "active") ) ); } }); if (localizedString.IsPreviewActive) { UpdatePreview(); } }