12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412 |
- using BeatSaberMarkupLanguage.Components;
- using HMUI;
- using SongBrowser.DataAccess;
- using SongBrowser.Internals;
- using SongCore.Utilities;
- using SongDataCore.BeatStar;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- using UnityEngine.UI;
- using VRUIControls;
- using Logger = SongBrowser.Logging.Logger;
- namespace SongBrowser.UI
- {
- public enum UIState
- {
- Disabled,
- Main,
- SortBy,
- FilterBy
- }
- public class SongBrowserViewController : ViewController
- {
- // Named instance
- }
- /// <summary>
- /// Hijack the flow coordinator. Have access to all StandardLevel easily.
- /// </summary>
- public class SongBrowserUI : MonoBehaviour
- {
- // Logging
- public const String Name = "SongBrowserUI";
- private const float SEGMENT_PERCENT = 0.1f;
- private const int LIST_ITEMS_VISIBLE_AT_ONCE = 6;
- private const float CLEAR_BUTTON_Y = -31.5f;
- private const float BUTTON_ROW_Y = -31.5f;
- // BeatSaber Internal UI structures
- DataAccess.BeatSaberUIController _beatUi;
- // New UI Elements
- private SongBrowserViewController _viewController;
- private List<SongSortButton> _sortButtonGroup;
- private List<SongFilterButton> _filterButtonGroup;
- private Button _sortByButton;
- private Button _sortByDisplay;
- private Button _filterByButton;
- private Button _filterByDisplay;
- private Button _randomButton;
- private Button _clearSortFilterButton;
- private SimpleDialogPromptViewController _deleteDialog;
- private Button _deleteButton;
- private Button _pageUpFastButton;
- private Button _pageDownFastButton;
- private RectTransform _ppStatButton;
- private RectTransform _starStatButton;
- private RectTransform _njsStatButton;
- private RectTransform _noteJumpStartBeatOffsetLabel;
- private IAnnotatedBeatmapLevelCollection _lastLevelCollection;
- bool _selectingCategory = false;
- private SongBrowserModel _model;
- public SongBrowserModel Model
- {
- set
- {
- _model = value;
- }
- get
- {
- return _model;
- }
- }
- private bool _uiCreated = false;
- private UIState _currentUiState = UIState.Disabled;
- private bool _asyncUpdating = false;
- /// <summary>
- /// Builds the UI for this plugin.
- /// </summary>
- public void CreateUI(MainMenuViewController.MenuButton mode)
- {
- Logger.Trace("CreateUI()");
- // Determine the flow controller to use
- FlowCoordinator flowCoordinator;
- if (mode == MainMenuViewController.MenuButton.SoloFreePlay)
- {
- Logger.Debug("Entering SOLO mode...");
- flowCoordinator = Resources.FindObjectsOfTypeAll<SoloFreePlayFlowCoordinator>().Last();
- }
- else if (mode == MainMenuViewController.MenuButton.Party)
- {
- Logger.Debug("Entering PARTY mode...");
- flowCoordinator = Resources.FindObjectsOfTypeAll<PartyFreePlayFlowCoordinator>().Last();
- }
- else
- {
- Logger.Info("Entering Unsupported mode...");
- return;
- }
- Logger.Debug("Done fetching Flow Coordinator for the appropriate mode...");
- _beatUi = new DataAccess.BeatSaberUIController(flowCoordinator);
- _lastLevelCollection = null;
- // returning to the menu and switching modes could trigger this.
- if (_uiCreated)
- {
- return;
- }
- try
- {
- // Create a view controller to store all SongBrowser elements
- if (_viewController)
- {
- UnityEngine.GameObject.Destroy(_viewController);
- }
- _viewController = BeatSaberUI.CreateCurvedViewController<SongBrowserViewController>("SongBrowserViewController", 125.0f);
- _viewController.rectTransform.SetParent(_beatUi.LevelCollectionNavigationController.rectTransform, false);
- _viewController.rectTransform.anchorMin = new Vector2(0f, 0f);
- _viewController.rectTransform.anchorMax = new Vector2(1f, 1f);
- _viewController.rectTransform.anchoredPosition = new Vector2(0, 0);
- _viewController.rectTransform.sizeDelta = new Vector2(125, 25);
- _viewController.gameObject.SetActive(true);
- // create song browser main ui
- CreateOuterUi();
- CreateSortButtons();
- CreateFilterButtons();
- CreateDeleteUI();
- CreateFastPageButtons();
- this.InstallHandlers();
- this.ModifySongStatsPanel();
- this.ResizeSongUI();
- _uiCreated = true;
- RefreshSortButtonUI();
- Logger.Debug("Done Creating UI...");
- }
- catch (Exception e)
- {
- Logger.Exception("Exception during CreateUI: ", e);
- }
- }
- /// <summary>
- /// Create the outer ui.
- /// </summary>
- private void CreateOuterUi()
- {
- Logger.Debug("Creating outer UI...");
- float clearButtonX = -72.5f;
- float clearButtonY = CLEAR_BUTTON_Y;
- float buttonY = BUTTON_ROW_Y;
- float buttonHeight = 5.0f;
- float sortByButtonX = -62.5f + buttonHeight;
- float outerButtonFontSize = 3.0f;
- float displayButtonFontSize = 2.5f;
- float outerButtonWidth = 24.0f;
- float randomButtonWidth = 10.0f;
- // clear button
- _clearSortFilterButton = _viewController.CreateIconButton(
- "ClearSortAndFilterButton",
- "PracticeButton",
- new Vector2(clearButtonX, clearButtonY),
- new Vector2(randomButtonWidth, randomButtonWidth),
- () =>
- {
- if (_currentUiState == UIState.FilterBy || _currentUiState == UIState.SortBy)
- {
- RefreshOuterUIState(UIState.Main);
- }
- else
- {
- OnClearButtonClickEvent();
- }
- },
- Base64Sprites.XIcon);
- _clearSortFilterButton.SetButtonBackgroundActive(false);
- // create SortBy button and its display
- float curX = sortByButtonX;
- Logger.Debug("Creating Sort By...");
- _sortByButton = _viewController.CreateUIButton("sortBy", "PracticeButton", new Vector2(curX, buttonY), new Vector2(outerButtonWidth, buttonHeight), () =>
- {
- RefreshOuterUIState(UIState.SortBy);
- }, "Sort By");
- _sortByButton.SetButtonTextSize(outerButtonFontSize);
- _sortByButton.ToggleWordWrapping(false);
- curX += outerButtonWidth;
- Logger.Debug("Creating Sort By Display...");
- _sortByDisplay = _viewController.CreateUIButton("sortByValue", "PracticeButton", new Vector2(curX, buttonY), new Vector2(outerButtonWidth, buttonHeight), () =>
- {
- OnSortButtonClickEvent(_model.Settings.sortMode);
- }, "");
- _sortByDisplay.SetButtonTextSize(displayButtonFontSize);
- _sortByDisplay.ToggleWordWrapping(false);
- curX += outerButtonWidth;
- // create FilterBy button and its display
- Logger.Debug("Creating Filter By...");
- _filterByButton = _viewController.CreateUIButton("filterBy", "PracticeButton", new Vector2(curX, buttonY), new Vector2(outerButtonWidth, buttonHeight), () =>
- {
- RefreshOuterUIState(UIState.FilterBy);
- }, "Filter By");
- _filterByButton.SetButtonTextSize(outerButtonFontSize);
- _filterByButton.ToggleWordWrapping(false);
- curX += outerButtonWidth;
- Logger.Debug("Creating Filter By Display...");
- _filterByDisplay = _viewController.CreateUIButton("filterValue", "PracticeButton", new Vector2(curX, buttonY), new Vector2(outerButtonWidth, buttonHeight), () =>
- {
- _model.Settings.filterMode = SongFilterMode.None;
- CancelFilter();
- ProcessSongList();
- RefreshSongUI();
- }, "");
- _filterByDisplay.SetButtonTextSize(displayButtonFontSize);
- _filterByDisplay.ToggleWordWrapping(false);
- // random button
- Logger.Debug("Creating Random Button...");
- _randomButton = _viewController.CreateIconButton("randomButton", "PracticeButton", new Vector2(curX + (outerButtonWidth / 2.0f) + (randomButtonWidth / 4.0f), clearButtonY), new Vector2(randomButtonWidth, randomButtonWidth), () =>
- {
- OnSortButtonClickEvent(SongSortMode.Random);
- }, Base64Sprites.RandomIcon);
- _randomButton.SetButtonBackgroundActive(false);
- }
- /// <summary>
- /// Create the sort button ribbon
- /// </summary>
- private void CreateSortButtons()
- {
- Logger.Debug("Create sort buttons...");
- float sortButtonFontSize = 2.0f;
- float sortButtonX = -63.0f;
- float sortButtonWidth = 12.0f;
- float buttonSpacing = 0.25f;
- float buttonY = BUTTON_ROW_Y;
- float buttonHeight = 5.0f;
- string[] sortButtonNames = new string[]
- {
- "Title", "Author", "Newest", "#Plays", "PP", "Stars", "UpVotes", "Rating", "Heat"
- };
- SongSortMode[] sortModes = new SongSortMode[]
- {
- SongSortMode.Default, SongSortMode.Author, SongSortMode.Newest, SongSortMode.YourPlayCount, SongSortMode.PP, SongSortMode.Stars, SongSortMode.UpVotes, SongSortMode.Rating, SongSortMode.Heat
- };
- _sortButtonGroup = new List<SongSortButton>();
- for (int i = 0; i < sortButtonNames.Length; i++)
- {
- float curButtonX = sortButtonX + (sortButtonWidth * i) + (buttonSpacing * i);
- SongSortButton sortButton = new SongSortButton();
- sortButton.SortMode = sortModes[i];
- sortButton.Button = _viewController.CreateUIButton(String.Format("Sort{0}Button", sortButton.SortMode), "PracticeButton",
- new Vector2(curButtonX, buttonY), new Vector2(sortButtonWidth, buttonHeight),
- () =>
- {
- OnSortButtonClickEvent(sortButton.SortMode);
- RefreshOuterUIState(UIState.Main);
- },
- sortButtonNames[i]);
- sortButton.Button.SetButtonTextSize(sortButtonFontSize);
- sortButton.Button.ToggleWordWrapping(false);
- _sortButtonGroup.Add(sortButton);
- }
- }
- /// <summary>
- /// Create the filter by buttons
- /// </summary>
- private void CreateFilterButtons()
- {
- Logger.Debug("Creating filter buttons...");
- float filterButtonFontSize = 2.25f;
- float filterButtonX = -63.0f;
- float filterButtonWidth = 14.25f;
- float buttonSpacing = 0.5f;
- float buttonY = BUTTON_ROW_Y;
- float buttonHeight = 5.0f;
- string[] filterButtonNames = new string[]
- {
- "Search", "Ranked", "Unranked"
- };
- SongFilterMode[] filterModes = new SongFilterMode[]
- {
- SongFilterMode.Search, SongFilterMode.Ranked, SongFilterMode.Unranked
- };
- _filterButtonGroup = new List<SongFilterButton>();
- for (int i = 0; i < filterButtonNames.Length; i++)
- {
- float curButtonX = filterButtonX + (filterButtonWidth * i) + (buttonSpacing * i);
- SongFilterButton filterButton = new SongFilterButton();
- filterButton.FilterMode = filterModes[i];
- filterButton.Button = _viewController.CreateUIButton(String.Format("Filter{0}Button", filterButton.FilterMode), "PracticeButton",
- new Vector2(curButtonX, buttonY), new Vector2(filterButtonWidth, buttonHeight),
- () =>
- {
- OnFilterButtonClickEvent(filterButton.FilterMode);
- RefreshOuterUIState(UIState.Main);
- },
- filterButtonNames[i]);
- filterButton.Button.SetButtonTextSize(filterButtonFontSize);
- filterButton.Button.ToggleWordWrapping(false);
- _filterButtonGroup.Add(filterButton);
- }
- }
- /// <summary>
- /// Create the fast page up and down buttons
- /// </summary>
- private void CreateFastPageButtons()
- {
- Logger.Debug("Creating fast scroll button...");
- _pageUpFastButton = BeatSaberUI.CreatePageButton("PageUpFast",
- _beatUi.LevelCollectionNavigationController.transform as RectTransform, "UpButton",
- new Vector2(2.0f, 24f),
- new Vector2(8f, 8f),
- delegate ()
- {
- this.JumpSongList(-1, SEGMENT_PERCENT);
- }, Base64Sprites.DoubleArrow);
- _pageDownFastButton = BeatSaberUI.CreatePageButton("PageDownFast",
- _beatUi.LevelCollectionNavigationController.transform as RectTransform, "DownButton",
- new Vector2(2.0f, -24f),
- new Vector2(8f, 8f),
- delegate ()
- {
- this.JumpSongList(1, SEGMENT_PERCENT);
- }, Base64Sprites.DoubleArrow);
- }
- /// <summary>
- /// Create the delete button in the play button container
- /// </summary>
- private void CreateDeleteUI()
- {
- Logger.Debug("Creating delete dialog...");
- _deleteDialog = UnityEngine.Object.Instantiate<SimpleDialogPromptViewController>(_beatUi.SimpleDialogPromptViewControllerPrefab);
- _deleteDialog.GetComponent<VRGraphicRaycaster>().SetField("_physicsRaycaster", BeatSaberUI.PhysicsRaycasterWithCache);
- _deleteDialog.name = "DeleteDialogPromptViewController";
- _deleteDialog.gameObject.SetActive(false);
- Logger.Debug("Creating delete button...");
- _deleteButton = BeatSaberUI.CreateIconButton("DeleteLevelButton", _beatUi.ActionButtons, "PracticeButton", Base64Sprites.DeleteIcon);
- _deleteButton.transform.SetAsFirstSibling();
- _deleteButton.onClick.AddListener(delegate () {
- HandleDeleteSelectedLevel();
- });
- }
- /// <summary>
- /// Resize the stats panel to fit more stats.
- /// </summary>
- private void ModifySongStatsPanel()
- {
- // modify stat panel, inject extra row of stats
- Logger.Debug("Resizing Stats Panel...");
- var statsPanel = _beatUi.StandardLevelDetailView.GetPrivateField<LevelParamsPanel>("_levelParamsPanel");
- (statsPanel.transform as RectTransform).Translate(0, 0.05f, 0);
- _ppStatButton = BeatSaberUI.CreateStatIcon("PPStatLabel",
- statsPanel.GetComponentsInChildren<RectTransform>().First(x => x.name == "NPS"),
- statsPanel.transform,
- Base64Sprites.GraphIcon,
- "PP Value");
- _starStatButton = BeatSaberUI.CreateStatIcon("StarStatLabel",
- statsPanel.GetComponentsInChildren<RectTransform>().First(x => x.name == "NotesCount"),
- statsPanel.transform,
- Base64Sprites.StarFullIcon,
- "Star Difficulty Rating");
- _njsStatButton = BeatSaberUI.CreateStatIcon("NoteJumpSpeedLabel",
- statsPanel.GetComponentsInChildren<RectTransform>().First(x => x.name == "ObstaclesCount"),
- statsPanel.transform,
- Base64Sprites.SpeedIcon,
- "Note Jump Speed");
- _noteJumpStartBeatOffsetLabel = BeatSaberUI.CreateStatIcon("NoteJumpStartBeatOffsetLabel",
- statsPanel.GetComponentsInChildren<RectTransform>().First(x => x.name == "BombsCount"),
- statsPanel.transform,
- Base64Sprites.NoteStartOffsetIcon,
- "Note Jump Start Beat Offset");
- }
- /// <summary>
- /// Resize some of the song table elements.
- /// </summary>
- public void ResizeSongUI()
- {
- // shrink play button container
- _beatUi.ActionButtons.localScale = new Vector3(0.875f, 0.875f, 0.875f);
- }
- /// <summary>
- /// Add our handlers into BeatSaber.
- /// </summary>
- private void InstallHandlers()
- {
- // level collection, level, difficulty handlers, characteristics
- TableView tableView = ReflectionUtil.GetPrivateField<TableView>(_beatUi.LevelCollectionTableView, "_tableView");
- // update stats
- _beatUi.LevelCollectionViewController.didSelectLevelEvent -= OnDidSelectLevelEvent;
- _beatUi.LevelCollectionViewController.didSelectLevelEvent += OnDidSelectLevelEvent;
- _beatUi.LevelDetailViewController.didChangeContentEvent -= OnDidPresentContentEvent;
- _beatUi.LevelDetailViewController.didChangeContentEvent += OnDidPresentContentEvent;
- _beatUi.LevelDetailViewController.didChangeDifficultyBeatmapEvent -= OnDidChangeDifficultyEvent;
- _beatUi.LevelDetailViewController.didChangeDifficultyBeatmapEvent += OnDidChangeDifficultyEvent;
- // update our view of the game state
- _beatUi.LevelFilteringNavigationController.didSelectAnnotatedBeatmapLevelCollectionEvent -= _levelFilteringNavController_didSelectAnnotatedBeatmapLevelCollectionEvent;
- _beatUi.LevelFilteringNavigationController.didSelectAnnotatedBeatmapLevelCollectionEvent += _levelFilteringNavController_didSelectAnnotatedBeatmapLevelCollectionEvent;
- _beatUi.AnnotatedBeatmapLevelCollectionsViewController.didSelectAnnotatedBeatmapLevelCollectionEvent -= handleDidSelectAnnotatedBeatmapLevelCollection;
- _beatUi.AnnotatedBeatmapLevelCollectionsViewController.didSelectAnnotatedBeatmapLevelCollectionEvent += handleDidSelectAnnotatedBeatmapLevelCollection;
- // Respond to characteristics changes
- _beatUi.BeatmapCharacteristicSelectionViewController.didSelectBeatmapCharacteristicEvent -= OnDidSelectBeatmapCharacteristic;
- _beatUi.BeatmapCharacteristicSelectionViewController.didSelectBeatmapCharacteristicEvent += OnDidSelectBeatmapCharacteristic;
- // make sure the quick scroll buttons don't desync with regular scrolling
- _beatUi.TableViewPageDownButton.onClick.AddListener(delegate ()
- {
- StartCoroutine(RefreshQuickScrollButtonsAsync());
- });
- _beatUi.TableViewPageUpButton.onClick.AddListener(delegate ()
- {
- StartCoroutine(RefreshQuickScrollButtonsAsync());
- });
- }
- /// <summary>
- /// Waits for the song UI to be available before trying to update.
- /// </summary>
- /// <returns></returns>
- public IEnumerator AsyncWaitForSongUIUpdate()
- {
- if (_asyncUpdating)
- {
- yield break;
- }
- if (!_uiCreated)
- {
- yield break;
- }
- if (!_model.SortWasMissingData)
- {
- yield break;
- }
- _asyncUpdating = true;
- while (_beatUi != null && (_beatUi.LevelSelectionNavigationController.GetPrivateField<bool>("_isInTransition") ||
- _beatUi.LevelDetailViewController.GetPrivateField<bool>("_isInTransition") ||
- !_beatUi.LevelSelectionNavigationController.isInViewControllerHierarchy ||
- !_beatUi.LevelDetailViewController.isInViewControllerHierarchy ||
- !_beatUi.LevelSelectionNavigationController.isActiveAndEnabled ||
- !_beatUi.LevelDetailViewController.isActiveAndEnabled))
- {
- yield return null;
- }
- //yield return new WaitForEndOfFrame();
- if (_model.Settings.sortMode.NeedsScoreSaberData() && SongDataCore.Plugin.Songs.IsDataAvailable())
- {
- ProcessSongList();
- RefreshSongUI();
- }
- _asyncUpdating = false;
- }
- /// <summary>
- /// Helper to reduce code duplication...
- /// </summary>
- public void RefreshSongUI(bool scrollToLevel = true)
- {
- if (!_uiCreated)
- {
- return;
- }
- RefreshSongList();
- RefreshSortButtonUI();
- if (!scrollToLevel)
- {
- _beatUi.ScrollToLevelByRow(0);
- }
- RefreshQuickScrollButtons();
- RefreshCurrentSelectionDisplay();
- }
- /// <summary>
- /// External helper.
- /// </summary>
- public void ProcessSongList()
- {
- if (!_uiCreated)
- {
- return;
- }
- this._model.ProcessSongList(_lastLevelCollection, _beatUi.LevelSelectionNavigationController);
- }
- /// <summary>
- /// Helper for common filter cancellation logic.
- /// </summary>
- public void CancelFilter()
- {
- Logger.Debug($"Cancelling filter, levelCollection {_lastLevelCollection}");
- _model.Settings.filterMode = SongFilterMode.None;
- GameObject _noDataGO = _beatUi.LevelCollectionViewController.GetPrivateField<GameObject>("_noDataInfoGO");
- string _headerText = _beatUi.LevelCollectionTableView.GetPrivateField<string>("_headerText");
- Sprite _headerSprite = _beatUi.LevelCollectionTableView.GetPrivateField<Sprite>("_headerSprite");
- IBeatmapLevelCollection levelCollection = _beatUi.GetCurrentSelectedAnnotatedBeatmapLevelCollection().beatmapLevelCollection;
- _beatUi.LevelCollectionViewController.SetData(levelCollection, _headerText, _headerSprite, false, _noDataGO);
- }
- /// <summary>
- /// Playlists (fancy name for AnnotatedBeatmapLevelCollection)
- /// </summary>
- /// <param name="annotatedBeatmapLevelCollection"></param>
- public virtual void handleDidSelectAnnotatedBeatmapLevelCollection(IAnnotatedBeatmapLevelCollection annotatedBeatmapLevelCollection)
- {
- Logger.Trace("handleDidSelectAnnotatedBeatmapLevelCollection()");
- _lastLevelCollection = annotatedBeatmapLevelCollection;
- Model.Settings.currentLevelCategoryName = _beatUi.LevelFilteringNavigationController.selectedLevelCategory.ToString();
- Model.Settings.Save();
- Logger.Debug("AnnotatedBeatmapLevelCollection, Selected Level Collection={0}", _lastLevelCollection);
- }
- /// <summary>
- /// Handler for level collection selection, controller.
- /// Sets the current level collection into the model and updates.
- /// </summary>
- /// <param name="arg1"></param>
- /// <param name="arg2"></param>
- /// <param name="arg3"></param>
- /// <param name="arg4"></param>
- private void _levelFilteringNavController_didSelectAnnotatedBeatmapLevelCollectionEvent(LevelFilteringNavigationController arg1, IAnnotatedBeatmapLevelCollection arg2,
- GameObject arg3, BeatmapCharacteristicSO arg4)
- {
- Logger.Trace("_levelFilteringNavController_didSelectAnnotatedBeatmapLevelCollectionEvent(levelCollection={0})", arg2);
- if (arg2 == null)
- {
- // Probably means we transitioned between Music Packs and Playlists
- arg2 = _beatUi.GetCurrentSelectedAnnotatedBeatmapLevelCollection();
- if (arg2 == null)
- {
- Logger.Warning("Nothing selected. This is likely an error.");
- return;
- }
- }
- Logger.Debug("Selected Level Collection={0}", arg2);
- // Do something about preview level packs, they can't be used past this point
- if (arg2 as PreviewBeatmapLevelPackSO)
- {
- Logger.Info("Hiding SongBrowser, previewing a song pack.");
- Hide();
- return;
- }
- Show();
- // category transition, just record the new collection
- if (_selectingCategory)
- {
- Logger.Info("Transitioning level category");
- _lastLevelCollection = arg2;
- StartCoroutine(RefreshSongListEndOfFrame());
- return;
- }
- // Skip the first time - prevents a bunch of reload content spam
- if (_lastLevelCollection == null)
- {
- return;
- }
- SelectLevelCollection(arg2);
- }
- /// <summary>
- /// Logic for selecting a level collection.
- /// </summary>
- /// <param name="levelPack"></param>
- public void SelectLevelCollection(IAnnotatedBeatmapLevelCollection levelCollection)
- {
- try
- {
- if (levelCollection == null)
- {
- Logger.Debug("No level collection selected...");
- return;
- }
- // store the real level collection
- if (levelCollection.collectionName != SongBrowserModel.FilteredSongsCollectionName && _lastLevelCollection != null)
- {
- Logger.Debug("Recording levelCollection: {0}", levelCollection.collectionName);
- _lastLevelCollection = levelCollection;
- Model.Settings.currentLevelCategoryName = _beatUi.LevelFilteringNavigationController.selectedLevelCategory.ToString();
- }
- // reset level selection
- _model.LastSelectedLevelId = null;
- // save level collection
- this._model.Settings.currentLevelCollectionName = levelCollection.collectionName;
- this._model.Settings.Save();
- StartCoroutine(ProcessSongListEndOfFrame());
- }
- catch (Exception e)
- {
- Logger.Exception("Exception handling SelectLevelCollection...", e);
- }
- }
- /// <summary>
- /// End of frame update the song list, the game seems to stomp on us sometimes otherwise
- /// TODO - Might not be nice to other plugins
- /// </summary>
- /// <returns></returns>
- public IEnumerator ProcessSongListEndOfFrame()
- {
- yield return new WaitForEndOfFrame();
- ProcessSongList();
- RefreshSongUI();
- }
- public IEnumerator RefreshSongListEndOfFrame()
- {
- yield return new WaitForEndOfFrame();
- RefreshSongUI();
- }
- /// <summary>
- /// Remove all filters, update song list, save.
- /// </summary>
- private void OnClearButtonClickEvent()
- {
- Logger.Debug("Clearing all sorts and filters.");
- _model.Settings.sortMode = SongSortMode.Original;
- _model.Settings.invertSortResults = false;
- _model.Settings.filterMode = SongFilterMode.None;
- _model.Settings.Save();
- CancelFilter();
- ProcessSongList();
- RefreshSongUI();
- }
- /// <summary>
- /// Sort button clicked.
- /// </summary>
- private void OnSortButtonClickEvent(SongSortMode sortMode)
- {
- Logger.Debug("Sort button - {0} - pressed.", sortMode.ToString());
- if ((sortMode.NeedsScoreSaberData() && !SongDataCore.Plugin.Songs.IsDataAvailable()))
- {
- Logger.Info("Data for sort type is not available.");
- return;
- }
- // Clear current selected level id so our song list jumps to the start
- _model.LastSelectedLevelId = null;
- if (_model.Settings.sortMode == sortMode)
- {
- _model.ToggleInverting();
- }
- _model.Settings.sortMode = sortMode;
- // update the seed
- if (_model.Settings.sortMode == SongSortMode.Random)
- {
- _model.Settings.randomSongSeed = Guid.NewGuid().GetHashCode();
- }
- _model.Settings.Save();
- ProcessSongList();
- RefreshSongUI();
- }
- /// <summary>
- /// Handle filter button logic. Some filters have sub menus that need special logic.
- /// </summary>
- /// <param name="mode"></param>
- private void OnFilterButtonClickEvent(SongFilterMode mode)
- {
- Logger.Debug($"FilterButton {mode} clicked.");
- var curCollection = _beatUi.GetCurrentSelectedAnnotatedBeatmapLevelCollection();
- if (_lastLevelCollection == null ||
- (curCollection != null &&
- curCollection.collectionName != SongBrowserModel.FilteredSongsCollectionName &&
- curCollection.collectionName != SongBrowserModel.PlaylistSongsCollectionName))
- {
- _lastLevelCollection = _beatUi.GetCurrentSelectedAnnotatedBeatmapLevelCollection();
- }
- if (mode == SongFilterMode.Favorites)
- {
- _beatUi.SelectLevelCategory(SelectLevelCategoryViewController.LevelCategory.Favorites.ToString());
- }
- else
- {
- GameObject _noDataGO = _beatUi.LevelCollectionViewController.GetPrivateField<GameObject>("_noDataInfoGO");
- string _headerText = _beatUi.LevelCollectionTableView.GetPrivateField<string>("_headerText");
- Sprite _headerSprite = _beatUi.LevelCollectionTableView.GetPrivateField<Sprite>("_headerSprite");
- IBeatmapLevelCollection levelCollection = _beatUi.GetCurrentSelectedAnnotatedBeatmapLevelCollection().beatmapLevelCollection;
- _beatUi.LevelCollectionViewController.SetData(levelCollection, _headerText, _headerSprite, false, _noDataGO);
- }
- // If selecting the same filter, cancel
- if (_model.Settings.filterMode == mode)
- {
- _model.Settings.filterMode = SongFilterMode.None;
- }
- else
- {
- _model.Settings.filterMode = mode;
- }
- switch (mode)
- {
- case SongFilterMode.Search:
- OnSearchButtonClickEvent();
- break;
- default:
- _model.Settings.Save();
- ProcessSongList();
- RefreshSongUI();
- break;
- }
- }
- /// <summary>
- /// Display the keyboard.
- /// </summary>
- /// <param name="sortMode"></param>
- private void OnSearchButtonClickEvent()
- {
- Logger.Debug("Filter button - {0} - pressed.", SongFilterMode.Search.ToString());
- this.ShowSearchKeyboard();
- }
- /// <summary>
- /// Adjust UI based on level selected.
- /// Various ways of detecting if a level is not properly selected. Seems most hit the first one.
- /// </summary>
- private void OnDidSelectLevelEvent(LevelCollectionViewController view, IPreviewBeatmapLevel level)
- {
- try
- {
- Logger.Trace("OnDidSelectLevelEvent()");
- if (level == null)
- {
- Logger.Debug("No level selected?");
- return;
- }
- if (_model.Settings == null)
- {
- Logger.Debug("Settings not instantiated yet?");
- return;
- }
- _model.LastSelectedLevelId = level.levelID;
- HandleDidSelectLevelRow(level);
- }
- catch (Exception e)
- {
- Logger.Exception("Exception selecting song:", e);
- }
- }
- /// <summary>
- /// Switching one-saber modes for example.
- /// </summary>
- /// <param name="view"></param>
- /// <param name="bc"></param>
- private void OnDidSelectBeatmapCharacteristic(BeatmapCharacteristicSegmentedControlController view, BeatmapCharacteristicSO bc)
- {
- try
- {
- Logger.Trace("OnDidSelectBeatmapCharacteristic({0})", bc.compoundIdPartName);
- _model.CurrentBeatmapCharacteristicSO = bc;
- if (_beatUi.StandardLevelDetailView != null)
- {
- RefreshScoreSaberData(_beatUi.StandardLevelDetailView.selectedDifficultyBeatmap.level);
- RefreshNoteJumpSpeed(_beatUi.StandardLevelDetailView.selectedDifficultyBeatmap.noteJumpMovementSpeed,
- _beatUi.StandardLevelDetailView.selectedDifficultyBeatmap.noteJumpStartBeatOffset);
- }
- }
- catch (Exception e)
- {
- Logger.Exception(e);
- }
- }
- /// <summary>
- /// Handle difficulty level selection.
- /// </summary>
- private void OnDidChangeDifficultyEvent(StandardLevelDetailViewController view, IDifficultyBeatmap beatmap)
- {
- Logger.Trace("OnDidChangeDifficultyEvent({0})", beatmap);
- if (view.selectedDifficultyBeatmap == null)
- {
- return;
- }
- UpdateDeleteButtonState(view.selectedDifficultyBeatmap.level.levelID);
- RefreshScoreSaberData(view.selectedDifficultyBeatmap.level);
- RefreshNoteJumpSpeed(beatmap.noteJumpMovementSpeed, beatmap.noteJumpStartBeatOffset);
- }
- /// <summary>
- /// BeatSaber finished loading content. This is when the difficulty is finally updated.
- /// </summary>
- /// <param name="view"></param>
- /// <param name="type"></param>
- private void OnDidPresentContentEvent(StandardLevelDetailViewController view, StandardLevelDetailViewController.ContentType type)
- {
- Logger.Trace("OnDidPresentContentEvent()");
- if (type != StandardLevelDetailViewController.ContentType.OwnedAndReady)
- {
- return;
- }
- if (view.selectedDifficultyBeatmap == null)
- {
- return;
- }
- UpdateDeleteButtonState(_beatUi.LevelDetailViewController.selectedDifficultyBeatmap.level.levelID);
- RefreshScoreSaberData(view.selectedDifficultyBeatmap.level);
- RefreshNoteJumpSpeed(view.selectedDifficultyBeatmap.noteJumpMovementSpeed, view.selectedDifficultyBeatmap.noteJumpStartBeatOffset);
- }
- /// <summary>
- /// Refresh stats panel.
- /// </summary>
- /// <param name="level"></param>
- private void HandleDidSelectLevelRow(IPreviewBeatmapLevel level)
- {
- Logger.Trace("HandleDidSelectLevelRow({0})", level);
- UpdateDeleteButtonState(level.levelID);
- RefreshQuickScrollButtons();
- }
- /// <summary>
- /// Pop up a delete dialog.
- /// </summary>
- private void HandleDeleteSelectedLevel()
- {
- IBeatmapLevel level = _beatUi.LevelDetailViewController.selectedDifficultyBeatmap.level;
- _deleteDialog.Init("Delete song", $"Do you really want to delete \"{ level.songName} {level.songSubName}\"?", "Delete", "Cancel",
- (selectedButton) =>
- {
- _deleteDialog.__DismissViewController(null);
- _beatUi.ScreenSystem.titleViewController.gameObject.SetActive(true);
- if (selectedButton == 0)
- {
- try
- {
- List<IPreviewBeatmapLevel> levels = _beatUi.GetCurrentLevelCollectionLevels().ToList();
- int selectedIndex = levels.FindIndex(x => x.levelID == _beatUi.StandardLevelDetailView.selectedDifficultyBeatmap.level.levelID);
- if (selectedIndex > -1)
- {
- var song = SongCore.Loader.CustomLevels.First(x => x.Value.levelID == _beatUi.LevelDetailViewController.selectedDifficultyBeatmap.level.levelID).Value;
- Logger.Info($"Deleting song: {song.customLevelPath}");
- SongCore.Loader.Instance.DeleteSong(song.customLevelPath);
- int removedLevels = levels.RemoveAll(x => x.levelID == _beatUi.StandardLevelDetailView.selectedDifficultyBeatmap.level.levelID);
- Logger.Info($"Removed [{removedLevels}] level(s) from song list!");
- this.UpdateLevelDataModel();
- // if we have a song to select at the same index, set the last selected level id, UI updates takes care of the rest.
- if (selectedIndex < levels.Count)
- {
- if (levels[selectedIndex].levelID != null)
- {
- _model.LastSelectedLevelId = levels[selectedIndex].levelID;
- }
- }
- this.RefreshSongList();
- }
- }
- catch (Exception e)
- {
- Logger.Error("Unable to delete song! Exception: " + e);
- }
- }
- });
- _beatUi.ScreenSystem.titleViewController.gameObject.SetActive(false);
- _beatUi.LevelSelectionNavigationController.__PresentViewController(_deleteDialog, null);
- }
- /// <summary>
- /// Display the search keyboard
- /// </summary>
- void ShowSearchKeyboard()
- {
- var modalKbTag = new BeatSaberMarkupLanguage.Tags.ModalKeyboardTag();
- var modalKbView = modalKbTag.CreateObject(_beatUi.LevelSelectionNavigationController.rectTransform);
- modalKbView.gameObject.SetActive(true);
- var modalKb = modalKbView.GetComponent<ModalKeyboard>();
- modalKb.gameObject.SetActive(true);
- modalKb.keyboard.EnterPressed += SearchViewControllerSearchButtonPressed;
- modalKb.modalView.Show(true, true);
- }
- /// <summary>
- /// Handle search.
- /// </summary>
- /// <param name="searchFor"></param>
- private void SearchViewControllerSearchButtonPressed(string searchFor)
- {
- Logger.Debug("Searching for \"{0}\"...", searchFor);
- _model.Settings.filterMode = SongFilterMode.Search;
- _model.Settings.searchTerms.Insert(0, searchFor);
- _model.Settings.Save();
- _model.LastSelectedLevelId = null;
- ProcessSongList();
- RefreshSongUI();
- }
- /// <summary>
- /// Make big jumps in the song list.
- /// </summary>
- /// <param name="numJumps"></param>
- private void JumpSongList(int numJumps, float segmentPercent)
- {
- var levels = _beatUi.GetCurrentLevelCollectionLevels();
- if (levels == null)
- {
- return;
- }
- int totalSize = levels.Count();
- int segmentSize = (int)(totalSize * segmentPercent);
- // Jump at least one scree size.
- if (segmentSize < LIST_ITEMS_VISIBLE_AT_ONCE)
- {
- segmentSize = LIST_ITEMS_VISIBLE_AT_ONCE;
- }
- int currentRow = _beatUi.LevelCollectionTableView.GetPrivateField<int>("_selectedRow");
- int jumpDirection = Math.Sign(numJumps);
- int newRow = currentRow + (jumpDirection * segmentSize);
- if (newRow <= 0)
- {
- newRow = 0;
- }
- else if (newRow >= totalSize)
- {
- newRow = totalSize - 1;
- }
- Logger.Debug("jumpDirection: {0}, newRow: {1}", jumpDirection, newRow);
- _beatUi.ScrollToLevelByRow(newRow);
- RefreshQuickScrollButtons();
- }
- /// <summary>
- /// Update GUI elements that show score saber data.
- /// </summary>
- public void RefreshScoreSaberData(IPreviewBeatmapLevel level)
- {
- Logger.Trace("RefreshScoreSaberData({0})", level.levelID);
- if (!SongDataCore.Plugin.Songs.IsDataAvailable())
- {
- return;
- }
- BeatmapDifficulty difficulty = _beatUi.LevelDifficultyViewController.selectedDifficulty;
- string difficultyString = difficulty.ToString();
- if (difficultyString.Equals("ExpertPlus"))
- {
- difficultyString = "Expert+";
- }
- Logger.Debug(difficultyString);
- // Check if we have data for this song
- Logger.Debug("Checking if have info for song {0}", level.songName);
- var hash = SongBrowserModel.GetSongHash(level.levelID);
- if (SongDataCore.Plugin.Songs.Data.Songs.ContainsKey(hash))
- {
- Logger.Debug("Checking if have difficulty for song {0} difficulty {1}", level.songName, difficultyString);
- BeatStarSong scoreSaberSong = SongDataCore.Plugin.Songs.Data.Songs[hash];
- BeatStarSongDifficultyStats scoreSaberSongDifficulty = scoreSaberSong.diffs.FirstOrDefault(x => String.Equals(x.diff, difficultyString));
- if (scoreSaberSongDifficulty != null)
- {
- Logger.Debug("Display pp for song.");
- double pp = scoreSaberSongDifficulty.pp;
- double star = scoreSaberSongDifficulty.star;
- BeatSaberUI.SetStatButtonText(_ppStatButton, String.Format("{0:0.#}", pp));
- BeatSaberUI.SetStatButtonText(_starStatButton, String.Format("{0:0.#}", star));
- }
- else
- {
- BeatSaberUI.SetStatButtonText(_ppStatButton, "NA");
- BeatSaberUI.SetStatButtonText(_starStatButton, "NA");
- }
- }
- else
- {
- BeatSaberUI.SetStatButtonText(_ppStatButton, "NA");
- BeatSaberUI.SetStatButtonText(_starStatButton, "NA");
- }
- Logger.Debug("Done refreshing score saber stats.");
- }
- /// <summary>
- /// Helper to refresh the NJS widget.
- /// </summary>
- /// <param name="noteJumpMovementSpeed"></param>
- private void RefreshNoteJumpSpeed(float noteJumpMovementSpeed, float noteJumpStartBeatOffset)
- {
- BeatSaberUI.SetStatButtonText(_njsStatButton, String.Format("{0}", noteJumpMovementSpeed));
- BeatSaberUI.SetStatButtonText(_noteJumpStartBeatOffsetLabel, String.Format("{0}", noteJumpStartBeatOffset));
- }
- /// <summary>
- /// Update interactive state of the quick scroll buttons.
- /// </summary>
- private void RefreshQuickScrollButtons()
- {
- if (!_uiCreated)
- {
- return;
- }
- _pageUpFastButton.interactable = _beatUi.TableViewPageUpButton.interactable;
- _pageUpFastButton.gameObject.SetActive(_beatUi.TableViewPageUpButton.IsActive());
- _pageDownFastButton.interactable = _beatUi.TableViewPageDownButton.interactable;
- _pageDownFastButton.gameObject.SetActive(_beatUi.TableViewPageDownButton.IsActive());
- }
- /// <summary>
- /// TODO - evaluate this sillyness...
- /// </summary>
- /// <returns></returns>
- public IEnumerator RefreshQuickScrollButtonsAsync()
- {
- yield return new WaitForEndOfFrame();
- RefreshQuickScrollButtons();
- }
- /// <summary>
- /// Update delete button state. Enable for custom levels, disable for all else.
- /// </summary>
- /// <param name="levelId"></param>
- public void UpdateDeleteButtonState(String levelId)
- {
- if (_deleteButton == null)
- {
- return;
- }
- _deleteButton.gameObject.SetActive(levelId.Length >= 32);
- }
- /// <summary>
- /// Show the UI.
- /// </summary>
- public void Show()
- {
- Logger.Trace("Show SongBrowserUI()");
- this.SetVisibility(true);
- }
- /// <summary>
- /// Hide the UI.
- /// </summary>
- public void Hide()
- {
- Logger.Trace("Hide SongBrowserUI()");
- this.SetVisibility(false);
- }
- /// <summary>
- /// Handle showing or hiding UI logic.
- /// </summary>
- /// <param name="visible"></param>
- private void SetVisibility(bool visible)
- {
- // UI not created, nothing visible to hide...
- if (!_uiCreated)
- {
- return;
- }
- _ppStatButton?.gameObject.SetActive(visible);
- _starStatButton?.gameObject.SetActive(visible);
- _njsStatButton?.gameObject.SetActive(visible);
- RefreshOuterUIState(visible == true ? UIState.Main : UIState.Disabled);
- _deleteButton?.gameObject.SetActive(visible);
- _pageUpFastButton?.gameObject.SetActive(visible);
- _pageDownFastButton?.gameObject.SetActive(visible);
- }
- /// <summary>
- /// Update the top UI state.
- /// Hides the outer ui, sort, and filter buttons depending on the state.
- /// </summary>
- private void RefreshOuterUIState(UIState state)
- {
- bool sortButtons = false;
- bool filterButtons = false;
- bool outerButtons = false;
- bool clearButton = true;
- if (state == UIState.SortBy)
- {
- sortButtons = true;
- }
- else if (state == UIState.FilterBy)
- {
- filterButtons = true;
- }
- else if (state == UIState.Main)
- {
- outerButtons = true;
- }
- else
- {
- clearButton = false;
- }
- _sortButtonGroup.ForEach(x => x.Button.gameObject.SetActive(sortButtons));
- _filterButtonGroup.ForEach(x => x.Button.gameObject.SetActive(filterButtons));
- _sortByButton?.gameObject.SetActive(outerButtons);
- _sortByDisplay?.gameObject.SetActive(outerButtons);
- _filterByButton?.gameObject.SetActive(outerButtons);
- _filterByDisplay?.gameObject.SetActive(outerButtons);
- _clearSortFilterButton?.gameObject.SetActive(clearButton);
- _randomButton?.gameObject.SetActive(outerButtons);
- RefreshCurrentSelectionDisplay();
- _currentUiState = state;
- }
- /// <summary>
- /// Adjust the text field of the sort by and filter by displays.
- /// </summary>
- private void RefreshCurrentSelectionDisplay()
- {
- string sortByDisplay;
- if (_model.Settings.sortMode == SongSortMode.Default)
- {
- sortByDisplay = "Title";
- }
- else
- {
- sortByDisplay = _model.Settings.sortMode.ToString();
- }
- _sortByDisplay.SetButtonText(sortByDisplay);
- if (_model.Settings.filterMode != SongFilterMode.Custom)
- {
- // Custom SongFilterMod implies that another mod has modified the text of this button (do not overwrite)
- _filterByDisplay.SetButtonText(_model.Settings.filterMode.ToString());
- }
- }
- /// <summary>
- /// Adjust the UI colors.
- /// </summary>
- public void RefreshSortButtonUI()
- {
- if (!_uiCreated)
- {
- return;
- }
- foreach (SongSortButton sortButton in _sortButtonGroup)
- {
- if (sortButton.SortMode.NeedsScoreSaberData() && !SongDataCore.Plugin.Songs.IsDataAvailable())
- {
- sortButton.Button.SetButtonUnderlineColor(Color.gray);
- }
- else
- {
- sortButton.Button.SetButtonUnderlineColor(Color.white);
- }
- if (sortButton.SortMode == _model.Settings.sortMode)
- {
- if (this._model.Settings.invertSortResults)
- {
- sortButton.Button.SetButtonUnderlineColor(Color.red);
- }
- else
- {
- sortButton.Button.SetButtonUnderlineColor(Color.green);
- }
- }
- }
- foreach (SongFilterButton filterButton in _filterButtonGroup)
- {
- filterButton.Button.SetButtonUnderlineColor(Color.white);
- if (filterButton.FilterMode == _model.Settings.filterMode)
- {
- filterButton.Button.SetButtonUnderlineColor(Color.green);
- }
- }
- if (this._model.Settings.invertSortResults)
- {
- _sortByDisplay.SetButtonUnderlineColor(Color.red);
- }
- else
- {
- _sortByDisplay.SetButtonUnderlineColor(Color.green);
- }
- if (this._model.Settings.filterMode != SongFilterMode.None)
- {
- _filterByDisplay.SetButtonUnderlineColor(Color.green);
- }
- else
- {
- _filterByDisplay.SetButtonUnderlineColor(Color.white);
- }
- }
- /// <summary>
- ///
- /// </summary>
- public void RefreshSongList()
- {
- if (!_uiCreated)
- {
- return;
- }
- _beatUi.RefreshSongList(_model.LastSelectedLevelId);
- }
- /// <summary>
- /// Helper for updating the model (which updates the song list)
- /// </summary>
- public void UpdateLevelDataModel()
- {
- try
- {
- Logger.Trace("UpdateLevelDataModel()");
- // get a current beatmap characteristic...
- if (_model.CurrentBeatmapCharacteristicSO == null && _uiCreated)
- {
- _model.CurrentBeatmapCharacteristicSO = _beatUi.BeatmapCharacteristicSelectionViewController.GetPrivateField<BeatmapCharacteristicSO>("_selectedBeatmapCharacteristic");
- }
- _model.UpdateLevelRecords();
- }
- catch (Exception e)
- {
- Logger.Exception("SongBrowser UI crashed trying to update the internal song lists: ", e);
- }
- }
- /// <summary>
- /// Logic for fixing BeatSaber's level pack selection bugs.
- /// </summary>
- public bool UpdateLevelCollectionSelection()
- {
- if (_uiCreated)
- {
- IAnnotatedBeatmapLevelCollection currentSelected = _beatUi.GetCurrentSelectedAnnotatedBeatmapLevelCollection();
- Logger.Debug("Updating level collection, current selected level collection: {0}", currentSelected);
- // select category
- if (!String.IsNullOrEmpty(_model.Settings.currentLevelCategoryName))
- {
- _selectingCategory = true;
- _beatUi.SelectLevelCategory(_model.Settings.currentLevelCategoryName);
- _selectingCategory = false;
- }
- // select collection
- if (String.IsNullOrEmpty(_model.Settings.currentLevelCollectionName))
- {
- if (currentSelected == null && String.IsNullOrEmpty(_model.Settings.currentLevelCategoryName))
- {
- Logger.Debug("No level collection selected, acquiring the first available, likely OST1...");
- currentSelected = _beatUi.BeatmapLevelsModel.allLoadedBeatmapLevelPackCollection.beatmapLevelPacks[0];
- }
- }
- else if (currentSelected == null || (currentSelected.collectionName != _model.Settings.currentLevelCollectionName))
- {
- Logger.Debug("Automatically selecting level collection: {0}", _model.Settings.currentLevelCollectionName);
- _beatUi.LevelFilteringNavigationController.didSelectAnnotatedBeatmapLevelCollectionEvent -= _levelFilteringNavController_didSelectAnnotatedBeatmapLevelCollectionEvent;
- _lastLevelCollection = _beatUi.GetLevelCollectionByName(_model.Settings.currentLevelCollectionName);
- if (_lastLevelCollection as PreviewBeatmapLevelPackSO)
- {
- Hide();
- }
- _beatUi.SelectLevelCollection(_model.Settings.currentLevelCollectionName);
- _beatUi.LevelFilteringNavigationController.didSelectAnnotatedBeatmapLevelCollectionEvent += _levelFilteringNavController_didSelectAnnotatedBeatmapLevelCollectionEvent;
- }
- if (_lastLevelCollection == null)
- {
- if (currentSelected != null && currentSelected.collectionName != SongBrowserModel.FilteredSongsCollectionName && currentSelected.collectionName != SongBrowserModel.PlaylistSongsCollectionName)
- {
- _lastLevelCollection = currentSelected;
- }
- }
- Logger.Debug("Current Level Collection is: {0}", _lastLevelCollection);
- ProcessSongList();
- }
- return false;
- }
- }
- }
|