mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 20:22:55 +08:00
Split out separate component
This commit is contained in:
parent
d5fcc5f762
commit
6aa894e55e
@ -6,7 +6,6 @@ using JetBrains.Annotations;
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Audio;
|
|
||||||
using osu.Game.Rulesets.Objects.Drawables;
|
using osu.Game.Rulesets.Objects.Drawables;
|
||||||
using osu.Game.Rulesets.UI.Scrolling;
|
using osu.Game.Rulesets.UI.Scrolling;
|
||||||
using osu.Game.Rulesets.Mania.UI;
|
using osu.Game.Rulesets.Mania.UI;
|
||||||
@ -29,11 +28,6 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
|
|||||||
[Resolved(canBeNull: true)]
|
[Resolved(canBeNull: true)]
|
||||||
private ManiaPlayfield playfield { get; set; }
|
private ManiaPlayfield playfield { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the samples that are played by this object during gameplay.
|
|
||||||
/// </summary>
|
|
||||||
public ISampleInfo[] GetGameplaySamples() => Samples.Samples;
|
|
||||||
|
|
||||||
protected override float SamplePlaybackPosition
|
protected override float SamplePlaybackPosition
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Linq;
|
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -19,6 +18,7 @@ using osuTK;
|
|||||||
using osu.Game.Rulesets.Mania.Beatmaps;
|
using osu.Game.Rulesets.Mania.Beatmaps;
|
||||||
using osu.Game.Rulesets.Mania.Objects;
|
using osu.Game.Rulesets.Mania.Objects;
|
||||||
using osu.Game.Rulesets.Mania.Objects.Drawables;
|
using osu.Game.Rulesets.Mania.Objects.Drawables;
|
||||||
|
using osu.Game.Rulesets.UI;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Mania.UI
|
namespace osu.Game.Rulesets.Mania.UI
|
||||||
{
|
{
|
||||||
@ -28,12 +28,6 @@ namespace osu.Game.Rulesets.Mania.UI
|
|||||||
public const float COLUMN_WIDTH = 80;
|
public const float COLUMN_WIDTH = 80;
|
||||||
public const float SPECIAL_COLUMN_WIDTH = 70;
|
public const float SPECIAL_COLUMN_WIDTH = 70;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// For hitsounds played by this <see cref="Column"/> (i.e. not as a result of hitting a hitobject),
|
|
||||||
/// a certain number of samples are allowed to be played concurrently so that it feels better when spam-pressing the key.
|
|
||||||
/// </summary>
|
|
||||||
private const int max_concurrent_hitsounds = OsuGameBase.SAMPLE_CONCURRENCY;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The index of this column as part of the whole playfield.
|
/// The index of this column as part of the whole playfield.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -45,10 +39,10 @@ namespace osu.Game.Rulesets.Mania.UI
|
|||||||
internal readonly Container TopLevelContainer;
|
internal readonly Container TopLevelContainer;
|
||||||
private readonly DrawablePool<PoolableHitExplosion> hitExplosionPool;
|
private readonly DrawablePool<PoolableHitExplosion> hitExplosionPool;
|
||||||
private readonly OrderedHitPolicy hitPolicy;
|
private readonly OrderedHitPolicy hitPolicy;
|
||||||
private readonly Container<SkinnableSound> hitSounds;
|
|
||||||
|
|
||||||
public Container UnderlayElements => HitObjectArea.UnderlayElements;
|
public Container UnderlayElements => HitObjectArea.UnderlayElements;
|
||||||
|
|
||||||
|
private readonly GameplaySampleTriggerSource sampleTriggerSource;
|
||||||
|
|
||||||
public Column(int index)
|
public Column(int index)
|
||||||
{
|
{
|
||||||
Index = index;
|
Index = index;
|
||||||
@ -64,6 +58,7 @@ namespace osu.Game.Rulesets.Mania.UI
|
|||||||
InternalChildren = new[]
|
InternalChildren = new[]
|
||||||
{
|
{
|
||||||
hitExplosionPool = new DrawablePool<PoolableHitExplosion>(5),
|
hitExplosionPool = new DrawablePool<PoolableHitExplosion>(5),
|
||||||
|
sampleTriggerSource = new GameplaySampleTriggerSource(HitObjectContainer),
|
||||||
// For input purposes, the background is added at the highest depth, but is then proxied back below all other elements
|
// For input purposes, the background is added at the highest depth, but is then proxied back below all other elements
|
||||||
background.CreateProxy(),
|
background.CreateProxy(),
|
||||||
HitObjectArea = new ColumnHitObjectArea(Index, HitObjectContainer) { RelativeSizeAxes = Axes.Both },
|
HitObjectArea = new ColumnHitObjectArea(Index, HitObjectContainer) { RelativeSizeAxes = Axes.Both },
|
||||||
@ -72,12 +67,6 @@ namespace osu.Game.Rulesets.Mania.UI
|
|||||||
RelativeSizeAxes = Axes.Both
|
RelativeSizeAxes = Axes.Both
|
||||||
},
|
},
|
||||||
background,
|
background,
|
||||||
hitSounds = new Container<SkinnableSound>
|
|
||||||
{
|
|
||||||
Name = "Column samples pool",
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Children = Enumerable.Range(0, max_concurrent_hitsounds).Select(_ => new SkinnableSound()).ToArray()
|
|
||||||
},
|
|
||||||
TopLevelContainer = new Container { RelativeSizeAxes = Axes.Both }
|
TopLevelContainer = new Container { RelativeSizeAxes = Axes.Both }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -133,29 +122,12 @@ namespace osu.Game.Rulesets.Mania.UI
|
|||||||
HitObjectArea.Explosions.Add(hitExplosionPool.Get(e => e.Apply(result)));
|
HitObjectArea.Explosions.Add(hitExplosionPool.Get(e => e.Apply(result)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private int nextHitSoundIndex;
|
|
||||||
|
|
||||||
public bool OnPressed(ManiaAction action)
|
public bool OnPressed(ManiaAction action)
|
||||||
{
|
{
|
||||||
if (action != Action.Value)
|
if (action != Action.Value)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var nextObject =
|
sampleTriggerSource.Play();
|
||||||
HitObjectContainer.AliveObjects.FirstOrDefault(h => h.HitObject.StartTime > Time.Current) ??
|
|
||||||
// fallback to non-alive objects to find next off-screen object
|
|
||||||
HitObjectContainer.Objects.FirstOrDefault(h => h.HitObject.StartTime > Time.Current) ??
|
|
||||||
HitObjectContainer.Objects.LastOrDefault();
|
|
||||||
|
|
||||||
if (nextObject is DrawableManiaHitObject maniaObject)
|
|
||||||
{
|
|
||||||
var hitSound = hitSounds[nextHitSoundIndex];
|
|
||||||
|
|
||||||
hitSound.Samples = maniaObject.GetGameplaySamples();
|
|
||||||
hitSound.Play();
|
|
||||||
|
|
||||||
nextHitSoundIndex = (nextHitSoundIndex + 1) % max_concurrent_hitsounds;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,6 +54,11 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly Bindable<Color4> AccentColour = new Bindable<Color4>(Color4.Gray);
|
public readonly Bindable<Color4> AccentColour = new Bindable<Color4>(Color4.Gray);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the samples that are played by this object during gameplay.
|
||||||
|
/// </summary>
|
||||||
|
public ISampleInfo[] GetGameplaySamples() => Samples.Samples;
|
||||||
|
|
||||||
protected PausableSkinnableSound Samples { get; private set; }
|
protected PausableSkinnableSound Samples { get; private set; }
|
||||||
|
|
||||||
public virtual IEnumerable<HitSampleInfo> GetSamples() => HitObject.Samples;
|
public virtual IEnumerable<HitSampleInfo> GetSamples() => HitObject.Samples;
|
||||||
|
84
osu.Game/Rulesets/UI/GameplaySampleTriggerSource.cs
Normal file
84
osu.Game/Rulesets/UI/GameplaySampleTriggerSource.cs
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT 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.Graphics.Containers;
|
||||||
|
using osu.Game.Audio;
|
||||||
|
using osu.Game.Rulesets.Objects;
|
||||||
|
using osu.Game.Skinning;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.UI
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A component which can trigger the most appropriate hit sound for a given point in time, based on the state of a <see cref="HitObjectContainer"/>
|
||||||
|
/// </summary>
|
||||||
|
public class GameplaySampleTriggerSource : CompositeDrawable
|
||||||
|
{
|
||||||
|
private readonly HitObjectContainer hitObjectContainer;
|
||||||
|
|
||||||
|
private int nextHitSoundIndex;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The number of concurrent samples allowed to be played concurrently so that it feels better when spam-pressing a key.
|
||||||
|
/// </summary>
|
||||||
|
private const int max_concurrent_hitsounds = OsuGameBase.SAMPLE_CONCURRENCY;
|
||||||
|
|
||||||
|
private readonly Container<SkinnableSound> hitSounds;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private DrawableRuleset drawableRuleset { get; set; }
|
||||||
|
|
||||||
|
public GameplaySampleTriggerSource(HitObjectContainer hitObjectContainer)
|
||||||
|
{
|
||||||
|
this.hitObjectContainer = hitObjectContainer;
|
||||||
|
InternalChildren = new Drawable[]
|
||||||
|
{
|
||||||
|
hitSounds = new Container<SkinnableSound>
|
||||||
|
{
|
||||||
|
Name = "concurrent sample pool",
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Children = Enumerable.Range(0, max_concurrent_hitsounds).Select(_ => new SkinnableSound()).ToArray()
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private ISampleInfo[] playableSampleInfo;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Play the most appropriate hit sound for the current point in time.
|
||||||
|
/// </summary>
|
||||||
|
public void Play()
|
||||||
|
{
|
||||||
|
var nextObject =
|
||||||
|
hitObjectContainer.AliveObjects.FirstOrDefault(h => h.HitObject.StartTime > Time.Current)?.HitObject ??
|
||||||
|
// fallback to non-alive objects to find next off-screen object
|
||||||
|
// TODO: make lookup more efficient?
|
||||||
|
drawableRuleset.Objects.FirstOrDefault(h => h.StartTime > Time.Current) ??
|
||||||
|
drawableRuleset.Objects.LastOrDefault();
|
||||||
|
|
||||||
|
if (nextObject != null)
|
||||||
|
{
|
||||||
|
var hitSound = getNextSample();
|
||||||
|
playableSampleInfo = GetPlayableSampleInfo(nextObject);
|
||||||
|
hitSound.Samples = playableSampleInfo;
|
||||||
|
hitSound.Play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual ISampleInfo[] GetPlayableSampleInfo(HitObject nextObject) =>
|
||||||
|
// TODO: avoid cast somehow?
|
||||||
|
nextObject.Samples.Cast<ISampleInfo>().ToArray();
|
||||||
|
|
||||||
|
private SkinnableSound getNextSample()
|
||||||
|
{
|
||||||
|
var hitSound = hitSounds[nextHitSoundIndex];
|
||||||
|
|
||||||
|
// round robin over available samples to allow for concurrent playback.
|
||||||
|
nextHitSoundIndex = (nextHitSoundIndex + 1) % max_concurrent_hitsounds;
|
||||||
|
|
||||||
|
return hitSound;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user