From 9a075cc4e7b351ed98d4f5e1bddb70dba19ba63e Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 23 Apr 2022 11:57:26 +0800 Subject: [PATCH 1/5] Remove beatmap passing in the practice overlay and practice setting. --- .../Mods/KaraokeModPractice.cs | 11 +---------- .../UI/HUD/PracticeOverlay.cs | 5 ++--- .../UI/PlayerSettings/LyricsPreview.cs | 18 +++++++++++------- .../UI/PlayerSettings/PracticeSettings.cs | 9 ++------- 4 files changed, 16 insertions(+), 27 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Mods/KaraokeModPractice.cs b/osu.Game.Rulesets.Karaoke/Mods/KaraokeModPractice.cs index 1854c253a..888433153 100644 --- a/osu.Game.Rulesets.Karaoke/Mods/KaraokeModPractice.cs +++ b/osu.Game.Rulesets.Karaoke/Mods/KaraokeModPractice.cs @@ -1,12 +1,10 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -using System; using System.Collections.Generic; using osu.Framework.Bindables; using osu.Framework.Graphics.Sprites; using osu.Game.Beatmaps; -using osu.Game.Rulesets.Karaoke.Beatmaps; using osu.Game.Rulesets.Karaoke.Graphics.Sprites; using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Replays; @@ -26,15 +24,11 @@ public class KaraokeModPractice : ModAutoplay, IApplicableToDrawableRuleset KaraokeIcon.ModPractice; public override ModType Type => ModType.Fun; - private KaraokeBeatmap beatmap; - public override ModReplayData CreateReplayData(IBeatmap beatmap, IReadOnlyList mods) => new(new KaraokeAutoGenerator(beatmap, mods).Generate(), new ModCreatedUser { Username = "practice master" }); public void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) { - beatmap = drawableRuleset.Beatmap as KaraokeBeatmap; - if (drawableRuleset.Playfield is KaraokePlayfield karaokePlayfield) { karaokePlayfield.DisplayCursor = new BindableBool @@ -47,11 +41,8 @@ public void ApplyToDrawableRuleset(DrawableRuleset drawableRul public void ApplyToOverlay(ISettingHUDOverlay overlay) { - if (beatmap == null) - throw new ArgumentNullException(nameof(beatmap)); - // Add practice overlay - overlay.AddExtraOverlay(new PracticeOverlay(beatmap)); + overlay.AddExtraOverlay(new PracticeOverlay()); // Add playback group into main overlay overlay.AddSettingsGroup(new PlaybackSettings diff --git a/osu.Game.Rulesets.Karaoke/UI/HUD/PracticeOverlay.cs b/osu.Game.Rulesets.Karaoke/UI/HUD/PracticeOverlay.cs index 770e7e83f..c750fb01e 100644 --- a/osu.Game.Rulesets.Karaoke/UI/HUD/PracticeOverlay.cs +++ b/osu.Game.Rulesets.Karaoke/UI/HUD/PracticeOverlay.cs @@ -1,16 +1,15 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Game.Beatmaps; using osu.Game.Rulesets.Karaoke.UI.PlayerSettings; namespace osu.Game.Rulesets.Karaoke.UI.HUD { public class PracticeOverlay : SettingOverlay { - public PracticeOverlay(IBeatmap beatmap) + public PracticeOverlay() { - Add(new PracticeSettings(beatmap) + Add(new PracticeSettings { Expanded = { diff --git a/osu.Game.Rulesets.Karaoke/UI/PlayerSettings/LyricsPreview.cs b/osu.Game.Rulesets.Karaoke/UI/PlayerSettings/LyricsPreview.cs index 54ee8a69b..c04454829 100644 --- a/osu.Game.Rulesets.Karaoke/UI/PlayerSettings/LyricsPreview.cs +++ b/osu.Game.Rulesets.Karaoke/UI/PlayerSettings/LyricsPreview.cs @@ -1,7 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; @@ -31,7 +30,7 @@ public class LyricsPreview : CompositeDrawable [Resolved] private IBindable beatmap { get; set; } - public LyricsPreview(IEnumerable lyrics) + public LyricsPreview() { InternalChild = new OsuScrollContainer { @@ -41,11 +40,6 @@ public LyricsPreview(IEnumerable lyrics) AutoSizeAxes = Axes.Y, RelativeSizeAxes = Axes.X, Direction = FillDirection.Vertical, - Children = lyrics.Select(x => createLyricContainer(x).With(c => - { - c.Selected = false; - c.Action = () => triggerLyric(x); - })).ToList() } }; @@ -59,6 +53,16 @@ public LyricsPreview(IEnumerable lyrics) if (newValue != null) lyricTable.Where(x => newValue.Contains(x.HitObject)).ForEach(x => { x.Selected = true; }); }); + + Schedule(() => + { + var lyrics = beatmap.Value.Beatmap.HitObjects.OfType().ToList(); + lyricTable.Children = lyrics.Select(x => createLyricContainer(x).With(c => + { + c.Selected = false; + c.Action = () => triggerLyric(x); + })).ToList(); + }); } private ClickableLyric createLyricContainer(Lyric lyric) => new(lyric); diff --git a/osu.Game.Rulesets.Karaoke/UI/PlayerSettings/PracticeSettings.cs b/osu.Game.Rulesets.Karaoke/UI/PlayerSettings/PracticeSettings.cs index 9ac90c53f..3f76ccaeb 100644 --- a/osu.Game.Rulesets.Karaoke/UI/PlayerSettings/PracticeSettings.cs +++ b/osu.Game.Rulesets.Karaoke/UI/PlayerSettings/PracticeSettings.cs @@ -1,15 +1,12 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -using System.Linq; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; -using osu.Game.Beatmaps; using osu.Game.Graphics.Sprites; using osu.Game.Rulesets.Karaoke.Configuration; -using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Screens.Play.PlayerSettings; using osuTK; @@ -19,11 +16,9 @@ public class PracticeSettings : PlayerSettingsGroup, IKeyBindingHandler preemptTimeSliderBar; - public PracticeSettings(IBeatmap beatmap) + public PracticeSettings() : base("Practice") { - var lyrics = beatmap.HitObjects.OfType().ToList(); - Children = new Drawable[] { new OsuSpriteText @@ -35,7 +30,7 @@ public PracticeSettings(IBeatmap beatmap) { Text = "Lyric:" }, - new LyricsPreview(lyrics) + new LyricsPreview { Height = 580, RelativeSizeAxes = Axes.X, From 85567fa3f0c546f4a4761feea07939f216657a20 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 23 Apr 2022 12:06:17 +0800 Subject: [PATCH 2/5] There's no need to pass the available translate in the translate settings. --- .../UI/HUD/GeneralSettingOverlay.cs | 28 +++++++++---------- .../UI/HUD/SettingOverlayContainer.cs | 3 +- .../UI/PlayerSettings/TranslateSettings.cs | 11 +++++--- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/UI/HUD/GeneralSettingOverlay.cs b/osu.Game.Rulesets.Karaoke/UI/HUD/GeneralSettingOverlay.cs index 752200d1b..7e6caa885 100644 --- a/osu.Game.Rulesets.Karaoke/UI/HUD/GeneralSettingOverlay.cs +++ b/osu.Game.Rulesets.Karaoke/UI/HUD/GeneralSettingOverlay.cs @@ -20,7 +20,7 @@ public class GeneralSettingOverlay : SettingOverlay, IKeyBindingHandler new() @@ -131,8 +119,20 @@ public virtual void OnReleased(KeyBindingReleaseEvent e) } [BackgroundDependencyLoader] - private void load(KaraokeSessionStatics session) + private void load(IBindable beatmap, KaraokeSessionStatics session) { + // Add translate group if this beatmap has translate + if (beatmap.Value.Beatmap.AnyTranslate()) + { + Add(new TranslateSettings + { + Expanded = + { + Value = false + } + }); + } + session.BindWith(KaraokeRulesetSession.Pitch, bindablePitch); session.BindWith(KaraokeRulesetSession.VocalPitch, bindableVocalPitch); session.BindWith(KaraokeRulesetSession.SaitenPitch, bindableSaitenPitch); diff --git a/osu.Game.Rulesets.Karaoke/UI/HUD/SettingOverlayContainer.cs b/osu.Game.Rulesets.Karaoke/UI/HUD/SettingOverlayContainer.cs index c19a6ac26..9db71645f 100644 --- a/osu.Game.Rulesets.Karaoke/UI/HUD/SettingOverlayContainer.cs +++ b/osu.Game.Rulesets.Karaoke/UI/HUD/SettingOverlayContainer.cs @@ -23,8 +23,7 @@ public class SettingOverlayContainer : CompositeDrawable, IKeyBindingHandler. Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; using System.Globalization; using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Game.Beatmaps; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; +using osu.Game.Rulesets.Karaoke.Beatmaps; using osu.Game.Rulesets.Karaoke.Configuration; using osu.Game.Screens.Play.PlayerSettings; @@ -18,7 +20,7 @@ public class TranslateSettings : PlayerSettingsGroup private readonly OsuSpriteText translateText; private readonly OsuDropdown translateDropDown; - public TranslateSettings(IEnumerable translates) + public TranslateSettings() : base("Translate") { Children = new Drawable[] @@ -34,14 +36,15 @@ public TranslateSettings(IEnumerable translates) translateDropDown = new OsuDropdown { RelativeSizeAxes = Axes.X, - Items = translates }, }; } [BackgroundDependencyLoader] - private void load(KaraokeSessionStatics session) + private void load(IBindable beatmap, KaraokeSessionStatics session) { + translateDropDown.Items = beatmap.Value.Beatmap.AvailableTranslates(); + // Translate translateCheckBox.Current = session.GetBindable(KaraokeRulesetSession.UseTranslate); translateDropDown.Current = session.GetBindable(KaraokeRulesetSession.PreferLanguage); From cbdb5b3bc8e427ce30cf361901a9bfce78189c0a Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 23 Apr 2022 12:27:23 +0800 Subject: [PATCH 3/5] There's no need to get bindable mode from the player. --- .../UI/HUD/SettingOverlayContainer.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/UI/HUD/SettingOverlayContainer.cs b/osu.Game.Rulesets.Karaoke/UI/HUD/SettingOverlayContainer.cs index 9db71645f..ba62d0bd3 100644 --- a/osu.Game.Rulesets.Karaoke/UI/HUD/SettingOverlayContainer.cs +++ b/osu.Game.Rulesets.Karaoke/UI/HUD/SettingOverlayContainer.cs @@ -2,14 +2,16 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Graphics.Containers; using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; using osu.Game.Rulesets.Karaoke.Mods; +using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.UI; -using osu.Game.Screens.Play; using osu.Game.Screens.Play.PlayerSettings; namespace osu.Game.Rulesets.Karaoke.UI.HUD @@ -20,16 +22,15 @@ public class SettingOverlayContainer : CompositeDrawable, IKeyBindingHandler OnNewOverlayAdded; - [BackgroundDependencyLoader(true)] - private void load(Player player) + [BackgroundDependencyLoader] + private void load(IBindable> mods) { AddExtraOverlay(generalSettingsOverlay = new GeneralSettingOverlay()); - var mods = player?.GameplayState.Mods; if (mods == null) return; - foreach (var mod in mods.OfType()) + foreach (var mod in mods.Value.OfType()) mod.ApplyToOverlay(this); } From d15a263f68b96153cabfd93112b5febddefd7547 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 23 Apr 2022 12:31:48 +0800 Subject: [PATCH 4/5] assign the ruleset to the test case for able to get the config without re-create it. --- .../Skinning/TestSceneNotePlayfield.cs | 2 +- osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneControlLayer.cs | 6 ++++-- .../UI/TestSceneNotePlayfield.cs | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Skinning/TestSceneNotePlayfield.cs b/osu.Game.Rulesets.Karaoke.Tests/Skinning/TestSceneNotePlayfield.cs index 887f06e6d..338034beb 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Skinning/TestSceneNotePlayfield.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Skinning/TestSceneNotePlayfield.cs @@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Skinning public class TestSceneNotePlayfield : KaraokeSkinnableColumnTestScene { [BackgroundDependencyLoader] - private void load(IRulesetConfigCache configCache) + private void load() { SetContents(_ => new KaraokeInputManager(new KaraokeRuleset().RulesetInfo) { diff --git a/osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneControlLayer.cs b/osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneControlLayer.cs index 8c344696f..500c486d2 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneControlLayer.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneControlLayer.cs @@ -16,10 +16,12 @@ public class TestSceneControlLayer : OsuTestScene { public SettingOverlayContainer SettingOverlayContainer { get; set; } + protected override Ruleset CreateRuleset() => new KaraokeRuleset(); + [BackgroundDependencyLoader] - private void load(IRulesetConfigCache configCache) + private void load() { - var config = (KaraokeRulesetConfigManager)configCache.GetConfigFor(Ruleset.Value.CreateInstance()); + var config = Dependencies.Get(); Dependencies.Cache(new KaraokeSessionStatics(config, null)); // Cannot work now because it need extra BDL in child diff --git a/osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneNotePlayfield.cs b/osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneNotePlayfield.cs index 147343a13..f8d16169e 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneNotePlayfield.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneNotePlayfield.cs @@ -37,10 +37,12 @@ public class TestSceneNotePlayfield : OsuTestScene private readonly List notePlayfields = new(); + protected override Ruleset CreateRuleset() => new KaraokeRuleset(); + [BackgroundDependencyLoader] - private void load(IRulesetConfigCache configCache) + private void load() { - var config = (KaraokeRulesetConfigManager)configCache.GetConfigFor(Ruleset.Value.CreateInstance()); + var config = Dependencies.Get(); Dependencies.Cache(new KaraokeSessionStatics(config, null)); Child = new GridContainer From becb9bbacae9dce9e337b22949622cbfd4a08569 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 23 Apr 2022 12:33:45 +0800 Subject: [PATCH 5/5] Guess it should be possible to get the config directly? --- .../Screens/Skin/Style/NoteStylePreview.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Screens/Skin/Style/NoteStylePreview.cs b/osu.Game.Rulesets.Karaoke/Screens/Skin/Style/NoteStylePreview.cs index 1d293589a..3102c2ddd 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Skin/Style/NoteStylePreview.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Skin/Style/NoteStylePreview.cs @@ -29,8 +29,7 @@ public class NoteStylePreview : Container protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) { - var configCache = parent.Get(); - var config = (KaraokeRulesetConfigManager)configCache.GetConfigFor(new KaraokeRuleset()); + var config = Dependencies.Get(); var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); dependencies.Cache(new KaraokeSessionStatics(config, null));