-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathSRM-SongSelection.diff
205 lines (181 loc) · 9.99 KB
/
SRM-SongSelection.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
diff --git a/EnhancedTwitchIntegration/SongRequestManager.csproj b/EnhancedTwitchIntegration/SongRequestManager.csproj
index 2ba0721..7e790e1 100644
--- a/EnhancedTwitchIntegration/SongRequestManager.csproj
+++ b/EnhancedTwitchIntegration/SongRequestManager.csproj
@@ -50,6 +50,9 @@
<Reference Include="IPA.Loader">
<HintPath>C:\Games\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\IPA.Loader.dll</HintPath>
</Reference>
+ <Reference Include="SongBrowser">
+ <HintPath>C:\Games\Steam\steamapps\common\Beat Saber\Plugins\SongBrowser.dll</HintPath>
+ </Reference>
<Reference Include="SongCore, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Games\Steam\steamapps\common\Beat Saber\Plugins\SongCore.dll</HintPath>
diff --git a/EnhancedTwitchIntegration/UI/SongListUtils.cs b/EnhancedTwitchIntegration/UI/SongListUtils.cs
index 9c1382f..54f587b 100644
--- a/EnhancedTwitchIntegration/UI/SongListUtils.cs
+++ b/EnhancedTwitchIntegration/UI/SongListUtils.cs
@@ -6,7 +6,7 @@ using System;
using System.Collections;
using System.Linq;
using UnityEngine;
-using SongLoaderPlugin;
+using IPA.Utilities;
namespace SongRequestManager
{
@@ -53,14 +53,18 @@ namespace SongRequestManager
private enum SongBrowserAction { ResetFilter = 1 }
private static void ExecuteSongBrowserAction(SongBrowserAction action)
{
- //var _songBrowserUI = SongBrowserApplication.Instance.GetPrivateField<SongBrowser.UI.SongBrowserUI>("_songBrowserUI");
- //if (_songBrowserUI)
- //{
- // if (action.HasFlag(SongBrowserAction.ResetFilter))
- // {
- // _songBrowserUI.Model.Settings.filterMode = SongFilterMode.None;
- // }
- //}
+ var _songBrowserUI = SongBrowser.SongBrowserApplication.Instance.GetPrivateField<SongBrowser.UI.SongBrowserUI>("_songBrowserUI");
+ if (_songBrowserUI)
+ {
+ if (action.HasFlag(SongBrowserAction.ResetFilter))
+ {
+ // if filter mode is set, clear it
+ if (_songBrowserUI.Model.Settings.filterMode != SongBrowser.DataAccess.SongFilterMode.None)
+ {
+ _songBrowserUI.InvokePrivateMethod("OnClearButtonClickEvent");
+ }
+ }
+ }
}
private enum SongDownloaderAction { ResetFilter = 1 }
@@ -79,11 +83,11 @@ namespace SongRequestManager
public static IEnumerator RetrieveNewSong(string songFolderName, bool resetFilterMode = false)
{
- if (!SongLoader.AreSongsLoaded) yield break;
+ if (!SongLoaderPlugin.SongLoader.AreSongsLoaded) yield break;
if (!_standardLevelListViewController) yield break;
-
- SongLoader.Instance.RetrieveNewSong(songFolderName);
+
+ SongLoaderPlugin.SongLoader.Instance.RetrieveNewSong(songFolderName);
//// If beatsaver downloader is installed and songbrowser isnt, then we need to change the filter mode through it
//if (resetFilterMode)
@@ -103,16 +107,16 @@ namespace SongRequestManager
public static IEnumerator RefreshSongs(bool fullRefresh = false, bool selectOldLevel = true)
{
- if (!SongLoader.AreSongsLoaded) yield break;
+ if (!SongLoaderPlugin.SongLoader.AreSongsLoaded) yield break;
if (!_standardLevelListViewController) yield break;
// // Grab the currently selected level id so we can restore it after refreshing
// string selectedLevelId = _standardLevelListViewController.selectedLevel?.levelID;
// Wait until song loader is finished loading, then refresh the song list
- while (SongLoader.AreSongsLoading) yield return null;
- SongLoader.Instance.RefreshSongs(fullRefresh);
- while (SongLoader.AreSongsLoading) yield return null;
+ while (SongLoaderPlugin.SongLoader.AreSongsLoading) yield return null;
+ SongLoaderPlugin.SongLoader.Instance.RefreshSongs(fullRefresh);
+ while (SongLoaderPlugin.SongLoader.AreSongsLoading) yield return null;
//// Set the row index to the previously selected song
@@ -120,16 +124,13 @@ namespace SongRequestManager
// ScrollToLevel(selectedLevelId);
}
- public static void SelectCustomSongPack(bool resetFilters = true)
+ public static int SelectCustomSongPack(bool resetFilters = true)
{
var levelPacksTableView = Resources.FindObjectsOfTypeAll<LevelPacksTableView>().First();
var tableView = levelPacksTableView.GetPrivateField<TableView>("_tableView");
var packsCollection = levelPacksTableView.GetPrivateField<IBeatmapLevelPackCollection>("_levelPackCollection");
- int customSongPackIndex = -1;
- for(int i=0; i< packsCollection.beatmapLevelPacks.Length; i++)
- if(packsCollection.beatmapLevelPacks[i].packName == "Modded Custom Maps")
- customSongPackIndex = i;
+ var customSongPackIndex = Array.FindIndex(packsCollection.beatmapLevelPacks, x => x.packID == "ModdedCustomMaps");
if (customSongPackIndex != -1 && levelPacksTableView.GetPrivateField<int>("_selectedColumn") != customSongPackIndex)
{
@@ -141,12 +142,29 @@ namespace SongRequestManager
//// If song browser is installed, update/refresh it
if (_songBrowserInstalled)
+ {
ExecuteSongBrowserAction(SongBrowserAction.ResetFilter);
+ }
//// If beatsaver downloader is installed and songbrowser isnt, then we need to change the filter mode through it
else if (_songDownloaderInstalled)
- ExecuteSongDownloaderAction(SongDownloaderAction.ResetFilter);
+ {
+ // get levels for selected pack
+ var packWithLevels = BeatSaverDownloaderGetLevelPackWithLevels();
+
+ // force an update to the levels
+ _standardLevelListViewController.SetData(packWithLevels);
+ }
+
+ return customSongPackIndex;
}
-
+
+ private static BeatmapLevelPackSO BeatSaverDownloaderGetLevelPackWithLevels()
+ {
+ var levels = SongLoaderPlugin.SongLoader.CustomBeatmapLevelPackSO.beatmapLevelCollection.beatmapLevels.Cast<BeatmapLevelSO>().ToArray();
+ var pack = SongLoaderPlugin.SongLoader.CustomBeatmapLevelPackCollectionSO.beatmapLevelPacks.First(x => x.packID == "ModdedCustomMaps");
+ return BeatSaverDownloader.Misc.CustomHelpers.GetLevelPackWithLevels(levels, "Custom Songs", pack.coverImage);
+ }
+
public static int GetLevelIndex(LevelPackLevelsViewController table, string levelID)
{
for (int i = 0; i < table.levelPack.beatmapLevelCollection.beatmapLevels.Length; i++)
@@ -167,27 +185,37 @@ namespace SongRequestManager
Plugin.Log($"Scrolling to {levelID}! Retry={isRetry}");
- SelectCustomSongPack();
+ var packIndex = SelectCustomSongPack();
- TableView tableView = _standardLevelListViewController.GetComponentInChildren<TableView>();
- tableView.ReloadData();
+ yield return null;
- var levels = _standardLevelListViewController.levelPack.beatmapLevelCollection.beatmapLevels.Where(l => l.levelID == levelID).ToArray();
+ // get the table view
+ var levelsTableView = _standardLevelListViewController.GetPrivateField<LevelPackLevelsTableView>("_levelPackLevelsTableView");
- if (levels.Length > 0)
- {
-
- int row = GetLevelIndex(_standardLevelListViewController, levelID);
+ // get the table view
+ var tableView = levelsTableView.GetPrivateField<TableView>("_tableView");
- Plugin.Log($"Row={row}");
+ // get the row number for the song we want
+ var songIndex = Array.FindIndex(SongLoaderPlugin.SongLoader.CustomBeatmapLevelPackCollectionSO.beatmapLevelPacks[packIndex].beatmapLevelCollection.beatmapLevels, x => x.levelID == levelID);
- if (row != -1)
+ // bail if song is not found, shouldn't happen
+ if (songIndex >= 0)
+ {
+ // if header is being shown, increment row
+ if (levelsTableView.GetPrivateField<bool>("_showLevelPackHeader"))
{
- tableView.SelectCellWithIdx(row, true);
- tableView.ScrollToCellWithIdx(row, TableView.ScrollPositionType.Beginning, animated);
- callback?.Invoke(true);
- yield break;
+ songIndex++;
}
+
+ // scroll to song
+ tableView.ScrollToCellWithIdx(songIndex, TableView.ScrollPositionType.Beginning, animated);
+
+ // select song, and fire the event
+ tableView.SelectCellWithIdx(songIndex, true);
+
+ Plugin.Log("Selected song with index " + songIndex);
+ callback?.Invoke(true);
+ yield break;
}
}
@@ -198,9 +226,9 @@ namespace SongRequestManager
yield break;
}
- var tempLevels = SongLoader.CustomLevels.Where(l => l.levelID == levelID).ToArray();
+ var tempLevels = SongLoaderPlugin.SongLoader.CustomLevels.Where(l => l.levelID == levelID).ToArray();
foreach (var l in tempLevels)
- SongLoader.CustomLevels.Remove(l);
+ SongLoaderPlugin.SongLoader.CustomLevels.Remove(l);
Plugin.Log($"Failed to scroll to {levelID}!");
callback?.Invoke(false);