-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[+] toggle the display of self-made charts
- Loading branch information
Showing
11 changed files
with
198 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using DB; | ||
using HarmonyLib; | ||
using Manager; | ||
using MelonLoader; | ||
using Process; | ||
|
||
namespace AquaMai.Helpers; | ||
|
||
public class MessageHelper | ||
{ | ||
private static IGenericManager _genericManager = null; | ||
|
||
[HarmonyPostfix] | ||
[HarmonyPatch(typeof(ProcessManager), "SetMessageManager")] | ||
private static void OnSetMessageManager(IGenericManager genericManager) | ||
{ | ||
_genericManager = genericManager; | ||
} | ||
|
||
public static void ShowMessage(string message, WindowSizeID size = WindowSizeID.Middle) | ||
{ | ||
if (_genericManager is null) | ||
{ | ||
MelonLogger.Error($"[MessageHelper] Unable to show message: `{message}` GenericManager is null"); | ||
return; | ||
} | ||
|
||
_genericManager.Enqueue(0, WindowMessageID.CollectionAttentionEmptyFavorite, new WindowParam() | ||
{ | ||
hideTitle = true, | ||
replaceText = true, | ||
text = message, | ||
changeSize = true, | ||
sizeID = size | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using HarmonyLib; | ||
using Manager; | ||
using MelonLoader; | ||
|
||
namespace AquaMai.Helpers; | ||
|
||
public class MusicDirHelper | ||
{ | ||
private static Dictionary<int, string> _map = new(); | ||
|
||
[HarmonyPostfix] | ||
[HarmonyPatch(typeof(Manager.MaiStudio.Serialize.MusicData), "AddPath")] | ||
private static void AddPath(Manager.MaiStudio.Serialize.MusicData __instance, string parentPath) | ||
{ | ||
_map[__instance.GetID()] = parentPath; | ||
} | ||
|
||
public static string LookupPath(int id) | ||
{ | ||
return _map.GetValueOrDefault(id); | ||
} | ||
|
||
public static string LookupPath(Manager.MaiStudio.Serialize.MusicData musicData) | ||
{ | ||
return LookupPath(musicData.GetID()); | ||
} | ||
|
||
public static string LookupPath(Manager.MaiStudio.MusicData musicData) | ||
{ | ||
return LookupPath(musicData.GetID()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using HarmonyLib; | ||
using Process; | ||
|
||
namespace AquaMai.Helpers; | ||
|
||
public class SharedInstances | ||
{ | ||
public static ProcessDataContainer ProcessDataContainer { get; private set; } | ||
|
||
[HarmonyPrefix] | ||
[HarmonyPatch(typeof(ProcessDataContainer), MethodType.Constructor)] | ||
public static void OnCreateProcessDataContainer(ProcessDataContainer __instance) | ||
{ | ||
ProcessDataContainer = __instance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters