1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 09:52:55 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/UI/InputDrum.cs

206 lines
7.2 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
using System;
2018-11-20 15:51:59 +08:00
using osuTK;
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
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.Beatmaps.ControlPoints;
using osu.Game.Graphics;
using osu.Game.Rulesets.Taiko.Audio;
2020-05-21 09:59:30 +08:00
using osu.Game.Screens.Play;
using osu.Game.Skinning;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Taiko.UI
{
/// <summary>
/// A component of the playfield that captures input and displays input as a drum.
/// </summary>
internal class InputDrum : Container
{
private const float middle_split = 0.025f;
[Cached]
private DrumSampleMapping sampleMapping;
2018-04-13 17:19:50 +08:00
public InputDrum(ControlPointInfo controlPoints)
{
sampleMapping = new DrumSampleMapping(controlPoints);
2018-04-13 17:19:50 +08:00
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load()
{
Child = new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.InputDrum), _ => new Container
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fit,
Scale = new Vector2(0.9f),
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
new TaikoHalfDrum(false)
{
Name = "Left Half",
Anchor = Anchor.Centre,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.X,
X = -middle_split / 2,
RimAction = TaikoAction.LeftRim,
CentreAction = TaikoAction.LeftCentre
},
new TaikoHalfDrum(true)
{
Name = "Right Half",
Anchor = Anchor.Centre,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.X,
X = middle_split / 2,
RimAction = TaikoAction.RightRim,
CentreAction = TaikoAction.RightCentre
}
2018-04-13 17:19:50 +08:00
}
});
2018-04-13 17:19:50 +08:00
AddRangeInternal(sampleMapping.Sounds);
2018-04-13 17:19:50 +08:00
}
/// <summary>
/// A half-drum. Contains one centre and one rim hit.
/// </summary>
private class TaikoHalfDrum : Container, IKeyBindingHandler<TaikoAction>
{
/// <summary>
/// The key to be used for the rim of the half-drum.
/// </summary>
public TaikoAction RimAction;
/// <summary>
/// The key to be used for the centre of the half-drum.
/// </summary>
public TaikoAction CentreAction;
private readonly Sprite rim;
private readonly Sprite rimHit;
private readonly Sprite centre;
private readonly Sprite centreHit;
[Resolved]
private DrumSampleMapping sampleMappings { get; set; }
2018-04-13 17:19:50 +08:00
public TaikoHalfDrum(bool flipped)
2018-04-13 17:19:50 +08:00
{
Masking = true;
Children = new Drawable[]
{
rim = new Sprite
{
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both
},
rimHit = new Sprite
{
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Alpha = 0,
2019-08-21 12:29:50 +08:00
Blending = BlendingParameters.Additive,
2018-04-13 17:19:50 +08:00
},
centre = new Sprite
{
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.7f)
},
centreHit = new Sprite
{
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.7f),
Alpha = 0,
2019-08-21 12:29:50 +08:00
Blending = BlendingParameters.Additive
2018-04-13 17:19:50 +08:00
}
};
}
[BackgroundDependencyLoader]
2018-08-31 06:04:40 +08:00
private void load(TextureStore textures, OsuColour colours)
2018-04-13 17:19:50 +08:00
{
rim.Texture = textures.Get(@"Gameplay/taiko/taiko-drum-outer");
rimHit.Texture = textures.Get(@"Gameplay/taiko/taiko-drum-outer-hit");
centre.Texture = textures.Get(@"Gameplay/taiko/taiko-drum-inner");
centreHit.Texture = textures.Get(@"Gameplay/taiko/taiko-drum-inner-hit");
2018-04-13 17:19:50 +08:00
rimHit.Colour = colours.Blue;
centreHit.Colour = colours.Pink;
}
2020-05-21 09:59:30 +08:00
[Resolved(canBeNull: true)]
private GameplayClock gameplayClock { get; set; }
2018-04-13 17:19:50 +08:00
public bool OnPressed(TaikoAction action)
{
Drawable target = null;
Drawable back = null;
var drumSample = sampleMappings.SampleAt(Time.Current);
if (action == CentreAction)
{
target = centreHit;
back = centre;
2020-05-21 09:59:30 +08:00
if (gameplayClock?.IsSeeking != true)
drumSample.Centre?.Play();
2018-04-13 17:19:50 +08:00
}
else if (action == RimAction)
{
target = rimHit;
back = rim;
2020-05-21 09:59:30 +08:00
if (gameplayClock?.IsSeeking != true)
drumSample.Rim?.Play();
2018-04-13 17:19:50 +08:00
}
if (target != null)
{
const float scale_amount = 0.05f;
const float alpha_amount = 0.5f;
const float down_time = 40;
const float up_time = 1000;
back.ScaleTo(target.Scale.X - scale_amount, down_time, Easing.OutQuint)
.Then()
.ScaleTo(1, up_time, Easing.OutQuint);
target.Animate(
t => t.ScaleTo(target.Scale.X - scale_amount, down_time, Easing.OutQuint),
t => t.FadeTo(Math.Min(target.Alpha + alpha_amount, 1), down_time, Easing.OutQuint)
).Then(
t => t.ScaleTo(1, up_time, Easing.OutQuint),
t => t.FadeOut(up_time, Easing.OutQuint)
);
}
return false;
}
public void OnReleased(TaikoAction action)
{
}
2018-04-13 17:19:50 +08:00
}
}
}