Skip to content

Commit

Permalink
Merge pull request #1283 from andy840119/do-not-pass-beatmap-in-pract…
Browse files Browse the repository at this point in the history
…ice-overlay

Do not pass beatmap in practice overlay.
  • Loading branch information
andy840119 authored Apr 23, 2022
2 parents 6b0d4f5 + becb9bb commit 14b70de
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 4 additions & 2 deletions osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneControlLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<KaraokeRulesetConfigManager>();
Dependencies.Cache(new KaraokeSessionStatics(config, null));

// Cannot work now because it need extra BDL in child
Expand Down
6 changes: 4 additions & 2 deletions osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneNotePlayfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ public class TestSceneNotePlayfield : OsuTestScene

private readonly List<NotePlayfield> 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<KaraokeRulesetConfigManager>();
Dependencies.Cache(new KaraokeSessionStatics(config, null));

Child = new GridContainer
Expand Down
11 changes: 1 addition & 10 deletions osu.Game.Rulesets.Karaoke/Mods/KaraokeModPractice.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Copyright (c) andy840119 <[email protected]>. 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;
Expand All @@ -26,15 +24,11 @@ public class KaraokeModPractice : ModAutoplay, IApplicableToDrawableRuleset<Kara
public override IconUsage? Icon => KaraokeIcon.ModPractice;
public override ModType Type => ModType.Fun;

private KaraokeBeatmap beatmap;

public override ModReplayData CreateReplayData(IBeatmap beatmap, IReadOnlyList<Mod> mods)
=> new(new KaraokeAutoGenerator(beatmap, mods).Generate(), new ModCreatedUser { Username = "practice master" });

public void ApplyToDrawableRuleset(DrawableRuleset<KaraokeHitObject> drawableRuleset)
{
beatmap = drawableRuleset.Beatmap as KaraokeBeatmap;

if (drawableRuleset.Playfield is KaraokePlayfield karaokePlayfield)
{
karaokePlayfield.DisplayCursor = new BindableBool
Expand All @@ -47,11 +41,8 @@ public void ApplyToDrawableRuleset(DrawableRuleset<KaraokeHitObject> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public class NoteStylePreview : Container

protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var configCache = parent.Get<IRulesetConfigCache>();
var config = (KaraokeRulesetConfigManager)configCache.GetConfigFor(new KaraokeRuleset());
var config = Dependencies.Get<KaraokeRulesetConfigManager>();
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.Cache(new KaraokeSessionStatics(config, null));

Expand Down
28 changes: 14 additions & 14 deletions osu.Game.Rulesets.Karaoke/UI/HUD/GeneralSettingOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class GeneralSettingOverlay : SettingOverlay, IKeyBindingHandler<KaraokeA
private readonly BindableInt bindableVocalPitch = new();
private readonly BindableInt bindableSaitenPitch = new();

public GeneralSettingOverlay(IBeatmap beatmap)
public GeneralSettingOverlay()
{
// Add common group
Add(new VisualSettings
Expand All @@ -44,18 +44,6 @@ public GeneralSettingOverlay(IBeatmap beatmap)
Value = false
}
});

// Add translate group if this beatmap has translate
if (beatmap.AnyTranslate())
{
Add(new TranslateSettings(beatmap.AvailableTranslates())
{
Expanded =
{
Value = false
}
});
}
}

public override SettingButton CreateToggleButton() => new()
Expand Down Expand Up @@ -131,8 +119,20 @@ public virtual void OnReleased(KeyBindingReleaseEvent<KaraokeAction> e)
}

[BackgroundDependencyLoader]
private void load(KaraokeSessionStatics session)
private void load(IBindable<WorkingBeatmap> 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);
Expand Down
5 changes: 2 additions & 3 deletions osu.Game.Rulesets.Karaoke/UI/HUD/PracticeOverlay.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// Copyright (c) andy840119 <[email protected]>. 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 =
{
Expand Down
14 changes: 7 additions & 7 deletions osu.Game.Rulesets.Karaoke/UI/HUD/SettingOverlayContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,17 +22,15 @@ public class SettingOverlayContainer : CompositeDrawable, IKeyBindingHandler<Kar

public Action<SettingOverlay> OnNewOverlayAdded;

[BackgroundDependencyLoader(true)]
private void load(Player player)
[BackgroundDependencyLoader]
private void load(IBindable<IReadOnlyList<Mod>> mods)
{
var beatmap = player?.Beatmap?.Value.Beatmap;
AddExtraOverlay(generalSettingsOverlay = new GeneralSettingOverlay(beatmap));
AddExtraOverlay(generalSettingsOverlay = new GeneralSettingOverlay());

var mods = player?.GameplayState.Mods;
if (mods == null)
return;

foreach (var mod in mods.OfType<IApplicableToSettingHUDOverlay>())
foreach (var mod in mods.Value.OfType<IApplicableToSettingHUDOverlay>())
mod.ApplyToOverlay(this);
}

Expand Down
18 changes: 11 additions & 7 deletions osu.Game.Rulesets.Karaoke/UI/PlayerSettings/LyricsPreview.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. 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;
Expand Down Expand Up @@ -31,7 +30,7 @@ public class LyricsPreview : CompositeDrawable
[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; }

public LyricsPreview(IEnumerable<Lyric> lyrics)
public LyricsPreview()
{
InternalChild = new OsuScrollContainer
{
Expand All @@ -41,11 +40,6 @@ public LyricsPreview(IEnumerable<Lyric> 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()
}
};

Expand All @@ -59,6 +53,16 @@ public LyricsPreview(IEnumerable<Lyric> lyrics)
if (newValue != null)
lyricTable.Where(x => newValue.Contains(x.HitObject)).ForEach(x => { x.Selected = true; });
});

Schedule(() =>
{
var lyrics = beatmap.Value.Beatmap.HitObjects.OfType<Lyric>().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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
// Copyright (c) andy840119 <[email protected]>. 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;

Expand All @@ -19,11 +16,9 @@ public class PracticeSettings : PlayerSettingsGroup, IKeyBindingHandler<KaraokeA
{
private readonly PlayerSliderBar<double> preemptTimeSliderBar;

public PracticeSettings(IBeatmap beatmap)
public PracticeSettings()
: base("Practice")
{
var lyrics = beatmap.HitObjects.OfType<Lyric>().ToList();

Children = new Drawable[]
{
new OsuSpriteText
Expand All @@ -35,7 +30,7 @@ public PracticeSettings(IBeatmap beatmap)
{
Text = "Lyric:"
},
new LyricsPreview(lyrics)
new LyricsPreview
{
Height = 580,
RelativeSizeAxes = Axes.X,
Expand Down
11 changes: 7 additions & 4 deletions osu.Game.Rulesets.Karaoke/UI/PlayerSettings/TranslateSettings.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Copyright (c) andy840119 <[email protected]>. 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;

Expand All @@ -18,7 +20,7 @@ public class TranslateSettings : PlayerSettingsGroup
private readonly OsuSpriteText translateText;
private readonly OsuDropdown<CultureInfo> translateDropDown;

public TranslateSettings(IEnumerable<CultureInfo> translates)
public TranslateSettings()
: base("Translate")
{
Children = new Drawable[]
Expand All @@ -34,14 +36,15 @@ public TranslateSettings(IEnumerable<CultureInfo> translates)
translateDropDown = new OsuDropdown<CultureInfo>
{
RelativeSizeAxes = Axes.X,
Items = translates
},
};
}

[BackgroundDependencyLoader]
private void load(KaraokeSessionStatics session)
private void load(IBindable<WorkingBeatmap> beatmap, KaraokeSessionStatics session)
{
translateDropDown.Items = beatmap.Value.Beatmap.AvailableTranslates();

// Translate
translateCheckBox.Current = session.GetBindable<bool>(KaraokeRulesetSession.UseTranslate);
translateDropDown.Current = session.GetBindable<CultureInfo>(KaraokeRulesetSession.PreferLanguage);
Expand Down

0 comments on commit 14b70de

Please sign in to comment.