Skip to content

Commit

Permalink
Use the existing ProgressBar instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Meivyn committed Jun 12, 2024
1 parent 2cc1fdf commit 37dbd1e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
27 changes: 9 additions & 18 deletions PlaylistManager/UI/RefreshButtonUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
using SongCore;
using SongCore.UI;
using System;
using System.Threading.Tasks;
using Zenject;

namespace PlaylistManager.UI
{
public class RefreshButtonUI : IInitializable, IDisposable
{
private readonly ProgressBar _progressBar;

private MenuButton refreshButton;
private ProgressBar progressBar;
private const int kMessageTime = 5;

private RefreshButtonUI(ProgressBar progressBar)
{
_progressBar = progressBar;
}

public void Initialize()
{
Expand All @@ -21,28 +25,15 @@ public void Initialize()
Loader.SongsLoadedEvent += SongsLoaded;
}

private async void SongsLoaded(Loader _, System.Collections.Concurrent.ConcurrentDictionary<string, BeatmapLevel> songs)
private void SongsLoaded(Loader _, System.Collections.Concurrent.ConcurrentDictionary<string, BeatmapLevel> songs)
{
if (progressBar == null)
{
progressBar = ProgressBar.Create();
}

PlaylistLibUtils.playlistManager.RefreshPlaylists(true);
var numPlaylists = PlaylistLibUtils.playlistManager.GetPlaylistCount(true);

// This event handler is loading sprites and accessing Unity objects so it must be done on the main thread.
// Although SongsLoadedEvent is already invoked on the main thread, the default event handler in ProgressBar
// will overwrite our message. We're essentially skipping a frame to let the default event handler run first.
await Task.Yield();

progressBar.enabled = true;
progressBar.ShowMessage($"\n{numPlaylists} playlists loaded.", kMessageTime, false);
_progressBar.AppendText($"\n{numPlaylists} playlists loaded");
}

public void Dispose()
{
UnityEngine.Object.Destroy(progressBar);
MenuButtons.instance.UnregisterButton(refreshButton);
Loader.SongsLoadedEvent -= SongsLoaded;
}
Expand Down
4 changes: 2 additions & 2 deletions PlaylistManager/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"icon": "PlaylistManager.Icons.Logo.png",
"dependsOn": {
"BSIPA": "^4.3.0",
"SongCore": "^3.9.5",
"SongCore": "^3.14.5",
"BeatSaberMarkupLanguage": "^1.7.5",
"SiraUtil": "^3.0.0",
"BeatSaberPlaylistsLib": "^1.6.8",
"BeatSaberPlaylistsLib": "^1.7.0",
"BeatSaverSharp": "^3.4.5",
"System.IO.Compression": "^4.6.57",
"System.IO.Compression.FileSystem": "^4.7.3056"
Expand Down

0 comments on commit 37dbd1e

Please sign in to comment.