Преглед изворни кода

Async wait for song ui before trying to refresh it.
Do not bother updating UI if we don't need to.
Version bump.

Stephen Damm пре 5 година
родитељ
комит
a6a6fc5c02

+ 11 - 4
SongBrowserPlugin/DataAccess/SongBrowserModel.cs

@@ -33,6 +33,8 @@ namespace SongBrowser
         public static Func<IBeatmapLevelPack, List<IPreviewBeatmapLevel>> CustomFilterHandler;
         public static Func<IBeatmapLevelPack, List<IPreviewBeatmapLevel>> CustomFilterHandler;
         public static Action<Dictionary<string, CustomPreviewBeatmapLevel>> didFinishProcessingSongs;
         public static Action<Dictionary<string, CustomPreviewBeatmapLevel>> didFinishProcessingSongs;
 
 
+        public bool SortWasMissingData { get; private set; } = false;
+
         /// <summary>
         /// <summary>
         /// Get the settings the model is using.
         /// Get the settings the model is using.
         /// </summary>
         /// </summary>
@@ -260,6 +262,8 @@ namespace SongBrowser
             Logger.Debug("Starting to sort songs...");
             Logger.Debug("Starting to sort songs...");
             stopwatch = Stopwatch.StartNew();
             stopwatch = Stopwatch.StartNew();
 
 
+            SortWasMissingData = false;
+
             switch (_settings.sortMode)
             switch (_settings.sortMode)
             {
             {
                 case SongSortMode.Original:
                 case SongSortMode.Original:
@@ -324,10 +328,7 @@ namespace SongBrowser
             bool _showPlayerStatsInDetailView = navController.GetPrivateField<bool>("_showPlayerStatsInDetailView");
             bool _showPlayerStatsInDetailView = navController.GetPrivateField<bool>("_showPlayerStatsInDetailView");
             bool _showPracticeButtonInDetailView = navController.GetPrivateField<bool>("_showPracticeButtonInDetailView");
             bool _showPracticeButtonInDetailView = navController.GetPrivateField<bool>("_showPracticeButtonInDetailView");
 
 
-            if (navController.isInViewControllerHierarchy && navController.isActiveAndEnabled)
-            {
-                navController.SetData(levelPack, true, _showPlayerStatsInDetailView, _showPracticeButtonInDetailView, _noDataText.text);
-            }
+            navController.SetData(levelPack, true, _showPlayerStatsInDetailView, _showPracticeButtonInDetailView, _noDataText.text);
 
 
             //_sortedSongs.ForEach(x => Logger.Debug(x.levelID));
             //_sortedSongs.ForEach(x => Logger.Debug(x.levelID));
         }
         }
@@ -473,6 +474,7 @@ namespace SongBrowser
 
 
             if (!SongDataCore.Plugin.ScoreSaber.IsDataAvailable())
             if (!SongDataCore.Plugin.ScoreSaber.IsDataAvailable())
             {
             {
+                SortWasMissingData = true;
                 return levels;
                 return levels;
             }
             }
 
 
@@ -503,6 +505,7 @@ namespace SongBrowser
 
 
             if (!SongDataCore.Plugin.ScoreSaber.IsDataAvailable())
             if (!SongDataCore.Plugin.ScoreSaber.IsDataAvailable())
             {
             {
+                SortWasMissingData = true;
                 return levels;
                 return levels;
             }
             }
 
 
@@ -578,6 +581,7 @@ namespace SongBrowser
             // Do not always have data when trying to sort by UpVotes
             // Do not always have data when trying to sort by UpVotes
             if (!SongDataCore.Plugin.BeatSaver.IsDataAvailable())
             if (!SongDataCore.Plugin.BeatSaver.IsDataAvailable())
             {
             {
+                SortWasMissingData = true;
                 return levelIds;
                 return levelIds;
             }
             }
 
 
@@ -608,6 +612,7 @@ namespace SongBrowser
             // Do not always have data when trying to sort by UpVotes
             // Do not always have data when trying to sort by UpVotes
             if (!SongDataCore.Plugin.BeatSaver.IsDataAvailable())
             if (!SongDataCore.Plugin.BeatSaver.IsDataAvailable())
             {
             {
+                SortWasMissingData = true;
                 return levelIds;
                 return levelIds;
             }
             }
 
 
@@ -638,6 +643,7 @@ namespace SongBrowser
             // Do not always have data when trying to sort by rating
             // Do not always have data when trying to sort by rating
             if (!SongDataCore.Plugin.BeatSaver.IsDataAvailable())
             if (!SongDataCore.Plugin.BeatSaver.IsDataAvailable())
             {
             {
+                SortWasMissingData = true;
                 return levelIds;
                 return levelIds;
             }
             }
 
 
@@ -668,6 +674,7 @@ namespace SongBrowser
             // Do not always have data when trying to sort by heat
             // Do not always have data when trying to sort by heat
             if (!SongDataCore.Plugin.BeatSaver.IsDataAvailable())
             if (!SongDataCore.Plugin.BeatSaver.IsDataAvailable())
             {
             {
+                SortWasMissingData = true;
                 return levelIds;
                 return levelIds;
             }
             }
 
 

+ 1 - 1
SongBrowserPlugin/Plugin.cs

@@ -9,7 +9,7 @@ namespace SongBrowser
 {
 {
     public class Plugin : IBeatSaberPlugin
     public class Plugin : IBeatSaberPlugin
     {
     {
-        public const string VERSION_NUMBER = "6.0.2";
+        public const string VERSION_NUMBER = "6.0.3";
         public static Plugin Instance;
         public static Plugin Instance;
         public static IPA.Logging.Logger Log;
         public static IPA.Logging.Logger Log;
 
 

+ 2 - 2
SongBrowserPlugin/Properties/AssemblyInfo.cs

@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
 // You can specify all the values or you can default the Build and Revision Numbers 
 // You can specify all the values or you can default the Build and Revision Numbers 
 // by using the '*' as shown below:
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("6.0.2")]
-[assembly: AssemblyFileVersion("6.0.2")]
+[assembly: AssemblyVersion("6.0.3")]
+[assembly: AssemblyFileVersion("6.0.3")]

+ 3 - 19
SongBrowserPlugin/SongBrowserApplication.cs

@@ -125,15 +125,7 @@ namespace SongBrowser
             Logger.Trace("OnScoreSaberDataDownloaded");
             Logger.Trace("OnScoreSaberDataDownloaded");
             try
             try
             {
             {
-                if (_songBrowserModel.Settings.sortMode.NeedsScoreSaberData())
-                {
-                    _songBrowserUI.ProcessSongList();
-                    _songBrowserUI.RefreshSongUI();
-                }
-                else
-                {
-                    _songBrowserUI.RefreshSortButtonUI();
-                }
+                StartCoroutine(_songBrowserUI.AsyncWaitForSongUIUpdate());
             }
             }
             catch (Exception e)
             catch (Exception e)
             {
             {
@@ -149,19 +141,11 @@ namespace SongBrowser
             Logger.Trace("OnBeatSaverDataDownloaded");
             Logger.Trace("OnBeatSaverDataDownloaded");
             try
             try
             {
             {
-                if (_songBrowserModel.Settings.sortMode.NeedsBeatSaverData())
-                {
-                    _songBrowserUI.ProcessSongList();
-                    _songBrowserUI.RefreshSongUI();
-                }
-                else
-                {
-                    _songBrowserUI.RefreshSortButtonUI();
-                }
+                StartCoroutine(_songBrowserUI.AsyncWaitForSongUIUpdate());
             }
             }
             catch (Exception e)
             catch (Exception e)
             {
             {
-                Logger.Exception("Exception during OnDownloaderScrappedDataDownloaded: ", e);
+                Logger.Exception("Exception during OnBeatSaverDataDownloaded: ", e);
             }
             }
         }
         }
 
 

+ 81 - 2
SongBrowserPlugin/UI/Browser/SongBrowserUI.cs

@@ -62,7 +62,6 @@ namespace SongBrowser.UI
 
 
         private IBeatmapLevelPack _lastLevelPack;
         private IBeatmapLevelPack _lastLevelPack;
 
 
-        // Model
         private SongBrowserModel _model;
         private SongBrowserModel _model;
         public SongBrowserModel Model
         public SongBrowserModel Model
         {
         {
@@ -77,10 +76,12 @@ namespace SongBrowser.UI
             }
             }
         }
         }
 
 
-        // UI Created
         private bool _uiCreated = false;
         private bool _uiCreated = false;
+        
         private UIState _currentUiState = UIState.Disabled;
         private UIState _currentUiState = UIState.Disabled;
 
 
+        private bool _asyncUpdating = false;
+
         /// <summary>
         /// <summary>
         /// Builds the UI for this plugin.
         /// Builds the UI for this plugin.
         /// </summary>
         /// </summary>
@@ -501,6 +502,84 @@ namespace SongBrowser.UI
             {
             {
                 StartCoroutine(RefreshQuickScrollButtonsAsync());
                 StartCoroutine(RefreshQuickScrollButtonsAsync());
             });
             });
+
+            // finished level	
+            //ResultsViewController resultsViewController = _beatUi.LevelSelectionFlowCoordinator.GetPrivateField<ResultsViewController>("_resultsViewController");
+            //resultsViewController.continueButtonPressedEvent += ResultsViewController_continueButtonPressedEvent;
+        }
+
+        /*/// <summary>	
+        /// Handle updating the level pack selection after returning from a song.	
+        /// </summary>SongBrowserPlugin/UI/Browser/SongBrowserUI.cs 	
+        /// <param name="obj"></param>	
+        private void ResultsViewController_continueButtonPressedEvent(ResultsViewController obj)
+        {
+            StartCoroutine(this.UpdateLevelPackSelectionEndOfFrame());
+        }
+
+        /// <summary>	
+        /// TODO - evaluate this sillyness...	
+        /// </summary>	
+        /// <returns></returns>	
+        public IEnumerator UpdateLevelPackSelectionEndOfFrame()
+        {
+            yield return new WaitForEndOfFrame();
+
+            try
+            {
+                UpdateLevelPackSelection();
+                _beatUi.SelectAndScrollToLevel(_model.LastSelectedLevelId);
+                RefreshQuickScrollButtons();
+            }
+            catch (Exception e)
+            {
+                Logger.Exception("Exception:", e);
+            }
+        }*/
+
+        /// <summary>
+        /// Waits for the song UI to be available before trying to update.
+        /// </summary>
+        /// <returns></returns>
+        public IEnumerator AsyncWaitForSongUIUpdate()
+        {
+            if (_asyncUpdating)
+            {
+                yield break;
+            }
+
+            if (!_uiCreated)
+            {
+                yield break;
+            }
+
+            if (!_model.SortWasMissingData)
+            {
+                yield break;
+            }
+
+            _asyncUpdating = true;
+
+            while (_beatUi.LevelSelectionNavigationController.GetPrivateField<bool>("_isInTransition") ||
+                   _beatUi.LevelDetailViewController.GetPrivateField<bool>("_isInTransition") ||
+                   !_beatUi.LevelSelectionNavigationController.isInViewControllerHierarchy ||
+                   !_beatUi.LevelDetailViewController.isInViewControllerHierarchy ||
+                   !_beatUi.LevelSelectionNavigationController.isActiveAndEnabled ||
+                   !_beatUi.LevelDetailViewController.isActiveAndEnabled)
+            {
+                yield return null;
+            }
+
+            //yield return new WaitForEndOfFrame();
+
+            if (_model.Settings.sortMode.NeedsBeatSaverData() && SongDataCore.Plugin.BeatSaver.IsDataAvailable() ||
+                _model.Settings.sortMode.NeedsScoreSaberData() && SongDataCore.Plugin.ScoreSaber.IsDataAvailable())
+            {
+                ProcessSongList();
+                RefreshSongUI();
+            }
+
+            _asyncUpdating = false;
         }
         }
 
 
         /// <summary>
         /// <summary>

+ 1 - 1
SongBrowserPlugin/manifest.json

@@ -5,7 +5,7 @@
   "gameVersion": "1.6.0",
   "gameVersion": "1.6.0",
   "id": "SongBrowser",
   "id": "SongBrowser",
   "name": "Song Browser",
   "name": "Song Browser",
-  "version": "6.0.2",
+  "version": "6.0.3",
   "dependsOn": {
   "dependsOn": {
     "SongCore": "^2.7.2",
     "SongCore": "^2.7.2",
     "SongDataCore": "^1.1.5"
     "SongDataCore": "^1.1.5"