From 69b31c866c6787943e4a44b57e8f810df3ddaebb Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 2 Aug 2020 12:20:26 +0900 Subject: [PATCH] 1. Add more 4 cases 2. Implemenrt change in gameplay. --- .../UI/TestCaseSaitenStatus.cs | 4 ++ .../Configuration/KaraokeSessionStatics.cs | 7 +++ .../KaraokeInputManager.cs | 35 +++++++++--- .../Mods/KaraokeModDisableNote.cs | 4 +- .../UI/Components/SaitenStatus.cs | 54 +++++++++++++++++-- osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs | 7 ++- 6 files changed, 96 insertions(+), 15 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/UI/TestCaseSaitenStatus.cs b/osu.Game.Rulesets.Karaoke.Tests/UI/TestCaseSaitenStatus.cs index 00b5174a1..28d3a1750 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/UI/TestCaseSaitenStatus.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/UI/TestCaseSaitenStatus.cs @@ -19,7 +19,11 @@ public class TestCaseSaitenStatus : OsuTestScene [TestCase(SaitenStatusMode.OSXDoesNotSupported)] [TestCase(SaitenStatusMode.WindowsMicrophonePermissionDeclined)] [TestCase(SaitenStatusMode.NoMicrophoneDevice)] + [TestCase(SaitenStatusMode.NotSaitening)] + [TestCase(SaitenStatusMode.AutoPlay)] + [TestCase(SaitenStatusMode.Edit)] [TestCase(SaitenStatusMode.Saitening)] + [TestCase(SaitenStatusMode.NotInitialized)] public void TestMode(SaitenStatusMode mode) { AddStep("create mod display", () => diff --git a/osu.Game.Rulesets.Karaoke/Configuration/KaraokeSessionStatics.cs b/osu.Game.Rulesets.Karaoke/Configuration/KaraokeSessionStatics.cs index 83c9e0648..8264105f2 100644 --- a/osu.Game.Rulesets.Karaoke/Configuration/KaraokeSessionStatics.cs +++ b/osu.Game.Rulesets.Karaoke/Configuration/KaraokeSessionStatics.cs @@ -6,6 +6,7 @@ using osu.Game.Configuration; using osu.Game.Rulesets.Karaoke.Beatmaps; using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Rulesets.Karaoke.UI.Components; namespace osu.Game.Rulesets.Karaoke.Configuration { @@ -50,6 +51,9 @@ public KaraokeSessionStatics(KaraokeRulesetConfigManager config, IBeatmap beatma // Practice Set(KaraokeRulesetSession.NowLyric, null); + + // Saiten stsus + Set(KaraokeRulesetSession.SaitenStatus, SaitenStatusMode.NotInitialized); } private T getValue(KaraokeRulesetSetting setting) => rulesetConfigManager.GetBindable(setting).Value; @@ -75,5 +79,8 @@ public enum KaraokeRulesetSession // Practice NowLyric, + + // Saiten status + SaitenStatus, } } diff --git a/osu.Game.Rulesets.Karaoke/KaraokeInputManager.cs b/osu.Game.Rulesets.Karaoke/KaraokeInputManager.cs index 42ed0428c..a0d67dde8 100644 --- a/osu.Game.Rulesets.Karaoke/KaraokeInputManager.cs +++ b/osu.Game.Rulesets.Karaoke/KaraokeInputManager.cs @@ -12,11 +12,13 @@ using osu.Framework.Input.Handlers.Microphone; using osu.Framework.Input.StateChanges.Events; using osu.Framework.Input.States; +using osu.Framework.Logging; using osu.Game.Beatmaps; using osu.Game.Input.Handlers; using osu.Game.Rulesets.Karaoke.Beatmaps; using osu.Game.Rulesets.Karaoke.Configuration; using osu.Game.Rulesets.Karaoke.Mods; +using osu.Game.Rulesets.Karaoke.UI.Components; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.UI; using osu.Game.Screens.Edit; @@ -34,27 +36,48 @@ public KaraokeInputManager(RulesetInfo ruleset) private IBeatmap beatmap; [BackgroundDependencyLoader(true)] - private void load(KaraokeRulesetConfigManager config, IBindable> mods, IBindable beatmap, EditorBeatmap editorBeatmap) + private void load(KaraokeRulesetConfigManager config, IBindable> mods, IBindable beatmap, KaraokeSessionStatics session, EditorBeatmap editorBeatmap) { if (editorBeatmap != null) + { + session.Set(KaraokeRulesetSession.SaitenStatus, SaitenStatusMode.Edit); return; + } this.beatmap = beatmap.Value.Beatmap; var disableMicrophoneDeviceByMod = mods.Value.OfType().Any(x => !x.MicrophoneEnabled); if (disableMicrophoneDeviceByMod) + { + session.Set(KaraokeRulesetSession.SaitenStatus, SaitenStatusMode.AutoPlay); return; + } + var beatmapSaitenable = beatmap.Value.Beatmap.IsScorable(); if (!beatmapSaitenable) + { + session.Set(KaraokeRulesetSession.SaitenStatus, SaitenStatusMode.NotSaitening); return; + } - var selectedDevice = config.GetBindable(KaraokeRulesetSetting.MicrophoneDevice).Value; - var microphoneList = new MicrophoneManager().MicrophoneDeviceNames.ToList(); + try + { + var selectedDevice = config.GetBindable(KaraokeRulesetSetting.MicrophoneDevice).Value; + var microphoneList = new MicrophoneManager().MicrophoneDeviceNames.ToList(); + + // Find index by selection id + var deviceIndex = microphoneList.IndexOf(selectedDevice); + AddHandler(new OsuTKMicrophoneHandler(deviceIndex)); - // Find index by selection id - var deviceIndex = microphoneList.IndexOf(selectedDevice); - AddHandler(new OsuTKMicrophoneHandler(deviceIndex)); + session.Set(KaraokeRulesetSession.SaitenStatus, SaitenStatusMode.Saitening); + } + catch(Exception ex) + { + Logger.Error(ex, "Microphone initialize error."); + // todo : set real error by exception + session.Set(KaraokeRulesetSession.SaitenStatus, SaitenStatusMode.WindowsMicrophonePermissionDeclined); + } } protected override InputState CreateInitialState() diff --git a/osu.Game.Rulesets.Karaoke/Mods/KaraokeModDisableNote.cs b/osu.Game.Rulesets.Karaoke/Mods/KaraokeModDisableNote.cs index a1c02dbf0..aae74dce0 100644 --- a/osu.Game.Rulesets.Karaoke/Mods/KaraokeModDisableNote.cs +++ b/osu.Game.Rulesets.Karaoke/Mods/KaraokeModDisableNote.cs @@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Karaoke.Mods { - public class KaraokeModDisableNote : Mod, IApplicableToHitObject, IApplicableToMicrophone + public class KaraokeModDisableNote : Mod, IApplicableToHitObject { public override string Name => "Disable note"; public override string Acronym => "DN"; @@ -17,8 +17,6 @@ public class KaraokeModDisableNote : Mod, IApplicableToHitObject, IApplicableToM public override IconUsage? Icon => KaraokeIcon.ModDisableNote; public override ModType Type => ModType.Fun; - public bool MicrophoneEnabled => false; - public void ApplyToHitObject(HitObject hitObject) { if (hitObject is Note note) diff --git a/osu.Game.Rulesets.Karaoke/UI/Components/SaitenStatus.cs b/osu.Game.Rulesets.Karaoke/UI/Components/SaitenStatus.cs index 47605531a..dca433c2e 100644 --- a/osu.Game.Rulesets.Karaoke/UI/Components/SaitenStatus.cs +++ b/osu.Game.Rulesets.Karaoke/UI/Components/SaitenStatus.cs @@ -39,11 +39,23 @@ public SaitenStatus(SaitenStatusMode statusMode) Spacing = new Vector2(5); Direction = FillDirection.Horizontal; AutoSizeAxes = Axes.Both; - Children = new Drawable[] + SaitenStatusMode = statusMode; + } + + private SaitenStatusMode statusMode; + + public SaitenStatusMode SaitenStatusMode + { + get => statusMode; + set { - CreateIcon(statusMode == SaitenStatusMode.Saitening), - CreateStatusSpriteText(GetSaitenStatusText(statusMode)) - }; + statusMode = value; + Children = new Drawable[] + { + CreateIcon(statusMode == SaitenStatusMode.Saitening), + CreateStatusSpriteText(GetSaitenStatusText(statusMode)) + }; + } } protected virtual string GetSaitenStatusText(SaitenStatusMode statusMode) @@ -64,10 +76,18 @@ protected virtual string GetSaitenStatusText(SaitenStatusMode statusMode) return "Osx device haven't support saiten system yet :("; case SaitenStatusMode.WindowsMicrophonePermissionDeclined: return "Open lazer with admin permission to enable saiten system."; + case SaitenStatusMode.NotSaitening: + return "This beatmap is not saitenable."; + case SaitenStatusMode.AutoPlay: + return "Auto play mode."; + case SaitenStatusMode.Edit: + return "Edit mode."; case SaitenStatusMode.Saitening: return "Saiteining..."; + case SaitenStatusMode.NotInitialized: + return "Weird... Should not goes to here :thinking:"; default: - return "Oops..."; + return "Weird... Should not goes to here either :oops:"; } } @@ -141,10 +161,34 @@ public enum SaitenStatusMode [Description("No microphone device.")] NoMicrophoneDevice, + /// + /// Beatmap is not scoring. + /// + [Description("No saitening.")] + NotSaitening, + + /// + /// Beatmap is not scoring. + /// + [Description("Autoplay.")] + AutoPlay, + + /// + /// In edit mode. + /// + [Description("Edit mode.")] + Edit, + /// /// Everything works well. /// [Description("Saitening...")] Saitening, + + /// + /// Microphone statis is not initialized. + /// + [Description("Not initialized.")] + NotInitialized, } } diff --git a/osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs b/osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs index d3645605c..6e455914a 100644 --- a/osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs +++ b/osu.Game.Rulesets.Karaoke/UI/NotePlayfield.cs @@ -170,7 +170,7 @@ public NotePlayfield(int columns) }, } }, - new SaitenStatus(SaitenStatusMode.Saitening) + saitenStatus = new SaitenStatus(SaitenStatusMode.NotInitialized) { Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, @@ -305,6 +305,11 @@ private void load(OsuColour colours, KaraokeSessionStatics session) realTimeSaitenVisualization.LineColour = colours.Yellow; session.BindWith(KaraokeRulesetSession.SaitenPitch, saitenPitch); + + session.GetBindable(KaraokeRulesetSession.SaitenStatus).BindValueChanged(e => + { + saitenStatus.SaitenStatusMode = e.NewValue; + }); } public bool OnPressed(KaraokeSaitenAction action)