// ---------[ UI FUNCTIONALITY ]---------
        /// <summary>Displays a Mod Gallery Image.</summary>
        public virtual void DisplayGalleryImage(int modId, GalleryImageLocator locator)
        {
            this.m_modId = modId;

            if (this.m_locator != locator)
            {
                this.m_locator = locator;

                this.image.sprite  = null;
                this.image.enabled = false;

                if (this.onTextureChanged != null)
                {
                    this.onTextureChanged.Invoke(null);
                }

                if (locator != null)
                {
                    System.Action <Texture2D> displayDelegate  = (t) => ApplyTexture(locator, t);
                    System.Action <Texture2D> fallbackDelegate = null;
                    if (imageSize == ModGalleryImageSize.Original)
                    {
                        fallbackDelegate = displayDelegate;
                    }

                    ImageRequestManager.instance.RequestModGalleryImage(modId, locator, this.imageSize,
                                                                        displayDelegate,
                                                                        fallbackDelegate,
                                                                        WebRequestError.LogAsWarning);
                }
            }
        }
Example #2
0
        /// <summary>Requests the image for a given locator.</summary>
        public virtual void RequestModGalleryImage(int modId, GalleryImageLocator locator,
                                                   ModGalleryImageSize size,
                                                   Action <Texture2D> onImageReceived,
                                                   Action <Texture2D> onFallbackFound,
                                                   Action <WebRequestError> onError)
        {
            Debug.Assert(locator != null);
            Debug.Assert(onImageReceived != null);

            // set loading function
            Func <Texture2D> loadFromDisk = () => CacheClient.LoadModGalleryImage(modId, locator.GetFileName(), size);

            // set saving function
            Action <Texture2D> saveToDisk = null;

            if (this.storeIfSubscribed)
            {
                saveToDisk = (t) =>
                {
                    if (LocalUser.SubscribedModIds.Contains(modId))
                    {
                        CacheClient.SaveModGalleryImage(modId, locator.GetFileName(), size, t);
                    }
                };
            }

            // do the work
            this.RequestImage_Internal(locator, size, loadFromDisk, saveToDisk,
                                       onImageReceived, onFallbackFound, onError);
        }
Example #3
0
        public void DisplayGalleryImage(int modId, GalleryImageLocator locator)
        {
            Debug.Assert(locator != null);

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

            m_data = displayData;

            PresentData();
        }
Example #4
0
        private Texture2D GetGalleryImageByIndex(int index)
        {
            string imageFileName             = GetGalleryImageFileName(index);
            GalleryImageLocator imageLocator = null;

            if (this.profile != null &&
                this.profile.media != null)
            {
                imageLocator = this.profile.media.GetGalleryImageWithFileName(imageFileName);
            }

            Texture2D texture;

            if (String.IsNullOrEmpty(imageFileName))
            {
                return(null);
            }
            // - Get -
            else if (this.textureCache.TryGetValue(imageFileName, out texture))
            {
                return(texture);
            }
            // - LoadOrDownload -
            else if (imageLocator != null)
            {
                this.textureCache.Add(imageFileName, EditorImages.LoadingPlaceholder);

                ModManager.GetModGalleryImage(this.profile.id,
                                              imageLocator,
                                              IMAGE_PREVIEW_SIZE,
                                              (t) => { this.textureCache[imageFileName] = t; isRepaintRequired = true; },
                                              null);

                return(this.textureCache[imageFileName]);
            }
            // - Load -
            else
            {
                string imageSource = GetGalleryImageSource(index);

                byte[]    data      = null;
                Texture2D imageData = null;

                data = File.ReadAllBytes(imageSource);

                if (data != null)
                {
                    imageData = IOUtilities.ParseImageData(data);
                }

                this.textureCache.Add(imageFileName, imageData);
                return(this.textureCache[imageFileName]);
            }
        }
        /// <summary>Copies the data of another component to display.</summary>
        public void DisplayGalleryImage(GalleryImageDisplay display)
        {
            int modId = ModProfile.NULL_ID;
            GalleryImageLocator locator = null;

            if (display != null)
            {
                modId   = display.ModId;
                locator = display.Locator;
            }

            this.DisplayGalleryImage(modId, locator);
        }
        /// <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);
        }
Example #7
0
        // ------[ INITIALIZATION ]------
        public void OnEnable(SerializedProperty serializedEditableModProfile, ModProfile baseProfile, UserProfile user)
        {
            this.profile           = baseProfile;
            this.youTubeURLsProp   = serializedEditableModProfile.FindPropertyRelative("youTubeURLs");
            this.sketchfabURLsProp = serializedEditableModProfile.FindPropertyRelative("sketchfabURLs");
            this.galleryImagesProp = serializedEditableModProfile.FindPropertyRelative("galleryImageLocators");

            this.isYouTubeExpanded   = false;
            this.isSketchFabExpanded = false;
            this.isImagesExpanded    = false;

            // Initialize textureCache
            int arraySize = galleryImagesProp.FindPropertyRelative("value").arraySize;

            this.textureCache = new Dictionary <string, Texture2D>(arraySize);
            for (int i = 0;
                 i < arraySize;
                 ++i)
            {
                string imageFileName = GetGalleryImageFileName(i);
                string imageURL      = GetGalleryImageSource(i);

                if (!String.IsNullOrEmpty(imageFileName) &&
                    !String.IsNullOrEmpty(imageURL))
                {
                    GalleryImageLocator imageLocator = baseProfile.media.GetGalleryImageWithFileName(imageFileName);
                    this.textureCache[imageFileName] = EditorImages.LoadingPlaceholder;

                    if (imageLocator != null)
                    {
                        ModManager.GetModGalleryImage(baseProfile.id,
                                                      imageLocator,
                                                      IMAGE_PREVIEW_SIZE,
                                                      (t) => { this.textureCache[imageFileName] = t; isRepaintRequired = true; },
                                                      null);
                    }
                    else
                    {
                        byte[] data    = null;
                        bool   success = false;

                        success = LocalDataStorage.ReadFile(imageURL, out data);

                        if (success)
                        {
                            this.textureCache[imageFileName] = IOUtilities.ParseImageData(data);
                        }
                    }
                }
            }
        }
        /// <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);
                }
            }
        }
        /// <summary>Display a gallery image via the linked image display.</summary>
        public void DisplayGalleryImage(int modId, GalleryImageLocator locator)
        {
            // disable other components
            if (this.logo != null)
            {
                this.logo.gameObject.SetActive(false);
            }
            if (this.youTubeThumbnail != null)
            {
                this.youTubeThumbnail.gameObject.SetActive(false);
            }

            // display gallery image
            if (this.galleryImage != null)
            {
                this.galleryImage.gameObject.SetActive(locator != null);

                if (locator != null)
                {
                    this.galleryImage.DisplayGalleryImage(modId, locator);
                }
            }
        }
Example #10
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);
        }
Example #11
0
        /// <summary>Requests the image for a given locator.</summary>
        public virtual void RequestModGalleryImage(int modId, GalleryImageLocator locator,
                                                   ModGalleryImageSize size,
                                                   Action <Texture2D> onImageReceived,
                                                   Action <Texture2D> onFallbackFound,
                                                   Action <WebRequestError> onError)
        {
            Debug.Assert(locator != null);
            Debug.Assert(onImageReceived != null);

            string url      = locator.GetSizeURL(size);
            string fileName = locator.GetFileName();

            // check cache and existing callbacks
            if (this.TryGetCacheOrSetCallbacks(url, onImageReceived, onFallbackFound, onError))
            {
                return;
            }

            // - Start new request -
            Callbacks callbacks = this.CreateCallbacksEntry(url, onImageReceived, onError);

            // check for fallback
            callbacks.fallback = this.FindFallbackTexture(locator);

            if (onFallbackFound != null &&
                callbacks.fallback != null)
            {
                onFallbackFound.Invoke(callbacks.fallback);
            }

            // add save function to download callback
            if (this.storeIfSubscribed)
            {
                callbacks.onTextureDownloaded = (texture) =>
                {
                    if (LocalUser.SubscribedModIds.Contains(modId))
                    {
                        CacheClient.SaveModGalleryImage(modId, fileName, size, texture, null);
                    }
                };
            }

            // start process by checking the cache
            CacheClient.LoadModGalleryImage(modId, fileName, size, (texture) =>
            {
                if (this == null)
                {
                    return;
                }

                if (texture != null)
                {
                    this.OnRequestSucceeded(url, texture);
                }
                else
                {
                    // do the download
                    this.DownloadImage(url);
                }
            });
        }