mirror of
https://github.com/ppy/osu
synced 2025-01-11 16:49:39 +00:00
Make InputDrum handle all Normals/Claps, hitobjects all others
This commit is contained in:
parent
58c35b8ba5
commit
14162b5d46
@ -1,7 +1,8 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Audio;
|
using osu.Framework.Audio;
|
||||||
using osu.Framework.Audio.Sample;
|
using osu.Framework.Audio.Sample;
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
@ -9,32 +10,38 @@ using osu.Game.Beatmaps.ControlPoints;
|
|||||||
|
|
||||||
namespace osu.Game.Rulesets.Taiko.Audio
|
namespace osu.Game.Rulesets.Taiko.Audio
|
||||||
{
|
{
|
||||||
public class DrumSampleMapping : IComparable<DrumSampleMapping>
|
public class DrumSampleMapping
|
||||||
{
|
{
|
||||||
public double Time;
|
private readonly ControlPointInfo controlPoints;
|
||||||
public readonly SampleInfo Centre;
|
private readonly Dictionary<SampleControlPoint, DrumSample> mappings = new Dictionary<SampleControlPoint, DrumSample>();
|
||||||
public readonly SampleInfo Rim;
|
|
||||||
|
|
||||||
public SampleChannel CentreChannel { get; private set; }
|
public DrumSampleMapping(ControlPointInfo controlPoints, AudioManager audio)
|
||||||
public SampleChannel RimChannel { get; private set; }
|
|
||||||
|
|
||||||
public DrumSampleMapping()
|
|
||||||
{
|
{
|
||||||
|
this.controlPoints = controlPoints;
|
||||||
|
|
||||||
|
IEnumerable<SampleControlPoint> samplePoints;
|
||||||
|
if (controlPoints.SamplePoints.Count == 0)
|
||||||
|
// Get the default sample point
|
||||||
|
samplePoints = new[] { controlPoints.SamplePointAt(double.MinValue) };
|
||||||
|
else
|
||||||
|
samplePoints = controlPoints.SamplePoints;
|
||||||
|
|
||||||
|
foreach (var s in samplePoints.Distinct())
|
||||||
|
{
|
||||||
|
mappings[s] = new DrumSample
|
||||||
|
{
|
||||||
|
Centre = s.GetSampleInfo().GetChannel(audio.Sample),
|
||||||
|
Rim = s.GetSampleInfo(SampleInfo.HIT_CLAP).GetChannel(audio.Sample)
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DrumSampleMapping(SampleControlPoint samplePoint)
|
public DrumSample SampleAt(double time) => mappings[controlPoints.SamplePointAt(time)];
|
||||||
{
|
|
||||||
Time = samplePoint.Time;
|
|
||||||
Centre = samplePoint.GetSampleInfo();
|
|
||||||
Rim = samplePoint.GetSampleInfo(SampleInfo.HIT_CLAP);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RetrieveChannels(AudioManager audio)
|
public class DrumSample
|
||||||
{
|
{
|
||||||
CentreChannel = Centre.GetChannel(audio.Sample);
|
public SampleChannel Centre;
|
||||||
RimChannel = Rim.GetChannel(audio.Sample);
|
public SampleChannel Rim;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int CompareTo(DrumSampleMapping other) => Time.CompareTo(other.Time);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,9 +123,6 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
|||||||
MainPiece.AccentColour = colours.YellowDark;
|
MainPiece.AccentColour = colours.YellowDark;
|
||||||
expandingRing.Colour = colours.YellowLight;
|
expandingRing.Colour = colours.YellowLight;
|
||||||
targetRing.BorderColour = colours.YellowDark.Opacity(0.25f);
|
targetRing.BorderColour = colours.YellowDark.Opacity(0.25f);
|
||||||
|
|
||||||
foreach (var mapping in HitObject.ProgressionSamples)
|
|
||||||
mapping.RetrieveChannels(audio);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
@ -223,22 +220,6 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
|||||||
|
|
||||||
UpdateJudgement(true);
|
UpdateJudgement(true);
|
||||||
|
|
||||||
if (AllJudged)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// While the swell hasn't been fully judged, input is still blocked so it doesn't fall through to other hitobjects
|
|
||||||
// This causes the playfield to not play sounds, so they need to be handled locally
|
|
||||||
|
|
||||||
var mappingIndex = HitObject.ProgressionSamples.BinarySearch(new DrumSampleMapping { Time = Time.Current });
|
|
||||||
if (mappingIndex < 0)
|
|
||||||
mappingIndex = ~mappingIndex - 1;
|
|
||||||
|
|
||||||
var mapping = HitObject.ProgressionSamples[mappingIndex];
|
|
||||||
if (isCentre)
|
|
||||||
mapping.CentreChannel.Play();
|
|
||||||
else
|
|
||||||
mapping.RimChannel.Play();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,10 @@ using osu.Framework.Input.Bindings;
|
|||||||
using osu.Game.Rulesets.Objects.Drawables;
|
using osu.Game.Rulesets.Objects.Drawables;
|
||||||
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
|
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Game.Audio;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
||||||
{
|
{
|
||||||
@ -35,6 +39,9 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
|||||||
MainPiece.KiaiMode = HitObject.Kiai;
|
MainPiece.KiaiMode = HitObject.Kiai;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Normal and clap samples are handled by the drum
|
||||||
|
protected override IEnumerable<SampleInfo> GetSamples() => HitObject.Samples.Where(s => s.Name != SampleInfo.HIT_NORMAL && s.Name != SampleInfo.HIT_CLAP);
|
||||||
|
|
||||||
protected virtual TaikoPiece CreateMainPiece() => new CirclePiece();
|
protected virtual TaikoPiece CreateMainPiece() => new CirclePiece();
|
||||||
|
|
||||||
public abstract bool OnPressed(TaikoAction action);
|
public abstract bool OnPressed(TaikoAction action);
|
||||||
|
@ -20,18 +20,5 @@ namespace osu.Game.Rulesets.Taiko.Objects
|
|||||||
/// The number of hits required to complete the swell successfully.
|
/// The number of hits required to complete the swell successfully.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int RequiredHits = 10;
|
public int RequiredHits = 10;
|
||||||
|
|
||||||
public List<DrumSampleMapping> ProgressionSamples = new List<DrumSampleMapping>();
|
|
||||||
|
|
||||||
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
|
|
||||||
{
|
|
||||||
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
|
|
||||||
|
|
||||||
var progressionSamplePoints = new[] { controlPointInfo.SamplePointAt(StartTime) }
|
|
||||||
.Concat(controlPointInfo.SamplePoints.Where(p => p.Time > StartTime && p.Time <= EndTime));
|
|
||||||
|
|
||||||
foreach (var point in progressionSamplePoints)
|
|
||||||
ProgressionSamples.Add(new DrumSampleMapping(point));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,20 @@
|
|||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Audio;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
|
using osu.Game.Audio;
|
||||||
|
using osu.Game.Beatmaps.ControlPoints;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Rulesets.Taiko.Audio;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Taiko.UI
|
namespace osu.Game.Rulesets.Taiko.UI
|
||||||
{
|
{
|
||||||
@ -18,16 +24,26 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal class InputDrum : Container
|
internal class InputDrum : Container
|
||||||
{
|
{
|
||||||
public InputDrum()
|
private const float middle_split = 0.025f;
|
||||||
|
|
||||||
|
private readonly ControlPointInfo controlPoints;
|
||||||
|
|
||||||
|
public InputDrum(ControlPointInfo controlPoints)
|
||||||
{
|
{
|
||||||
|
this.controlPoints = controlPoints;
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
FillMode = FillMode.Fit;
|
FillMode = FillMode.Fit;
|
||||||
|
}
|
||||||
|
|
||||||
const float middle_split = 0.025f;
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(AudioManager audio)
|
||||||
|
{
|
||||||
|
var sampleMappings = new DrumSampleMapping(controlPoints, audio);
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new TaikoHalfDrum(false)
|
new TaikoHalfDrum(false, sampleMappings)
|
||||||
{
|
{
|
||||||
Name = "Left Half",
|
Name = "Left Half",
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
@ -38,7 +54,7 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
RimAction = TaikoAction.LeftRim,
|
RimAction = TaikoAction.LeftRim,
|
||||||
CentreAction = TaikoAction.LeftCentre
|
CentreAction = TaikoAction.LeftCentre
|
||||||
},
|
},
|
||||||
new TaikoHalfDrum(true)
|
new TaikoHalfDrum(true, sampleMappings)
|
||||||
{
|
{
|
||||||
Name = "Right Half",
|
Name = "Right Half",
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
@ -72,8 +88,12 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
private readonly Sprite centre;
|
private readonly Sprite centre;
|
||||||
private readonly Sprite centreHit;
|
private readonly Sprite centreHit;
|
||||||
|
|
||||||
public TaikoHalfDrum(bool flipped)
|
private readonly DrumSampleMapping sampleMappings;
|
||||||
|
|
||||||
|
public TaikoHalfDrum(bool flipped, DrumSampleMapping sampleMappings)
|
||||||
{
|
{
|
||||||
|
this.sampleMappings = sampleMappings;
|
||||||
|
|
||||||
Masking = true;
|
Masking = true;
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
@ -128,15 +148,21 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
Drawable target = null;
|
Drawable target = null;
|
||||||
Drawable back = null;
|
Drawable back = null;
|
||||||
|
|
||||||
|
var drumSample = sampleMappings.SampleAt(Time.Current);
|
||||||
|
|
||||||
if (action == CentreAction)
|
if (action == CentreAction)
|
||||||
{
|
{
|
||||||
target = centreHit;
|
target = centreHit;
|
||||||
back = centre;
|
back = centre;
|
||||||
|
|
||||||
|
drumSample.Centre.Play();
|
||||||
}
|
}
|
||||||
else if (action == RimAction)
|
else if (action == RimAction)
|
||||||
{
|
{
|
||||||
target = rimHit;
|
target = rimHit;
|
||||||
back = rim;
|
back = rim;
|
||||||
|
|
||||||
|
drumSample.Rim.Play();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target != null)
|
if (target != null)
|
||||||
|
@ -24,7 +24,7 @@ using osu.Game.Rulesets.Taiko.Audio;
|
|||||||
|
|
||||||
namespace osu.Game.Rulesets.Taiko.UI
|
namespace osu.Game.Rulesets.Taiko.UI
|
||||||
{
|
{
|
||||||
public class TaikoPlayfield : ScrollingPlayfield, IKeyBindingHandler<TaikoAction>
|
public class TaikoPlayfield : ScrollingPlayfield
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default height of a <see cref="TaikoPlayfield"/> when inside a <see cref="TaikoRulesetContainer"/>.
|
/// Default height of a <see cref="TaikoPlayfield"/> when inside a <see cref="TaikoRulesetContainer"/>.
|
||||||
@ -59,13 +59,9 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
private readonly Box overlayBackground;
|
private readonly Box overlayBackground;
|
||||||
private readonly Box background;
|
private readonly Box background;
|
||||||
|
|
||||||
private readonly ControlPointInfo controlPointInfo;
|
public TaikoPlayfield(ControlPointInfo controlPoints)
|
||||||
private readonly List<DrumSampleMapping> drumSampleMappings = new List<DrumSampleMapping>();
|
|
||||||
|
|
||||||
public TaikoPlayfield(ControlPointInfo controlPointInfo)
|
|
||||||
: base(Axes.X)
|
: base(Axes.X)
|
||||||
{
|
{
|
||||||
this.controlPointInfo = controlPointInfo;
|
|
||||||
AddRangeInternal(new Drawable[]
|
AddRangeInternal(new Drawable[]
|
||||||
{
|
{
|
||||||
backgroundContainer = new Container
|
backgroundContainer = new Container
|
||||||
@ -158,7 +154,7 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
},
|
},
|
||||||
new InputDrum
|
new InputDrum(controlPoints)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.CentreRight,
|
Anchor = Anchor.CentreRight,
|
||||||
Origin = Anchor.CentreRight,
|
Origin = Anchor.CentreRight,
|
||||||
@ -205,17 +201,7 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours, AudioManager audio)
|
private void load(OsuColour colours, AudioManager audio)
|
||||||
{
|
{
|
||||||
// We may have 0 sample points, but we need at least the default one
|
|
||||||
var samplePoints = new[] { controlPointInfo.SamplePointAt(double.MinValue) }
|
|
||||||
.Concat(controlPointInfo.SamplePoints);
|
|
||||||
|
|
||||||
foreach (var s in samplePoints)
|
|
||||||
{
|
|
||||||
var mapping = new DrumSampleMapping(s);
|
|
||||||
mapping.RetrieveChannels(audio);
|
|
||||||
|
|
||||||
drumSampleMappings.Add(mapping);
|
|
||||||
}
|
|
||||||
|
|
||||||
overlayBackgroundContainer.BorderColour = colours.Gray0;
|
overlayBackgroundContainer.BorderColour = colours.Gray0;
|
||||||
overlayBackground.Colour = colours.Gray1;
|
overlayBackground.Colour = colours.Gray1;
|
||||||
@ -281,23 +267,5 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
kiaiExplosionContainer.Add(new KiaiHitExplosion(judgedObject, isRim));
|
kiaiExplosionContainer.Add(new KiaiHitExplosion(judgedObject, isRim));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool OnPressed(TaikoAction action)
|
|
||||||
{
|
|
||||||
var mappingIndex = drumSampleMappings.BinarySearch(new DrumSampleMapping { Time = Time.Current });
|
|
||||||
if (mappingIndex < 0)
|
|
||||||
mappingIndex = ~mappingIndex - 1;
|
|
||||||
|
|
||||||
var mapping = drumSampleMappings[mappingIndex];
|
|
||||||
|
|
||||||
if (action == TaikoAction.LeftCentre || action == TaikoAction.RightCentre)
|
|
||||||
mapping.CentreChannel.Play();
|
|
||||||
else
|
|
||||||
mapping.RimChannel.Play();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool OnReleased(TaikoAction action) => false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
|||||||
public IReadOnlyList<Judgement> Judgements => judgements;
|
public IReadOnlyList<Judgement> Judgements => judgements;
|
||||||
|
|
||||||
protected List<SampleChannel> Samples = new List<SampleChannel>();
|
protected List<SampleChannel> Samples = new List<SampleChannel>();
|
||||||
|
protected virtual IEnumerable<SampleInfo> GetSamples() => HitObject.Samples;
|
||||||
|
|
||||||
public readonly Bindable<ArmedState> State = new Bindable<ArmedState>();
|
public readonly Bindable<ArmedState> State = new Bindable<ArmedState>();
|
||||||
|
|
||||||
@ -84,13 +85,14 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(AudioManager audio)
|
private void load(AudioManager audio)
|
||||||
{
|
{
|
||||||
if (Samples.Count > 0)
|
var samples = GetSamples();
|
||||||
|
if (samples.Any())
|
||||||
{
|
{
|
||||||
if (HitObject.SampleControlPoint == null)
|
if (HitObject.SampleControlPoint == null)
|
||||||
throw new ArgumentNullException(nameof(HitObject.SampleControlPoint), $"{nameof(HitObject)}s must always have an attached {nameof(HitObject.SampleControlPoint)}."
|
throw new ArgumentNullException(nameof(HitObject.SampleControlPoint), $"{nameof(HitObject)}s must always have an attached {nameof(HitObject.SampleControlPoint)}."
|
||||||
+ $" This is an indication that {nameof(HitObject.ApplyDefaults)} has not been invoked on {this}.");
|
+ $" This is an indication that {nameof(HitObject.ApplyDefaults)} has not been invoked on {this}.");
|
||||||
|
|
||||||
foreach (SampleInfo s in HitObject.Samples)
|
foreach (SampleInfo s in samples)
|
||||||
{
|
{
|
||||||
SampleInfo localSampleInfo = new SampleInfo
|
SampleInfo localSampleInfo = new SampleInfo
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user