예제 #1
0
        /// <summary>Displays a set of tags.</summary>
        public void DisplayTags(IEnumerable <string> tags)
        {
            // copy tags
            if (this.m_tags != tags)
            {
                if (tags == null)
                {
                    tags = new string[0];
                }

                // copy tags
                List <string> newTagList = new List <string>();
                foreach (string tagName in tags)
                {
                    newTagList.Add(tagName);
                }
                this.m_tags = newTagList.ToArray();
            }

            // display
            if (this.m_itemTemplate != null)
            {
                int tagCount = this.m_tags.Length;
                UIUtilities.SetInstanceCount(this.m_container, this.m_itemTemplate,
                                             "Tag", tagCount,
                                             ref this.m_displays);

                // display categories?
                if (m_itemTemplate.categoryName.displayComponent != null &&
                    this.m_tagCategoryMap.Count > 0)
                {
                    for (int i = 0;
                         i < tagCount;
                         ++i)
                    {
                        string categoryName;
                        if (this.m_tagCategoryMap.TryGetValue(this.m_tags[i], out categoryName))
                        {
                            this.m_displays[i].categoryName.text = categoryName;
                        }
                    }
                }

                // display tag names
                for (int i = 0;
                     i < tagCount;
                     ++i)
                {
                    this.m_displays[i].tagName.text = this.m_tags[i];
                }

                this.m_templateClone.SetActive(tagCount > 0 || !this.hideIfEmpty);
            }
        }
예제 #2
0
        private void PresentData()
        {
            if (loadingOverlay != null)
            {
                loadingOverlay.SetActive(false);
            }

            if (avatarOverlay != null)
            {
                avatarOverlay.SetActive(m_data.mediaType == ImageDisplayData.MediaType.UserAvatar);
            }
            if (logoOverlay != null)
            {
                logoOverlay.SetActive(m_data.mediaType == ImageDisplayData.MediaType.ModLogo);
            }
            if (galleryImageOverlay != null)
            {
                galleryImageOverlay.SetActive(m_data.mediaType == ImageDisplayData.MediaType.ModGalleryImage);
            }
            if (youTubeOverlay != null)
            {
                youTubeOverlay.SetActive(m_data.mediaType == ImageDisplayData.MediaType.YouTubeThumbnail);
            }

            if (image != null)
            {
                // if original is missing, just use thumbnail
                bool original = m_useOriginal;
                if (original && m_data.GetImageTexture(true) == null)
                {
                    original = false;
                }

                Texture2D texture = m_data.GetImageTexture(original);
                if (texture != null)
                {
                    image.sprite = UIUtilities.CreateSpriteFromTexture(texture);

                    if (fitter != null)
                    {
                        fitter.aspectRatio = ((float)texture.width
                                              / (float)texture.height);
                    }
                    image.enabled = true;
                }
                else
                {
                    image.enabled = false;
                }
            }
        }
        /// <summary>Internal function for applying the texture.</summary>
        protected virtual void ApplyTexture(GalleryImageLocator locator, Texture2D texture)
        {
            if (this != null &&
                texture != null &&
                this.m_locator == locator)
            {
                this.image.sprite  = UIUtilities.CreateSpriteFromTexture(texture);
                this.image.enabled = true;

                if (this.onTextureChanged != null)
                {
                    this.onTextureChanged.Invoke(texture);
                }
            }
        }
예제 #4
0
        /// <summary>Internal function for applying the texture.</summary>
        protected virtual void ApplyTexture(string youTubeId, Texture2D texture)
        {
            if (this != null &&
                texture != null &&
                this.m_youTubeId == youTubeId)
            {
                this.image.sprite  = UIUtilities.CreateSpriteFromTexture(texture);
                this.image.enabled = true;

                if (this.onTextureChanged != null)
                {
                    this.onTextureChanged.Invoke(texture);
                }
            }
        }
        private void OnGUI()
        {
            if (this.m_lastDimensions != this.rectTransform.rect)
            {
                int newCount = UIUtilities.CountVisibleGridCells(this.grid);
                if (newCount != this.m_lastCellCount &&
                    this.onCellCountChanged != null)
                {
                    this.onCellCountChanged.Invoke(newCount);
                }

                this.m_lastCellCount  = newCount;
                this.m_lastDimensions = this.rectTransform.rect;
            }
        }
예제 #6
0
 private void UpdatePageNumberDisplay()
 {
     if (pageNumberText != null)
     {
         pageNumberText.text = CurrentPageNumber.ToString();
     }
     if (pageCountText != null)
     {
         pageCountText.text = CurrentPageCount.ToString();
     }
     if (resultCountText != null)
     {
         resultCountText.text = UIUtilities.ValueToDisplayString(currentPage.resultTotal);
     }
 }
예제 #7
0
        private void DisplayTexture(Texture2D texture)
        {
            Debug.Assert(texture != null);

            if (image != null)
            {
                image.sprite = UIUtilities.CreateSpriteFromTexture(texture);

                if (fitter != null)
                {
                    fitter.aspectRatio = ((float)texture.width / (float)texture.height);
                }

                image.enabled = true;
            }
        }
예제 #8
0
        // ---------[ INITIALIZATION ]---------
        public void Initialize()
        {
            // TODO(@jackson): Asserts
            ModMediaContainer mediaContainer = null;

            if (modView != null)
            {
                modView.Initialize();

                if (modView.statisticsDisplay != null)
                {
                    modView.statisticsDisplay.Initialize();
                }

                mediaContainer = modView.mediaContainer as ModMediaContainer;
            }

            if (selectedMediaPreview != null)
            {
                selectedMediaPreview.Initialize();
                selectedMediaPreview.onClick += (d) =>
                {
                    if (d.data.mediaType == ImageDisplayData.MediaType.YouTubeThumbnail)
                    {
                        UIUtilities.OpenYouTubeVideoURL(d.data.youTubeId);
                    }
                };

                if (mediaContainer != null)
                {
                    mediaContainer.logoClicked             += MediaPreview_Logo;
                    mediaContainer.galleryImageClicked     += MediaPreview_GalleryImage;
                    mediaContainer.youTubeThumbnailClicked += MediaPreview_YouTubeThumbnail;
                }
            }

            if ((versionHistoryContainer != null && versionHistoryItemPrefab == null) ||
                (versionHistoryItemPrefab != null && versionHistoryContainer == null))
            {
                Debug.LogWarning("[mod.io] In order to display a version history both the "
                                 + "versionHistoryItemPrefab and versionHistoryContainer variables must "
                                 + "be set for the InspectorView.", this);
            }

            Debug.Assert(!(versionHistoryItemPrefab != null && versionHistoryItemPrefab.GetComponent <ModfileDisplayComponent>() == null),
                         "[mod.io] The versionHistoryItemPrefab requires a ModfileDisplayComponent on the root Game Object.");
        }
        // ---------[ UI FUNCTIONALITY ]---------
        /// <summary>Displays a set of modfiles.</summary>
        public virtual void DisplayModfiles(IList <Modfile> modfiles)
        {
            // copy data
            if (this.m_modfiles != modfiles)
            {
                int modfileCount = 0;
                if (modfiles != null)
                {
                    modfileCount = modfiles.Count;
                }

                this.m_modfiles = new Modfile[modfileCount];
                for (int i = 0; i < modfileCount; ++i)
                {
                    this.m_modfiles[i] = modfiles[i];
                }
            }

            // display
            if (this.m_itemTemplate != null)
            {
                // set instance count
                int itemCount = this.m_modfiles.Length;;
                if (this.m_itemLimit >= 0 &&
                    this.m_itemLimit < itemCount)
                {
                    itemCount = this.m_itemLimit;
                }

                // set view count
                UIUtilities.SetInstanceCount(this.m_container, this.m_itemTemplate,
                                             "Modfile View", itemCount,
                                             ref this.m_views);

                // display data
                for (int i = 0; i < itemCount; ++i)
                {
                    this.m_views[i].modfile = this.m_modfiles[i];
                }

                // hide if necessary
                this.m_templateClone.SetActive(itemCount > 0 || !this.hideIfEmpty);
            }
        }
예제 #10
0
        private void PresentData()
        {
            float percentComplete = 0f;

            if (data.bytesTotal > 0)
            {
                percentComplete = (float)data.bytesReceived / (float)data.bytesTotal;
            }

            if (percentageText != null)
            {
                percentageText.text = (percentComplete * 100f).ToString("0.0") + "%";
            }
            if (progressBar != null)
            {
                progressBar.percentComplete = percentComplete;
            }

            if (bytesReceivedText != null)
            {
                bytesReceivedText.text = UIUtilities.ByteCountToDisplayString(data.bytesReceived);
            }

            if (bytesTotalText != null)
            {
                bytesTotalText.text = UIUtilities.ByteCountToDisplayString(data.bytesTotal);
            }

            if (bytesPerSecondText != null)
            {
                bytesPerSecondText.text = UIUtilities.ByteCountToDisplayString(data.bytesPerSecond) + "/s";
            }

            if (timeRemainingText != null)
            {
                // TODO(@jackson): Localize?
                TimeSpan remaining = TimeSpan.FromSeconds(0f);

                timeRemainingText.text = (remaining.TotalHours + ":"
                                          + remaining.Minutes + ":"
                                          + remaining.Seconds);
            }
        }
        /// <summary>Displays a set of YouTube thumbnails.</summary>
        public virtual void DisplayThumbnails(int modId, IList <string> youTubeIds)
        {
            this.m_modId = modId;

            // copy ids
            if (this.m_youTubeIds != youTubeIds)
            {
                int thumbCount = 0;
                if (youTubeIds != null)
                {
                    thumbCount = youTubeIds.Count;
                }

                this.m_youTubeIds = new string[thumbCount];
                for (int i = 0; i < thumbCount; ++i)
                {
                    this.m_youTubeIds[i] = youTubeIds[i];
                }
            }

            // display
            if (this.m_itemTemplate != null)
            {
                // set view count
                UIUtilities.SetInstanceCount(this.m_container, this.m_itemTemplate,
                                             "YouTube Thumbnail", this.m_youTubeIds.Length,
                                             ref this.m_displays);

                // display data
                for (int i = 0;
                     i < this.m_youTubeIds.Length;
                     ++i)
                {
                    this.m_displays[i].DisplayThumbnail(this.m_modId, this.m_youTubeIds[i]);
                }

                // hide if necessary
                this.m_templateClone.SetActive(this.m_youTubeIds.Length > 0 || !this.hideIfEmpty);
            }
        }
예제 #12
0
        /// <summary>Displays a set of gallery images.</summary>
        public virtual void DisplayImages(int modId, IList <GalleryImageLocator> locators)
        {
            this.m_modId = modId;

            // copy locators
            if (this.m_locators != locators)
            {
                int imageCount = 0;
                if (locators != null)
                {
                    imageCount = locators.Count;
                }

                this.m_locators = new GalleryImageLocator[imageCount];
                for (int i = 0; i < imageCount; ++i)
                {
                    this.m_locators[i] = locators[i];
                }
            }

            // display
            if (this.m_itemTemplate != null)
            {
                // set view count
                UIUtilities.SetInstanceCount(this.m_container, this.m_itemTemplate,
                                             "Gallery Image", this.m_locators.Length,
                                             ref this.m_displays);

                // display data
                for (int i = 0; i < this.m_locators.Length; ++i)
                {
                    this.m_displays[i].DisplayGalleryImage(modId, this.m_locators[i]);
                }

                // hide if necessary
                this.m_templateClone.SetActive(this.m_locators.Length > 0 || !this.hideIfEmpty);
            }
        }
예제 #13
0
        // ---------[ UI FUNCTIONALITY ]---------
        /// <summary>Displays a set of mods.</summary>
        public virtual void DisplayMods(IList <ModProfile> profiles, IList <ModStatistics> statistics)
        {
            // assert validity
            if (profiles != null &&
                statistics != null &&
                profiles.Count != statistics.Count)
            {
                Debug.LogWarning("[mod.io] Cannot display a collection of profiles"
                                 + " and statistics where the counts are not equal."
                                 + "\n profiles.Count = " + profiles.Count.ToString()
                                 + "\n statistics.Count = " + statistics.Count.ToString(),
                                 this);

                statistics = null;
            }

            int itemCount = 0;

            if (profiles != null)
            {
                itemCount = profiles.Count;
            }
            else if (statistics != null)
            {
                itemCount = statistics.Count;
            }

            // copy arrays
            if (this.m_modProfiles != profiles)
            {
                this.m_modProfiles = new ModProfile[itemCount];
                for (int i = 0; i < itemCount; ++i)
                {
                    this.m_modProfiles[i] = profiles[i];
                }
            }
            if (this.m_modStatistics != statistics)
            {
                this.m_modStatistics = new ModStatistics[itemCount];
                for (int i = 0; i < itemCount; ++i)
                {
                    this.m_modStatistics[i] = statistics[i];
                }
            }

            // display
            if (this.m_itemTemplate != null)
            {
                Debug.Assert(this.m_container != null);

                // set instance count
                int viewCount = itemCount;
                if (this.m_fillToLimit && this.m_itemLimit >= 0)
                {
                    viewCount = this.m_itemLimit;

                    if (viewCount < itemCount)
                    {
                        itemCount = viewCount;
                    }
                }

                UIUtilities.SetInstanceCount(this.m_container, this.m_itemTemplate,
                                             "Mod View", viewCount,
                                             ref this.m_views, true);


                // -- set view visibility --
                if (this.m_fillToLimit && this.m_itemLimit >= 0)
                {
                    int visibleCount = itemCount;

                    for (int i = 0;
                         i < visibleCount;
                         ++i)
                    {
                        CanvasGroup c = this.m_views[i].GetComponent <CanvasGroup>();
                        c.alpha          = 1f;
                        c.interactable   = true;
                        c.blocksRaycasts = true;
                    }

                    for (int i = visibleCount;
                         i < viewCount;
                         ++i)
                    {
                        CanvasGroup c = this.m_views[i].GetComponent <CanvasGroup>();
                        c.alpha          = 0f;
                        c.interactable   = false;
                        c.blocksRaycasts = false;
                    }
                }

                // display data
                if (this.m_modProfiles != null)
                {
                    for (int i = 0;
                         i < this.m_modProfiles.Length && i < viewCount;
                         ++i)
                    {
                        this.m_views[i].profile = this.m_modProfiles[i];
                    }
                }
                if (this.m_modStatistics != null)
                {
                    for (int i = 0;
                         i < this.m_modStatistics.Length && i < viewCount;
                         ++i)
                    {
                        this.m_views[i].statistics = this.m_modStatistics[i];
                    }
                }

                // hide if necessary
                this.m_templateClone.SetActive(itemCount > 0 || !this.hideIfEmpty);
            }
        }
예제 #14
0
        // ---------[ UI FUNCTIONALITY ]---------
        /// <summary>Displays a collection of tag categories.</summary>
        public void DisplayTagCategories(IEnumerable <ModTagCategory> tagCategories)
        {
            // copy categories
            if (this.m_tagCategories != tagCategories)
            {
                if (tagCategories == null)
                {
                    tagCategories = new ModTagCategory[0];
                }

                // copy categories
                List <ModTagCategory> categories = new List <ModTagCategory>();
                foreach (ModTagCategory category in tagCategories)
                {
                    if (category != null &&
                        category.tags != null &&
                        category.tags.Length > 0 &&
                        (displayHidden || !category.isHidden))
                    {
                        categories.Add(category);
                    }
                }
                this.m_tagCategories = categories.ToArray();
            }

            // display
            if (this.isActiveAndEnabled)
            {
                int categoryCount = this.m_tagCategories.Length;

                // create/destroy category displays
                UIUtilities.SetInstanceCount(this.m_container, this.m_itemTemplate,
                                             "Tag Category", categoryCount,
                                             ref this.m_itemInstances);

                // set category labels
                if (this.template.categoryLabel.displayComponent != null)
                {
                    for (int i = 0; i < categoryCount; ++i)
                    {
                        this.m_itemInstances[i].label.text = this.m_tagCategories[i].name;
                    }
                }

                // tag displays
                for (int cat_i = 0; cat_i < categoryCount; ++cat_i)
                {
                    ModTagCategory category     = this.m_tagCategories[cat_i];
                    CategoryItem   categoryItem = this.m_itemInstances[cat_i];

                    // create/destroy
                    UIUtilities.SetInstanceCount(categoryItem.tagContainer,
                                                 this.template.tagTemplate,
                                                 "Tag",
                                                 category.tags.Length,
                                                 ref categoryItem.tagInstances);

                    // set category name
                    if (this.template.tagTemplate.categoryName.displayComponent != null)
                    {
                        for (int tag_i = 0; tag_i < category.tags.Length; ++tag_i)
                        {
                            categoryItem.tagInstances[tag_i].categoryName.text = category.name;
                        }
                    }

                    // set tag name
                    for (int tag_i = 0; tag_i < category.tags.Length; ++tag_i)
                    {
                        categoryItem.tagInstances[tag_i].tagName.text = category.tags[tag_i];
                    }
                }

                // fire event
                if (this.onTagsChanged != null)
                {
                    this.onTagsChanged(this.tagItems);
                }
            }
        }
        private void BuildDisplayMap()
        {
            m_displayMapping = new Dictionary <Text, GetDisplayString>();

            if (popularityRankDisplay != null)
            {
                m_displayMapping.Add(popularityRankDisplay,
                                     (s) => UIUtilities.ValueToDisplayString(s.popularityRankPosition));
            }
            if (popularityModCountDisplay != null)
            {
                m_displayMapping.Add(popularityModCountDisplay,
                                     (s) => UIUtilities.ValueToDisplayString(s.popularityRankModCount));
            }
            if (downloadCountDisplay != null)
            {
                m_displayMapping.Add(downloadCountDisplay,
                                     (s) => UIUtilities.ValueToDisplayString(s.downloadCount));
            }
            if (subscriberCountDisplay != null)
            {
                m_displayMapping.Add(subscriberCountDisplay,
                                     (s) => UIUtilities.ValueToDisplayString(s.subscriberCount));
            }
            if (ratingCountDisplay != null)
            {
                m_displayMapping.Add(ratingCountDisplay,
                                     (s) => UIUtilities.ValueToDisplayString(s.ratingCount));
            }
            if (ratingPositiveCountDisplay != null)
            {
                m_displayMapping.Add(ratingPositiveCountDisplay,
                                     (s) => UIUtilities.ValueToDisplayString(s.ratingPositiveCount));
            }
            if (ratingPositivePercentageDisplay != null)
            {
                m_displayMapping.Add(ratingPositivePercentageDisplay,
                                     (s) => (s.ratingCount > 0
                                             ? (100f * (float)s.ratingPositiveCount / (float)s.ratingCount).ToString("0") + "%"
                                             : "--"));
            }
            if (ratingNegativeCountDisplay != null)
            {
                m_displayMapping.Add(ratingNegativeCountDisplay,
                                     (s) => UIUtilities.ValueToDisplayString(s.ratingNegativeCount));
            }
            if (ratingNegativePercentageDisplay != null)
            {
                m_displayMapping.Add(ratingNegativePercentageDisplay,
                                     (s) => (s.ratingCount > 0
                                             ? (100f * (float)s.ratingNegativeCount / (float)s.ratingCount).ToString("0") + "%"
                                             : "--"));
            }
            if (ratingWeightedAggregateDisplay != null)
            {
                m_displayMapping.Add(ratingWeightedAggregateDisplay,
                                     (s) => (100f * s.ratingWeightedAggregate).ToString("0") + "%");
            }
            if (ratingAsTextDisplay != null)
            {
                m_displayMapping.Add(ratingAsTextDisplay,
                                     (s) => s.ratingDisplayText);
            }
        }
        /// <summary>Applies the navigation settings to the child objects.</summary>
        public void UpdateNavigationForChildren()
        {
            LayoutGroup lg = this.GetComponent <LayoutGroup>();

            if (lg == null)
            {
                return;
            }

            int columnCount = 1;
            List <Selectable> selectables = null;

            if (this.selectableDepth < 0)
            {
                selectables = new List <Selectable>(this.gameObject.GetComponentsInChildren <Selectable>());
            }
            else
            {
                selectables = new List <Selectable>();

                Action <Transform, int> appendChildSelectables = null;
                appendChildSelectables = (t, depth) =>
                {
                    foreach (var ignorer in t.gameObject.GetComponents <ILayoutIgnorer>())
                    {
                        if (ignorer.ignoreLayout)
                        {
                            return;
                        }
                    }

                    if (!t.gameObject.activeSelf)
                    {
                        return;
                    }

                    if (depth == selectableDepth)
                    {
                        Selectable s = t.gameObject.GetComponent <Selectable>();
                        if (s != null)
                        {
                            selectables.Add(s);
                        }
                    }
                    else
                    {
                        foreach (Transform child in t)
                        {
                            appendChildSelectables(child, depth + 1);
                        }
                    }
                };

                appendChildSelectables(this.transform, 0);
            }

            if (lg is HorizontalLayoutGroup)
            {
                columnCount = selectables.Count;
            }
            else if (lg is GridLayoutGroup)
            {
                columnCount = UIUtilities.CalculateGridColumnCount((GridLayoutGroup)lg);
            }

            UIUtilities.SetExplicitGridNavigation(selectables, columnCount,
                                                  this.horizontalNavigation,
                                                  this.verticalNavigation);
        }