Skip to content

Commit d72abcb

Browse files
committed
Made Validation create error noise when wrong. Made sorting options description dynamic to enum types. Made sure changing setting refreshes the UI. Made sure the correct replay was selected after refresh. Made sure the metadata lerp actually gets overwritten correctly TwT. Separated sorting options into a reverse direction option. Made favorites option not overwrite sorting. Added a local player bool to player info.
1 parent a2c4fcb commit d72abcb

6 files changed

Lines changed: 47 additions & 46 deletions

File tree

512 Bytes
Binary file not shown.

src/Core/Main.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ public class Validation : ValidationParameters
4949
{
5050
public override bool DoValidation(string Input)
5151
{
52-
return Enum.TryParse(typeof(ReplayExplorer.SortingType), Input, true, out _);
52+
if (Enum.TryParse(typeof(ReplayExplorer.SortingType), Input, true, out _))
53+
{
54+
Main.ReplayError();
55+
return true;
56+
}
57+
58+
return false;
5359
}
5460
}
5561

@@ -113,6 +119,7 @@ public class Main : MelonMod
113119

114120
// Replay Explorer
115121
public ModSetting<string> ExplorerSorting = new();
122+
public ModSetting<bool> SortingDirection = new();
116123
public ModSetting<bool> FavoritesFirst = new();
117124

118125
// Replay Buffer
@@ -448,21 +455,16 @@ public void OnUIInitialized()
448455
string sortingOptionDesc =
449456
"The sorting option for the list of replays.\n" +
450457
"Available options:\n" +
451-
"NameAscending\n" +
452-
"NameDescending\n" +
453-
"DateNewestFirst\n" +
454-
"DateOldestFirst\n" +
455-
"DurationLongestFirst\n" +
456-
"DurationShortestFirst\n" +
457-
"MapAscending\n" +
458-
"PlayerCountDescending";
458+
string.Join("\n", Enum.GetNames(typeof(ReplayExplorer.SortingType)));
459459

460460
ExplorerSorting = replayMod.AddToList("Sorting Option", "DateNewestFirst", sortingOptionDesc, new Tags());
461+
SortingDirection = replayMod.AddToList("Reverse Sorting", false, 0, "If enabled, reverses the sort order.", new Tags());
461462
FavoritesFirst = replayMod.AddToList("Put Favorites First", true, 0, "Toggles whether favorited replays should always come first in the list.", new Tags());
462463

463464
replayMod.AddValidation("Sorting Option", new Validation());
464465

465466
replayExplorerFolder.AddSetting(ExplorerSorting);
467+
replayExplorerFolder.AddSetting(SortingDirection);
466468
replayExplorerFolder.AddSetting(FavoritesFirst);
467469

468470
var replayBufferFolder = replayMod.AddFolder("Replay Buffer", "Settings for the replay buffer used to save recent gameplay.");
@@ -558,6 +560,10 @@ bool IsValidBindingList(string input)
558560
ReplayError($"'{value}' is not a valid binding (Right Controller).");
559561
};
560562

563+
ExplorerSorting.SavedValueChanged += (obj, sender) => ReplayFiles.ReloadReplays();
564+
SortingDirection.SavedValueChanged += (obj, sender) => ReplayFiles.ReloadReplays();
565+
FavoritesFirst.SavedValueChanged += (obj, sender) => ReplayFiles.ReloadReplays();
566+
561567
replayMod.GetFromFile();
562568

563569
UI.instance.AddMod(replayMod);
@@ -1505,8 +1511,7 @@ public void LoadReplayObjects()
15051511

15061512
ReplaySettings.favoritedIcon.SetActive(!isFavorited);
15071513

1508-
ReplayFiles.explorer.Refresh();
1509-
ReplayFiles.RefreshUI();
1514+
ReplayFiles.ReloadReplays();
15101515
}));
15111516

15121517
ReplaySettings.replaySettingsGO = replaySettingsGO;

src/Replay/Files/ReplayExplorer.cs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,12 @@ public class ReplayExplorer
2323

2424
public enum SortingType
2525
{
26-
NameAscending,
27-
NameDescending,
28-
29-
DateNewestFirst,
30-
DateOldestFirst,
31-
32-
DurationLongestFirst,
33-
DurationShortestFirst,
34-
35-
MapAscending,
36-
PlayerCountDescending
26+
Name,
27+
Date,
28+
Duration,
29+
Map,
30+
PlayerCount,
31+
OpponentBP,
3732
}
3833

3934
public string CurrentReplayPath =>
@@ -61,7 +56,7 @@ public void Refresh()
6156
currentIndex = Clamp(currentIndex, -1, currentReplayEntries.Count - 1);
6257
}
6358

64-
public List<Entry> GetEntries(SortingType sorting = SortingType.DateNewestFirst)
59+
public List<Entry> GetEntries(SortingType sorting = SortingType.Date)
6560
{
6661
var folders = Directory
6762
.GetDirectories(CurrentFolderPath)
@@ -107,24 +102,27 @@ public List<Entry> GetEntries(SortingType sorting = SortingType.DateNewestFirst)
107102

108103
private List<Entry> SortFiles(List<Entry> files, SortingType sorting)
109104
{
105+
if ((bool)Main.instance.FavoritesFirst.SavedValue)
106+
files = files.OrderByDescending(f => f.header.isFavorited).ToList();
107+
110108
var newFiles = sorting switch
111109
{
112-
SortingType.NameAscending => files.OrderBy(f => f.Name).ToList(),
113-
SortingType.NameDescending => files.OrderByDescending(f => f.Name).ToList(),
114-
115-
SortingType.DateNewestFirst => files.OrderByDescending(f => File.GetLastWriteTimeUtc(f.FullPath)).ToList(),
116-
SortingType.DateOldestFirst => files.OrderBy(f => File.GetLastWriteTimeUtc(f.FullPath)).ToList(),
117-
118-
SortingType.DurationLongestFirst => files.OrderByDescending(f => f.header.Duration).ToList(),
119-
SortingType.DurationShortestFirst => files.OrderBy(f => f.header.Duration).ToList(),
120-
121-
SortingType.MapAscending => files.OrderBy(f => ReplayFormatting.GetMapName(header: f.header), StringComparer.OrdinalIgnoreCase).ToList(),
122-
SortingType.PlayerCountDescending => files.OrderByDescending(f => f.header.Players?.Length).ToList(),
110+
SortingType.Name => files.OrderBy(f => f.Name).ToList(),
111+
SortingType.Date => files.OrderByDescending(f => File.GetLastWriteTimeUtc(f.FullPath)).ToList(),
112+
SortingType.Duration => files.OrderByDescending(f => f.header.Duration).ToList(),
113+
SortingType.Map => files.OrderBy(f => ReplayFormatting.GetMapName(header: f.header), StringComparer.OrdinalIgnoreCase).ToList(),
114+
SortingType.PlayerCount => files.OrderByDescending(f => f.header.Players?.Length).ToList(),
115+
SortingType.OpponentBP => files.OrderByDescending(f => f.header.Players
116+
.Where(p => !p.IsLocal)
117+
.Select(p => p.BattlePoints)
118+
.DefaultIfEmpty(0).Max()
119+
).ToList(),
123120

124121
_ => files
125122
};
126123

127-
newFiles = newFiles.OrderByDescending(f => f.header.isFavorited).ToList();
124+
if ((bool)Main.instance.SortingDirection.SavedValue)
125+
newFiles.Reverse();
128126

129127
return newFiles;
130128
}

src/Replay/Files/ReplayFiles.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.IO;
55
using System.Linq;
66
using Il2CppRUMBLE.Interactions.InteractionBase;
7-
using Il2CppRUMBLE.Players.Subsystems;
87
using Il2CppRUMBLE.Social.Phone;
98
using Il2CppTMPro;
109
using MelonLoader;
@@ -197,7 +196,7 @@ public static void HideMetadata()
197196
if (metadataScaleRoutine != null)
198197
MelonCoroutines.Stop(metadataScaleRoutine);
199198

200-
MelonCoroutines.Start(Utilities.LerpValue(
199+
metadataHeightRoutine = MelonCoroutines.Start(Utilities.LerpValue(
201200
() => table.desiredMetadataTextHeight,
202201
v => table.desiredMetadataTextHeight = v,
203202
Lerp,
@@ -206,7 +205,7 @@ public static void HideMetadata()
206205
Utilities.EaseInOut
207206
));
208207

209-
MelonCoroutines.Start(Utilities.LerpValue(
208+
metadataScaleRoutine = MelonCoroutines.Start(Utilities.LerpValue(
210209
() => table.metadataText.transform.localScale,
211210
v => table.metadataText.transform.localScale = v,
212211
Vector3.Lerp,
@@ -371,11 +370,7 @@ public static void ReloadReplays()
371370
{
372371
int newIndex = explorer.currentReplayEntries
373372
.Select((entry, i) => new { entry, i })
374-
.FirstOrDefault(x =>
375-
{
376-
var header = ReplayArchive.GetManifest(x.entry.FullPath);
377-
return header.Guid == previousGuid;
378-
})?.i ?? -1;
373+
.FirstOrDefault(x => x.entry.header?.Guid == previousGuid)?.i ?? -1;
379374

380375
explorer.Select(newIndex);
381376
}
@@ -392,6 +387,9 @@ public static void ReloadReplays()
392387

393388
public static void RefreshUI()
394389
{
390+
if (ReplaySettings.replayExplorerGO == null)
391+
return;
392+
395393
var page = explorer.GetPage();
396394
var tags = ReplaySettings.replayExplorerGO.GetComponentsInChildren<PlayerTag>(true);
397395

src/Replay/Serialization/ReplaySerializer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,7 @@ public class PlayerInfo
11761176
public PlayerMeasurement Measurement;
11771177

11781178
public bool WasHost;
1179+
public bool IsLocal;
11791180

11801181
public PlayerInfo(Player copyPlayer)
11811182
{
@@ -1188,6 +1189,7 @@ public PlayerInfo(Player copyPlayer)
11881189
EquippedShiftStones = player.EquipedShiftStones.ToArray();
11891190
Measurement = player.PlayerMeasurement;
11901191
WasHost = (player.GeneralData.ActorNo == PhotonNetwork.MasterClient?.ActorNumber);
1192+
IsLocal = player.GeneralData.PlayFabMasterId == Main.LocalPlayer.Data.GeneralData.PlayFabMasterId;
11911193
}
11921194

11931195
[JsonConstructor]

src/Replay/UI/ReplaySettings.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using ReplayMod.Replay.Files;
1717
using ReplayMod.Replay.Serialization;
1818
using UnityEngine;
19-
using UnityEngine.VFX;
2019
using static UnityEngine.Mathf;
2120
using Main = ReplayMod.Core.Main;
2221

@@ -227,8 +226,7 @@ private void TryRename(string newName)
227226
currentPath = newPath;
228227
Show(currentPath);
229228

230-
ReplayFiles.explorer.Refresh();
231-
ReplayFiles.RefreshUI();
229+
ReplayFiles.ReloadReplays();
232230

233231
ReplayAPI.ReplayRenamedInternal(currentHeader, newPath);
234232

0 commit comments

Comments
 (0)