diff --git a/AquaMai/AquaMai.csproj b/AquaMai/AquaMai.csproj index c29301a1..2ae6bd60 100644 --- a/AquaMai/AquaMai.csproj +++ b/AquaMai/AquaMai.csproj @@ -320,6 +320,7 @@ DEBUG + diff --git a/AquaMai/Utils/PractiseMode.cs b/AquaMai/Utils/PractiseMode.cs index e8475bda..e2319411 100644 --- a/AquaMai/Utils/PractiseMode.cs +++ b/AquaMai/Utils/PractiseMode.cs @@ -5,7 +5,6 @@ using AquaMai.Fix; using AquaMai.Helpers; using HarmonyLib; using Manager; -using MelonLoader; using Monitor; using Process; using UnityEngine; @@ -15,13 +14,13 @@ namespace AquaMai.Utils; public class PractiseMode { - private static double repeatStart = -1; - private static double repeatEnd = -1; - private static float speed = 1; + public static double repeatStart = -1; + public static double repeatEnd = -1; + public static float speed = 1; private static CriAtomExPlayer player; private static MovieMaterialMai2 movie; - private static void SetRepeatEnd(double time) + public static void SetRepeatEnd(double time) { if (repeatStart == -1) { @@ -38,13 +37,13 @@ public class PractiseMode repeatEnd = time; } - private static void ClearRepeat() + public static void ClearRepeat() { repeatStart = -1; repeatEnd = -1; } - private static void SetSpeed() + public static void SetSpeed() { player.SetPitch((float)(1200 * Math.Log(speed, 2))); // player.SetDspTimeStretchRatio(1 / speed); @@ -53,7 +52,7 @@ public class PractiseMode movie.player.SetSpeed(speed); } - private static void SpeedUp() + public static void SpeedUp() { speed += .05f; if (speed > 2) @@ -64,7 +63,7 @@ public class PractiseMode SetSpeed(); } - private static void SpeedDown() + public static void SpeedDown() { speed -= .05f; if (speed < 0.5) @@ -75,7 +74,7 @@ public class PractiseMode SetSpeed(); } - private static void SpeedReset() + public static void SpeedReset() { speed = 1; SetSpeed(); @@ -108,7 +107,7 @@ public class PractiseMode } } - private static DebugWindow debugWin; + public static PractiseModeUI ui; [HarmonyPatch(typeof(GameProcess), "OnStart")] [HarmonyPostfix] @@ -117,23 +116,31 @@ public class PractiseMode repeatStart = -1; repeatEnd = -1; speed = 1; + ui = null; SetSpeed(); } + [HarmonyPrefix] + [HarmonyPatch(typeof(GenericProcess), "OnUpdate")] + public static void OnGenericProcessUpdate(GenericMonitor[] ____monitors) + { + if (Input.GetKeyDown(KeyCode.F12)) + { + ____monitors[0].gameObject.AddComponent(); + } + else if (Input.GetKeyDown(KeyCode.F11)) + { + ____monitors[0].gameObject.AddComponent(); + } + } + [HarmonyPatch(typeof(GameProcess), "OnUpdate")] [HarmonyPostfix] public static void GameProcessPostUpdate(GameProcess __instance, GameMonitor[] ____monitors) { - if (Input.GetKeyDown(KeyCode.F12)) + if (InputManager.GetSystemInputPush(InputManager.SystemButtonSetting.ButtonTest) && ui is null) { - if (debugWin is null) - { - debugWin = ____monitors[0].gameObject.AddComponent(); - } - else - { - MelonLogger.Msg("[PractiseMode] 调试窗口作用中"); - } + ui = ____monitors[0].gameObject.AddComponent(); } if (repeatStart >= 0 && repeatEnd >= 0) diff --git a/AquaMai/Utils/PractiseModeUI.cs b/AquaMai/Utils/PractiseModeUI.cs new file mode 100644 index 00000000..7d161689 --- /dev/null +++ b/AquaMai/Utils/PractiseModeUI.cs @@ -0,0 +1,163 @@ +using System; +using AquaMai.Fix; +using Manager; +using UnityEngine; +using UrGUI.GUIWindow; + +namespace AquaMai.Utils; + +public class PractiseModeUI : MonoBehaviour +{ + private GUIWindow window; + + private float playerWidth; + private float playerCenter; + private float windowTop; + private float controlHeight; + private float margin; + private float sideButtonWidth; + private float centerButtonWidth; + private int fontSize; + + public void Start() + { + playerWidth = Screen.height / 1920f * 1080; + if (AquaMai.AppConfig.UX.SinglePlayer) + { + playerCenter = Screen.width / 2f; + } + else + { + playerCenter = Screen.width / 2f - playerWidth / 2; + } + + windowTop = Screen.height - playerWidth + playerWidth * .22f; + controlHeight = playerWidth * .13f; + margin = playerWidth * .01f; + sideButtonWidth = playerWidth * .1f; + centerButtonWidth = playerWidth * .28f; + fontSize = (int)(playerWidth * .02f); + } + + public Rect GetButtonRect(int pos, int row) + { + float x; + float width; + switch (pos) + { + case 0: + x = playerCenter - centerButtonWidth / 2 - sideButtonWidth - margin; + width = sideButtonWidth; + break; + case 1: + x = playerCenter - centerButtonWidth / 2; + width = centerButtonWidth; + break; + case 2: + x = playerCenter + centerButtonWidth / 2 + margin; + width = sideButtonWidth; + break; + default: + throw new ArgumentOutOfRangeException(nameof(pos), pos, null); + } + + return new Rect(x, windowTop + (margin + controlHeight) * row + margin, width, controlHeight); + } + + public void OnGUI() + { + var labelStyle = GUI.skin.GetStyle("label"); + labelStyle.fontSize = fontSize; + labelStyle.alignment = TextAnchor.MiddleCenter; + + var buttonStyle = GUI.skin.GetStyle("button"); + buttonStyle.fontSize = fontSize; + + GUI.Box(new Rect( + playerCenter - centerButtonWidth / 2 - sideButtonWidth - margin * 2, + windowTop, + centerButtonWidth + sideButtonWidth * 2 + margin * 4, + controlHeight * 4 + margin * 5 + ), ""); + + GUI.Button(GetButtonRect(0, 0), "Seek <<"); + GUI.Button(GetButtonRect(1, 0), "Pause"); + GUI.Button(GetButtonRect(2, 0), "Seek >>"); + + if (PractiseMode.repeatStart == -1) + { + GUI.Button(GetButtonRect(0, 1), "Start"); + GUI.Label(GetButtonRect(1, 1), "Loop not set"); + } + else if (PractiseMode.repeatEnd == -1) + { + GUI.Button(GetButtonRect(0, 1), "End"); + GUI.Label(GetButtonRect(1, 1), "Loop start set"); + GUI.Button(GetButtonRect(2, 1), "Reset"); + } + else + { + GUI.Label(GetButtonRect(1, 1), "Loop set"); + GUI.Button(GetButtonRect(2, 1), "Reset"); + } + + GUI.Button(GetButtonRect(0, 2), "Speed -"); + GUI.Label(GetButtonRect(1, 2), $"Speed {PractiseMode.speed * 100:000}%"); + GUI.Button(GetButtonRect(2, 2), "Speed +"); + GUI.Button(GetButtonRect(1, 3), "Speed Reset"); + } + + public void Update() + { + if (InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.E8)) + { + DebugFeature.Seek(-1000); + } + else if (InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.E2)) + { + DebugFeature.Seek(1000); + } + else if (InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.B8) || InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.B1)) + { + DebugFeature.Pause = !DebugFeature.Pause; + } + else if (InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.B7) && PractiseMode.repeatStart == -1) + { + PractiseMode.repeatStart = DebugFeature.CurrentPlayMsec; + } + else if (InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.B7) && PractiseMode.repeatEnd == -1) + { + PractiseMode.SetRepeatEnd(DebugFeature.CurrentPlayMsec); + } + else if (InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.B2)) + { + PractiseMode.ClearRepeat(); + } + else if (InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.B6)) + { + PractiseMode.SpeedDown(); + } + else if (InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.B3)) + { + PractiseMode.SpeedUp(); + } + else if (InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.B5) || InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.B4)) + { + PractiseMode.SpeedReset(); + } + else if ( + InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.A1) || + InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.A2) || + InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.A3) || + InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.A4) || + InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.A5) || + InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.A6) || + InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.A7) || + InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.A8) + ) + { + PractiseMode.ui = null; + Destroy(this); + } + } +}