Skip to content

Commit

Permalink
YARG-176 Add button to go to currently-playing song in music player (Y…
Browse files Browse the repository at this point in the history
…ARC-Official#690)

* YARG-176 Add button to go to currently-playing song in music player

* Adding NowPlaying save to MusicPlayer.

---------

Co-authored-by: Vinay Kapadia <[email protected]>
  • Loading branch information
vinaykapadia and Vinay Kapadia authored Feb 20, 2024
1 parent 9a5db10 commit ec311c0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
12 changes: 11 additions & 1 deletion Assets/Script/Menu/Main/MainMenu.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using TMPro;
using TMPro;
using UnityEngine;
using YARG.Core.Input;
using YARG.Helpers;
using YARG.Menu.MusicLibrary;
using YARG.Menu.Settings;
Expand Down Expand Up @@ -45,6 +46,7 @@ private void OnEnable()
NavigationScheme.Entry.NavigateSelect,
NavigationScheme.Entry.NavigateUp,
NavigationScheme.Entry.NavigateDown,
new NavigationScheme.Entry(MenuAction.Select, "Go To Currently Playing", CurrentlyPlaying),
}, true));
}

Expand All @@ -53,6 +55,14 @@ private void OnDisable()
Navigator.Instance.PopScheme();
}

public void CurrentlyPlaying()
{
MusicLibraryMenu.InitialSelect = MusicPlayer.NowPlaying;
MusicLibraryMenu.SetRefresh();

QuickPlay();
}

public void QuickPlay()
{
var menu = MenuManager.Instance.PushMenu(MenuManager.Menu.MusicLibrary, false);
Expand Down
12 changes: 11 additions & 1 deletion Assets/Script/Menu/MusicLibrary/MusicLibraryMenu.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -31,6 +31,9 @@ public class MusicLibraryMenu : ListMenu<ViewType, SongView>
public static MusicLibraryMode LibraryMode;

public static SongAttribute Sort { get; private set; } = SongAttribute.Name;

public static SongMetadata InitialSelect = null;

#nullable enable
private static List<SongEntry>? _recommendedSongs;
#nullable disable
Expand Down Expand Up @@ -101,6 +104,11 @@ private void OnEnable()
// Get songs
if (_doRefresh)
{
if (InitialSelect != null)
{
_currentSong = InitialSelect;
}

Refresh();
_doRefresh = false;
}
Expand All @@ -110,6 +118,8 @@ private void OnEnable()
// Restore index
SelectedIndex = _savedIndex;
}

InitialSelect = null;

// Set proper text
_subHeader.text = LibraryMode switch
Expand Down
4 changes: 4 additions & 0 deletions Assets/Script/Menu/Persistent/MusicPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
using YARG.Settings;
using YARG.Helpers.Extensions;
using YARG.Core.Audio;
using YARG.Core.Song;

namespace YARG.Menu.Persistent
{
public class MusicPlayer : MonoBehaviour
{
public static SongMetadata NowPlaying = null;

[SerializeField]
private Image _playPauseButton;
[SerializeField]
Expand Down Expand Up @@ -55,6 +58,7 @@ private void OnDisable()
private async UniTask NextSong()
{
var song = GlobalVariables.Instance.SongContainer.GetRandomSong();
NowPlaying = song;
await UniTask.RunOnThreadPool(() => song.LoadAudio(GlobalVariables.AudioManager, 1f, SongStem.Crowd));

// Set song title text
Expand Down

0 comments on commit ec311c0

Please sign in to comment.