Skip to content

Commit

Permalink
Made sorting persist**e**nt in music library
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteAsian123 committed Jul 16, 2023
1 parent 90e4c5f commit b96d5c2
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions Assets/Script/Menu/MusicLibrary/SongSelection.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using System.Text;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using Cysharp.Threading.Tasks;
Expand All @@ -9,13 +6,11 @@
using UnityEngine.InputSystem;
using UnityEngine.UI;
using YARG.Audio;
using YARG.Data;
using YARG.Input;
using YARG.Song;
using YARG.UI.MusicLibrary.ViewTypes;
using Random = UnityEngine.Random;
using System.Threading;
using UnityEngine.Serialization;
using YARG.Settings;

namespace YARG.UI.MusicLibrary
Expand All @@ -26,6 +21,9 @@ public class SongSelection : MonoBehaviour

public static bool RefreshFlag = true;

// This stuff should stay the same even after you exit the menus
private static SongSorting.Sort _sort = SongSorting.Sort.Song;

private const int SONG_VIEW_EXTRA = 15;
private const float SCROLL_TIME = 1f / 60f;

Expand All @@ -45,7 +43,6 @@ public class SongSelection : MonoBehaviour
[SerializeField]
private Scrollbar _scrollbar;

private SongSorting.Sort _sort = SongSorting.Sort.Song;
private string _nextSortCriteria = "Order by artist";
private string _nextFilter = "Search artist";

Expand Down Expand Up @@ -120,6 +117,9 @@ private void OnEnable()
// Set up preview context
_previewContext = new(GameManager.AudioManager);

// Update sort name
_nextSortCriteria = SongSorting.GetNextSortButtonName(_sort);

// Set navigation scheme
var navigationScheme = GetNavigationScheme();
Navigator.Instance.PushScheme(navigationScheme);
Expand Down Expand Up @@ -230,7 +230,7 @@ private void ChangeSongOrder()
public void NextSort()
{
_sort = SongSorting.GetNextSortCriteria(_sort);
_nextSortCriteria = GetNextSortCriteriaButtonName();
_nextSortCriteria = SongSorting.GetNextSortButtonName(_sort);
}

private void UpdateNavigationScheme()
Expand Down Expand Up @@ -497,10 +497,13 @@ private int GetIndexOfSelectedSong()
{
var selectedSong = GameManager.Instance.SelectedSong;

return _viewList.FindIndex(song =>
{
return song is SongViewType songType && songType.SongEntry == selectedSong;
});
// Get the first index after the recommended songs
int startOfSongs = _viewList.FindIndex(i => i is SortHeaderViewType);

int songIndex = _viewList.FindIndex(startOfSongs,
song => song is SongViewType songType && songType.SongEntry == selectedSong);

return songIndex;
}

private void FillRecommendedSongs()
Expand Down Expand Up @@ -577,11 +580,6 @@ private int GetSkip()
return Mathf.Max(1, _viewList.Count - SongContainer.Songs.Count);
}

private string GetNextSortCriteriaButtonName()
{
return SongSorting.GetNextSortButtonName(_sort);
}

#if UNITY_EDITOR
public void SetAsTestPlaySong()
{
Expand Down

0 comments on commit b96d5c2

Please sign in to comment.