Skip to content

Commit

Permalink
重构 ModGUI面板部分,将方法拆分方便后续维护
Browse files Browse the repository at this point in the history
  • Loading branch information
WYH2004-MC committed Sep 30, 2024
1 parent 767a59b commit ee7f3f7
Show file tree
Hide file tree
Showing 17 changed files with 455 additions and 342 deletions.
4 changes: 2 additions & 2 deletions BuildInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SinmaiAssist {
public static partial class BuildInfo {
public const string CommitHash = "2196223";
public const string BuildDate = "2024-09-30T00:19:20.6886613+08:00";
public const string CommitHash = "767a59b";
public const string BuildDate = "2024-09-30T21:25:02.8173266+08:00";
}
}
9 changes: 5 additions & 4 deletions Common/DummyAimeLogin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using HarmonyLib;
using Mai2.Mai2Cue;
using Manager;
using SinmaiAssist.GUI;
using SinmaiAssist.Utils;

namespace SinmaiAssist.Common;
Expand All @@ -14,7 +15,7 @@ public class DummyAimeLogin
{
public static void ReadCard(string accesscode=null, string oldCode=null)
{
accesscode ??= ModGUI.DummyQrCode.Trim();
accesscode ??= DummyLoginPanel.DummyLoginCode.Trim();
if (!Directory.Exists("DEVICE")) Directory.CreateDirectory("DEVICE");
if (accesscode.Length == 20 && Regex.IsMatch(accesscode, @"^\d+$"))
{
Expand Down Expand Up @@ -107,9 +108,9 @@ public static void ReadCard(string accesscode=null, string oldCode=null)
[HarmonyPatch(typeof(AimeId), "Value", MethodType.Getter)]
public static bool GetAimeId(ref uint __result)
{
if (ModGUI.UserIdLoginFlag)
if (DummyLoginPanel.UserIdLoginFlag)
{
__result = Convert.ToUInt32(ModGUI.DummyUserId);
__result = Convert.ToUInt32(DummyLoginPanel.DummyUserId);
return false;
}
return true;
Expand All @@ -119,6 +120,6 @@ public static bool GetAimeId(ref uint __result)
[HarmonyPatch(typeof(Process.Entry.TryAime), "Execute")]
public static void ClearFlag()
{
ModGUI.UserIdLoginFlag = false;
DummyLoginPanel.UserIdLoginFlag = false;
}
}
18 changes: 9 additions & 9 deletions Common/DummyChimeLogin.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using ChimeLib.NET;
using HarmonyLib;
using Manager;
using SinmaiAssist;
using System.Collections;
using System.Reflection;
using SinmaiAssist.GUI;
using UnityEngine;

namespace SinmaiAssist.SDGB;
Expand Down Expand Up @@ -122,17 +122,17 @@ public static bool IsReady(ref bool __result)
[HarmonyPatch(typeof(ChimeDevice), "GetDecodeStrings")]
public static bool GetDecodeStrings(ref string[] __result)
{
if (ModGUI.QrLoginFlag)
if (DummyLoginPanel.CodeLoginFlag)
{
ModGUI.QrLoginFlag = false;
if (ModGUI.DummyQrCode == null)
DummyLoginPanel.CodeLoginFlag = false;
if (DummyLoginPanel.DummyLoginCode == null)
{
__result = null;
return false;
}
else
{
__result = new string[1] { ModGUI.DummyQrCode };
__result = new string[1] { DummyLoginPanel.DummyLoginCode };
return false;
}
}
Expand All @@ -148,12 +148,12 @@ public static bool Execute(ChimeReaderManager __instance)
var result = AccessTools.Field(typeof(ChimeReaderManager), "_result");
var aimeId = AccessTools.Field(typeof(ChimeReaderManager), "_aimeId");
var currentState = AccessTools.Field(typeof(ChimeReaderManager), "currentState");
if (ModGUI.UserIdLoginFlag)
if (DummyLoginPanel.UserIdLoginFlag)
{
ChimeId _aimeId;
System.Type chimeIdType = System.Type.GetType("ChimeLib.NET.ChimeId, ChimeLib.NET");
MethodInfo makeMethod = chimeIdType.GetMethod("Make", BindingFlags.NonPublic | BindingFlags.Static);
_aimeId = (ChimeId)makeMethod.Invoke(null, new object[] { uint.Parse(ModGUI.DummyUserId) });
_aimeId = (ChimeId)makeMethod.Invoke(null, new object[] { uint.Parse(DummyLoginPanel.DummyUserId) });
result.SetValue(__instance, ChimeReaderManager.Result.Done);
aimeId.SetValue(__instance, _aimeId);
currentState.SetValue(__instance, 9);
Expand All @@ -166,7 +166,7 @@ public static bool Execute(ChimeReaderManager __instance)
[HarmonyPatch(typeof(ChimeReaderManager), "AdvCheck")]
public static bool AdvCheck(ref bool __result)
{
if (ModGUI.UserIdLoginFlag)
if (DummyLoginPanel.UserIdLoginFlag)
{
__result = true;
return false;
Expand All @@ -181,6 +181,6 @@ public static bool AdvCheck(ref bool __result)
[HarmonyPatch(typeof(Process.Entry.TryAime), "Execute")]
public static void ClearFlag()
{
ModGUI.UserIdLoginFlag = false;
DummyLoginPanel.UserIdLoginFlag = false;
}
}
4 changes: 2 additions & 2 deletions Common/ShowFPS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public static void OnGUI()
style.fontSize = 24;
style.normal.textColor = Color.black;
style.alignment = TextAnchor.UpperLeft;
GUI.Label(new Rect(10 + 2, 10 + 2, 500, 30), fpsText, style);
UnityEngine.GUI.Label(new Rect(10 + 2, 10 + 2, 500, 30), fpsText, style);
style.normal.textColor = Color.white;
GUI.Label(new Rect(10, 10, 500, 30), fpsText, style);
UnityEngine.GUI.Label(new Rect(10, 10, 500, 30), fpsText, style);
}

private static void Update()
Expand Down
22 changes: 22 additions & 0 deletions GUI/AutoPlayPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using SinmaiAssist.Cheat;
using UnityEngine;

namespace SinmaiAssist.GUI;

public class AutoPlayPanel
{
public static void OnGUI()
{
GUILayout.Label($"Mode: {AutoPlay.autoPlayMode}");
AutoPlay.DisableUpdate = GUILayout.Toggle(AutoPlay.DisableUpdate, "Disable Mode Update");
if (GUILayout.Button("Critical (AP+)")) AutoPlay.autoPlayMode = AutoPlay.AutoPlayMode.Critical;
if (GUILayout.Button("Perfect")) AutoPlay.autoPlayMode = AutoPlay.AutoPlayMode.Perfect;
if (GUILayout.Button("Great")) AutoPlay.autoPlayMode = AutoPlay.AutoPlayMode.Great;
if (GUILayout.Button("Good")) AutoPlay.autoPlayMode = AutoPlay.AutoPlayMode.Good;
if (GUILayout.Button("Random")) AutoPlay.autoPlayMode = AutoPlay.AutoPlayMode.Random;
if (GUILayout.Button("RandomAllPerfect")) AutoPlay.autoPlayMode = AutoPlay.AutoPlayMode.RandomAllPerfect;
if (GUILayout.Button("RandomFullComboPlus")) AutoPlay.autoPlayMode = AutoPlay.AutoPlayMode.RandomFullComboPlus;
if (GUILayout.Button("RandomFullCombo")) AutoPlay.autoPlayMode = AutoPlay.AutoPlayMode.RandomFullCombo;
if (GUILayout.Button("None")) AutoPlay.autoPlayMode = AutoPlay.AutoPlayMode.None;
}
}
35 changes: 35 additions & 0 deletions GUI/ChartTimerPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using SinmaiAssist.Cheat;
using UnityEngine;

namespace SinmaiAssist.GUI;

public class ChartTimerPanel
{
public static void OnGUI()
{
GUIStyle buttonStyle = new GUIStyle(UnityEngine.GUI.skin.button) { fontSize = 24 };
ChartTimer.ButtonStatus = ChartTimer.Button.None;
Manager.NotesManager notesManager = new Manager.NotesManager();
GUILayout.Label($"Timer Status: {(notesManager.IsPlaying() ? (ChartTimer.IsPlaying ? "Playing" : "Paused") : "Not Play")}");
GUILayout.Label($"Timer:", new GUIStyle(UnityEngine.GUI.skin.label) { fontSize = 20 });
GUILayout.Label($"{ChartTimer.Timer.ToString("0000000.0000")}", new GUIStyle(MainGUI.Style.Title) { fontSize = 20 });
if (GUILayout.Button($"{(ChartTimer.IsPlaying ? "Pause" : "Play")}", buttonStyle, GUILayout.Height(45f))) ChartTimer.ButtonStatus = ChartTimer.Button.Pause;
GUILayout.BeginHorizontal();
if (GUILayout.Button("<<<", buttonStyle, GUILayout.Height(45f))) ChartTimer.ButtonStatus = ChartTimer.Button.TimeSkipSub3;
if (GUILayout.Button("<<", buttonStyle, GUILayout.Height(45f))) ChartTimer.ButtonStatus = ChartTimer.Button.TimeSkipSub2;
if (GUILayout.Button("<", buttonStyle, GUILayout.Height(45f))) ChartTimer.ButtonStatus = ChartTimer.Button.TimeSkipSub;
if (GUILayout.Button(">", buttonStyle, GUILayout.Height(45f))) ChartTimer.ButtonStatus = ChartTimer.Button.TimeSkipAdd;
if (GUILayout.Button(">>", buttonStyle, GUILayout.Height(45f))) ChartTimer.ButtonStatus = ChartTimer.Button.TimeSkipAdd2;
if (GUILayout.Button(">>>", buttonStyle, GUILayout.Height(45f))) ChartTimer.ButtonStatus = ChartTimer.Button.TimeSkipAdd3;
GUILayout.EndHorizontal();
if (GUILayout.Button("Reset", buttonStyle, GUILayout.Height(45f))) ChartTimer.ButtonStatus = ChartTimer.Button.Reset;
GUILayout.Label(
"While paused, you can use the LeftArrow and RightArrow keys to perform small range fast forward or rewind.",
new GUIStyle(UnityEngine.GUI.skin.label)
{
fontSize = 12,
wordWrap = true
}
);
}
}
40 changes: 40 additions & 0 deletions GUI/DebugPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using Manager;
using SinmaiAssist.Utils;
using UnityEngine;

namespace SinmaiAssist.GUI;

public class DebugPanel
{
private static readonly GUIStyle MiddleStyle = new GUIStyle()
{
fontSize = 12,
normal = new GUIStyleState() { textColor = Color.white },
alignment = TextAnchor.MiddleCenter
};

public static void OnGUI()
{
GUILayout.Label($"Throw Exception Test", MiddleStyle);
if (GUILayout.Button("NullReferenceException"))
{
GameObject obj = null;
obj.SetActive(true);
}
if (GUILayout.Button("InvalidCastException")) throw new InvalidCastException("Debug");
GUILayout.Label($"Test Tools", MiddleStyle);
if (GUILayout.Button("TouchArea Display")) Common.InputManager.TouchAreaDisplayButton = true;
if (GUILayout.Button("Send Test Message"))
{
GameMessageManager.SendGameMessage("Hello World!\nMonitorId: 0", 0);
GameMessageManager.SendGameMessage("Hello World!\nMonitorId: 1", 1);
}
if (GUILayout.Button("Save P1 Option To DefaultOption")) Common.ChangeDefaultOption.SaveOptionFile(0L);
if (GUILayout.Button("Save P2 Option To DefaultOption")) Common.ChangeDefaultOption.SaveOptionFile(1L);
if (GUILayout.Button("↑ ↓ ↑ ↓")) SoundManager.PlaySE(Mai2.Mai2Cue.Cue.SE_ENTRY_AIME_ERROR, 1);
GUILayout.Label($"GUI Toggle", MiddleStyle);
if (GUILayout.Button("Toggle Show Info")) SinmaiAssist.config.ModSetting.ShowInfo = !SinmaiAssist.config.ModSetting.ShowInfo;
if (GUILayout.Button("Toggle Show FPS")) SinmaiAssist.config.Common.ShowFPS = !SinmaiAssist.config.Common.ShowFPS;
}
}
51 changes: 51 additions & 0 deletions GUI/DummyLoginPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Manager;
using Net.Packet;
using Net.Packet.Helper;
using SinmaiAssist.Common;
using SinmaiAssist.Utils;
using UnityEngine;

namespace SinmaiAssist.GUI;

public class DummyLoginPanel
{
public static string DummyLoginCode = "";
public static string DummyUserId = "";
public static bool CodeLoginFlag = false;
public static bool UserIdLoginFlag = false;

public static void OnGUI()
{
GUILayout.Label(SinmaiAssist.IsSDGB?"QrCode:":"AccessCode:");
DummyLoginCode = GUILayout.TextArea(DummyLoginCode, GUILayout.Height(100f));
if (GUILayout.Button(SinmaiAssist.IsSDGB?"QrCode Login":"AccessCode Login"))
{
CodeLoginFlag = true;
if (!SinmaiAssist.IsSDGB) DummyAimeLogin.ReadCard();
}
GUILayout.Label("UserID:");
DummyUserId = GUILayout.TextField(DummyUserId, GUILayout.Height(20f));
if (GUILayout.Button("UserId Login"))
{
UserIdLoginFlag = true;
if (!SinmaiAssist.IsSDGB) DummyAimeLogin.ReadCard("12312312312312312312", DummyLoginCode);
}
GUILayout.Label($"AMDaemon BootTime: {AMDaemon.Allnet.Auth.AuthTime}");
if (GUILayout.Button("UserId Logout"))
{
PacketHelper.StartPacket(new UserLogout(ulong.Parse(DummyUserId), AMDaemon.Allnet.Auth.AuthTime, "", LogoutComplete,LogoutFailed));
}
}

private static void LogoutComplete()
{
SoundManager.PlayVoice(Mai2.Voice_000001.Cue.VO_000012, 1);
GameMessageManager.SendGameMessage($"Id: {DummyUserId} Logout Complete.");
}

private static void LogoutFailed(PacketStatus status)
{
SoundManager.PlaySE(Mai2.Mai2Cue.Cue.SE_ENTRY_AIME_ERROR, 1);
GameMessageManager.SendGameMessage($"Id: {DummyUserId} Logout Failed.");
}
}
41 changes: 41 additions & 0 deletions GUI/FastSkipPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using SinmaiAssist.Cheat;
using UnityEngine;

namespace SinmaiAssist.GUI;

public class FastSkipPanel
{
private static string _scoreInput = "0";

public static void OnGUI()
{
FastSkip.SkipButton = false;
GUILayout.Label($"Skip Mode: {(FastSkip.CustomSkip ? "Custom" : "Default")}");
if (GUILayout.Button("Skip", new GUIStyle(UnityEngine.GUI.skin.button){ fontSize=20 }, GUILayout.Height(45f))) FastSkip.SkipButton = true;
GUILayout.Label($"Mode Setting", MainGUI.Style.Title);
if (GUILayout.Button("Default")) FastSkip.CustomSkip = false;
if (GUILayout.Button("Custom")) FastSkip.CustomSkip = true;
if (FastSkip.CustomSkip)
{
GUILayout.Label($"Custom Setting", MainGUI.Style.Title);
GUILayout.Label($"Custom Score(0 - 101): ");
_scoreInput = GUILayout.TextField(_scoreInput);
if (int.TryParse(_scoreInput, out int scoreValue))
{
if (scoreValue >= 0f && scoreValue <= 101f)
{
FastSkip.CustomAchivement = scoreValue;
GUILayout.Label($"Custom Score: {scoreValue} %");
}
else
{
GUILayout.Label("Error: Please enter a value between 0 and 101.", MainGUI.Style.ErrorMessage);
}
}
else
{
GUILayout.Label("Error: Please enter a valid int value.", MainGUI.Style.ErrorMessage);
}
}
}
}
40 changes: 40 additions & 0 deletions GUI/GraphicPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using SinmaiAssist.Common;
using UnityEngine;

namespace SinmaiAssist.GUI;

public class GraphicPanel
{
private static string screenWidth = $"{Graphic.GetResolutionWidth()}";
private static string screenHeight = $"{Graphic.GetResolutionHeight()}";
private static string frameRate = $"{Graphic.GetMaxFrameRate()}";


public static void OnGUI()
{
if (GUILayout.Button("Toggle full screen", GUILayout.Height(50))) Graphic.ToggleFullscreen();
GUILayout.Label($"Custom Graphic Settings", MainGUI.Style.Title);
GUILayout.BeginHorizontal();
GUILayout.BeginVertical();
GUILayout.Label($"Width:");
screenWidth = GUILayout.TextField(screenWidth);
GUILayout.EndVertical();
GUILayout.BeginVertical();
GUILayout.Label($"Height:");
screenHeight = GUILayout.TextField(screenHeight);
GUILayout.EndVertical();
GUILayout.BeginVertical();
GUILayout.Label($"Max FPS (Unlimited is -1):");
frameRate = GUILayout.TextField(frameRate);
GUILayout.EndVertical();
GUILayout.EndHorizontal();
if (GUILayout.Button("Apply", GUILayout.Height(20)) && int.TryParse(screenWidth, out int widthValue) && int.TryParse(screenHeight, out int heightValue) && int.TryParse(frameRate, out int fpsValue))
{
if (widthValue >= 360f && heightValue >= 360f)
{
Graphic.SetResolution(widthValue, heightValue);
Graphic.SetMaxFrameRate(fpsValue);
}
}
}
}
Loading

0 comments on commit ee7f3f7

Please sign in to comment.