private DisplayedTask InitializeTask(Progress.Item progressItem, VisualElement parentElement) { var displayedTask = new DisplayedTask( parentElement.Q <Label>("BackgroundTaskNameLabel"), parentElement.Q <Label>("ProgressionLabel"), parentElement.Q <VisualElement>("BackgroundTaskStatusIcon"), parentElement.Q <Label>("BackgroundTaskDescriptionLabel"), parentElement.Q <Label>("BackgroundTaskElapsedTimeLabel"), parentElement.Q <ProgressBar>("ProgressBar"), parentElement.Q <Button>("CancelButton") ); Assert.IsNotNull(displayedTask.nameLabel); Assert.IsNotNull(displayedTask.descriptionIcon); Assert.IsNotNull(displayedTask.descriptionLabel); Assert.IsNotNull(displayedTask.elapsedTimeLabel); Assert.IsNotNull(displayedTask.progressLabel); Assert.IsNotNull(displayedTask.progressBar); Assert.IsNotNull(displayedTask.cancelButton); displayedTask.cancelButton.RemoveFromClassList("unity-text-element"); displayedTask.cancelButton.RemoveFromClassList("unity-button"); displayedTask.cancelButton.userData = progressItem; displayedTask.cancelButton.clickable.clickedWithEventInfo += CancelButtonClicked; UpdateDisplay(displayedTask, progressItem); UpdateResponsiveness(displayedTask, progressItem); return(displayedTask); }
private static void UpdateStatusIcon(DisplayedTask task, string iconName) { task.descriptionIcon.style.backgroundImage = EditorGUIUtility.LoadIcon(iconName); task.descriptionIcon.style.unityBackgroundScaleMode = ScaleMode.ScaleToFit; task.descriptionIcon.style.height = ProgressWindow.kIconSize; task.descriptionIcon.style.width = ProgressWindow.kIconSize; }
private static void UpdateProgressCompletion(DisplayedTask task, string iconName) { task.progressLabel.style.backgroundImage = EditorGUIUtility.LoadIcon(iconName); task.progressLabel.style.unityBackgroundScaleMode = ScaleMode.ScaleToFit; task.progressLabel.text = ""; task.progressLabel.style.width = 30; task.progressLabel.style.height = ProgressWindow.kIconSize; }
public ProgressElement(Progress.Item dataSource) { rootVisualElement = new TemplateContainer(); if (s_VisualTreeBackgroundTask == null) { s_VisualTreeBackgroundTask = EditorGUIUtility.Load(k_UxmlProgressPath) as VisualTreeAsset; } var task = new VisualElement() { name = "Task" }; rootVisualElement.Add(task); var horizontalLayout = new VisualElement() { name = "TaskOnly" }; horizontalLayout.style.flexDirection = FlexDirection.Row; task.Add(horizontalLayout); m_DetailsFoldoutToggle = new Toggle() { visible = false }; m_DetailsFoldoutToggle.AddToClassList("unity-foldout__toggle"); m_DetailsFoldoutToggle.RegisterValueChangedCallback(ToggleDetailsFoldout); horizontalLayout.Add(m_DetailsFoldoutToggle); var parentTask = s_VisualTreeBackgroundTask.CloneTree(); parentTask.name = "ParentTask"; horizontalLayout.Add(parentTask); var details = new VisualElement() { name = "Details" }; details.style.display = DisplayStyle.None; task.Add(details); m_Details = rootVisualElement.Q <VisualElement>("Details"); m_DetailsScrollView = new ScrollView(); m_Details.Add(m_DetailsScrollView); m_DetailsScrollView.AddToClassList("details-content"); this.dataSource = dataSource; if (s_VisualTreeSubTask == null) { s_VisualTreeSubTask = EditorGUIUtility.Load(k_UxmlSubTaskPath) as VisualTreeAsset; } m_ProgressItemChildren = new List <Progress.Item>(); m_SubTasks = new List <DisplayedTask>(); m_MainTask = InitializeTask(dataSource, rootVisualElement); }
private void UpdateDisplay(DisplayedTask task, Progress.Item dataSource) { task.nameLabel.text = dataSource.name; task.descriptionLabel.text = dataSource.description; task.SetIndefinite(dataSource.indefinite); if (!dataSource.indefinite) { var p01 = Mathf.Clamp01(dataSource.progress); task.progressBar.value = p01 * 100.0f; if (task.progressLabel != null) { task.progressLabel.text = $"{Mathf.FloorToInt(p01 * 100.0f)}%"; } task.SetProgressStyleFull(dataSource.progress > 0.96f); } if (dataSource.status == Progress.Status.Canceled) { task.descriptionLabel.text = "Cancelled"; UpdateStatusIcon(task, ProgressWindow.kCanceledIcon); task.progress.AddToClassList("unity-progress-bar__progress__inactive"); } else if (dataSource.status == Progress.Status.Failed) { if (string.IsNullOrEmpty(task.descriptionLabel.text)) { task.descriptionLabel.text = "Failed"; } UpdateStatusIcon(task, ProgressWindow.kFailedIcon); task.progress.AddToClassList("unity-progress-bar__progress__inactive"); } else if (dataSource.status == Progress.Status.Succeeded) { if (string.IsNullOrEmpty(task.descriptionLabel.text)) { task.descriptionLabel.text = "Done"; } task.progressBar.value = 100; task.SetProgressStyleFull(true); UpdateStatusIcon(task, ProgressWindow.kSuccessIcon); task.progressLabel.style.unityBackgroundImageTintColor = new StyleColor(Color.green); // Update running time to force elapsed time to show when the task is set to show ETA UpdateRunningTime(); if (m_MainTask == task && m_DetailsFoldoutToggle.value) { m_DetailsFoldoutToggle.value = false; } } task.cancelButton.style.display = dataSource.running ? DisplayStyle.Flex : DisplayStyle.None; task.cancelButton.visible = dataSource.cancellable; }
private void SubTaskInitialization(Progress.Item subTaskSource) { var parentElement = s_VisualTreeBackgroundTask.CloneTree(); parentElement.name = "SubTask"; DisplayedTask displayedSubTask = InitializeTask(subTaskSource, parentElement); m_ProgressItemChildren.Add(subTaskSource); m_SubTasks.Add(displayedSubTask); m_DetailsScrollView.Add(parentElement); }
private void UpdateDisplay(DisplayedTask task, ProgressItem dataSource) { task.nameLabel.text = dataSource.name; task.descriptionLabel.text = dataSource.description; task.SetIndefinite(dataSource.indefinite); if (!dataSource.indefinite) { var p01 = Mathf.Clamp01(dataSource.progress); task.progressBar.value = p01 * 100.0f; if (task.progressLabel != null) { task.progressLabel.text = $"{Mathf.FloorToInt(p01 * 100.0f)}%"; } task.SetProgressStyleFull(dataSource.progress > 0.96f); } if (dataSource.status == ProgressStatus.Canceled) { task.descriptionLabel.text += " (Cancelled)"; UpdateProgressCompletion(task, ProgressWindow.kCanceledIcon); } else if (dataSource.status == ProgressStatus.Failed) { task.descriptionLabel.text += " (Failed)"; UpdateProgressCompletion(task, ProgressWindow.kFailedIcon); } else if (dataSource.status == ProgressStatus.Succeeded) { task.progressBar.value = 100; task.SetProgressStyleFull(true); UpdateProgressCompletion(task, ProgressWindow.kSuccessIcon); task.progressLabel.style.unityBackgroundImageTintColor = new StyleColor(Color.green); if (m_MainTask == task && m_DetailsFoldoutToggle.value) { m_DetailsFoldoutToggle.value = false; } } task.deleteButton.style.display = !dataSource.running ? DisplayStyle.Flex : DisplayStyle.None; task.cancelButton.style.display = dataSource.running ? DisplayStyle.Flex : DisplayStyle.None; task.cancelButton.visible = dataSource.cancellable; }
private static void UpdateResponsiveness(DisplayedTask task, Progress.Item dataSource) { if (dataSource.responding && !task.isResponding) { task.descriptionLabel.text = dataSource.description; if (task.progress.ClassListContains("unity-progress-bar__progress__unresponding")) { task.progress.RemoveFromClassList("unity-progress-bar__progress__unresponding"); } } else if (!dataSource.responding && task.isResponding) { task.descriptionLabel.text = string.IsNullOrEmpty(dataSource.description) ? "(Not Responding)" : $"{dataSource.description} (Not Responding)"; if (!task.progress.ClassListContains("unity-progress-bar__progress__unresponding")) { task.progress.AddToClassList("unity-progress-bar__progress__unresponding"); } } task.isResponding = dataSource.responding; }