Пример #1
0
        public static ModTagDisplayData[] GenerateArray(IEnumerable <string> tagNames,
                                                        IEnumerable <ModTagCategory> categories)
        {
            UnityEngine.Debug.Assert(tagNames != null);

            // init
            List <string> unmatchedTags = new List <string>(tagNames);

            if (unmatchedTags.Count == 0)
            {
                return(new ModTagDisplayData[0]);
            }

            if (categories == null)
            {
                categories = new List <ModTagCategory>(0);
            }

            // match
            List <ModTagDisplayData> tags = new List <ModTagDisplayData>(unmatchedTags.Count);

            foreach (ModTagCategory category in categories)
            {
                foreach (string categoryTag in category.tags)
                {
                    if (unmatchedTags.Contains(categoryTag))
                    {
                        ModTagDisplayData newTag = new ModTagDisplayData()
                        {
                            tagName      = categoryTag,
                            categoryName = category.name,
                        };
                        tags.Add(newTag);

                        while (unmatchedTags.Remove(categoryTag))
                        {
                        }

                        if (unmatchedTags.Count == 0)
                        {
                            return(tags.ToArray());
                        }
                    }
                }
            }

            foreach (string tag in unmatchedTags)
            {
                ModTagDisplayData newTag = new ModTagDisplayData()
                {
                    tagName      = tag,
                    categoryName = null,
                };
                tags.Add(newTag);
            }

            return(tags.ToArray());
        }
        public override void DisplayTags(IEnumerable <string> tags, IEnumerable <ModTagCategory> tagCategories)
        {
            if (tags == null)
            {
                tags = new string[0];
            }

            m_data = ModTagDisplayData.GenerateArray(tags, tagCategories);
            PresentData(m_data);
        }
        public override void DisplayModTag(string tagName, string categoryName)
        {
            ModTagDisplayData newData = new ModTagDisplayData()
            {
                tagName      = tagName,
                categoryName = (categoryName == null
                                ? string.Empty
                                : categoryName),
            };

            m_data = newData;

            PresentData();
        }
Пример #4
0
        private void PresentData_Editor(IEnumerable <ModTagDisplayData> displayData)
        {
            Debug.Assert(!Application.isPlaying);

            if (loadingOverlay != null)
            {
                loadingOverlay.SetActive(false);
            }

            // clear
            if (m_tagDisplays != null)
            {
                foreach (ModTagDisplayComponent display in m_tagDisplays)
                {
                    GameObject displayGO = display.gameObject;
                    UnityEditor.EditorApplication.delayCall += () =>
                    {
                        DestroyImmediate(displayGO);
                    };
                }
                m_tagDisplays.Clear();
            }

            if (tagDisplayPrefab == null || container == null)
            {
                return;
            }

            // create
            foreach (ModTagDisplayData tagData in displayData)
            {
                ModTagDisplayData tdata = tagData;

                UnityEditor.EditorApplication.delayCall += () =>
                {
                    GameObject displayGO = GameObject.Instantiate(tagDisplayPrefab,
                                                                  new Vector3(),
                                                                  Quaternion.identity,
                                                                  container);
                    displayGO.hideFlags = HideFlags.HideAndDontSave | HideFlags.HideInInspector;

                    ModTagDisplayComponent display = displayGO.GetComponent <ModTagDisplayComponent>();
                    display.data = tdata;

                    m_tagDisplays.Add(display);
                };
            }

            // TODO: fix layouting?
        }
        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
        }