/// <summary> /// When a song is selected /// </summary> /// <param name="p_TableView">Source table</param> /// <param name="p_Row">Selected row</param> private void OnSongSelected(TableView p_TableView, int p_Row) { /// Fetch song entry var l_SongEntry = m_SongList.Data[p_Row]; /// Hide if invalid song if (l_SongEntry == null) { /// Hide song info panel UnselectSong(); return; } /// Show UIs m_SongInfoPanel.SetActive(true); FlowCoordinator.DetailView.SetVisible(true); /// Update UIs m_SongInfo_Detail.FromBeatSaver(l_SongEntry.BeatMap, l_SongEntry.Cover); m_SongInfo_Detail.SetFavoriteToggleValue(m_TypeSegmentControl.selectedCellNumber == 2 /* Blacklist */); FlowCoordinator.DetailView.SetDetail(l_SongEntry.BeatMap); /// Set selected song m_SelectedSong = l_SongEntry; /// Launch preview music if local map var l_LocalSong = SongCore.Loader.GetLevelByHash(m_SelectedSong.BeatMap.Hash); if (l_LocalSong != null && SongCore.Loader.CustomLevels.ContainsKey(l_LocalSong.customLevelPath)) { m_SongInfo_Detail.SetPlayButtonText("Play"); /// Load the song clip to get duration if (Config.ChatRequest.PlayPreviewMusic) { l_LocalSong.GetPreviewAudioClipAsync(CancellationToken.None).ContinueWith(x => { if (x.IsCompleted && x.Status == TaskStatus.RanToCompletion) { HMMainThreadDispatcher.instance.Enqueue(() => { /// Start preview song m_SongPreviewPlayer.CrossfadeTo(x.Result, l_LocalSong.previewStartTime, l_LocalSong.previewDuration, 1f); }); } }); } } /// Stop preview music if any else { m_SongInfo_Detail.SetPlayButtonText("Download"); m_SongPreviewPlayer.CrossfadeToDefault(); } }
/// <summary> /// When a song is selected /// </summary> /// <param name="p_TableView">Source table</param> /// <param name="p_Row">Selected row</param> private void OnSongSelected(TableView p_TableView, int p_Row) { /// Fetch song entry BeatSaverCustomSongCellInfo l_SongRow = m_SongList.data[p_Row] as BeatSaverCustomSongCellInfo; /// Get song entry var l_SongEntry = m_SongsProvider.Where(x => x.BeatMap.Hash == l_SongRow.SongHash).FirstOrDefault(); /// Hide if invalid song if (l_SongEntry == null) { /// Hide song info panel UnselectSong(); return; } /// Show UIs m_SongInfoPanel.SetActive(true); /// Update UIs m_SongInfo_Detail.FromBeatSaver(l_SongEntry.BeatMap, l_SongEntry.Cover); /// Set selected song m_SelectedSong = l_SongEntry; /// Launch preview music if local map var l_LocalSong = SongCore.Loader.GetLevelByHash(m_SelectedSong.BeatMap.Hash); if (l_LocalSong != null) { m_SongInfo_Detail.SetPlayButtonText("Play"); /// Load the song clip to get duration if (Config.ChatRequest.PlayPreviewMusic) { l_LocalSong.GetPreviewAudioClipAsync(CancellationToken.None).ContinueWith(x => { if (x.IsCompleted && x.Status == TaskStatus.RanToCompletion) { HMMainThreadDispatcher.instance.Enqueue(() => { /// Start preview song m_SongPreviewPlayer.CrossfadeTo(x.Result, l_LocalSong.previewStartTime, l_LocalSong.previewDuration, 1f); }); } }); } } /// Stop preview music if any else { m_SongInfo_Detail.SetPlayButtonText("Download"); m_SongPreviewPlayer.CrossfadeToDefault(); } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// /// <summary> /// On activation /// </summary> /// <param name="p_FirstActivation">Is the first activation ?</param> /// <param name="p_AddedToHierarchy">Activation type</param> /// <param name="p_ScreenSystemEnabling">Is screen system enabled</param> protected override void DidActivate(bool p_FirstActivation, bool p_AddedToHierarchy, bool p_ScreenSystemEnabling) { /// Forward event base.DidActivate(p_FirstActivation, p_AddedToHierarchy, p_ScreenSystemEnabling); if (p_FirstActivation) { /// Scale down up & down button m_SongUpButton.transform.localScale = Vector3.one * 0.6f; m_SongDownButton.transform.localScale = Vector3.one * 0.6f; /// Create type selector m_TypeSegmentControl = Utils.GameUI.CreateTextSegmentedControl(m_TypeSegmentPanel.transform as RectTransform, false); m_TypeSegmentControl.SetTexts(new string[] { "Requests", "History", "Blacklist" }); m_TypeSegmentControl.ReloadData(); m_TypeSegmentControl.didSelectCellEvent += OnQueueTypeChanged; /// Prepare song list var l_BSMLTableView = m_SongListView.GetComponentInChildren <BSMLTableView>(); l_BSMLTableView.SetDataSource(null, false); GameObject.DestroyImmediate(m_SongListView.GetComponentInChildren <CustomListTableData>()); m_SongList = l_BSMLTableView.gameObject.AddComponent <SongListDataSource>(); m_SongList.TableViewInstance = l_BSMLTableView; l_BSMLTableView.SetDataSource(m_SongList, false); /// Bind events m_SongUpButton.onClick.AddListener(OnSongPageUpPressed); m_SongList.TableViewInstance.didSelectCellWithIdxEvent += OnSongSelected; m_SongDownButton.onClick.AddListener(OnSongPageDownPressed); /// Find song preview object m_SongPreviewPlayer = Resources.FindObjectsOfTypeAll <SongPreviewPlayer>().First(); /// Show song info panel m_SongInfo_Detail = new BeatSaberPlus.UI.Widget.SongDetail(m_SongInfoPanel.transform); UnselectSong(); m_SongInfo_Detail.SetFavoriteToggleEnabled(true); m_SongInfo_Detail.SetFavoriteToggleImage("BeatSaberPlus.Plugins.ChatRequest.Resources.Blacklist.png", "BeatSaberPlus.Plugins.ChatRequest.Resources.Unblacklist.png"); m_SongInfo_Detail.SetFavoriteToggleHoverHint("Add/Remove to blacklist"); m_SongInfo_Detail.SetFavoriteToggleCallback(OnBlacklistButtonPressed); m_SongInfo_Detail.SetPracticeButtonEnabled(true); m_SongInfo_Detail.SetPracticeButtonText("Skip"); m_SongInfo_Detail.SetPracticeButtonAction(SkipSong); m_SongInfo_Detail.SetPlayButtonText("Play"); m_SongInfo_Detail.SetPlayButtonEnabled(true); m_SongInfo_Detail.SetPlayButtonAction(PlaySong); /// Init loading modal m_LoadingModalSpinner = GameObject.Instantiate(Resources.FindObjectsOfTypeAll <LoadingControl>().First(), m_LoadingModal.transform); m_LoadingModalSpinner.transform.SetAsLastSibling(); Destroy(m_LoadingModalSpinner.GetComponent <Touchable>()); /// Force change to tab Request OnQueueTypeChanged(null, 0); } /// Go back to request tab if (!p_FirstActivation && m_TypeSegmentControl.selectedCellNumber != 0) { m_TypeSegmentControl.SelectCellWithNumber(0); OnQueueTypeChanged(null, 0); } else { RebuildSongList(true); } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// /// <summary> /// On activation /// </summary> /// <param name="p_FirstActivation">Is the first activation ?</param> /// <param name="p_AddedToHierarchy">Activation type</param> /// <param name="p_ScreenSystemEnabling">Is screen system enabled</param> protected override void DidActivate(bool p_FirstActivation, bool p_AddedToHierarchy, bool p_ScreenSystemEnabling) { /// Forward event base.DidActivate(p_FirstActivation, p_AddedToHierarchy, p_ScreenSystemEnabling); if (p_FirstActivation) { m_SongsProvider = Plugins.ChatRequest.ChatRequest.Instance.SongHistory; /// Scale down up & down button m_SongUpButton.transform.localScale = Vector3.one * 0.6f; m_SongDownButton.transform.localScale = Vector3.one * 0.6f; /// Create type selector m_TypeSegmentControl = Utils.GameUI.CreateTextSegmentedControl(m_TypeSegmentPanel.transform as RectTransform, false); m_TypeSegmentControl.SetTexts(new string[] { "Playlist Generator", "Playlist" }); m_TypeSegmentControl.ReloadData(); m_TypeSegmentControl.didSelectCellEvent += OnTabChanged; /// Bind events m_SongUpButton.onClick.AddListener(OnSongPageUpPressed); m_SongList.tableView.didSelectCellWithIdxEvent += OnSongSelected; m_SongDownButton.onClick.AddListener(OnSongPageDownPressed); /// Find song preview object m_SongPreviewPlayer = Resources.FindObjectsOfTypeAll <SongPreviewPlayer>().First(); /// Show song info panel m_SongInfo_Detail = new BeatSaberPlus.UI.Widget.SongDetail(m_SongInfoPanel.transform); UnselectSong(); m_SongInfo_Detail.SetPlayButtonText("Play"); m_SongInfo_Detail.SetPlayButtonEnabled(true); m_SongInfo_Detail.SetPlayButtonAction(PlaySong); m_SongInfo_Detail.OnActiveDifficultyChanged += (x) => { /// Hide if no data if (x == null) { BeatSaberPlus.UI.ViewFlowCoordinator.Instance.SetRightScreen(null); } /// Show score board var l_ScoreBoard = Resources.FindObjectsOfTypeAll <PlatformLeaderboardViewController>().FirstOrDefault(); if (l_ScoreBoard != null) { if (!l_ScoreBoard.isInViewControllerHierarchy) { BeatSaberPlus.UI.ViewFlowCoordinator.Instance.SetRightScreen(l_ScoreBoard); } l_ScoreBoard.SetData(x); } }; /// Init loading modal m_LoadingModalSpinner = GameObject.Instantiate(Resources.FindObjectsOfTypeAll <LoadingControl>().First(), m_LoadingModal.transform); m_LoadingModalSpinner.transform.SetAsLastSibling(); Destroy(m_LoadingModalSpinner.GetComponent <Touchable>()); /// Force change to tab Request OnTabChanged(null, 0); } }