[+] toggle the display of self-made charts

This commit is contained in:
Clansty
2024-09-05 02:31:07 +08:00
parent ca425cf949
commit e8307cdcd9
11 changed files with 198 additions and 20 deletions

View File

@@ -0,0 +1,80 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using AquaMai.Helpers;
using HarmonyLib;
using Manager;
using MelonLoader;
using Process;
using UnityEngine;
using Util;
namespace AquaMai.UX;
public class HideSelfMadeCharts
{
private static Safe.ReadonlySortedDictionary<int, Manager.MaiStudio.MusicData> _musics;
private static Safe.ReadonlySortedDictionary<int, Manager.MaiStudio.MusicData> _musicsNoneSelfMade;
private static bool isShowSelfMadeCharts = true;
[HarmonyPostfix]
[HarmonyPatch(typeof(DataManager), "GetMusics")]
public static void GetMusics(ref Safe.ReadonlySortedDictionary<int, Manager.MaiStudio.MusicData> __result, List<string> ____targetDirs)
{
if (_musics is null)
{
// init musics for the first time
if (__result.Count == 0) return;
_musics = __result;
var nonSelfMadeList = new SortedDictionary<int, Manager.MaiStudio.MusicData>();
var officialDirs = ____targetDirs.Where(it => File.Exists(Path.Combine(it, "DataConfig.xml")) || File.Exists(Path.Combine(it, "OfficialChartsMark.txt")));
foreach (var music in __result)
{
if (officialDirs.Any(it => MusicDirHelper.LookupPath(music.Value).StartsWith(it)))
{
nonSelfMadeList.Add(music.Key, music.Value);
}
}
_musicsNoneSelfMade = new Safe.ReadonlySortedDictionary<int, Manager.MaiStudio.MusicData>(nonSelfMadeList);
MelonLogger.Msg($"[HideSelfMadeCharts] All music count: {__result.Count}, Official music count: {_musicsNoneSelfMade.Count}");
}
var stackTrace = new StackTrace(); // get call stack
var stackFrames = stackTrace.GetFrames(); // get method calls (frames)
if (stackFrames.All(it => it.GetMethod().DeclaringType.Name != "MusicSelectProcess")) return;
if (isShowSelfMadeCharts) return;
__result = _musicsNoneSelfMade;
}
private static int _keyPressFrames;
[HarmonyPostfix]
[HarmonyPatch(typeof(MusicSelectProcess), "OnUpdate")]
public static void MusicSelectProcessOnUpdate(ref MusicSelectProcess __instance)
{
if (Input.GetKey(KeyCode.Alpha7) || InputManager.GetSystemInputPush(InputManager.SystemButtonSetting.ButtonService))
{
_keyPressFrames++;
}
else if (_keyPressFrames is > 0 and < 30 && !Input.GetKey(KeyCode.Alpha7) && !InputManager.GetSystemInputPush(InputManager.SystemButtonSetting.ButtonService))
{
_keyPressFrames = 0;
isShowSelfMadeCharts = !isShowSelfMadeCharts;
MelonLogger.Msg($"[HideSelfMadeCharts] isShowSelfMadeCharts: {isShowSelfMadeCharts}");
SharedInstances.ProcessDataContainer.processManager.AddProcess(new FadeProcess(SharedInstances.ProcessDataContainer, __instance, new MusicSelectProcess(SharedInstances.ProcessDataContainer)));
Task.Run(async () =>
{
await Task.Delay(1000);
MessageHelper.ShowMessage($"{(isShowSelfMadeCharts ? "Show" : "Hide")} Self-Made Charts");
});
}
else
{
_keyPressFrames = 0;
}
}
}

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -67,7 +66,7 @@ namespace AquaMai.UX
jacketPaths[match.Groups[1].Value] = laFile;
}
MelonLogger.Msg($"Loaded {jacketPaths.Count} custom jacket images.");
MelonLogger.Msg($"[LoadJacketPng] Loaded {jacketPaths.Count} custom jacket images.");
}
private static string GetJacketPath(string id)

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using AquaMai.Helpers;
using HarmonyLib;
using Mai2.Mai2Cue;
using MAI2.Util;
@@ -12,16 +13,8 @@ namespace AquaMai.UX
{
public class QuickSkip
{
private static ProcessDataContainer _container;
private static int _keyPressFrames;
[HarmonyPrefix]
[HarmonyPatch(typeof(ProcessDataContainer), MethodType.Constructor)]
public static void OnCreateProcessDataContainer(ProcessDataContainer __instance)
{
_container = __instance;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GameMainObject), "Update")]
public static void OnGameMainObjectUpdate()
@@ -32,14 +25,14 @@ namespace AquaMai.UX
if (_keyPressFrames > 0 && !Input.GetKey(KeyCode.Alpha7) && !InputManager.GetSystemInputPush(InputManager.SystemButtonSetting.ButtonService))
{
_keyPressFrames = 0;
MelonLogger.Msg(_container.processManager.Dump());
MelonLogger.Msg(SharedInstances.ProcessDataContainer.processManager.Dump());
return;
}
if (_keyPressFrames != 60) return;
MelonLogger.Msg("[QuickSkip] Activated");
var traverse = Traverse.Create(_container.processManager);
var traverse = Traverse.Create(SharedInstances.ProcessDataContainer.processManager);
var processList = traverse.Field("_processList").GetValue<LinkedList<ProcessManager.ProcessControle>>();
ProcessBase processToRelease = null;
@@ -61,7 +54,7 @@ namespace AquaMai.UX
// Skip to save
SoundManager.PreviewEnd();
SoundManager.PlayBGM(Cue.BGM_COLLECTION, 2);
_container.processManager.AddProcess(new FadeProcess(_container, process.Process, new UnlockMusicProcess(_container)));
SharedInstances.ProcessDataContainer.processManager.AddProcess(new FadeProcess(SharedInstances.ProcessDataContainer, process.Process, new UnlockMusicProcess(SharedInstances.ProcessDataContainer)));
break;
}
}
@@ -69,7 +62,7 @@ namespace AquaMai.UX
if (processToRelease != null)
{
GameManager.SetMaxTrack();
_container.processManager.AddProcess(new FadeProcess(_container, processToRelease, new MusicSelectProcess(_container)));
SharedInstances.ProcessDataContainer.processManager.AddProcess(new FadeProcess(SharedInstances.ProcessDataContainer, processToRelease, new MusicSelectProcess(SharedInstances.ProcessDataContainer)));
}
}