Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions AquaMai.Mods/Utils/MoveAnswerSound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,44 @@ namespace AquaMai.Mods.Utils;

[ConfigSection(
en: "Move answer sound",
zh: "移动正解音。此设置提供分用户设置,请在游戏内设置中调整偏移量")]
zh: "移动正解音")]
public class MoveAnswerSound : IPlayerSettingsItem
{
[ConfigEntry(
en: "Display in-game config entry for player. If disabled, the user's settings will be ignored.",
zh: "在游戏内添加设置项给用户,使用户能够在游戏内调整正解音偏移量。如果关闭此选项,则就算用户之前设置过,也会忽略。")]
private static readonly bool DisplayInGameConfig = true;

[ConfigEntry(
en: "Answer sound move value in ms, this value will be combined with user's setting in game. Increase this value to make the answer sound appear later, vice versa.",
zh: "正解音偏移量,单位为毫秒,此设定值会与用户游戏内的设置相加。增大这个值将会使正解音出现得更晚,反之则更早。")]
private static readonly float MoveValue_1P = 0f;

[ConfigEntry(
en: "Same as MoveValue_1P.",
zh: "与 MoveValue_1P 作用相同。")]
private static readonly float MoveValue_2P = 0f;

private static float[] userSettings = [0, 0];
private static IPersistentStorage storage = new PlayerPrefsStorage();

private static float GetCabinSettingsValue(uint monitorIndex) => monitorIndex == 0 ? MoveValue_1P : MoveValue_2P;
private static float GetSettingsValue(uint monitorIndex)
{
var moveValue = GetCabinSettingsValue(monitorIndex);
return DisplayInGameConfig ? userSettings[monitorIndex] + moveValue : moveValue;
}

private static float GetSettingsValue(int monitorIndex) => GetSettingsValue((uint)monitorIndex);

#region 设置界面注入

public static void OnBeforePatch()
{
GameSettingsManager.RegisterSetting(new MoveAnswerSound());
if (DisplayInGameConfig)
{
GameSettingsManager.RegisterSetting(new MoveAnswerSound());
}
}

public int Sort => 50;
Expand Down Expand Up @@ -67,7 +94,14 @@ public static void LoadSettings()
var userData = UserDataManager.Instance.GetUserData(i);
if (!userData.IsEntry) continue;
userSettings[i] = storage.GetFloat(i, "MoveAnswerSound", 0);
MelonLogger.Msg($"玩家 {i} 的移动正解音设置为 {userSettings[i]} 毫秒");
if (DisplayInGameConfig)
{
MelonLogger.Msg($"玩家 {i} 的移动正解音设置为 {GetSettingsValue(i)} 毫秒,其中游戏内设置为 {userSettings[i]} 毫秒,机台设置为 {GetCabinSettingsValue(i)} 毫秒");
}
else
{
MelonLogger.Msg($"玩家 {i} 的移动正解音设置为 {GetSettingsValue(i)} 毫秒,其中游戏内设置已被禁用,机台设置为 {GetCabinSettingsValue(i)} 毫秒");
}
}
}

Expand Down Expand Up @@ -103,12 +137,12 @@ public static void PreUpdateControl(GameObject ____NoteRoot, GameCtrl __instance
continue;
}
if (note.type.isSlide() || note.type.isConnectSlide()) continue;
if (NotesManager.GetCurrentMsec() - 33f - userSettings[__instance.MonitorIndex] > note.time.msec && !note.playAnsSoundHead)
if (NotesManager.GetCurrentMsec() - 33f - GetSettingsValue(__instance.MonitorIndex) > note.time.msec && !note.playAnsSoundHead)
{
Singleton<GameSingleCueCtrl>.Instance.ReserveAnswerSe(__instance.MonitorIndex);
note.playAnsSoundHead = true;
}
if (note.type.isHold() && NotesManager.GetCurrentMsec() - 33f - userSettings[__instance.MonitorIndex] > note.end.msec && !note.playAnsSoundTail)
if (note.type.isHold() && NotesManager.GetCurrentMsec() - 33f - GetSettingsValue(__instance.MonitorIndex) > note.end.msec && !note.playAnsSoundTail)
{
Singleton<GameSingleCueCtrl>.Instance.ReserveAnswerSe(__instance.MonitorIndex);
note.playAnsSoundTail = true;
Expand Down
Loading