Skip to content

Commit

Permalink
Fix "Random Instant Queue" enabled by default (renamed setting).
Browse files Browse the repository at this point in the history
Fix random instant queue feature (crash when pressing random button).

Version bump.
  • Loading branch information
halsafar committed Sep 6, 2021
1 parent c0c8db3 commit a86a0bc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion SongBrowserPlugin/Configuration/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal class PluginConfig
public virtual string CurrentLevelId { get; set; } = default;
public virtual string CurrentLevelCollectionName { get; set; } = default;
public virtual string CurrentLevelCategoryName { get; set; } = default;
public virtual bool RandomInstantQueue { get; set; } = true;
public virtual bool RandomInstantQueueSong { get; set; } = false;
public virtual bool DeleteNumberedSongFolder { get; set; } = false;
public virtual bool InvertSortResults { get; set; } = false;
public virtual int RandomSongSeed { get; set; } = default;
Expand Down
20 changes: 19 additions & 1 deletion SongBrowserPlugin/UI/Browser/SongBrowserUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ private void OnSortButtonClickEvent(SongSortMode sortMode)
{
PluginConfig.Instance.RandomSongSeed = Guid.NewGuid().GetHashCode();

if (PluginConfig.Instance.RandomInstantQueue)
if (PluginConfig.Instance.RandomInstantQueueSong)
{
StartCoroutine(ForceStartSongEndOfFrame());
}
Expand All @@ -849,6 +849,24 @@ private void OnSortButtonClickEvent(SongSortMode sortMode)
private IEnumerator ForceStartSongEndOfFrame()
{
yield return new WaitForEndOfFrame();

// Level loading is done async.
// The level list might have been shuffled/reset.
// Need to wait for the ActionButton to be active and enabled.
var levelLoaded = false;
var maxIter = 5;
var i = 0;
for (i = 0; i < maxIter && !levelLoaded; i++)
{
yield return new WaitForSeconds(0.5f);

Button actionButton = _beatUi.ActionButtons.GetComponentsInChildren<Button>().FirstOrDefault(x => x.name == "ActionButton");
if (actionButton != null)
{
levelLoaded = actionButton.isActiveAndEnabled;
}
}

_beatUi.LevelSelectionFlowCoordinator.InvokeMethod("ActionButtonWasPressed", new object[0]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class SettingsViewController : IInitializable, IDisposable, INotifyProper
[UIValue("random-instant-queue")]
public bool DefaultAllowDuplicates
{
get => PluginConfig.Instance.RandomInstantQueue;
set => PluginConfig.Instance.RandomInstantQueue = value;
get => PluginConfig.Instance.RandomInstantQueueSong;
set => PluginConfig.Instance.RandomInstantQueueSong = value;
}

public void Initialize() => BSMLSettings.instance.AddSettingsMenu(nameof(SongBrowser), "SongBrowser.UI.Views.Settings.bsml", this);
Expand Down
2 changes: 1 addition & 1 deletion SongBrowserPlugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"gameVersion": "1.17.0",
"id": "SongBrowser",
"name": "Song Browser",
"version": "6.3.0",
"version": "6.3.1",
"dependsOn": {
"SongCore": "^3.7.0",
"SongDataCore": "^1.3.8",
Expand Down

0 comments on commit a86a0bc

Please sign in to comment.