private void SetData(ModDisplayData value)
        {
            if (this.m_setDelegates == null)
            {
                CollectDelegates();
            }

            m_data = value;
            foreach (SetDataDelegate setDelegate in m_setDelegates)
            {
                setDelegate(value);
            }

            if (subscriptionDisplay != null)
            {
                subscriptionDisplay.isOn = value.isSubscribed;
            }

            if (modEnabledDisplay != null)
            {
                modEnabledDisplay.isOn = value.isModEnabled;
            }

            if (userRatingDisplay.positive != null)
            {
                userRatingDisplay.positive.isOn = (value.userRating == ModRatingValue.Positive);
            }
            if (userRatingDisplay.negative != null)
            {
                userRatingDisplay.negative.isOn = (value.userRating == ModRatingValue.Negative);
            }
        }
        // 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();
        }
Example #3
0
 public void OnModRatingAdded(int modId, ModRatingValue rating)
 {
     if (this.m_isInitialized &&
         this.m_modId == modId)
     {
         ModDisplayData data = this.modView.data;
         data.userRating   = rating;
         this.modView.data = data;
     }
 }
Example #4
0
        public void DisplayModEnabled(bool isEnabled)
        {
            this.isModEnabled = isEnabled;

            if (modView != null)
            {
                ModDisplayData data = modView.data;
                data.isModEnabled = isEnabled;
                modView.data      = data;
            }
        }
Example #5
0
 public void DisplayModSubscribed(bool isSubscribed)
 {
     if (this.m_isInitialized)
     {
         ModDisplayData data = modView.data;
         if (data.isSubscribed != isSubscribed)
         {
             data.isSubscribed = isSubscribed;
             modView.data      = data;
         }
     }
 }
Example #6
0
 public void DisplayModSubscribed(bool isSubscribed)
 {
     if (this.isActiveAndEnabled)
     {
         ModDisplayData data = modView.data;
         if (data.isSubscribed != isSubscribed)
         {
             data.isSubscribed = isSubscribed;
             modView.data      = data;
         }
     }
 }
 public void OnModDisabled(int modId)
 {
     foreach (ModView view in this.m_modViews)
     {
         if (view.data.profile.modId == modId)
         {
             ModDisplayData data = view.data;
             data.isModEnabled = false;
             view.data         = data;
         }
     }
 }
 public void OnModRatingAdded(int modId, ModRatingValue rating)
 {
     foreach (ModView view in this.modViews)
     {
         if (view.data.profile.modId == modId)
         {
             ModDisplayData data = view.data;
             data.userRating = rating;
             view.data       = data;
         }
     }
 }
Example #9
0
        public void OnModDisabled(int modId)
        {
            Debug.Assert(this.modView != null);

            if (this.m_isInitialized &&
                this.m_modId == modId)
            {
                ModDisplayData data = this.modView.data;
                data.isModEnabled = false;
                this.modView.data = data;
            }
        }
Example #10
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();
        }
Example #11
0
        public void UpdateSubscriptionsDisplay()
        {
            IList <int> subscribedModIds = ModManager.GetSubscribedModIds();

            foreach (ModView view in m_modViews)
            {
                ModDisplayData modData      = view.data;
                bool           isSubscribed = subscribedModIds.Contains(modData.profile.modId);

                if (modData.isSubscribed != isSubscribed)
                {
                    modData.isSubscribed = isSubscribed;
                    view.data            = modData;
                }
            }
        }
Example #12
0
        private void SetData(ModDisplayData value)
        {
            m_data = value;
            foreach (SetDataDelegate setDelegate in m_setDelegates)
            {
                setDelegate(value);
            }

            if (subscriptionDisplay != null)
            {
                subscriptionDisplay.isOn = m_data.isSubscribed;
            }

            if (modEnabledDisplay != null)
            {
                modEnabledDisplay.isOn = m_data.isModEnabled;
            }
        }
Example #13
0
        public void OnModSubscriptionsUpdated(IList <int> addedSubscriptions,
                                              IList <int> removedSubscriptions)
        {
            Debug.Assert(this.modView != null);

            if (this.m_isInitialized)
            {
                ModDisplayData data          = modView.data;
                bool           wasSubscribed = data.isSubscribed;
                bool           subChanged    = ((!wasSubscribed && addedSubscriptions.Contains(this.m_modId)) ||
                                                (wasSubscribed && removedSubscriptions.Contains(this.m_modId)));

                if (subChanged)
                {
                    data.isSubscribed = !wasSubscribed;
                    modView.data      = data;
                }
            }
        }
        protected virtual void UpdateStatisticsDisplays(IEnumerable <ModStatistics> statsData)
        {
            if (statsData == null)
            {
                return;
            }

            foreach (ModStatistics stats in statsData)
            {
                ModView view = null;
                if (this.m_viewMap.TryGetValue(stats.modId, out view) &&
                    view != null)
                {
                    ModDisplayData data = view.data;
                    data.statistics = ModStatisticsDisplayData.CreateFromStatistics(stats);
                    view.data       = data;
                }
            }
        }
        protected virtual void UpdateStatisticsDisplays(IEnumerable <ModStatistics> statsData)
        {
            if (statsData == null)
            {
                return;
            }

            List <ModStatistics> statsList = new List <ModStatistics>(statsData);

            foreach (ModView view in this.m_modViews)
            {
                if (view != null)
                {
                    ModDisplayData data  = view.data;
                    ModStatistics  stats = null;

                    for (int i = 0;
                         i < statsList.Count && stats == null;
                         ++i)
                    {
                        stats = statsList[i];
                        if (stats.modId == data.profile.modId)
                        {
                            statsList.RemoveAt(i);
                        }
                        else
                        {
                            stats = null;
                        }
                    }

                    if (stats != null)
                    {
                        data.statistics = ModStatisticsDisplayData.CreateFromStatistics(stats);
                        view.data       = data;
                    }
                }
            }
        }
Example #16
0
        // ---------[ UI FUNCTIONALITY ]------------
        public void DisplayProfiles(IEnumerable <ModProfile> profileCollection)
        {
            #if DEBUG
            if (!Application.isPlaying)
            {
                return;
            }
            #endif

            // sort lists
            List <ModProfile> orderedProfileList = new List <ModProfile>();
            List <int>        removedProfiles    = new List <int>(m_viewMap.Keys);

            if (profileCollection != null)
            {
                foreach (ModProfile profile in profileCollection)
                {
                    orderedProfileList.Add(profile);
                    removedProfiles.Remove(profile.id);
                }
            }

            // ensure there are enough game objects
            int excessProfileCount = orderedProfileList.Count - m_viewMap.Count;
            for (int i = 0; i < excessProfileCount; ++i)
            {
                // create GameObject
                GameObject viewGO = GameObject.Instantiate(itemPrefab,
                                                           new Vector3(),
                                                           Quaternion.identity,
                                                           scrollView.content);
                ModView view = viewGO.GetComponent <ModView>();
                view.onClick              += NotifyInspectRequested;
                view.subscribeRequested   += NotifySubscribeRequested;
                view.unsubscribeRequested += NotifyUnsubscribeRequested;
                view.enableModRequested   += NotifyEnableRequested;
                view.disableModRequested  += NotifyDisableRequested;
                view.Initialize();

                // register in map
                int fakeModId = -i - 1;
                m_viewMap.Add(fakeModId, view);
                removedProfiles.Add(fakeModId);
            }

            // order the game objects
            var enabledMods = ModManager.GetEnabledModIds();
            for (int i = 0; i < orderedProfileList.Count; ++i)
            {
                ModProfile profile = orderedProfileList[i];
                ModView    view;
                if (!m_viewMap.TryGetValue(profile.id, out view))
                {
                    // collect unused view
                    int oldModId = removedProfiles[0];
                    removedProfiles.RemoveAt(0);

                    view = m_viewMap[oldModId];

                    m_viewMap.Remove(oldModId);
                    m_viewMap.Add(profile.id, view);

                    // display mod
                    view.DisplayMod(orderedProfileList[i],
                                    null,
                                    tagCategories,
                                    true, // assume subscribed
                                    enabledMods.Contains(profile.id));

                    ModManager.GetModStatistics(profile.id,
                                                (s) =>
                    {
                        ModDisplayData data = view.data;
                        data.statistics     = ModStatisticsDisplayData.CreateFromStatistics(s);
                        view.data           = data;
                    },
                                                null);
                }

                view.transform.SetSiblingIndex(i);
            }

            // remove unused profiles
            foreach (int removedId in removedProfiles)
            {
                GameObject.Destroy(m_viewMap[removedId].gameObject);
                m_viewMap.Remove(removedId);
            }

            // result count
            if (resultCount != null)
            {
                resultCount.text = m_viewMap.Count.ToString();
            }

            // no results
            int subCountTotal = ModManager.GetSubscribedModIds().Count;

            if (noSubscriptionsDisplay != null)
            {
                noSubscriptionsDisplay.SetActive(subCountTotal == 0);
            }

            if (noResultsDisplay != null)
            {
                noResultsDisplay.SetActive(subCountTotal > 0 &&
                                           m_viewMap.Count == 0);
            }

            // fix layouting
            if (this.isActiveAndEnabled)
            {
                LayoutRebuilder.MarkLayoutForRebuild(scrollView.GetComponent <RectTransform>());
            }
        }
        public void DisplayMod(ModProfile profile,
                               ModStatistics statistics,
                               IEnumerable <ModTagCategory> tagCategories,
                               bool isSubscribed,
                               bool isModEnabled,
                               ModRatingValue userRating = ModRatingValue.None)
        {
            Debug.Assert(profile != null);

            if (this.m_displayDelegates == null)
            {
                CollectDelegates();
            }

            m_data = new ModDisplayData();

            foreach (DisplayProfileDelegate displayDelegate in m_displayDelegates)
            {
                displayDelegate(profile);
            }
            foreach (ProfileParserDelegate parserDelegate in m_missingDisplayParsers)
            {
                parserDelegate(profile, ref m_data);
            }

            // - tags -
            if (tagsDisplay != null)
            {
                tagsDisplay.DisplayTags(profile, tagCategories);
            }
            else
            {
                m_data.tags = ModTagDisplayData.GenerateArray(profile.tagNames, tagCategories);
            }

            // - stats -
            ModStatisticsDisplayData statsData;

            if (statistics == null)
            {
                statsData = new ModStatisticsDisplayData()
                {
                    modId = profile.id,
                };
            }
            else
            {
                statsData = ModStatisticsDisplayData.CreateFromStatistics(statistics);
            }

            if (statisticsDisplay != null)
            {
                statisticsDisplay.data = statsData;
            }
            else
            {
                m_data.statistics = statsData;
            }

            // - download -
            FileDownloadInfo downloadInfo = DownloadClient.GetActiveModBinaryDownload(m_data.profile.modId,
                                                                                      m_data.currentBuild.modfileId);

            DisplayDownload(downloadInfo);

            // - subscribed -
            if (subscriptionDisplay != null)
            {
                subscriptionDisplay.isOn = isSubscribed;
            }
            m_data.isSubscribed = isSubscribed;

            // - enabled -
            if (modEnabledDisplay != null)
            {
                modEnabledDisplay.isOn = isModEnabled;
            }
            m_data.isModEnabled = isModEnabled;

            // - rating -
            if (userRatingDisplay.positive != null)
            {
                userRatingDisplay.positive.isOn = (userRating == ModRatingValue.Positive);
            }
            if (userRatingDisplay.negative != null)
            {
                userRatingDisplay.negative.isOn = (userRating == ModRatingValue.Negative);
            }
            m_data.userRating = userRating;


            #if UNITY_EDITOR
            if (Application.isPlaying)
            {
                // updates for inspection convenience
                GetData();
            }
            #endif
        }
Example #18
0
        private void DisplayProfiles(IEnumerable <ModProfile> profileCollection, RectTransform pageTransform)
        {
            #if DEBUG
            if (!Application.isPlaying)
            {
                return;
            }
            #endif

            foreach (Transform t in pageTransform)
            {
                ModView view = t.GetComponentInChildren <ModView>();
                if (view != null)
                {
                    m_modViews.Remove(view);
                }
                GameObject.Destroy(t.gameObject);
            }

            List <ModView> pageModViews = new List <ModView>();
            if (profileCollection != null)
            {
                IList <int> subscribedModIds = ModManager.GetSubscribedModIds();
                IList <int> enabledModIds    = ModManager.GetEnabledModIds();
                Vector2     centerVector     = new Vector2(0.5f, 0.5f);

                foreach (ModProfile profile in profileCollection)
                {
                    if (pageModViews.Count >= itemsPerPage)
                    {
                        // Debug.LogWarning("[mod.io] ProfileCollection contained more profiles than "
                        //                  + "can be displayed per page");
                        break;
                    }

                    GameObject resizeWrapper = new GameObject("Mod Tile", typeof(RectTransform));
                    resizeWrapper.transform.SetParent(pageTransform);
                    resizeWrapper.transform.localScale = Vector3.one;

                    GameObject itemGO = GameObject.Instantiate(itemPrefab,
                                                               new Vector3(),
                                                               Quaternion.identity,
                                                               resizeWrapper.transform);

                    RectTransform itemTransform = itemGO.transform as RectTransform;
                    itemTransform.pivot            = centerVector;
                    itemTransform.anchorMin        = centerVector;
                    itemTransform.anchorMax        = centerVector;
                    itemTransform.anchoredPosition = Vector2.zero;
                    itemTransform.localScale       = this.m_tileScale;

                    // initialize item
                    ModView view = itemGO.GetComponent <ModView>();
                    view.onClick              += NotifyInspectRequested;
                    view.subscribeRequested   += NotifySubscribeRequested;
                    view.unsubscribeRequested += NotifyUnsubscribeRequested;
                    view.enableModRequested   += NotifyEnableRequested;
                    view.disableModRequested  += NotifyDisableRequested;
                    view.Initialize();

                    if (profile == null)
                    {
                        view.DisplayLoading();
                    }
                    else
                    {
                        bool isModSubscribed = subscribedModIds.Contains(profile.id);
                        bool isModEnabled    = enabledModIds.Contains(profile.id);

                        view.DisplayMod(profile,
                                        null,
                                        m_tagCategories,
                                        isModSubscribed,
                                        isModEnabled);

                        ModManager.GetModStatistics(profile.id,
                                                    (s) =>
                        {
                            ModDisplayData data = view.data;
                            data.statistics     = ModStatisticsDisplayData.CreateFromStatistics(s);
                            view.data           = data;
                        },
                                                    null);
                    }

                    pageModViews.Add(view);
                }

                if (pageModViews.Count > 0)
                {
                    for (int i = pageModViews.Count; i < itemsPerPage; ++i)
                    {
                        GameObject spacer = new GameObject("Spacing Tile [" + i.ToString("00") + "]",
                                                           typeof(RectTransform));
                        spacer.transform.SetParent(pageTransform);
                    }
                }
            }
            m_modViews.AddRange(pageModViews);

            // fix layouting
            if (this.isActiveAndEnabled)
            {
                LayoutRebuilder.MarkLayoutForRebuild(pageTransform);
            }
        }