From 7fc75ca2b10262e07fea63e0c5034afd65ad2892 Mon Sep 17 00:00:00 2001 From: akanyan Date: Wed, 25 Dec 2024 17:31:54 +0000 Subject: [PATCH] feat: rework Pause Now a dialog. * Also fix the new BetterGiveUp panic restart * Also move SortByInternal's PNG away from the root namespace --- .../MU3.Sequence/patch_PlayMusic.cs | 18 ++++- .../Pause/MU3.Battle/patch_GameEngine.cs | 80 ++++++++++++++++++- .../Pause/MU3.Sequence/patch_PlayMusic.cs | 40 ---------- .../Pause/MU3.Sound/patch_SoundManager.cs | 3 +- Enhancements/Pause/patch_GameDeviceManager.cs | 10 --- .../{ => MU3.Mod}/InternalSortPreview.cs | 4 +- .../MU3/patch_UISortButton.cs | 2 +- 7 files changed, 98 insertions(+), 59 deletions(-) delete mode 100644 Enhancements/Pause/MU3.Sequence/patch_PlayMusic.cs delete mode 100644 Enhancements/Pause/patch_GameDeviceManager.cs rename Extras/SortByInternalDifficulty/{ => MU3.Mod}/InternalSortPreview.cs (99%) diff --git a/Enhancements/BetterGiveUp/MU3.Sequence/patch_PlayMusic.cs b/Enhancements/BetterGiveUp/MU3.Sequence/patch_PlayMusic.cs index f2fe731..beef509 100644 --- a/Enhancements/BetterGiveUp/MU3.Sequence/patch_PlayMusic.cs +++ b/Enhancements/BetterGiveUp/MU3.Sequence/patch_PlayMusic.cs @@ -115,12 +115,24 @@ class patch_PlayMusic: PlayMusic { } } + private void listenForPanicRestart() { + if(Singleton.instance.getTriggerOn(UIInput.Key.MenuRight) && ntMgr.retireResult != RetireResult.None && !isPartyPlay()) { + Singleton.instance.gameBGM.stop(); + setNextState(EState.Init); + } + } + private extern void orig_Execute_DispCombo(); private void Execute_DispCombo() { orig_Execute_DispCombo(); - if(Singleton.instance.getTriggerOn(UIInput.Key.MenuRight) && ntMgr.retireResult != RetireResult.None && !isPartyPlay()) { - setNextState(EState.Init); - } + listenForPanicRestart(); + } + + private extern void orig_Execute_DispFinish(); + private void Execute_DispFinish() { + orig_Execute_DispFinish(); + + listenForPanicRestart(); } } \ No newline at end of file diff --git a/Enhancements/Pause/MU3.Battle/patch_GameEngine.cs b/Enhancements/Pause/MU3.Battle/patch_GameEngine.cs index d213448..62f3a71 100644 --- a/Enhancements/Pause/MU3.Battle/patch_GameEngine.cs +++ b/Enhancements/Pause/MU3.Battle/patch_GameEngine.cs @@ -1,11 +1,87 @@ -using MU3.Sequence; +using MU3.Collab; +using MU3.DB; +using MU3.Game; +using MU3.Notes; +using MU3.Util; +using System.Collections; +using System.Reflection; +using UnityEngine; namespace MU3.Battle; class patch_GameEngine: GameEngine { + private static readonly float PAUSE_CD = 5f; + + private NotesManager _notesManager; + + private static bool _paused; + private float _pauseTimer; + private UIDialog _dialog; + public extern void orig_reset(); public new void reset() { orig_reset(); - patch_PlayMusic.Paused = false; + togglePause(false); + _pauseTimer = 0; + + if(_dialog != null) { + _dialog.forceCancel(); + _dialog = null; + } + } + + public extern void orig_execute(); + public new void execute() { + if(_paused) { + return; + } + + orig_execute(); + + _pauseTimer -= Time.deltaTime; + + if(Singleton.instance.getTriggerOn(UIInput.Key.Service)) { + if(_pauseTimer < 0f && !isPartyPlay() && notesManager.isPlaying) { + togglePause(true); + _dialog = UIDialog.create(DialogID.LackOfGP, "Pause", (int _, bool _) => togglePause(false)); + StartCoroutine(killTimer(_dialog)); + } + } + } + + private void togglePause(bool value) { + ((patch_GameBGM)Singleton.instance.gameBGM).pause(value); + _paused = value; + _notesManager.setPause(value); + _pauseTimer = PAUSE_CD; + } + + private IEnumerator killTimer(UIDialog dialog) { + var fi = typeof(UIDialog).GetField("uiTimer_", BindingFlags.Instance | BindingFlags.NonPublic); + + if(fi == null) { + yield break; + } + + int limit = 500; + UITimer timer; + do { + yield return new WaitForEndOfFrame(); + timer = (UITimer)fi.GetValue(dialog); + if(--limit == 0) { + yield break; + } + } while(timer == null); + + timer.Pause = true; + timer.Show = false; + timer.enabled = false; + + yield break; + } + + private bool isPartyPlay() { + Party.IManager manager = Party.get(); + return manager != null && manager.isJoinAndActive(); } } \ No newline at end of file diff --git a/Enhancements/Pause/MU3.Sequence/patch_PlayMusic.cs b/Enhancements/Pause/MU3.Sequence/patch_PlayMusic.cs deleted file mode 100644 index c7ce37e..0000000 --- a/Enhancements/Pause/MU3.Sequence/patch_PlayMusic.cs +++ /dev/null @@ -1,40 +0,0 @@ -using MonoMod; -using MU3.Battle; -using MU3.Game; -using MU3.Notes; -using MU3.Util; - -namespace MU3.Sequence; - -class patch_PlayMusic: PlayMusic { - private static readonly float PAUSE_CD = 5f; - private static readonly float UNPAUSE_CD = 0.5f; - private GameEngine _gameEngine; - private NotesManager ntMgr => _gameEngine?.notesManager; - private patch_GameBGM pgm => (patch_GameBGM)Singleton.instance.gameBGM; - public static bool Paused = false; - private float pauseTimer = 0f; - - [MonoModIgnore] - private extern bool isPartyPlay(); - - private extern void orig_Enter_SetupScene(); - private void Enter_SetupScene() { - orig_Enter_SetupScene(); - Paused = false; - } - - public extern bool orig_updateState(float deltaTime = -1f); - public override bool updateState(float deltaTime = -1f) { - pauseTimer += deltaTime; - if(Singleton.instance.getTriggerOn(UIInput.Key.Service) && !Singleton.instance.getStateOn(UIInput.Key.Test)) { - if((!Paused && pauseTimer >= PAUSE_CD) || (Paused && pauseTimer >= UNPAUSE_CD) && !isPartyPlay()) { - Paused = !Paused; - pgm.pause(Paused); - ntMgr.setPause(Paused); - pauseTimer = 0f; - } - } - return orig_updateState(deltaTime); - } -} \ No newline at end of file diff --git a/Enhancements/Pause/MU3.Sound/patch_SoundManager.cs b/Enhancements/Pause/MU3.Sound/patch_SoundManager.cs index 2d4cab2..141dff5 100644 --- a/Enhancements/Pause/MU3.Sound/patch_SoundManager.cs +++ b/Enhancements/Pause/MU3.Sound/patch_SoundManager.cs @@ -1,9 +1,8 @@ namespace MU3.Sound; class patch_SoundManager: SoundManager { - private extern HandleInfo orig_getHandle(Priority priority); - private HandleInfo getHandle(Priority priority) => orig_getHandle(priority); private patch_SoundPlayer[] _soundPlayers; + public void pause(HandleInfo handle, bool val) { if(handle.Index < _soundPlayers.Length) { _soundPlayers[handle.Index].pause(val); diff --git a/Enhancements/Pause/patch_GameDeviceManager.cs b/Enhancements/Pause/patch_GameDeviceManager.cs deleted file mode 100644 index 289155d..0000000 --- a/Enhancements/Pause/patch_GameDeviceManager.cs +++ /dev/null @@ -1,10 +0,0 @@ -using MU3.Sequence; - -class patch_GameDeviceManager: GameDeviceManager { - private extern void orig_update(); - private void update() { - if(!patch_PlayMusic.Paused) { - orig_update(); - } - } -} \ No newline at end of file diff --git a/Extras/SortByInternalDifficulty/InternalSortPreview.cs b/Extras/SortByInternalDifficulty/MU3.Mod/InternalSortPreview.cs similarity index 99% rename from Extras/SortByInternalDifficulty/InternalSortPreview.cs rename to Extras/SortByInternalDifficulty/MU3.Mod/InternalSortPreview.cs index 75bdc75..d989631 100644 --- a/Extras/SortByInternalDifficulty/InternalSortPreview.cs +++ b/Extras/SortByInternalDifficulty/MU3.Mod/InternalSortPreview.cs @@ -1,4 +1,6 @@ -public static class InternalSortPreview { +namespace MU3.Mod; + +public static class InternalSortPreview { // This really shouldn't be a png but it's just one texture public static byte[] Bytes = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, diff --git a/Extras/SortByInternalDifficulty/MU3/patch_UISortButton.cs b/Extras/SortByInternalDifficulty/MU3/patch_UISortButton.cs index cafcf4d..8fb7c56 100644 --- a/Extras/SortByInternalDifficulty/MU3/patch_UISortButton.cs +++ b/Extras/SortByInternalDifficulty/MU3/patch_UISortButton.cs @@ -22,7 +22,7 @@ class patch_UISortButton: UISortButton { } Texture2D tex = new Texture2D(2, 2); - tex.LoadImage(InternalSortPreview.Bytes); + tex.LoadImage(Mod.InternalSortPreview.Bytes); newSprites[n] = Sprite.Create(tex, new Rect(0, 0, 254, 121), newSprites[0].pivot);