// ---------[ INITIALIZATION ]---------
        private void Start()
        {
            Debug.Assert(itemPrefab != null);
            Debug.Assert(scrollView != null);
            Debug.Assert(scrollView.viewport != null && scrollView.content != null);

            RectTransform prefabTransform = itemPrefab.GetComponent <RectTransform>();
            ModView       prefabView      = itemPrefab.GetComponent <ModView>();

            Debug.Assert(prefabTransform != null &&
                         prefabView != null,
                         "[mod.io] The SubscriptionView.itemPrefab does not have the required "
                         + "ModBrowserItem, ModView, and RectTransform components.\n"
                         + "Please ensure these are all present.");

            // init tag categories
            var tagCategories = ModBrowser.instance.gameProfile.tagCategories;

            if (tagCategories != null)
            {
                this.m_tagCategories = tagCategories;
            }

            // get page
            this.DisplayProfiles(null);
            this.Refresh();
        }
Esempio n. 2
0
 public void NotifyDisableRequested(ModView view)
 {
     if (disableModRequested != null)
     {
         disableModRequested(view);
     }
 }
Esempio n. 3
0
 // ---------[ EVENTS ]---------
 public void NotifyInspectRequested(ModView view)
 {
     if (inspectRequested != null)
     {
         inspectRequested(view);
     }
 }
Esempio n. 4
0
        /// <summary>IModViewElement interface.</summary>
        public void SetModView(ModView view)
        {
            // early out
            if (this.m_view == view)
            {
                return;
            }

            // unhook
            if (this.m_view != null)
            {
                this.m_view.onProfileChanged.RemoveListener(RequestReleaseHistory);
            }

            // assign
            this.m_view = view;

            // hook
            if (this.m_view != null)
            {
                this.m_view.onProfileChanged.AddListener(RequestReleaseHistory);
                this.RequestReleaseHistory(this.m_view.profile);
            }
            else
            {
                this.RequestReleaseHistory(null);
            }
        }
Esempio n. 5
0
        // ---------[ INITIALIZATION ]---------
        /// <summary>IModViewElement interface.</summary>
        public void SetModView(ModView view)
        {
            // early out
            if (this.m_view == view)
            {
                return;
            }

            // unhook
            if (this.m_view != null)
            {
                this.m_view.onProfileChanged.RemoveListener(DisplayModEnabled);
            }

            // assign
            this.m_view = view;

            // hook
            if (this.m_view != null)
            {
                this.m_view.onProfileChanged.AddListener(DisplayModEnabled);
                this.DisplayModEnabled(this.m_view.profile);
            }
            else
            {
                this.DisplayModEnabled(null);
            }
        }
Esempio n. 6
0
 public void NotifySubscribeRequested(ModView view)
 {
     if (subscribeRequested != null)
     {
         subscribeRequested(view);
     }
 }
Esempio n. 7
0
 public void NotifyUnsubscribeRequested(ModView view)
 {
     if (unsubscribeRequested != null)
     {
         unsubscribeRequested(view);
     }
 }
Esempio n. 8
0
 public void NotifyEnableRequested(ModView view)
 {
     if (enableModRequested != null)
     {
         enableModRequested(view);
     }
 }
        /// <summary>IModViewElement interface.</summary>
        public void SetModView(ModView view)
        {
            // early out
            if (this.m_view == view)
            {
                return;
            }

            // unhook
            if (this.m_view != null)
            {
                this.m_view.onStatisticsChanged.RemoveListener(DisplayStatistics);
            }

            // assign
            this.m_view = view;

            // hook
            if (this.m_view != null)
            {
                this.m_view.onStatisticsChanged.AddListener(DisplayStatistics);
                this.DisplayStatistics(this.m_view.statistics);
            }
            else
            {
                this.DisplayStatistics(null);
            }
        }
        private void Start()
        {
            // asserts
            Debug.Assert(itemPrefab != null);

            RectTransform prefabTransform = itemPrefab.GetComponent <RectTransform>();
            ModView       prefabView      = itemPrefab.GetComponent <ModView>();

            Debug.Assert(prefabTransform != null &&
                         prefabView != null,
                         "[mod.io] The ExplorerView.itemPrefab does not have the required "
                         + "ModBrowserItem, ModView, and RectTransform components.\n"
                         + "Please ensure these are all present.");

            if (pageTemplate == null)
            {
                Debug.LogWarning("[mod.io] Page Template variable needs to be set in order for the"
                                 + " Explorer View to function", this.gameObject);
                this.enabled = false;
                return;
            }

            this.gridLayout = pageTemplate.GetComponent <GridLayoutGroup>();
            if (this.gridLayout == null)
            {
                Debug.LogWarning("[mod.io] Page Template needs a grid layout component in order for the"
                                 + " Explorer View to function", this.gameObject);
                this.enabled = false;
                return;
            }

            // - create pages -
            pageTemplate.gameObject.SetActive(false);

            GameObject pageGO;

            pageGO               = (GameObject)GameObject.Instantiate(pageTemplate.gameObject, pageTemplate.parent);
            pageGO.name          = "Mod Page A";
            currentPageContainer = pageGO.GetComponent <RectTransform>();
            currentPageContainer.gameObject.SetActive(true);

            pageGO              = (GameObject)GameObject.Instantiate(pageTemplate.gameObject, pageTemplate.parent);
            pageGO.name         = "Mod Page B";
            targetPageContainer = pageGO.GetComponent <RectTransform>();
            targetPageContainer.gameObject.SetActive(false);

            this.UpdateCurrentPageDisplay();
            this.UpdatePageButtonInteractibility();

            // - perform initial fetch -
            this.Refresh();
        }
Esempio n. 11
0
        // ---------[ INITIALIZATION ]---------
        public void Initialize()
        {
            Debug.Assert(itemPrefab != null);
            Debug.Assert(scrollView != null);
            Debug.Assert(scrollView.viewport != null && scrollView.content != null);

            RectTransform prefabTransform = itemPrefab.GetComponent <RectTransform>();
            ModView       prefabView      = itemPrefab.GetComponent <ModView>();

            Debug.Assert(prefabTransform != null &&
                         prefabView != null,
                         "[mod.io] The SubscriptionView.itemPrefab does not have the required "
                         + "ModBrowserItem, ModView, and RectTransform components.\n"
                         + "Please ensure these are all present.");
        }
Esempio n. 12
0
        /// <summary>Sets the mod profile for the mod being reported.</summary>
        public void SetModProfile(ModProfile profile)
        {
            if (profile == null)
            {
                this.m_modId = ModProfile.NULL_ID;
            }
            else
            {
                this.m_modId = profile.id;
            }

            ModView view = this.GetComponent <ModView>();

            if (view != null)
            {
                view.profile = profile;
            }
        }
        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;
                }
            }
        }
Esempio n. 14
0
        /// <summary>Checks a ModContainer's template structure.</summary>
        public static bool HasValidTemplate(ModContainer container, out string helpMessage)
        {
            helpMessage = null;
            bool isValid = true;

            ModView itemTemplate = null;

            // null check
            if (container.containerTemplate == null)
            {
                helpMessage = ("Invalid template:"
                               + " The container template is unassigned.");
                isValid = false;
            }
            // containerTemplate is child of Component
            else if (!container.containerTemplate.IsChildOf(container.transform) ||
                     container.containerTemplate == container.transform)
            {
                helpMessage = ("Invalid template:"
                               + " The container template must be a child of this object.");
                isValid = false;
            }
            // ModView is found under containerTemplate
            else if ((itemTemplate = container.containerTemplate.gameObject.GetComponentInChildren <ModView>()) == null)
            {
                helpMessage = ("Invalid template:"
                               + " No ModView component found in the children of the container template.");
                isValid = false;
            }
            // ModView is on same gameObject as containerTemplate
            else if (itemTemplate.transform == container.containerTemplate)
            {
                helpMessage = ("Invalid template:"
                               + " The ModView component cannot share a GameObject with the container template.");
                isValid = false;
            }

            return(isValid);
        }
Esempio n. 15
0
        // ---------[ INTIALIZATION ]---------
        /// <summary>IModViewElement interface.</summary>
        public void SetModView(ModView view)
        {
            // early out
            if (this.m_view == view)
            {
                return;
            }

            // unhook
            if (this.m_view != null)
            {
                this.m_view.onProfileChanged.RemoveListener(DisplayProfile);
            }

            // hook
            if (view != null)
            {
                view.onProfileChanged.AddListener(DisplayProfile);
            }

            // finalize
            this.m_view = view;
            this.DisplayProfile(this.m_view.profile);
        }
Esempio n. 16
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);
            }
        }
Esempio n. 17
0
        /// <summary>Initialize template.</summary>
        protected virtual void Start()
        {
            // check template
            #if DEBUG
            string message;
            if (!ModContainer.HasValidTemplate(this, out message))
            {
                Debug.LogError("[mod.io] " + message, this);
                return;
            }
            #endif

            // get template vars
            Transform templateParent         = this.containerTemplate.parent;
            string    templateInstance_name  = this.containerTemplate.gameObject.name + " (Instance)";
            int       templateInstance_index = this.containerTemplate.GetSiblingIndex() + 1;

            // NOTE(@jackson): The canvas group is required to hide the unused
            // ModViews in the case of this.m_fillToLimit
            this.m_itemTemplate = this.containerTemplate.GetComponentInChildren <ModView>(true);
            if (this.m_itemTemplate.gameObject.GetComponent <CanvasGroup>() == null)
            {
                this.m_itemTemplate.gameObject.AddComponent <CanvasGroup>();
            }

            // duplication protection
            bool isInstantiated = (templateParent.childCount > templateInstance_index &&
                                   templateParent.GetChild(templateInstance_index).gameObject.name == templateInstance_name);
            if (isInstantiated)
            {
                this.m_templateClone = templateParent.GetChild(templateInstance_index).gameObject;
                ModView[] viewInstances = this.m_templateClone.GetComponentsInChildren <ModView>(true);

                if (viewInstances == null ||
                    viewInstances.Length == 0)
                {
                    isInstantiated = false;
                    GameObject.Destroy(this.m_templateClone);
                }
                else
                {
                    this.m_container = (RectTransform)viewInstances[0].transform.parent;

                    foreach (ModView view in viewInstances)
                    {
                        GameObject.Destroy(view.gameObject);
                    }
                }
            }

            if (!isInstantiated)
            {
                this.m_templateClone = GameObject.Instantiate(this.containerTemplate.gameObject, templateParent);
                this.m_templateClone.transform.SetSiblingIndex(templateInstance_index);
                this.m_templateClone.name = templateInstance_name;

                ModView viewInstance = this.m_templateClone.GetComponentInChildren <ModView>(true);
                this.m_container = (RectTransform)viewInstance.transform.parent;
                GameObject.Destroy(viewInstance.gameObject);

                this.m_templateClone.SetActive(true);
            }

            this.DisplayMods(this.m_modProfiles, this.m_modStatistics);
        }
        // ---------[ 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)
                {
                    if (profile != null)
                    {
                        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,
                                                           scrollView.content);
                ModView view = viewGO.GetComponent <ModView>();

                // add listeners
                view.onClick               += (v) => ViewManager.instance.InspectMod(v.data.profile.modId);
                view.subscribeRequested    += (v) => ModBrowser.instance.SubscribeToMod(v.data.profile.modId);
                view.unsubscribeRequested  += (v) => ModBrowser.instance.UnsubscribeFromMod(v.data.profile.modId);
                view.enableModRequested    += (v) => ModBrowser.instance.EnableMod(v.data.profile.modId);
                view.disableModRequested   += (v) => ModBrowser.instance.DisableMod(v.data.profile.modId);
                view.ratePositiveRequested += (v) => ModBrowser.instance.AttemptRateMod(v.data.profile.modId, ModRatingValue.Positive);
                view.rateNegativeRequested += (v) => ModBrowser.instance.AttemptRateMod(v.data.profile.modId, ModRatingValue.Negative);

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

            // order the game objects and display new mods
            var        enabledMods      = ModManager.GetEnabledModIds();
            List <int> missingStatsData = new List <int>();
            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
                    ModStatistics stats = ModStatisticsRequestManager.instance.TryGetValid(profile.id);
                    view.DisplayMod(orderedProfileList[i],
                                    stats,
                                    this.m_tagCategories,
                                    true, // assume subscribed
                                    enabledMods.Contains(profile.id),
                                    ModBrowser.instance.GetModRating(profile.id));

                    if (stats == null)
                    {
                        missingStatsData.Add(profile.id);
                    }
                }

                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);
            }

            if (missingStatsData.Count > 0)
            {
                ModStatisticsRequestManager.instance.RequestModStatistics(missingStatsData,
                                                                          (statsArray) =>
                {
                    if (this != null)
                    {
                        UpdateStatisticsDisplays(statsArray);
                    }

                    IList <int> subbedIds = ModManager.GetSubscribedModIds();
                    foreach (ModStatistics stats in statsArray)
                    {
                        if (subbedIds.Contains(stats.modId))
                        {
                            CacheClient.SaveModStatistics(stats);
                        }
                    }
                },
                                                                          // TODO(@jackson): something
                                                                          null);
            }

            // fix layouting
            if (this.isActiveAndEnabled)
            {
                LayoutRebuilder.MarkLayoutForRebuild(scrollView.GetComponent <RectTransform>());
            }
        }
        private void DisplayProfiles(IEnumerable <ModProfile> profileCollection, RectTransform pageTransform)
        {
            #if DEBUG
            if (!Application.isPlaying)
            {
                return;
            }
            #endif

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

            List <int>     missingStatsData = new List <int>();
            List <ModView> pageModViews     = new List <ModView>();
            if (profileCollection != null)
            {
                IList <int> subscribedModIds = ModManager.GetSubscribedModIds();
                IList <int> enabledModIds    = ModManager.GetEnabledModIds();

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

                    GameObject itemGO = GameObject.Instantiate(itemPrefab,
                                                               pageTransform);
                    itemGO.name = "Mod Tile [" + pageModViews.Count.ToString() + "]";

                    // initialize item
                    ModView view = itemGO.GetComponent <ModView>();

                    if (profile == null)
                    {
                        view.DisplayLoading();
                    }
                    else
                    {
                        // add listeners
                        view.onClick               += (v) => ViewManager.instance.InspectMod(v.data.profile.modId);
                        view.subscribeRequested    += (v) => ModBrowser.instance.SubscribeToMod(v.data.profile.modId);
                        view.unsubscribeRequested  += (v) => ModBrowser.instance.UnsubscribeFromMod(v.data.profile.modId);
                        view.enableModRequested    += (v) => ModBrowser.instance.EnableMod(v.data.profile.modId);
                        view.disableModRequested   += (v) => ModBrowser.instance.DisableMod(v.data.profile.modId);
                        view.ratePositiveRequested += (v) => ModBrowser.instance.AttemptRateMod(v.data.profile.modId, ModRatingValue.Positive);
                        view.rateNegativeRequested += (v) => ModBrowser.instance.AttemptRateMod(v.data.profile.modId, ModRatingValue.Negative);

                        // display
                        ModStatistics  stats           = ModStatisticsRequestManager.instance.TryGetValid(profile.id);
                        bool           isModSubscribed = subscribedModIds.Contains(profile.id);
                        bool           isModEnabled    = enabledModIds.Contains(profile.id);
                        ModRatingValue ratingValue     = ModBrowser.instance.GetModRating(profile.id);

                        view.DisplayMod(profile,
                                        stats,
                                        m_tagCategories,
                                        isModSubscribed,
                                        isModEnabled,
                                        ratingValue);

                        if (stats == null)
                        {
                            missingStatsData.Add(profile.id);
                        }
                    }

                    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);

            if (missingStatsData.Count > 0)
            {
                ModStatisticsRequestManager.instance.RequestModStatistics(missingStatsData,
                                                                          (statsArray) =>
                {
                    if (this != null)
                    {
                        UpdateStatisticsDisplays(statsArray);
                    }
                },
                                                                          WebRequestError.LogAsWarning);
            }

            // fix layouting
            if (this.isActiveAndEnabled)
            {
                LayoutRebuilder.MarkLayoutForRebuild(pageTransform);
            }
        }
Esempio n. 20
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. 21
0
        // ---------[ INITIALIZATION ]---------
        public void Initialize()
        {
            Debug.Assert(itemPrefab != null);

            RectTransform prefabTransform = itemPrefab.GetComponent <RectTransform>();
            ModView       prefabView      = itemPrefab.GetComponent <ModView>();

            Debug.Assert(prefabTransform != null &&
                         prefabView != null,
                         "[mod.io] The ExplorerView.itemPrefab does not have the required "
                         + "ModBrowserItem, ModView, and RectTransform components.\n"
                         + "Please ensure these are all present.");

            // - initialize pages -
            foreach (Transform t in contentPane)
            {
                GameObject.Destroy(t.gameObject);
            }

            RecalculateColumnCountAndCellDimensions();

            // create mod pages
            currentPageContainer = new GameObject("Mod Page", typeof(RectTransform)).transform as RectTransform;
            currentPageContainer.SetParent(contentPane);
            currentPageContainer.anchorMin  = Vector2.zero;
            currentPageContainer.offsetMin  = Vector2.zero;
            currentPageContainer.anchorMax  = Vector2.one;
            currentPageContainer.offsetMax  = Vector2.zero;
            currentPageContainer.localScale = Vector2.one;
            currentPageContainer.pivot      = Vector2.zero;
            GridLayoutGroup layouter = currentPageContainer.gameObject.AddComponent <GridLayoutGroup>();

            ApplyGridLayoutValues(layouter);

            targetPageContainer = GameObject.Instantiate(currentPageContainer, contentPane).transform as RectTransform;
            targetPageContainer.gameObject.SetActive(false);


            // - nested views -
            if (tagFilterView != null)
            {
                tagFilterView.Initialize();

                tagFilterView.tagFilterAdded += (tag) =>
                {
                    filterTags.Add(tag);

                    if (tagFilterBar != null)
                    {
                        tagFilterBar.gameObject.SetActive(true);
                        tagFilterBar.DisplayTags(filterTags, m_tagCategories);
                    }

                    if (onFilterTagsChanged != null)
                    {
                        onFilterTagsChanged();
                    }
                };
                tagFilterView.tagFilterRemoved += RemoveTag;
            }

            if (tagFilterBar != null)
            {
                tagFilterBar.Initialize();
                tagFilterBar.gameObject.SetActive(filterTags.Count > 0);

                tagFilterBar.tagClicked += (display) =>
                {
                    RemoveTag(display.data.tagName);
                };
            }
        }