List <Progress.Item> GetSiblingItems(Progress.Item item, out int newParentId)
        {
            newParentId = item.parentId;
            if (item.parentId == -1)
            {
                var rootIds = m_TreeView.GetRootIds();
                return(rootIds?.Select(id => m_TreeView.GetItemDataForId <Progress.Item>(id)).ToList());
            }

            if (!m_ContainedItems.Contains(newParentId))
            {
                // If the parent is missing, the item should be put at the root level for now.
                List <int> itemIds;
                if (!m_MissingParents.TryGetValue(item.parentId, out itemIds))
                {
                    itemIds = new List <int>();
                    m_MissingParents.Add(item.parentId, itemIds);
                }

                itemIds.Add(item.id);
                newParentId = -1;
                return(m_TreeView.GetRootIds()?.Select(id => m_TreeView.GetItemDataForId <Progress.Item>(id)).ToList());
            }

            var childrenIds = m_TreeView.viewController.GetChildrenIds(newParentId);

            return(childrenIds?.Select(id => m_TreeView.GetItemDataForId <Progress.Item>(id)).ToList());
        }
Example #2
0
        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);
        }
Example #3
0
        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;
        }
Example #5
0
 internal void AddElement(Progress.Item item)
 {
     m_DetailsFoldoutToggle.visible = true;
     SubTaskInitialization(item);
     if (dataSource.running)
     {
         m_DetailsFoldoutToggle.SetValueWithoutNotify(true);
         ToggleDetailsFoldout(ChangeEvent <bool> .GetPooled(false, true));
     }
 }
Example #6
0
        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);
        }
Example #7
0
        public void UnbindItem()
        {
            m_ProgressItem = null;

            EditorApplication.update -= OnUpdateVisualProgress;

            ResetStyleClasses();

            m_PauseButton.userData  = null;
            m_CancelButton.userData = null;

            m_LastUpdate      = 0.0;
            m_LastElapsedTime = 0f;
        }
        static int GetInsertionIndex(List <Progress.Item> items, Progress.Item itemToInsert)
        {
            if (items == null)
            {
                return(-1);
            }
            var insertionIndex = items.BinarySearch(itemToInsert, s_ProgressComparer);

            if (insertionIndex < 0)
            {
                return(~insertionIndex);
            }
            return(insertionIndex);
        }
Example #9
0
        public void BindItem(Progress.Item item)
        {
            if (m_ProgressItem == null || m_ProgressItem.id != item.id)
            {
                m_ProgressItem          = item;
                m_PauseButton.userData  = item;
                m_CancelButton.userData = item;
                OnEverythingChanged();
            }

            UpdateDisplay();

            EditorApplication.update -= OnUpdateVisualProgress;
            EditorApplication.update += OnUpdateVisualProgress;
        }
        private ProgressElement AddElement(Progress.Item progressItem)
        {
            if (progressItem.parentId >= 0)
            {
                for (int i = 0; i < m_Elements.Count; ++i)
                {
                    if (progressItem.parentId == m_Elements[i].dataSource.id)
                    {
                        m_Elements[i].AddElement(progressItem);
                        return(m_Elements[i]);
                    }
                }
                Assert.IsTrue(true);
            }
            // if parent was not found
            var element = new ProgressElement(progressItem);

            if (m_Elements.Count > 0 && progressItem.status == Progress.Status.Failed)
            {
                var insertIndex = -1;
                for (int i = 0; i < m_Elements.Count; i++)
                {
                    if ((m_Elements[i].dataSource.status == Progress.Status.Failed && progressItem.updateTime > m_Elements[i].dataSource.updateTime) ||
                        m_Elements[i].dataSource.status != Progress.Status.Failed)
                    {
                        insertIndex = i;
                        break;
                    }
                }
                m_Elements.Insert(insertIndex, element);
                m_ScrollView.Insert(insertIndex, element.rootVisualElement);
                if (insertIndex > m_LastParentFailedIndex)
                {
                    m_LastParentFailedIndex = insertIndex;
                }
                return(element);
            }
            else
            {
                m_Elements.Insert(m_LastParentFailedIndex + 1, element);
                m_ScrollView.Insert(m_LastParentFailedIndex + 1, element.rootVisualElement);
            }
            return(element);
        }
Example #11
0
 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;
 }
Example #12
0
 internal bool TryUpdate(Progress.Item op, int id)
 {
     if (dataSource.id == id)
     {
         dataSource = op;
         UpdateDisplay(m_MainTask, dataSource);
         return(true);
     }
     else
     {
         for (int i = 0; i < m_ProgressItemChildren.Count; ++i)
         {
             if (m_ProgressItemChildren[i].id == id)
             {
                 m_ProgressItemChildren[i] = op;
                 UpdateDisplay(m_SubTasks[i], m_ProgressItemChildren[i]);
                 return(true);
             }
         }
     }
     return(false);
 }