Make InputDrum handle all Normals/Claps, hitobjects all others

This commit is contained in:
smoogipoo
2017-12-26 14:18:23 +09:00
parent 58c35b8ba5
commit 14162b5d46
7 changed files with 72 additions and 94 deletions

View File

@ -2,14 +2,20 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
using OpenTK;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Input.Bindings;
using osu.Game.Audio;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics;
using osu.Game.Rulesets.Taiko.Audio;
namespace osu.Game.Rulesets.Taiko.UI
{
@ -18,16 +24,26 @@ namespace osu.Game.Rulesets.Taiko.UI
/// </summary>
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;
FillMode = FillMode.Fit;
}
const float middle_split = 0.025f;
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
var sampleMappings = new DrumSampleMapping(controlPoints, audio);
Children = new Drawable[]
{
new TaikoHalfDrum(false)
new TaikoHalfDrum(false, sampleMappings)
{
Name = "Left Half",
Anchor = Anchor.Centre,
@ -38,7 +54,7 @@ namespace osu.Game.Rulesets.Taiko.UI
RimAction = TaikoAction.LeftRim,
CentreAction = TaikoAction.LeftCentre
},
new TaikoHalfDrum(true)
new TaikoHalfDrum(true, sampleMappings)
{
Name = "Right Half",
Anchor = Anchor.Centre,
@ -72,8 +88,12 @@ namespace osu.Game.Rulesets.Taiko.UI
private readonly Sprite centre;
private readonly Sprite centreHit;
public TaikoHalfDrum(bool flipped)
private readonly DrumSampleMapping sampleMappings;
public TaikoHalfDrum(bool flipped, DrumSampleMapping sampleMappings)
{
this.sampleMappings = sampleMappings;
Masking = true;
Children = new Drawable[]
@ -128,15 +148,21 @@ namespace osu.Game.Rulesets.Taiko.UI
Drawable target = null;
Drawable back = null;
var drumSample = sampleMappings.SampleAt(Time.Current);
if (action == CentreAction)
{
target = centreHit;
back = centre;
drumSample.Centre.Play();
}
else if (action == RimAction)
{
target = rimHit;
back = rim;
drumSample.Rim.Play();
}
if (target != null)

View File

@ -24,7 +24,7 @@ using osu.Game.Rulesets.Taiko.Audio;
namespace osu.Game.Rulesets.Taiko.UI
{
public class TaikoPlayfield : ScrollingPlayfield, IKeyBindingHandler<TaikoAction>
public class TaikoPlayfield : ScrollingPlayfield
{
/// <summary>
/// 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 background;
private readonly ControlPointInfo controlPointInfo;
private readonly List<DrumSampleMapping> drumSampleMappings = new List<DrumSampleMapping>();
public TaikoPlayfield(ControlPointInfo controlPointInfo)
public TaikoPlayfield(ControlPointInfo controlPoints)
: base(Axes.X)
{
this.controlPointInfo = controlPointInfo;
AddRangeInternal(new Drawable[]
{
backgroundContainer = new Container
@ -158,7 +154,7 @@ namespace osu.Game.Rulesets.Taiko.UI
{
RelativeSizeAxes = Axes.Both,
},
new InputDrum
new InputDrum(controlPoints)
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
@ -205,17 +201,7 @@ namespace osu.Game.Rulesets.Taiko.UI
[BackgroundDependencyLoader]
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;
overlayBackground.Colour = colours.Gray1;
@ -281,23 +267,5 @@ namespace osu.Game.Rulesets.Taiko.UI
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;
}
}