Skip to content

Commit 15ea2cf

Browse files
Playlist Options menu (v1.1.0.0)
* Add Playlist Options menu (accessible from the level grid view with MenuStart). * Includes options to change display name and color. * Includes options to rename playlist file or delete playlist file. * Last-accessed playlist is now remembered when coming back to the level grid menu. * Can now change display name when using Quick Playlist feature. * Playlist names and file paths are now handled independently. Changing one will not overwrite the other and vice-versa. * Fixed instance where Quick Playlist display name would revert back to "QUICK PLAYLIST..." after adding(or removing?) a level (when working with a loaded playlist). * Option to show hidden sprint campaign level sets.
1 parent 320592a commit 15ea2cf

37 files changed

+2769
-16
lines changed

Distance.LevelSelectAdditions/ConfigurationLogic.cs

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Reactor.API.Configuration;
1+
using Distance.LevelSelectAdditions.Events;
2+
using Distance.LevelSelectAdditions.Sorting;
3+
using Reactor.API.Configuration;
24
using System;
35
using System.Collections;
46
using System.Collections.Generic;
@@ -97,6 +99,32 @@ public int RecentDownloadsLevelLimit
9799
set => Set(RecentDownloadsLevelLimit_ID, value);
98100
}*/
99101

102+
103+
104+
private const string EnableTheOtherSideSprintCampaign_ID = "levelsets.enable_extra_sprint_campaigns";
105+
public bool EnableTheOtherSideSprintCampaign
106+
{
107+
get => Get<bool>(EnableTheOtherSideSprintCampaign_ID);
108+
set => Set(EnableTheOtherSideSprintCampaign_ID, value);
109+
}
110+
111+
/*private const string LevelSetSettingsTable_ID = "levelsets.options";
112+
public Dictionary<LevelSelectMenuAbstract.DisplayType, Dictionary<GameModeID, string>> LevelSetSettingsTable
113+
{
114+
get => Convert(LevelSetSettingsTable_ID, new Dictionary<LevelSelectMenuAbstract.DisplayType, Dictionary<GameModeID, string>>(), overwriteNull: true);
115+
set => Set(LevelSetSettingsTable_ID, value);
116+
}*/
117+
118+
private const string State_LastLevelSets_ID = "state.last_levelsets";
119+
public Dictionary<LevelSelectMenuAbstract.DisplayType, Dictionary<GameModeID, string>> State_LastLevelSetIDs
120+
{
121+
get => Convert(State_LastLevelSets_ID, new Dictionary<LevelSelectMenuAbstract.DisplayType, Dictionary<GameModeID, string>>(), overwriteNull: true);
122+
set => Set(State_LastLevelSets_ID, value);
123+
}
124+
125+
// No config option for this yet
126+
public bool EnableLevelSetOptionsMenu => true;
127+
100128
#endregion
101129

102130
#region Helpers
@@ -110,6 +138,7 @@ public SortingMethod[] GetWorkshopSortingMethods()
110138
WorkshopSortingMethod3,
111139
};
112140
}
141+
113142
public bool[] GetWorkshopReverseSortingMethods()
114143
{
115144
return new bool[]
@@ -120,6 +149,30 @@ public bool[] GetWorkshopReverseSortingMethods()
120149
};
121150
}
122151

152+
public string GetStateLastLevelSetID(LevelSelectMenuAbstract.DisplayType displayType, GameModeID modeID)
153+
{
154+
if (State_LastLevelSetIDs.TryGetValue(displayType, out var lastPlaylists_mode))
155+
{
156+
if (lastPlaylists_mode.TryGetValue(modeID, out string pathName))
157+
{
158+
return pathName;
159+
}
160+
}
161+
return null;
162+
}
163+
164+
public void SetStateLastLevelSetID(LevelSelectMenuAbstract.DisplayType displayType, GameModeID modeID, string pathName)
165+
{
166+
var lastPlaylists_display = State_LastLevelSetIDs;
167+
if (!lastPlaylists_display.TryGetValue(displayType, out Dictionary<GameModeID, string> lastPlaylists_mode))
168+
{
169+
lastPlaylists_mode = new Dictionary<GameModeID, string>();
170+
lastPlaylists_display[displayType] = lastPlaylists_mode;
171+
}
172+
lastPlaylists_mode[modeID] = pathName;
173+
this.Save(); // auto save
174+
}
175+
123176
#endregion
124177

125178
internal Settings Config;
@@ -131,8 +184,47 @@ private void Load()
131184
Config = new Settings("Config");// Mod.FullName);
132185
}
133186

187+
private void OnPlaylistFileRenamed(PlaylistFileRenamed.Data data)
188+
{
189+
var lastPlaylists_display = State_LastLevelSetIDs;
190+
// Use ToArray to enumerate with foreach and allow updating values.
191+
foreach (var displayPair in lastPlaylists_display.ToArray())
192+
{
193+
foreach (var modePair in displayPair.Value.ToArray())
194+
{
195+
if (modePair.Value == data.oldLevelSetID)
196+
{
197+
lastPlaylists_display[displayPair.Key][modePair.Key] = data.newLevelSetID;
198+
}
199+
}
200+
}
201+
202+
//TODO: When LevelSetOptions dictionary gets added, enumerate over and rename here too.
203+
}
204+
205+
private void OnPlaylistFileDeleted(PlaylistFileDeleted.Data data)
206+
{
207+
var lastPlaylists_display = State_LastLevelSetIDs;
208+
// Use ToArray to enumerate with foreach and allow updating values.
209+
foreach (var displayPair in lastPlaylists_display.ToArray())
210+
{
211+
foreach (var modePair in displayPair.Value.ToArray())
212+
{
213+
if (modePair.Value == data.levelSetID)
214+
{
215+
lastPlaylists_display[displayPair.Key][modePair.Key] = null;
216+
}
217+
}
218+
}
219+
220+
//TODO: When LevelSetOptions dictionary gets added, enumerate over and delete here too.
221+
}
222+
134223
public void Awake()
135224
{
225+
PlaylistFileRenamed.Subscribe(OnPlaylistFileRenamed);
226+
PlaylistFileDeleted.Subscribe(OnPlaylistFileDeleted);
227+
136228
Load();
137229

138230
// Assign default settings (if not already assigned).
@@ -144,6 +236,7 @@ public void Awake()
144236
Get(WorkshopReverseSortingMethod_ID, false);
145237
Get(WorkshopReverseSortingMethod2_ID, false);
146238
Get(WorkshopReverseSortingMethod3_ID, false);
239+
Get(EnableTheOtherSideSprintCampaign_ID, false);
147240

148241
// Save settings, and any defaults that may have been added.
149242
Save();
@@ -154,6 +247,19 @@ public T Get<T>(string key, T @default = default)
154247
return Config.GetOrCreate(key, @default);
155248
}
156249

250+
public T Convert<T>(string key, T @default = default, bool overwriteNull = false)
251+
{
252+
// Assign the object back after conversion, this allows for deep nested settings
253+
// that can be preserved and updated without reassigning to the root property.
254+
var value = Config.GetOrCreate(key, @default);
255+
if (overwriteNull && value == null)
256+
{
257+
value = @default;
258+
}
259+
Config[key] = value;
260+
return value;
261+
}
262+
157263
public void Set<T>(string key, T value)
158264
{
159265
Config[key] = value;

Distance.LevelSelectAdditions/Distance.LevelSelectAdditions.csproj

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,40 @@
8787
</ItemGroup>
8888
<ItemGroup>
8989
<Compile Include="ConfigurationLogic.cs" />
90+
<Compile Include="Events\PlaylistColorChanged.cs" />
91+
<Compile Include="Events\PlaylistNameChanged.cs" />
92+
<Compile Include="Events\PlaylistFileDeleted.cs" />
93+
<Compile Include="Events\PlaylistFileRenamed.cs" />
94+
<Compile Include="Extensions\Assembly-CSharp\LevelPlaylist.cs" />
95+
<Compile Include="Extensions\Assembly-CSharp\NGUIExtensions.cs" />
96+
<Compile Include="Extensions\mscorlib\System\String.cs" />
97+
<Compile Include="Harmony\Assembly-CSharp\LevelGridGrid\PushGrid.cs" />
9098
<Compile Include="Harmony\Assembly-CSharp\LevelGridMenu\CreateAndAddLevelSet.cs" />
99+
<Compile Include="Harmony\Assembly-CSharp\LevelGridMenu\CreateEntries.cs" />
100+
<Compile Include="Harmony\Assembly-CSharp\LevelGridMenu\Display.cs" />
101+
<Compile Include="Harmony\Assembly-CSharp\LevelGridMenu\OnLevelEntrySelected.cs" />
102+
<Compile Include="Harmony\Assembly-CSharp\LevelGridMenu\PlaylistEntry\ctor.cs" />
103+
<Compile Include="Harmony\Assembly-CSharp\LevelGridMenu\PlaylistEntry\get_Color_.cs" />
104+
<Compile Include="Harmony\Assembly-CSharp\LevelPlaylist\Create.cs" />
105+
<Compile Include="Harmony\Assembly-CSharp\LevelPlaylist\Load.cs" />
106+
<Compile Include="Harmony\Assembly-CSharp\LevelPlaylist\Save.cs" />
107+
<Compile Include="Harmony\Assembly-CSharp\LevelSelectMenuLogic\ClearTempPlaylist.cs" />
108+
<Compile Include="Harmony\Assembly-CSharp\LevelSelectMenuLogic\OnLevelPlaylistMenuClickLoad.cs" />
109+
<Compile Include="Harmony\Assembly-CSharp\LevelSelectMenuLogic\OnLevelPlaylistMenuClickSave.cs" />
110+
<Compile Include="Harmony\Assembly-CSharp\LevelSelectMenuLogic\SetupLevelPlaylistVisuals.cs" />
111+
<Compile Include="Harmony\Assembly-CSharp\LevelSelectMenuLogic\Start.cs" />
112+
<Compile Include="Harmony\Assembly-CSharp\OptionsMenuLogic\GetSubmenus.cs" />
113+
<Compile Include="Helpers\Sanitizer.cs" />
91114
<Compile Include="Mod.cs" />
92-
<Compile Include="LevelFilter.cs" />
93-
<Compile Include="LevelSort.cs" />
115+
<Compile Include="Scripts\LevelPlaylistEntryUpdateLogic.cs" />
116+
<Compile Include="Scripts\Menus\LevelSetMenuType.cs" />
117+
<Compile Include="Sorting\LevelFilter.cs" />
118+
<Compile Include="Sorting\LevelSort.cs" />
94119
<Compile Include="Properties\AssemblyInfo.cs" />
120+
<Compile Include="Scripts\LevelGridLevelSetOptionsLogic.cs" />
121+
<Compile Include="Scripts\LevelPlaylistCompoundData.cs" />
122+
<Compile Include="Scripts\LevelPlaylistSelectRenameLogic.cs" />
123+
<Compile Include="Scripts\Menus\LevelSetOptionsMenu.cs" />
95124
</ItemGroup>
96125
<ItemGroup>
97126
<None Include="Distance.LevelSelectAdditions.targets" />
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Distance.LevelSelectAdditions.Extensions;
2+
using Events;
3+
using UnityEngine;
4+
5+
namespace Distance.LevelSelectAdditions.Events
6+
{
7+
public class PlaylistColorChanged : StaticEvent<PlaylistColorChanged.Data>
8+
{
9+
public struct Data
10+
{
11+
public LevelPlaylist playlist;
12+
13+
public string levelSetID;
14+
15+
public Color? oldColor;
16+
17+
public string oldNameColored;
18+
19+
public Color? newColor;
20+
21+
public string newNameColored;
22+
23+
public Data(LevelPlaylist playlist, Color? oldColor, string oldNameColored, Color? newColor)
24+
{
25+
this.playlist = playlist;
26+
this.levelSetID = playlist.GetLevelSetID();
27+
this.oldColor = oldColor;
28+
this.oldNameColored = oldNameColored;
29+
this.newColor = newColor;
30+
this.newNameColored = playlist.Name_;
31+
}
32+
}
33+
}
34+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Events;
2+
3+
namespace Distance.LevelSelectAdditions.Events
4+
{
5+
public class PlaylistFileDeleted : StaticEvent<PlaylistFileDeleted.Data>
6+
{
7+
public struct Data
8+
{
9+
public string filePath;
10+
11+
public string levelSetID;
12+
13+
public string name;
14+
15+
public Data(string oldFilePath, string oldLevelSetID, string name)
16+
{
17+
this.filePath = oldFilePath;
18+
this.levelSetID = oldLevelSetID;
19+
this.name = oldLevelSetID;
20+
}
21+
}
22+
}
23+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Distance.LevelSelectAdditions.Extensions;
2+
using Distance.LevelSelectAdditions.Scripts;
3+
using Events;
4+
5+
namespace Distance.LevelSelectAdditions.Events
6+
{
7+
public class PlaylistFileRenamed : StaticEvent<PlaylistFileRenamed.Data>
8+
{
9+
public struct Data
10+
{
11+
public LevelPlaylist playlist;
12+
13+
public string oldFilePath;
14+
15+
public string oldLevelSetID;
16+
17+
public string newFilePath;
18+
19+
public string newLevelSetID;
20+
21+
public Data(LevelPlaylist playlist, string oldFilePath, string oldLevelSetID)
22+
{
23+
this.playlist = playlist;
24+
this.oldFilePath = oldFilePath;
25+
this.oldLevelSetID = oldLevelSetID;
26+
this.newFilePath = playlist.GetComponent<LevelPlaylistCompoundData>().FilePath;
27+
this.newLevelSetID = playlist.GetLevelSetID();
28+
}
29+
}
30+
}
31+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Distance.LevelSelectAdditions.Extensions;
2+
using Events;
3+
4+
namespace Distance.LevelSelectAdditions.Events
5+
{
6+
public class PlaylistNameChanged : StaticEvent<PlaylistNameChanged.Data>
7+
{
8+
public struct Data
9+
{
10+
public LevelPlaylist playlist;
11+
12+
public string levelSetID;
13+
14+
public string oldNameColored;
15+
16+
public string oldNameUncolored;
17+
18+
public string newNameColored;
19+
20+
public string newNameUncolored;
21+
22+
public Data(LevelPlaylist playlist, string oldNameColored)
23+
{
24+
this.playlist = playlist;
25+
this.levelSetID = playlist.GetLevelSetID();
26+
this.oldNameColored = oldNameColored;
27+
this.oldNameColored.DecodeNGUIColor(out this.oldNameUncolored, out _, out _);
28+
this.newNameColored = playlist.Name_;
29+
this.newNameColored.DecodeNGUIColor(out this.newNameUncolored, out _, out _);
30+
}
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)