Skip to content
This repository has been archived by the owner on Nov 9, 2021. It is now read-only.

Commit

Permalink
Fixed sorting and voting on the new update
Browse files Browse the repository at this point in the history
  • Loading branch information
andruzzzhka committed Jul 20, 2018
1 parent ac1de2e commit d8ed2dc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
13 changes: 12 additions & 1 deletion BeatSaverDownloader/PluginUI/PluginUI.cs
Expand Up @@ -89,7 +89,14 @@ public void Start()
StartCoroutine(WaitForSongListUI());
}

SongLoader.SongsLoadedEvent += SongLoader_SongsLoadedEvent;
if (SongLoader.AreSongsLoaded)
{
SongLoader_SongsLoadedEvent(null, SongLoader.CustomLevels);
}
else
{
SongLoader.SongsLoadedEvent += SongLoader_SongsLoadedEvent;
}


try
Expand Down Expand Up @@ -147,6 +154,10 @@ private IEnumerator WaitForSongListUI()
private void _votingUI_continuePressed(string selectedLevelId)
{
UpdateDetailsUI(null, selectedLevelId);
if (SongListUITweaks.lastSortMode != SortMode.All)
{
_tweaks.ShowLevels(SongListUITweaks.lastSortMode);
}
}

private void UpdateDetailsUI(StandardLevelListViewController sender, string selectedLevel)
Expand Down
28 changes: 21 additions & 7 deletions BeatSaverDownloader/PluginUI/SongListUITweaks.cs
Expand Up @@ -138,10 +138,6 @@ public void SongListUIFound()
});
}

if (lastSortMode != SortMode.All)
{
ShowLevels(lastSortMode);
}
}

public void SelectTopButtons(TopButtonsState _newState)
Expand Down Expand Up @@ -206,13 +202,26 @@ private void _searchViewController_searchButtonPressed(string searchFor)

public void ShowLevels(SortMode mode)
{
SetSongListLevels(GetSortedLevels(mode));
if (_songListViewController != null && _songListViewController.selectedLevel != null)
{
SetSongListLevels(GetSortedLevels(mode), _songListViewController.selectedLevel.levelID);
}
else
{
SetSongListLevels(GetSortedLevels(mode));
}
}

public IStandardLevel[] GetSortedLevels(SortMode mode)
{
lastSortMode = mode;

if (_songSelectionMasterViewController == null)
{
_songSelectionMasterViewController = Resources.FindObjectsOfTypeAll<StandardLevelSelectionFlowCoordinator>().First();
}
GameplayMode gameplayMode = ReflectionUtil.GetPrivateField<GameplayMode>(_songSelectionMasterViewController, "_gameplayMode");


switch (mode)
{
Expand Down Expand Up @@ -269,16 +278,21 @@ IStandardLevel[] SortLevelsByCreationTime(GameplayMode gameplayMode)
}


void SetSongListLevels(IStandardLevel[] levels)
void SetSongListLevels(IStandardLevel[] levels, string selectedLevelID = "")
{
StandardLevelListViewController songListViewController = ReflectionUtil.GetPrivateField<StandardLevelListViewController>(_songSelectionMasterViewController, "_levelListViewController");

StandardLevelListTableView _songListTableView = songListViewController.GetComponentInChildren<StandardLevelListTableView>();

ReflectionUtil.SetPrivateField(_songListTableView, "_levels", levels);
songListViewController.Init(levels);
ReflectionUtil.SetPrivateField(songListViewController, "_levels", levels);

ReflectionUtil.GetPrivateField<TableView>(_songListTableView, "_tableView").ReloadData();

if (!string.IsNullOrEmpty(selectedLevelID))
{
_songListTableView.SelectAndScrollToLevel(selectedLevelID);
}
}

}
Expand Down
13 changes: 9 additions & 4 deletions BeatSaverDownloader/PluginUI/VotingUI.cs
Expand Up @@ -34,13 +34,18 @@ public IEnumerator WaitForResults()
{

log.Log("Waiting for results view controller");
yield return new WaitUntil(delegate () { return Resources.FindObjectsOfTypeAll<ResultsViewController>().Count() > 0; });
yield return new WaitUntil(delegate () { return Resources.FindObjectsOfTypeAll<ResultsViewController>().Any(); });

log.Log("Found results view controller!");

ResultsViewController results = Resources.FindObjectsOfTypeAll<ResultsViewController>().First();

levelId = ReflectionUtil.GetPrivateField<string>(results, "_levelId");
ResultsViewController results = Resources.FindObjectsOfTypeAll<ResultsViewController>().FirstOrDefault();

if(results == null)
{
yield break;
}

levelId = results.difficultyLevel.level.levelID;

results.continueButtonPressedEvent += Results_resultsViewControllerDidPressContinueButtonEvent;

Expand Down

0 comments on commit d8ed2dc

Please sign in to comment.