Exemple #1
0
        private void RefreshRemoveButton()
        {
            var visibleFlag = false;

            var current = package.Current;

            // Show only if there is a current package installed
            if (current != null)
            {
                visibleFlag = current.CanBeRemoved && !package.IsPackageManagerUI;

                var action     = current.IsBuiltIn ? PackageAction.Disable : PackageAction.Remove;
                var inprogress = package.RemoveSignal.Operation != null;

                var enableButton = visibleFlag && !EditorApplication.isCompiling && !inprogress && !Package.AddRemoveOperationInProgress;

                RemoveButton.SetEnabled(enableButton);
                RemoveButton.text = GetButtonText(action, inprogress);
            }

            UIUtils.SetElementDisplay(RemoveButton, visibleFlag);
        }
        private void UpdateReverseDependencies(IEnumerable <IPackageVersion> reverseDependencies)
        {
            reverseDependenciesNames.Clear();
            reverseDependenciesVersions.Clear();

            var hasReverseDependencies = reverseDependencies?.Any() ?? false;

            UIUtils.SetElementDisplay(noReverseDependencies, !hasReverseDependencies);
            UIUtils.SetElementDisplay(reverseDependenciesNames, hasReverseDependencies);
            UIUtils.SetElementDisplay(reverseDependenciesVersions, hasReverseDependencies);

            if (!hasReverseDependencies)
            {
                return;
            }

            foreach (var version in reverseDependencies)
            {
                reverseDependenciesNames.Add(BuildLabel(version.displayName ?? string.Empty, "text"));
                reverseDependenciesVersions.Add(BuildLabel(version.version.ToString(), "text"));
            }
        }
Exemple #3
0
        public void SetDependencies(DependencyInfo[] dependencies)
        {
            if (dependencies == null || dependencies.Length == 0)
            {
                ClearDependencies();
                return;
            }

            DependenciesNames.Clear();
            DependenciesVersions.Clear();
            DependenciesStatuses.Clear();
            foreach (var dependency in dependencies)
            {
                DependenciesNames.Add(BuildLabel(BuildNameText(dependency), "text"));
                DependenciesVersions.Add(BuildLabel(dependency.version, "text"));
                DependenciesStatuses.Add(BuildLabel(BuildStatusText(dependency), "text"));
            }

            UIUtils.SetElementDisplay(NoDependencies, false);
            UIUtils.SetElementDisplay(DependenciesNames, true);
            UIUtils.SetElementDisplay(DependenciesVersions, true);
        }
Exemple #4
0
        public void Start()
        {
            if (Started)
            {
                return;
            }

            // Weird hack to make sure loading spinner doesn't generate an error every frame.
            // Cannot put in constructor as it give really strange result.
            if (parent != null && parent.parent != null)
            {
                // TODO the "hack" has been upgraded according to UIElements API, but we should make sure it still is necessary
                parent.parent.cacheAsBitmap  = true;
                parent.parent.style.overflow = Overflow.Hidden;
            }
            rotation = 0;

            EditorApplication.update += UpdateProgress;

            Started = true;
            UIUtils.SetElementDisplay(this, true);
        }
Exemple #5
0
        private void RefreshSupportingImages()
        {
            UIUtils.SetElementDisplay(detailImagesContainer, displayVersion.images.Any());
            detailImages.Clear();

            if (s_LoadingTexture == null)
            {
                s_LoadingTexture = (Texture2D)EditorGUIUtility.LoadRequired("Icons/UnityLogo.png");
            }

            long id;

            if (long.TryParse(displayVersion.uniqueId, out id))
            {
                foreach (var packageImage in displayVersion.images)
                {
                    var image = new Label {
                        classList = { "image" }
                    };

                    if (packageImage.type == PackageImage.ImageType.Youtube || packageImage.type == PackageImage.ImageType.Sketchfab)
                    {
                        image.AddToClassList("url");
                        image.RegisterCallback <MouseDownEvent>(evt => { ApplicationUtil.instance.OpenURL(packageImage.url); });
                    }

                    image.style.backgroundImage = s_LoadingTexture;
                    detailImages.Add(image);

                    AssetStoreDownloadOperation.instance.DownloadImageAsync(id, packageImage.thumbnailUrl, (retId, texture) =>
                    {
                        if (retId.ToString() == displayVersion?.uniqueId)
                        {
                            image.style.backgroundImage = texture;
                        }
                    });
                }
            }
        }
        private void OnPackageChanged()
        {
            var displayPackage = package != null ? package.VersionToDisplay : null;

            if (displayPackage == null)
            {
                return;
            }

            NameLabel.text    = displayPackage.DisplayName;
            VersionLabel.text = displayPackage.Version.ToString();

            var stateClass = GetIconStateId(displayPackage);

            if (displayPackage.State == PackageState.Outdated && package.LatestUpdate == package.Current)
            {
                stateClass = GetIconStateId(PackageState.UpToDate);
            }
            if (PackageCollection.Instance.GetPackageError(package) != null)
            {
                stateClass = GetIconStateId(PackageState.Error);
            }
            if (stateClass == GetIconStateId(PackageState.UpToDate) && package.Current != null)
            {
                stateClass = "installed";
            }

            StateLabel.RemoveFromClassList(currentStateClass);
            StateLabel.AddToClassList(stateClass);

            UIUtils.SetElementDisplay(VersionLabel, !displayPackage.IsBuiltIn);

            currentStateClass = stateClass;
            if (displayPackage.State != PackageState.InProgress && Spinner.Started)
            {
                StopSpinner();
            }
        }
Exemple #7
0
        private void RefreshImportAndDownloadButtons()
        {
            if (displayVersion == null)
            {
                return;
            }

            var isAssetStore = displayVersion.HasTag(PackageTag.AssetStore);

            if (!isAssetStore)
            {
                UIUtils.SetElementDisplay(importButton, false);
                UIUtils.SetElementDisplay(downloadButton, false);
                downloadProgress.Hide();
                return;
            }

            importButton.text = GetButtonText(PackageAction.Import);

            var downloadInProgress = PackageDatabase.instance.IsDownloadInProgress(displayVersion);

            downloadButton.text = GetButtonText(package.state == PackageState.Outdated ? PackageAction.Upgrade : PackageAction.Download, downloadInProgress);

            var enableButton = !ApplicationUtil.instance.isCompiling;

            UIUtils.SetElementDisplay(importButton, true);
            importButton.SetEnabled(enableButton && displayVersion.isAvailableOnDisk);

            UIUtils.SetElementDisplay(downloadButton, true);
            var notOnDiskOrUpgradeAvailable = !displayVersion.isAvailableOnDisk || package.state == PackageState.Outdated;

            downloadButton.SetEnabled(enableButton && notOnDiskOrUpgradeAvailable);

            if (!downloadInProgress)
            {
                downloadProgress.Hide();
            }
        }
Exemple #8
0
        private void RefreshRemoveButton()
        {
            var displayPackage = Display(package);

            if (displayPackage == null)
            {
                UIUtils.SetElementDisplay(RemoveButton, false);
                return;
            }

            var visibleFlag = false;
            var actionLabel = displayPackage.Origin == PackageOrigin.Builtin ?
                              GetButtonText(PackageAction.Disable) :
                              GetButtonText(PackageAction.Remove, false, displayPackage.Version);
            var enableButton = false;

            if (filter != PackageFilter.All)
            {
                visibleFlag  = !package.IsPackageManagerUI;
                enableButton = !package.IsPackageManagerUI;
                if (package.RemoveSignal.Operation != null)
                {
                    actionLabel = displayPackage.Origin == PackageOrigin.Builtin ?
                                  GetButtonText(PackageAction.Disable, true) :
                                  GetButtonText(PackageAction.Remove, true, displayPackage.Version);;
                    enableButton = true;
                }
            }

            if (package.RemoveSignal.Operation != null)
            {
                enableButton = false;
            }

            RemoveButton.SetEnabled(enableButton);
            RemoveButton.text = actionLabel;
            UIUtils.SetElementDisplay(RemoveButton, visibleFlag);
        }
        public void UpdateVisualState(VisualState newVisualState = null)
        {
            var seeAllVersionsOld    = visualState?.seeAllVersions ?? false;
            var selectedVersionIdOld = visualState?.selectedVersionId ?? string.Empty;

            visualState = newVisualState?.Clone() ?? visualState ?? new VisualState(package?.uniqueId);

            if (UIUtils.IsElementVisible(this) != visualState.visible)
            {
                UIUtils.SetElementDisplay(this, visualState.visible);
            }

            if (selectedVersion != null && visualState != null && selectedVersion != targetVersion)
            {
                var keyVersions = package.versions.key.Where(p => p != package.versions.primary);
                var allVersions = package.versions.Where(p => p != package.versions.primary);

                visualState.expanded       = visualState.expanded || allVersions.Contains(selectedVersion);
                visualState.seeAllVersions = visualState.seeAllVersions || !keyVersions.Contains(selectedVersion);
            }

            var expansionChanged = expander.expanded != visualState.expanded;

            if (expansionChanged)
            {
                UpdateExpanderUI(visualState.expanded);
            }

            if (expansionChanged || seeAllVersionsOld != visualState.seeAllVersions)
            {
                RefreshVersions();
            }

            if (selectedVersionIdOld != visualState.selectedVersionId)
            {
                RefreshSelection();
            }
        }
Exemple #10
0
        private void RefreshCategories()
        {
            var isAssetStorePackage = displayVersion.HasTag(PackageTag.AssetStore);

            UIUtils.SetElementDisplay(detailCategories, isAssetStorePackage && !string.IsNullOrEmpty(displayVersion.category));
            detailCategories.Clear();

            if (isAssetStorePackage)
            {
                var categories     = displayVersion.category.Split('/');
                var parentCategory = "/";
                foreach (var category in categories)
                {
                    var lower = category.ToLower(CultureInfo.InvariantCulture);
                    var url   = $"{AssetStoreUtils.instance.assetStoreUrl}{parentCategory}{lower}";
                    detailCategories.Add(new Button(() => { ApplicationUtil.instance.OpenURL(url); })
                    {
                        text = category, classList = { "category", "unity-button", "link" }
                    });
                    parentCategory += lower + "/";
                }
            }
        }
Exemple #11
0
        private void SetStatusMessage(StatusType status, string message)
        {
            if (status == StatusType.Loading)
            {
                LoadingSpinner.Start();
            }
            else
            {
                LoadingSpinner.Stop();
            }

            UIUtils.SetElementDisplay(LoadingIcon, status == StatusType.Error);
            if (status == StatusType.Error)
            {
                LoadingText.AddToClassList("icon");
            }
            else
            {
                LoadingText.RemoveFromClassList("icon");
            }

            LoadingText.text = message;
        }
        public void SetPackage(PackageInfo package)
        {
            ImportStatusContainer.Clear();
            NameLabelContainer.Clear();
            SizeLabelContainer.Clear();
            ImportButtonContainer.Clear();

            if (package == null || package.Samples == null || package.Samples.Count == 0)
            {
                UIUtils.SetElementDisplay(this, false);
                return;
            }
            UIUtils.SetElementDisplay(this, true);
            foreach (var sample in package.Samples)
            {
                var sampleItem = new PackageSampleItem(sample);
                ImportStatusContainer.Add(sampleItem.ImportStatus);
                NameLabelContainer.Add(sampleItem.NameLabel);
                SizeLabelContainer.Add(sampleItem.SizeLabel);
                ImportButtonContainer.Add(sampleItem.ImportButton);
                sampleItem.ImportButton.SetEnabled(package.IsInstalled);
            }
        }
        public void SetPackage(IPackageVersion package)
        {
            importStatusContainer.Clear();
            nameLabelContainer.Clear();
            sizeLabelContainer.Clear();
            importButtonContainer.Clear();

            if (package == null || package.samples == null || !package.samples.Any())
            {
                UIUtils.SetElementDisplay(this, false);
                return;
            }
            UIUtils.SetElementDisplay(this, true);
            foreach (var sample in package.samples)
            {
                var sampleItem = new PackageSampleItem(sample);
                importStatusContainer.Add(sampleItem.importStatus);
                nameLabelContainer.Add(sampleItem.nameLabel);
                sizeLabelContainer.Add(sampleItem.sizeLabel);
                importButtonContainer.Add(sampleItem.importButton);
                sampleItem.importButton.SetEnabled(package.isInstalled);
            }
        }
Exemple #14
0
        public static void FilterPackageList(PackageList packageList)
        {
            PackageItem firstItem            = null;
            var         selectedItemInFilter = false;
            var         selectedItem         = packageList.selectedItem;
            var         packageItems         = packageList.Query <PackageItem>().ToList();

            foreach (var item in packageItems)
            {
                if (FilterByText(item, PackageSearchFilter.Instance.SearchText))
                {
                    if (firstItem == null)
                    {
                        firstItem = item;
                    }
                    if (item == selectedItem)
                    {
                        selectedItemInFilter = true;
                    }

                    UIUtils.SetElementDisplay(item, true);
                }
                else
                {
                    UIUtils.SetElementDisplay(item, false);
                }
            }

            if (firstItem == null)
            {
                packageList.ShowNoResults();
            }
            else
            {
                packageList.ShowResults(selectedItemInFilter ? selectedItem : firstItem);
            }
        }
        private bool RefreshSizeInfo()
        {
            var showSizes = displayVersion.sizes.Any();

            UIUtils.SetElementDisplay(detailSizesContainer, showSizes);
            detailSizes.Clear();

            var sizeInfo = displayVersion.sizes.FirstOrDefault(info => info.supportedUnityVersion == displayVersion.supportedVersion);

            if (sizeInfo == null)
            {
                sizeInfo = displayVersion.sizes.LastOrDefault();
            }

            if (sizeInfo != null)
            {
                var textField = new TextField();
                textField.SetValueWithoutNotify(string.Format(ApplicationUtil.instance.GetTranslationForText("Size: {0} (Number of files: {1})"), UIUtils.ConvertToHumanReadableSize(sizeInfo.downloadSize), sizeInfo.assetCount));
                textField.isReadOnly = true;
                detailSizes.Add(textField);
            }

            return(showSizes);
        }
Exemple #16
0
        private void RefreshSupportingImages()
        {
            UIUtils.SetElementDisplay(detailImagesContainer, package.images.Any());
            ClearSupportingImages();

            if (s_LoadingTexture == null)
            {
                s_LoadingTexture = (Texture2D)EditorGUIUtility.LoadRequired("Icons/UnityLogo.png");
            }

            long id;

            if (long.TryParse(package.uniqueId, out id))
            {
                foreach (var packageImage in package.images)
                {
                    var image = new Label {
                        classList = { "image" }
                    };
                    image.OnLeftClick(() => { ApplicationUtil.instance.OpenURL(packageImage.url); });
                    image.style.backgroundImage = s_LoadingTexture;
                    detailImages.Add(image);

                    AssetStoreDownloadManager.instance.DownloadImageAsync(id, packageImage.thumbnailUrl, (retId, texture) =>
                    {
                        if (retId.ToString() == package?.uniqueId)
                        {
                            texture.hideFlags           = HideFlags.HideAndDontSave;
                            image.style.backgroundImage = texture;
                        }
                    });
                }
            }

            detailImagesMoreLink.clicked += OnMoreImagesClicked;
        }
Exemple #17
0
        private void RefreshLabels()
        {
            detailLabels.Clear();

            if (enabledSelf && m_Package?.labels != null)
            {
                string labels = string.Join(", ", m_Package.labels.ToArray());

                if (!string.IsNullOrEmpty(labels))
                {
                    detailLabels.Add(new Label(labels));
                }
            }

            bool hasLabels           = detailLabels.Children().Any();
            bool isAssetStorePackage = m_Package is AssetStorePackage;

            if (!hasLabels && isAssetStorePackage)
            {
                detailLabels.Add(new Label(ApplicationUtil.instance.GetTranslationForText("(None)")));
            }

            UIUtils.SetElementDisplay(detailLabelsContainer, hasLabels || isAssetStorePackage);
        }
Exemple #18
0
        private void ImagesGeometryChangeEvent(GeometryChangedEvent evt)
        {
            // hide or show the last image depending on whether it fits on the screen
            IEnumerable <VisualElement> images        = detailImages.Children();
            IEnumerable <VisualElement> visibleImages = images.Where(elem => UIUtils.IsElementVisible(elem));

            VisualElement firstInvisibleImage = images.FirstOrDefault(elem => !UIUtils.IsElementVisible(elem));
            float         visibleImagesWidth  = visibleImages.Sum(elem => elem.rect.width);
            VisualElement lastVisibleImage    = visibleImages.LastOrDefault();

            float widthWhenLastImageRemoved = detailImagesWidthsWhenImagesRemoved.Any() ? detailImagesWidthsWhenImagesRemoved.Peek() : float.MaxValue;

            // if the container approximately doubles in height, that indicates the last image was wrapped around to another row
            if (lastVisibleImage != null && (evt.newRect.height >= 2 * lastVisibleImage.rect.height || visibleImagesWidth >= evt.newRect.width))
            {
                UIUtils.SetElementDisplay(lastVisibleImage, false);
                detailImagesWidthsWhenImagesRemoved.Push(evt.newRect.width);
            }
            else if (firstInvisibleImage != null && evt.newRect.width > widthWhenLastImageRemoved)
            {
                UIUtils.SetElementDisplay(firstInvisibleImage, true);
                detailImagesWidthsWhenImagesRemoved.Pop();
            }
        }
Exemple #19
0
        public PackageList()
        {
            var root = Resources.GetTemplate("PackageList.uxml");

            Add(root);
            root.StretchToParentSize();
            cache = new VisualElementCache(root);

            viewDataKey      = "package-list-key";
            list.viewDataKey = "package-list-scrollview-key";

            UIUtils.SetElementDisplay(emptyArea, false);
            UIUtils.SetElementDisplay(noResult, false);
            UIUtils.SetElementDisplay(mustLogin, false);

            emptyAreaText.text = L10n.Tr("There are no packages.");

            loginBtn.clickable.clicked += OnLoginClicked;

            RegisterCallback <AttachToPanelEvent>(OnEnterPanel);
            RegisterCallback <DetachFromPanelEvent>(OnLeavePanel);

            m_PackagesLoaded = false;
        }
Exemple #20
0
        private void UpdateDependencies(DependencyInfo[] dependencies)
        {
            dependenciesNames.Clear();
            dependenciesVersions.Clear();
            dependenciesStatuses.Clear();

            var hasDependencies = dependencies?.Any() ?? false;

            UIUtils.SetElementDisplay(noDependencies, !hasDependencies);
            UIUtils.SetElementDisplay(dependenciesNames, hasDependencies);
            UIUtils.SetElementDisplay(dependenciesVersions, hasDependencies);

            if (!hasDependencies)
            {
                return;
            }

            foreach (var dependency in dependencies)
            {
                dependenciesNames.Add(BuildTextField(GetNameText(dependency), "text"));
                dependenciesVersions.Add(BuildTextField(dependency.version, "text"));
                dependenciesStatuses.Add(BuildLabel(GetStatusText(dependency), "text"));
            }
        }
        public void LoadMoreItemsClicked()
        {
            UIUtils.SetElementDisplay(loadMoreContainer, false);

            PageManager.instance.LoadMore();
        }
 private void SetupOrdering()
 {
     orderingMenu.menu.MenuItems().Clear();
     orderingMenu.ShowTextTooltipOnSizeChange(-16);
     UIUtils.SetElementDisplay(orderingMenu, false);
 }
Exemple #23
0
        protected override void DoDisplay()
        {
            m_StatusFoldOut = new Foldout {
                text = L10n.Tr("Status"), name = k_StatusFoldOutName, classList = { k_FoldoutClass }
            };
            foreach (var status in k_Statuses)
            {
                var toggle = new Toggle(status)
                {
                    name = status.ToLower(), classList = { k_ToggleClass }
                };
                toggle.RegisterValueChangedCallback(evt =>
                {
                    if (evt.newValue)
                    {
                        foreach (var t in m_StatusFoldOut.Children().OfType <Toggle>())
                        {
                            if (t == toggle)
                            {
                                continue;
                            }

                            t.SetValueWithoutNotify(false);
                        }

                        if (status == k_Statuses[0] && m_LabelsFoldOut != null)
                        {
                            // Uncheck labels if checked
                            foreach (var t in m_LabelsFoldOut.Children().OfType <Toggle>())
                            {
                                t.value = false;
                            }
                        }
                    }

                    UpdateFiltersIfNeeded();
                });

                m_StatusFoldOut.Add(toggle);
            }
            m_Container.Add(m_StatusFoldOut);

            if (m_Categories.Any())
            {
                m_CategoriesFoldOut = new Foldout {
                    text = L10n.Tr("Categories"), name = k_CategoriesFoldOutName, classList = { k_FoldoutClass }
                };
                foreach (var category in m_Categories)
                {
                    var toggle = new Toggle(L10n.Tr(category))
                    {
                        name = category.ToLower(), classList = { k_ToggleClass }
                    };
                    toggle.RegisterValueChangedCallback(evt => UpdateFiltersIfNeeded());
                    m_CategoriesFoldOut.Add(toggle);
                }

                m_CategoriesFoldOut.Query <Label>().ForEach(UIUtils.TextTooltipOnSizeChange);
                m_Container.Add(m_CategoriesFoldOut);
            }

            if (m_Labels.Any())
            {
                m_LabelsFoldOut = new Foldout {
                    text = L10n.Tr("Labels"), name = k_LabelsFoldOutName, classList = { k_FoldoutClass }
                };
                var i = 0;
                foreach (var label in m_Labels)
                {
                    var toggle = new Toggle(L10n.Tr(label))
                    {
                        name = label, classList = { k_ToggleClass }
                    };
                    toggle.RegisterValueChangedCallback(evt =>
                    {
                        if (evt.newValue)
                        {
                            // Uncheck Unlabeled if checked
                            m_StatusFoldOut.Q <Toggle>(k_Statuses[0].ToLower()).value = false;
                        }
                        UpdateFiltersIfNeeded();
                    });
                    m_LabelsFoldOut.Add(toggle);

                    if (++i > k_MaxDisplayLabels)
                    {
                        UIUtils.SetElementDisplay(toggle, false);
                    }
                }

                m_LabelsFoldOut.Query <Label>().ForEach(UIUtils.TextTooltipOnSizeChange);
                m_Container.Add(m_LabelsFoldOut);
            }
        }
 private void StopSpinner()
 {
     spinner.Stop();
     UIUtils.SetElementDisplay(stateLabel, true);
 }
 private void StartSpinner()
 {
     spinner.Start();
     UIUtils.SetElementDisplay(stateLabel, false);
 }
 internal void UpdateExpanderUI(bool expanded)
 {
     arrowExpander.value = expanded;
     UIUtils.SetElementDisplay(versionsContainer, expanded);
 }
 internal void Hide()
 {
     UIUtils.SetElementDisplay(this, false);
 }
 private void SetEmptyAreaDisplay(bool value)
 {
     // empty area & scroll view should never be shown at the same time
     UIUtils.SetElementDisplay(emptyArea, value);
     UIUtils.SetElementDisplay(scrollView, !value);
 }
 private void OnRefreshOperationError(UIError error)
 {
     // if Load More operation fails, check if the Load More label should be displayed again
     UIUtils.SetElementDisplay(loadMoreContainer, PageManager.instance.GetCurrentPage().morePackagesToFetch);
 }
Exemple #30
0
 private void SetUpdateVisibility(bool value)
 {
     UIUtils.SetElementDisplay(updateButton, value);
 }