Beispiel #1
0
        // ---------[ FUNCTIONALITY ]---------
        /// <summary>Requests the image for a given locator.</summary>
        public virtual void RequestModLogo(int modId, LogoImageLocator locator,
                                           LogoSize size,
                                           Action <Texture2D> onLogoReceived,
                                           Action <Texture2D> onFallbackFound,
                                           Action <WebRequestError> onError)
        {
            Debug.Assert(locator != null);
            Debug.Assert(onLogoReceived != null);

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

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

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

            // do the work
            this.RequestImage_Internal(locator, size, loadFromDisk, saveToDisk,
                                       onLogoReceived, onFallbackFound, onError);
        }
Beispiel #2
0
        /// <summary>Displays a Mod Logo using the locator.</summary>
        public virtual void DisplayLogo(int modId, LogoImageLocator 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);

                    ImageRequestManager.instance.RequestModLogo(modId, locator, this.logoSize,
                                                                displayDelegate,
                                                                displayDelegate, // fallback
                                                                WebRequestError.LogAsWarning);
                }
            }
        }
Beispiel #3
0
        public void DisplayLogo(int modId, LogoImageLocator locator)
        {
            Debug.Assert(locator != null);

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

            m_data = displayData;

            PresentData();
        }
        /// <summary>Copies the data of another component to display.</summary>
        public void DisplayLogo(ModLogoDisplay display)
        {
            int modId = ModProfile.NULL_ID;
            LogoImageLocator locator = null;

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

            this.DisplayLogo(modId, locator);
        }
Beispiel #5
0
        // ---------[ UI FUNCTIONALITY ]---------
        /// <summary>Displays the logo of a profile.</summary>
        public virtual void DisplayProfile(ModProfile profile)
        {
            int modId = ModProfile.NULL_ID;
            LogoImageLocator locator = null;

            if (profile != null)
            {
                modId   = profile.id;
                locator = profile.logoLocator;
            }

            this.DisplayLogo(modId, locator);
        }
        // ---------[ 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);
        }
Beispiel #7
0
        /// <summary>Internal function for applying the texture.</summary>
        protected virtual void ApplyTexture(LogoImageLocator locator, Texture2D texture)
        {
            if (this != null &&
                this.m_locator == locator &&
                texture != null)
            {
                this.image.sprite  = UIUtilities.CreateSpriteFromTexture(texture);
                this.image.enabled = true;

                if (this.onTextureChanged != null)
                {
                    this.onTextureChanged.Invoke(texture);
                }
            }
        }
        public override void DisplayMedia(int modId,
                                          LogoImageLocator logoLocator,
                                          IEnumerable <GalleryImageLocator> galleryImageLocators,
                                          IEnumerable <string> youTubeURLs)
        {
            ClearDisplays();

            if (logoLocator != null &&
                logoPrefab != null)
            {
                var display = InstantiatePrefab(logoPrefab);
                display.DisplayLogo(modId, logoLocator);
                display.onClick += NotifyLogoClicked;

                this.m_logoDisplay = display;
            }

            if (youTubeURLs != null &&
                youTubeThumbnailPrefab != null)
            {
                foreach (string url in youTubeURLs)
                {
                    var display = InstantiatePrefab(youTubeThumbnailPrefab);
                    display.DisplayYouTubeThumbnail(modId, Utility.ExtractYouTubeIdFromURL(url));
                    display.onClick += NotifyYouTubeThumbnailClicked;

                    m_youTubeDisplays.Add(display);
                }
            }

            if (galleryImageLocators != null &&
                galleryImagePrefab != null)
            {
                foreach (GalleryImageLocator locator in galleryImageLocators)
                {
                    var display = InstantiatePrefab(galleryImagePrefab);
                    display.DisplayGalleryImage(modId, locator);
                    display.onClick += NotifyGalleryImageClicked;

                    m_galleryDisplays.Add(display);
                }
            }

            if (Application.isPlaying)
            {
                LateLayoutUpdate();
            }
        }
        /// <summary>Display a logo via the linked logo display.</summary>
        public void DisplayLogo(int modId, LogoImageLocator locator)
        {
            // disable other components
            if (this.galleryImage != null)
            {
                this.galleryImage.gameObject.SetActive(false);
            }
            if (this.youTubeThumbnail != null)
            {
                this.youTubeThumbnail.gameObject.SetActive(false);
            }

            // display logo
            if (this.logo != null)
            {
                this.logo.gameObject.SetActive(locator != null);

                if (locator != null)
                {
                    this.logo.DisplayLogo(modId, locator);
                }
            }
        }
Beispiel #10
0
        public void DisplayLogo(int modId, LogoImageLocator locator)
        {
            Debug.Assert(locator != null);
            bool     original = m_useOriginal;
            LogoSize size     = (original ? LogoSize.Original : ImageDisplayData.logoThumbnailSize);

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

            m_data = displayData;

            DisplayLoading();

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

                if (m_data.Equals(displayData))
                {
                    m_data.SetImageTexture(original, t);
                    PresentData();
                }
            },
                                  WebRequestError.LogAsWarning);
        }
Beispiel #11
0
 public abstract void DisplayMedia(int modId,
                                   LogoImageLocator logoLocator,
                                   IEnumerable <GalleryImageLocator> galleryImageLocators,
                                   IEnumerable <string> youTubeURLs);
Beispiel #12
0
        // ---------[ FUNCTIONALITY ]---------
        /// <summary>Requests the image for a given locator.</summary>
        public virtual void RequestModLogo(int modId, LogoImageLocator locator,
                                           LogoSize size,
                                           Action <Texture2D> onLogoReceived,
                                           Action <Texture2D> onFallbackFound,
                                           Action <WebRequestError> onError)
        {
            Debug.Assert(locator != null);
            Debug.Assert(onLogoReceived != null);

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

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

            // - Start new request -
            Callbacks callbacks = this.CreateCallbacksEntry(url, onLogoReceived, 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.SaveModLogo(modId, fileName, size, texture, null);
                    }
                };
            }

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

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