-
Notifications
You must be signed in to change notification settings - Fork 56
[+] 给一键重试和练习模式添加onlyInFreedomMode选项
#134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,13 +36,33 @@ public class PracticeMode | |
| [ConfigEntry] | ||
| public static readonly bool longPress = false; | ||
|
|
||
| [ConfigEntry( | ||
| name: "仅自由模式可用", | ||
| en: "Only allow Practice Mode in Freedom Mode while time remains.", | ||
| zh: "仅在自由模式且时间未耗尽时允许使用练习模式")] | ||
| public static readonly bool onlyInFreedomMode = false; | ||
|
|
||
| public static double repeatStart = -1; | ||
| public static double repeatEnd = -1; | ||
| public static float speed = 1; | ||
| private static CriAtomExPlayer player; | ||
| private static List<MovieMaterialMai2> movie; | ||
| private static GameCtrl[] gameCtrl = new GameCtrl[2]; | ||
| public static bool keepNoteSpeed = false; | ||
|
|
||
| private static void ClearPracticeEffects() | ||
| { | ||
| // 清除练习模式的所有效果。涉及的效果有五种:UI界面、循环、速度保持、速度、暂停。 | ||
| if (ui != null) | ||
| { | ||
| UnityEngine.Object.Destroy(ui); | ||
| ui = null; | ||
| } | ||
| if (repeatStart >= 0 || repeatEnd >= 0) ClearRepeat(); | ||
| keepNoteSpeed = false; | ||
| if (speed != 1f) SpeedReset(); | ||
| if (DebugFeature.Pause) TogglePause(); | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| } | ||
|
Comment on lines
+53
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为了简化更新循环中复杂的布尔逻辑,并保持与 private static void ClearPracticeEffects()
{
// 清除练习模式的所有效果。涉及的效果有四种:UI界面、循环、速度、暂停。
if (ui != null)
{
UnityEngine.Object.Destroy(ui);
ui = null;
}
if (repeatStart >= 0 || repeatEnd >= 0) ClearRepeat();
if (speed != 1f) SpeedReset();
if (DebugFeature.Pause) TogglePause();
}
private static bool IsPracticeAllowed()
{
if (!onlyInFreedomMode) return true;
return GameManager.IsFreedomMode && GameManager.GetFreedomModeMSec() > 0;
}References
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我觉得必要性不强。没必要
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 看起来只有一处用到这个逻辑,我觉得没事 |
||
|
|
||
| public static void SetRepeatEnd(double time) | ||
| { | ||
|
|
@@ -67,6 +87,15 @@ public static void ClearRepeat() | |
| repeatEnd = -1; | ||
| } | ||
|
|
||
| public static void TogglePause() | ||
| { | ||
| DebugFeature.Pause = !DebugFeature.Pause; | ||
| if (!DebugFeature.Pause) | ||
| { | ||
| Seek(0); | ||
| } | ||
| } | ||
|
|
||
| public static void GameCtrlResetOptionSpeed() | ||
| { | ||
| foreach (var g in gameCtrl) | ||
|
|
@@ -169,6 +198,8 @@ public static double CurrentPlayMsec | |
|
|
||
| public static PracticeModeUI ui; | ||
|
|
||
| private static long prevFreedomModeMSec = -1; // 上一帧时,自由模式的剩余秒数 | ||
|
|
||
| [HarmonyPatch] | ||
| public class PatchNoteSpeed | ||
| { | ||
|
|
@@ -192,7 +223,9 @@ public static void GameProcessPostStart() | |
| repeatStart = -1; | ||
| repeatEnd = -1; | ||
| speed = 1; | ||
| keepNoteSpeed = false; | ||
| ui = null; | ||
| prevFreedomModeMSec = GameManager.IsFreedomMode ? GameManager.GetFreedomModeMSec() : -1; | ||
| } | ||
|
|
||
| [HarmonyPatch(typeof(GameProcess), "OnRelease")] | ||
|
|
@@ -202,7 +235,9 @@ public static void GameProcessPostRelease() | |
| repeatStart = -1; | ||
| repeatEnd = -1; | ||
| speed = 1; | ||
| keepNoteSpeed = false; | ||
| ui = null; | ||
|
Starrah marked this conversation as resolved.
|
||
| prevFreedomModeMSec = -1; | ||
| } | ||
|
|
||
| [HarmonyPatch(typeof(GameCtrl), "Initialize")] | ||
|
|
@@ -228,10 +263,19 @@ public static void OnGenericProcessUpdate(GenericMonitor[] ____monitors) | |
| [HarmonyPostfix] | ||
| public static void GameProcessPostUpdate(GameProcess __instance, GameMonitor[] ____monitors) | ||
| { | ||
| if (KeyListener.GetKeyDownOrLongPress(key, longPress) && ui is null) | ||
| if (KeyListener.GetKeyDownOrLongPress(key, longPress) && ui is null && | ||
| (!onlyInFreedomMode || (GameManager.IsFreedomMode && GameManager.GetFreedomModeMSec() > 0))) // onlyInFreedomMode=true情况,则额外检查是否在练习模式内、且时间有剩余,如果不满足则不开启UI。 | ||
| { | ||
| ui = ____monitors[0].gameObject.AddComponent<PracticeModeUI>(); | ||
| } | ||
|
Comment on lines
+266
to
270
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在此处使用新提取的 if (KeyListener.GetKeyDownOrLongPress(key, longPress) && ui is null && IsPracticeAllowed())
{
ui = ____monitors[0].gameObject.AddComponent<PracticeModeUI>();
}References
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我觉得必要性不强。没必要。现在代码可读性也不差 |
||
|
|
||
| if (onlyInFreedomMode && GameManager.IsFreedomMode) | ||
| { | ||
| var currentFreedomModeMSec = GameManager.GetFreedomModeMSec(); | ||
| if (prevFreedomModeMSec > 0 && currentFreedomModeMSec <= 0) | ||
| ClearPracticeEffects(); // 如果这一帧内、练习模式的时间刚好归零了:则清空练习模式的一切效果。 | ||
| prevFreedomModeMSec = currentFreedomModeMSec; | ||
| } | ||
|
|
||
| if (repeatStart >= 0 && repeatEnd >= 0) | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.