// ---------[ UI FUNCTIONALITY ]--------- public override void DisplayStatistics(ModStatistics statistics) { Debug.Assert(statistics != null); ModStatisticsDisplayData statsData = ModStatisticsDisplayData.CreateFromStatistics(statistics); m_data = statsData; PresentData(); }
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; } } } }
// ---------[ 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 }
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); } }