Merge pull request #22635 from peppy/use-overlays-container-more

Use `Overlays` container rather than `KeyBindingInputManager` for flashlight
This commit is contained in:
Dean Herbert 2023-02-22 18:30:21 +09:00 committed by GitHub
commit a8c692a215
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 35 additions and 30 deletions

View File

@ -11,6 +11,7 @@
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
@ -26,7 +27,7 @@ public abstract partial class InputBlockingMod : Mod, IApplicableToDrawableRules
private const double flash_duration = 1000;
private DrawableRuleset<OsuHitObject> ruleset = null!;
private DrawableOsuRuleset ruleset = null!;
protected OsuAction? LastAcceptedAction { get; private set; }
@ -42,8 +43,8 @@ public abstract partial class InputBlockingMod : Mod, IApplicableToDrawableRules
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
{
ruleset = drawableRuleset;
drawableRuleset.KeyBindingInputManager.Add(new InputInterceptor(this));
ruleset = (DrawableOsuRuleset)drawableRuleset;
ruleset.KeyBindingInputManager.Add(new InputInterceptor(this));
var periods = new List<Period>();

View File

@ -11,6 +11,7 @@
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Replays;
using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.UI;
namespace osu.Game.Rulesets.Osu.Mods
@ -55,7 +56,7 @@ public void Update(Playfield playfield)
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
{
// Grab the input manager to disable the user's cursor, and for future use
inputManager = (OsuInputManager)drawableRuleset.KeyBindingInputManager;
inputManager = ((DrawableOsuRuleset)drawableRuleset).KeyBindingInputManager;
inputManager.AllowUserCursorMovement = false;
// Generate the replay frames the cursor should follow

View File

@ -10,6 +10,7 @@
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
@ -42,7 +43,7 @@ public class OsuModRelax : ModRelax, IUpdatableByPlayfield, IApplicableToDrawabl
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
{
// grab the input manager for future use.
osuInputManager = (OsuInputManager)drawableRuleset.KeyBindingInputManager;
osuInputManager = ((DrawableOsuRuleset)drawableRuleset).KeyBindingInputManager;
}
public void ApplyToPlayer(Player player)

View File

@ -26,6 +26,8 @@ public partial class DrawableOsuRuleset : DrawableRuleset<OsuHitObject>
{
protected new OsuRulesetConfigManager Config => (OsuRulesetConfigManager)base.Config;
public new OsuInputManager KeyBindingInputManager => (OsuInputManager)base.KeyBindingInputManager;
public new OsuPlayfield Playfield => (OsuPlayfield)base.Playfield;
public DrawableOsuRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList<Mod> mods = null)

View File

@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using NUnit.Framework;
using osu.Framework.Audio;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mods;
@ -93,6 +94,7 @@ public override event Action<JudgementResult> RevertResult
remove => throw new InvalidOperationException($"{nameof(RevertResult)} operations not supported in test context");
}
public override IAdjustableAudioComponent Audio { get; }
public override Playfield Playfield { get; }
public override Container Overlays { get; }
public override Container FrameStableComponents { get; }

View File

@ -9,6 +9,7 @@
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -281,6 +282,7 @@ public override event Action<JudgementResult> RevertResult
remove => throw new InvalidOperationException($"{nameof(RevertResult)} operations not supported in test context");
}
public override IAdjustableAudioComponent Audio { get; }
public override Playfield Playfield { get; }
public override Container Overlays { get; }
public override Container FrameStableComponents { get; }

View File

@ -82,7 +82,7 @@ public virtual void ApplyToDrawableRuleset(DrawableRuleset<T> drawableRuleset)
flashlight.Colour = Color4.Black;
flashlight.Combo.BindTo(Combo);
drawableRuleset.KeyBindingInputManager.Add(flashlight);
drawableRuleset.Overlays.Add(flashlight);
}
protected abstract Flashlight CreateFlashlight();

View File

@ -67,7 +67,8 @@ public void ApplyToDrawableRuleset(DrawableRuleset<TObject> drawableRuleset)
{
MetronomeBeat metronomeBeat;
drawableRuleset.Overlays.Add(metronomeBeat = new MetronomeBeat(drawableRuleset.Beatmap.HitObjects.First().StartTime));
// Importantly, this is added to FrameStableComponents and not Overlays as the latter would cause it to be self-muted by the mod's volume adjustment.
drawableRuleset.FrameStableComponents.Add(metronomeBeat = new MetronomeBeat(drawableRuleset.Beatmap.HitObjects.First().StartTime));
metronomeBeat.AddAdjustment(AdjustableProperty.Volume, metronomeVolumeAdjust);
}

View File

@ -53,7 +53,7 @@ public abstract partial class DrawableRuleset<TObject> : DrawableRuleset, IProvi
/// <summary>
/// The key conversion input manager for this DrawableRuleset.
/// </summary>
public PassThroughInputManager KeyBindingInputManager;
protected PassThroughInputManager KeyBindingInputManager;
public override double GameplayStartTime => Objects.FirstOrDefault()?.StartTime - 2000 ?? 0;
@ -66,6 +66,10 @@ public abstract partial class DrawableRuleset<TObject> : DrawableRuleset, IProvi
public override Container Overlays { get; } = new Container { RelativeSizeAxes = Axes.Both };
public override IAdjustableAudioComponent Audio => audioContainer;
private readonly AudioContainer audioContainer = new AudioContainer { RelativeSizeAxes = Axes.Both };
public override Container FrameStableComponents { get; } = new Container { RelativeSizeAxes = Axes.Both };
public override IFrameStableClock FrameStableClock => frameStabilityContainer;
@ -102,14 +106,6 @@ internal override bool FrameStablePlayback
private DrawableRulesetDependencies dependencies;
/// <summary>
/// Audio adjustments which are applied to the playfield.
/// </summary>
/// <remarks>
/// Does not affect <see cref="Overlays"/>.
/// </remarks>
public IAdjustableAudioComponent Audio { get; private set; }
/// <summary>
/// Creates a ruleset visualisation for the provided ruleset and beatmap.
/// </summary>
@ -172,28 +168,22 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl
[BackgroundDependencyLoader]
private void load(CancellationToken? cancellationToken)
{
AudioContainer audioContainer;
InternalChild = frameStabilityContainer = new FrameStabilityContainer(GameplayStartTime)
{
FrameStablePlayback = FrameStablePlayback,
Children = new Drawable[]
{
FrameStableComponents,
audioContainer = new AudioContainer
{
RelativeSizeAxes = Axes.Both,
Child = KeyBindingInputManager
.WithChild(CreatePlayfieldAdjustmentContainer()
.WithChild(Playfield)
),
},
Overlays,
audioContainer.WithChild(KeyBindingInputManager
.WithChildren(new Drawable[]
{
CreatePlayfieldAdjustmentContainer()
.WithChild(Playfield),
Overlays
})),
}
};
Audio = audioContainer;
if ((ResumeOverlay = CreateResumeOverlay()) != null)
{
AddInternal(CreateInputManager()
@ -436,13 +426,18 @@ public abstract partial class DrawableRuleset : CompositeDrawable
/// </summary>
public readonly BindableBool IsPaused = new BindableBool();
/// <summary>
/// Audio adjustments which are applied to the playfield.
/// </summary>
public abstract IAdjustableAudioComponent Audio { get; }
/// <summary>
/// The playfield.
/// </summary>
public abstract Playfield Playfield { get; }
/// <summary>
/// Content to be placed above hitobjects. Will be affected by frame stability.
/// Content to be placed above hitobjects. Will be affected by frame stability and adjustments applied to <see cref="Audio"/>.
/// </summary>
public abstract Container Overlays { get; }