Esempio n. 1
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.");
        }
Esempio n. 2
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>());
            }
        }
Esempio n. 3
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);
            }
        }