Esempio n. 1
0
        private void PresentData()
        {
            string imageURL = this.m_data.GetImageURL(this.useOriginal);

            DisplayLoading();

            // request missing texture
            if (!string.IsNullOrEmpty(imageURL))
            {
                ImageDisplayData iData = this.m_data;
                ImageRequestManager.instance.RequestImageForData(this.m_data, this.useOriginal,
                                                                 (t) =>
                {
                    if (this != null && iData.Equals(this.m_data))
                    {
                        if (loadingOverlay != null)
                        {
                            loadingOverlay.SetActive(false);
                        }

                        DisplayTexture(t);
                        SetOverlayVisibility(true);
                    }
                },
                                                                 null);
            }
        }
        public void DisplayUser(UserProfile profile)
        {
            Debug.Assert(profile != null);

            m_data = new UserDisplayData();

            if (profileDisplay != null)
            {
                profileDisplay.DisplayProfile(profile);
                m_data.profile = profileDisplay.data;
            }
            else
            {
                m_data.profile = UserProfileDisplayData.CreateFromProfile(profile);
            }

            if (avatarDisplay != null)
            {
                avatarDisplay.DisplayAvatar(profile.id, profile.avatarLocator);
                m_data.avatar = avatarDisplay.data;
            }
            else
            {
                if (profile.avatarLocator != null)
                {
                    m_data.avatar = ImageDisplayData.CreateForUserAvatar(profile.id,
                                                                         profile.avatarLocator);
                }
                else
                {
                    m_data.avatar = new ImageDisplayData();
                }
            }
        }
Esempio n. 3
0
        private void MediaPreview_GalleryImage(ImageDisplayComponent display)
        {
            ImageDisplayData imageData = display.data;

            selectedMediaPreview.data = imageData;

            if (imageData.GetImageTexture(selectedMediaPreview.useOriginal) == null)
            {
                bool original            = selectedMediaPreview.useOriginal;
                ModGalleryImageSize size = (original ? ModGalleryImageSize.Original : ImageDisplayData.galleryThumbnailSize);

                ModManager.GetModGalleryImage(profile, display.data.fileName,
                                              size,
                                              (t) =>
                {
                    if (Application.isPlaying &&
                        selectedMediaPreview.data.Equals(imageData))
                    {
                        imageData.SetImageTexture(original, t);
                        selectedMediaPreview.data = imageData;
                    }
                },
                                              WebRequestError.LogAsWarning);
            }
        }
Esempio n. 4
0
        public void DisplayYouTubeThumbnail(int modId, string youTubeVideoId)
        {
            Debug.Assert(!String.IsNullOrEmpty(youTubeVideoId),
                         "[mod.io] youTubeVideoId needs to be set to a valid YouTube video id.");

            ImageDisplayData displayData = new ImageDisplayData()
            {
                modId            = modId,
                mediaType        = ImageDisplayData.MediaType.YouTubeThumbnail,
                youTubeId        = youTubeVideoId,
                originalTexture  = null,
                thumbnailTexture = null,
            };

            m_data = displayData;

            DisplayLoading();

            ModManager.GetModYouTubeThumbnail(displayData.modId,
                                              displayData.youTubeId,
                                              (t) =>
            {
                if (!Application.isPlaying)
                {
                    return;
                }
                if (m_data.Equals(displayData))
                {
                    m_data.originalTexture  = t;
                    m_data.thumbnailTexture = t;
                    PresentData();
                }
            },
                                              WebRequestError.LogAsWarning);
        }
Esempio n. 5
0
        private void PresentData()
        {
            string    imageURL = this.m_data.GetImageURL(this.useOriginal);
            Texture2D texture  = null;

            // attempt cache retrieval
            ImageRequestManager.instance.cache.TryGetValue(imageURL, out texture);
            if (texture != null)
            {
                if (loadingOverlay != null)
                {
                    loadingOverlay.SetActive(false);
                }

                DisplayTexture(texture);
                SetOverlayVisibility(true);
                return;
            }

            // get fallback?
            if (this.enableFallback &&
                ImageRequestManager.instance.cache.TryGetValue(this.m_data.GetImageURL(!this.useOriginal),
                                                               out texture))
            {
                DisplayTexture(texture);
                SetOverlayVisibility(true);

                if (loadingOverlay != null)
                {
                    loadingOverlay.SetActive(true);
                }
            }
            else
            {
                DisplayLoading();
            }

            // request missing texture
            if (!string.IsNullOrEmpty(imageURL))
            {
                ImageDisplayData iData = this.m_data;
                ImageRequestManager.instance.RequestImageForData(this.m_data, this.useOriginal,
                                                                 (t) =>
                {
                    if (this != null && iData.Equals(this.m_data))
                    {
                        if (loadingOverlay != null)
                        {
                            loadingOverlay.SetActive(false);
                        }

                        DisplayTexture(t);
                        SetOverlayVisibility(true);
                    }
                },
                                                                 null);
            }
        }
        // NOTE(@jackson): This ignores the Logo as it'll be set anyway
        private void ParseProfileMedia(ModProfile profile, ref ModDisplayData data)
        {
            // - early out -
            if (profile.media == null)
            {
                data.galleryImages     = new ImageDisplayData[0];
                data.youTubeThumbnails = new ImageDisplayData[0];
                return;
            }

            // - parse -
            List <ImageDisplayData> media = new List <ImageDisplayData>();

            if (profile.media.galleryImageLocators != null &&
                profile.media.galleryImageLocators.Length > 0)
            {
                foreach (GalleryImageLocator locator in profile.media.galleryImageLocators)
                {
                    ImageDisplayData imageData;
                    if (locator != null)
                    {
                        imageData = ImageDisplayData.CreateForModGalleryImage(profile.id,
                                                                              locator);
                    }
                    else
                    {
                        imageData = new ImageDisplayData();
                    }

                    media.Add(imageData);
                }
            }
            data.galleryImages = media.ToArray();

            media.Clear();
            if (profile.media.youTubeURLs != null &&
                profile.media.youTubeURLs.Length > 0)
            {
                foreach (string url in profile.media.youTubeURLs)
                {
                    ImageDisplayData imageData;
                    if (!string.IsNullOrEmpty(url))
                    {
                        imageData = ImageDisplayData.CreateForYouTubeThumbnail(profile.id,
                                                                               Utility.ExtractYouTubeIdFromURL(url));
                    }
                    else
                    {
                        imageData = new ImageDisplayData();
                    }

                    media.Add(imageData);
                }
            }
            data.youTubeThumbnails = media.ToArray();
        }
Esempio n. 7
0
        public void DisplayGalleryImage(int modId, GalleryImageLocator locator)
        {
            Debug.Assert(locator != null);

            ImageDisplayData displayData = ImageDisplayData.CreateForModGalleryImage(modId, locator);

            m_data = displayData;

            PresentData();
        }
Esempio n. 8
0
        public void DisplayLogo(int modId, LogoImageLocator locator)
        {
            Debug.Assert(locator != null);

            ImageDisplayData displayData = ImageDisplayData.CreateForModLogo(modId, locator);

            m_data = displayData;

            PresentData();
        }
Esempio n. 9
0
        // ---------[ UI FUNCTIONALITY ]---------
        public void DisplayAvatar(int userId, AvatarImageLocator locator)
        {
            Debug.Assert(locator != null);

            ImageDisplayData displayData = ImageDisplayData.CreateForUserAvatar(userId, locator);

            m_data = displayData;

            PresentData();
        }
Esempio n. 10
0
        public void DisplayYouTubeThumbnail(int modId, string youTubeVideoId)
        {
            Debug.Assert(!String.IsNullOrEmpty(youTubeVideoId),
                         "[mod.io] youTubeVideoId needs to be set to a valid YouTube video id.");

            ImageDisplayData displayData = ImageDisplayData.CreateForYouTubeThumbnail(modId, youTubeVideoId);

            m_data = displayData;

            PresentData();
        }
Esempio n. 11
0
        // NOTE(@jackson): This ignores the Logo as it'll be set anyway
        private void ParseProfileMedia(ModProfile profile, ref ModDisplayData data)
        {
            // - early out -
            if (profile.media == null)
            {
                data.galleryImages     = new ImageDisplayData[0];
                data.youTubeThumbnails = new ImageDisplayData[0];
                return;
            }

            // - parse -
            List <ImageDisplayData> media = new List <ImageDisplayData>();

            if (profile.media.galleryImageLocators != null &&
                profile.media.galleryImageLocators.Length > 0)
            {
                foreach (GalleryImageLocator locator in profile.media.galleryImageLocators)
                {
                    ImageDisplayData imageData = new ImageDisplayData()
                    {
                        modId            = profile.id,
                        mediaType        = ImageDisplayData.MediaType.ModGalleryImage,
                        fileName         = locator.fileName,
                        originalTexture  = null,
                        thumbnailTexture = null,
                    };

                    media.Add(imageData);
                }
            }
            data.galleryImages = media.ToArray();

            media.Clear();
            if (profile.media.youTubeURLs != null &&
                profile.media.youTubeURLs.Length > 0)
            {
                foreach (string url in profile.media.youTubeURLs)
                {
                    ImageDisplayData imageData = new ImageDisplayData()
                    {
                        modId            = profile.id,
                        mediaType        = ImageDisplayData.MediaType.YouTubeThumbnail,
                        youTubeId        = Utility.ExtractYouTubeIdFromURL(url),
                        originalTexture  = null,
                        thumbnailTexture = null,
                    };

                    media.Add(imageData);
                }
            }
            data.youTubeThumbnails = media.ToArray();
        }
        /// <summary>Creates the ImageDisplayData for a mod gallery image.</summary>
        public static ImageDisplayData CreateForModGalleryImage(int modId, GalleryImageLocator locator)
        {
            ImageDisplayData retVal = new ImageDisplayData()
            {
                ownerId      = modId,
                descriptor   = ImageDescriptor.ModGalleryImage,
                imageId      = locator.GetFileName(),
                originalURL  = locator.GetSizeURL(ModGalleryImageSize.Original),
                thumbnailURL = locator.GetSizeURL(ImageDisplayData.galleryThumbnailSize),
            };

            return(retVal);
        }
        /// <summary>Creates the ImageDisplayData for a user avatar.</summary>
        public static ImageDisplayData CreateForUserAvatar(int userId, AvatarImageLocator locator)
        {
            ImageDisplayData retVal = new ImageDisplayData()
            {
                ownerId      = userId,
                descriptor   = ImageDescriptor.UserAvatar,
                imageId      = locator.GetFileName(),
                originalURL  = locator.GetSizeURL(UserAvatarSize.Original),
                thumbnailURL = locator.GetSizeURL(ImageDisplayData.avatarThumbnailSize),
            };

            return(retVal);
        }
        // ---------[ GENERATION ]---------
        /// <summary>Creates the ImageDisplayData for a mod logo.</summary>
        public static ImageDisplayData CreateForModLogo(int modId, LogoImageLocator locator)
        {
            ImageDisplayData retVal = new ImageDisplayData()
            {
                ownerId      = modId,
                descriptor   = ImageDescriptor.ModLogo,
                imageId      = locator.GetFileName(),
                originalURL  = locator.GetSizeURL(LogoSize.Original),
                thumbnailURL = locator.GetSizeURL(ImageDisplayData.logoThumbnailSize),
            };

            return(retVal);
        }
        /// <summary>Creates the ImageDisplayData for a YouTube thumbnail.</summary>
        public static ImageDisplayData CreateForYouTubeThumbnail(int modId, string youTubeId)
        {
            string url = Utility.GenerateYouTubeThumbnailURL(youTubeId);

            ImageDisplayData retVal = new ImageDisplayData()
            {
                ownerId      = modId,
                descriptor   = ImageDescriptor.YouTubeThumbnail,
                imageId      = youTubeId,
                originalURL  = url,
                thumbnailURL = url,
            };

            return(retVal);
        }
Esempio n. 16
0
        public void DisplayGalleryImage(int modId, GalleryImageLocator locator)
        {
            Debug.Assert(locator != null);
            bool original            = m_useOriginal;
            ModGalleryImageSize size = (original ? ModGalleryImageSize.Original : ImageDisplayData.galleryThumbnailSize);

            ImageDisplayData displayData = new ImageDisplayData()
            {
                modId            = modId,
                mediaType        = ImageDisplayData.MediaType.ModGalleryImage,
                fileName         = locator.fileName,
                originalTexture  = null,
                thumbnailTexture = null,
            };

            m_data = displayData;

            DisplayLoading();

            ModManager.GetModGalleryImage(displayData.modId,
                                          locator,
                                          size,
                                          (t) =>
            {
                if (!Application.isPlaying)
                {
                    return;
                }

                if (m_data.Equals(displayData))
                {
                    m_data.SetImageTexture(original, t);
                    PresentData();
                }
            },
                                          WebRequestError.LogAsWarning);
        }
Esempio n. 17
0
        // ---------[ UI FUNCTIONALITY ]---------
        public void DisplayAvatar(int userId, AvatarImageLocator locator)
        {
            Debug.Assert(locator != null);
            bool           original = m_useOriginal;
            UserAvatarSize size     = (original ? UserAvatarSize.Original : ImageDisplayData.avatarThumbnailSize);

            ImageDisplayData displayData = new ImageDisplayData()
            {
                userId           = userId,
                mediaType        = ImageDisplayData.MediaType.UserAvatar,
                fileName         = locator.fileName,
                originalTexture  = null,
                thumbnailTexture = null,
            };

            m_data = displayData;

            DisplayLoading();

            ModManager.GetUserAvatar(displayData.userId,
                                     locator,
                                     size,
                                     (t) =>
            {
                if (!Application.isPlaying)
                {
                    return;
                }

                if (m_data.Equals(displayData))
                {
                    m_data.SetImageTexture(original, t);
                    PresentData();
                }
            },
                                     WebRequestError.LogAsWarning);
        }
Esempio n. 18
0
        /// <summary>Requests the image for a given ImageDisplayData.</summary>
        public virtual void RequestImageForData(ImageDisplayData data, bool original,
                                                Action <Texture2D> onSuccess,
                                                Action <WebRequestError> onError)
        {
            string url = data.GetImageURL(original);

            // asserts
            Debug.Assert(onSuccess != null);
            Debug.Assert(!string.IsNullOrEmpty(url));

            // create delegates
            Func <Texture2D>   loadFromDisk = null;
            Action <Texture2D> saveToDisk   = null;

            switch (data.descriptor)
            {
            case ImageDescriptor.ModLogo:
            {
                LogoSize size = (original ? LogoSize.Original : ImageDisplayData.logoThumbnailSize);

                loadFromDisk = () => CacheClient.LoadModLogo(data.ownerId, data.imageId, size);

                if (this.storeIfSubscribed)
                {
                    saveToDisk = (t) =>
                    {
                        if (LocalUser.SubscribedModIds.Contains(data.ownerId))
                        {
                            CacheClient.SaveModLogo(data.ownerId, data.imageId, size, t);
                        }
                    };
                }
            }
            break;

            case ImageDescriptor.ModGalleryImage:
            {
                ModGalleryImageSize size = (original
                                                ? ModGalleryImageSize.Original
                                                : ImageDisplayData.galleryThumbnailSize);

                loadFromDisk = () => CacheClient.LoadModGalleryImage(data.ownerId, data.imageId, size);

                if (this.storeIfSubscribed)
                {
                    saveToDisk = (t) =>
                    {
                        if (LocalUser.SubscribedModIds.Contains(data.ownerId))
                        {
                            CacheClient.SaveModGalleryImage(data.ownerId, data.imageId, size, t);
                        }
                    };
                }
            }
            break;

            case ImageDescriptor.YouTubeThumbnail:
            {
                loadFromDisk = () => CacheClient.LoadModYouTubeThumbnail(data.ownerId, data.imageId);

                if (this.storeIfSubscribed)
                {
                    saveToDisk = (t) =>
                    {
                        if (LocalUser.SubscribedModIds.Contains(data.ownerId))
                        {
                            CacheClient.SaveModYouTubeThumbnail(data.ownerId, data.imageId, t);
                        }
                    };
                }
            }
            break;

            case ImageDescriptor.UserAvatar:
            {
                UserAvatarSize size = (original
                                           ? UserAvatarSize.Original
                                           : ImageDisplayData.avatarThumbnailSize);

                loadFromDisk = () => CacheClient.LoadUserAvatar(data.ownerId, size);
            }
            break;
            }

            // request image
            this.RequestImage_Internal(url,
                                       loadFromDisk,
                                       saveToDisk,
                                       onSuccess,
                                       onError);
        }
Esempio n. 19
0
        private void MediaPreview_YouTubeThumbnail(ImageDisplay display)
        {
            ImageDisplayData displayData = display.data;

            selectedMediaPreview.data = displayData;
        }
        private void CollectDelegates()
        {
            m_getDelegates          = new List <GetDataDelegate>();
            m_setDelegates          = new List <SetDataDelegate>();
            m_displayDelegates      = new List <DisplayProfileDelegate>();
            m_missingDisplayParsers = new List <ProfileParserDelegate>();
            m_loadingDelegates      = new List <DisplayLoadingDelegate>();

            // - profile -
            if (profileDisplay != null)
            {
                profileDisplay.Initialize();

                m_getDelegates.Add((ref ModDisplayData d) =>
                {
                    d.profile = profileDisplay.data;
                });
                m_setDelegates.Add((d) =>
                {
                    profileDisplay.data = d.profile;
                });

                m_displayDelegates.Add((p) => profileDisplay.DisplayProfile(p));
                m_loadingDelegates.Add(() => profileDisplay.DisplayLoading());
            }
            else
            {
                m_missingDisplayParsers.Add((ModProfile p, ref ModDisplayData d) =>
                {
                    d.profile = ModProfileDisplayData.CreateFromProfile(p);
                });
            }

            // - media -
            if (mediaContainer != null)
            {
                mediaContainer.Initialize();

                m_getDelegates.Add((ref ModDisplayData d) =>
                {
                    d.logo = mediaContainer.logoData;
                    d.youTubeThumbnails = mediaContainer.youTubeData.ToArray();
                    d.galleryImages     = mediaContainer.galleryData.ToArray();
                });
                m_setDelegates.Add((d) =>
                {
                    mediaContainer.logoData    = d.logo;
                    mediaContainer.youTubeData = d.youTubeThumbnails;
                    mediaContainer.galleryData = d.galleryImages;
                });

                m_displayDelegates.Add((p) => mediaContainer.DisplayMedia(p));
                m_loadingDelegates.Add(() => mediaContainer.DisplayLoading());
            }
            else
            {
                m_missingDisplayParsers.Add(ParseProfileMedia);
            }

            // - logo -
            // NOTE(@jackson): Logo Data overrides Media Container Logo Data
            if (logoDisplay != null)
            {
                logoDisplay.Initialize();

                m_getDelegates.Add((ref ModDisplayData d) =>
                {
                    d.logo = logoDisplay.data;
                });
                m_setDelegates.Add((d) =>
                {
                    logoDisplay.data = d.logo;
                });

                m_displayDelegates.Add((p) => logoDisplay.DisplayLogo(p.id, p.logoLocator));
                m_loadingDelegates.Add(() => logoDisplay.DisplayLoading());
            }
            else
            {
                m_missingDisplayParsers.Add((ModProfile p, ref ModDisplayData d) =>
                {
                    ImageDisplayData logoData;
                    if (p.logoLocator != null)
                    {
                        logoData = ImageDisplayData.CreateForModLogo(p.id, p.logoLocator);
                    }
                    else
                    {
                        logoData = new ImageDisplayData();
                    }

                    d.logo = logoData;
                });
            }

            // - submittor -
            if (submittorDisplay.profile != null)
            {
                submittorDisplay.profile.Initialize();

                m_getDelegates.Add((ref ModDisplayData d) =>
                {
                    d.submittorProfile = submittorDisplay.profile.data;
                });
                m_setDelegates.Add((d) =>
                {
                    submittorDisplay.profile.data = d.submittorProfile;
                });

                m_displayDelegates.Add((p) => submittorDisplay.profile.DisplayProfile(p.submittedBy));
                m_loadingDelegates.Add(() => submittorDisplay.profile.DisplayLoading());
            }
            else
            {
                m_missingDisplayParsers.Add((ModProfile p, ref ModDisplayData d) =>
                {
                    d.submittorProfile = UserProfileDisplayData.CreateFromProfile(p.submittedBy);
                });
            }

            if (submittorDisplay.avatar != null)
            {
                submittorDisplay.avatar.Initialize();

                m_getDelegates.Add((ref ModDisplayData d) =>
                {
                    d.submittorAvatar = submittorDisplay.avatar.data;
                });
                m_setDelegates.Add((d) =>
                {
                    submittorDisplay.avatar.data = d.submittorAvatar;
                });

                m_displayDelegates.Add((p) => submittorDisplay.avatar.DisplayAvatar(p.submittedBy.id,
                                                                                    p.submittedBy.avatarLocator));
                m_loadingDelegates.Add(() => submittorDisplay.avatar.DisplayLoading());
            }
            else
            {
                m_missingDisplayParsers.Add((ModProfile p, ref ModDisplayData d) =>
                {
                    ImageDisplayData avatarData;
                    if (p.submittedBy != null &&
                        p.submittedBy.avatarLocator != null)
                    {
                        avatarData = ImageDisplayData.CreateForUserAvatar(p.submittedBy.id,
                                                                          p.submittedBy.avatarLocator);
                    }
                    else
                    {
                        avatarData = new ImageDisplayData();
                    }

                    d.submittorAvatar = avatarData;
                });
            }

            // - build -
            if (buildDisplay != null)
            {
                buildDisplay.Initialize();

                m_getDelegates.Add((ref ModDisplayData d) =>
                {
                    d.currentBuild = buildDisplay.data;
                });
                m_setDelegates.Add((d) =>
                {
                    buildDisplay.data = d.currentBuild;
                });

                m_displayDelegates.Add((p) => buildDisplay.DisplayModfile(p.currentBuild));
                m_loadingDelegates.Add(() => buildDisplay.DisplayLoading());
            }
            else
            {
                m_missingDisplayParsers.Add((ModProfile p, ref ModDisplayData d) =>
                {
                    d.currentBuild = ModfileDisplayData.CreateFromModfile(p.currentBuild);
                });
            }

            // - tags -
            // NOTE(@jackson): tags has no display/missing parse delegate as it requires categories
            if (tagsDisplay != null)
            {
                tagsDisplay.Initialize();

                m_getDelegates.Add((ref ModDisplayData d) =>
                {
                    d.tags = tagsDisplay.data.ToArray();
                });
                m_setDelegates.Add((d) =>
                {
                    tagsDisplay.data = d.tags;
                });

                m_loadingDelegates.Add(() => tagsDisplay.DisplayLoading());
            }

            // - stats -
            if (statisticsDisplay != null)
            {
                statisticsDisplay.Initialize();

                m_getDelegates.Add((ref ModDisplayData d) =>
                {
                    d.statistics = statisticsDisplay.data;
                });
                m_setDelegates.Add((d) =>
                {
                    statisticsDisplay.data = d.statistics;
                });

                m_loadingDelegates.Add(() => statisticsDisplay.DisplayLoading());
            }

            // - download -
            if (downloadDisplay != null)
            {
                downloadDisplay.Initialize();

                // m_getDelegates.Add((ref ModDisplayData d) =>
                // {
                //     d.submittedBy = creatorView.data;
                // });
                // m_setDelegates.Add((d) =>
                // {
                //     creatorView.data = d.submittedBy;
                // });
            }
        }
Esempio n. 21
0
        private void MediaPreview_GalleryImage(ImageDisplay display)
        {
            ImageDisplayData imageData = display.data;

            selectedMediaPreview.data = imageData;
        }