osu/osu.Game.Rulesets.Taiko/UI/InputDrum.cs

193 lines
6.9 KiB
C#
Raw Normal View History

2018-01-05 11:21:19 +00:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-03-21 06:09:54 +00:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2017-03-23 06:28:17 +00:00
using System;
2017-03-21 06:09:54 +00:00
using OpenTK;
using osu.Framework.Allocation;
using osu.Framework.Audio;
2017-03-21 06:09:54 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
2017-08-20 12:51:56 +00:00
using osu.Framework.Input.Bindings;
using osu.Game.Beatmaps.ControlPoints;
2017-03-21 06:09:54 +00:00
using osu.Game.Graphics;
using osu.Game.Rulesets.Taiko.Audio;
2017-03-21 06:09:54 +00:00
2017-04-18 07:05:58 +00:00
namespace osu.Game.Rulesets.Taiko.UI
2017-03-21 06:09:54 +00:00
{
2017-03-21 09:16:14 +00:00
/// <summary>
/// A component of the playfield that captures input and displays input as a drum.
/// </summary>
2017-03-21 06:09:54 +00:00
internal class InputDrum : Container
{
private const float middle_split = 0.025f;
private readonly ControlPointInfo controlPoints;
public InputDrum(ControlPointInfo controlPoints)
2017-03-21 06:09:54 +00:00
{
this.controlPoints = controlPoints;
2017-08-02 22:49:25 +00:00
RelativeSizeAxes = Axes.Both;
FillMode = FillMode.Fit;
}
2017-03-21 06:09:54 +00:00
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
var sampleMappings = new DrumSampleMapping(controlPoints, audio);
2017-03-23 06:28:17 +00:00
2017-03-21 06:09:54 +00:00
Children = new Drawable[]
{
new TaikoHalfDrum(false, sampleMappings)
2017-03-21 06:09:54 +00:00
{
2017-03-21 09:16:14 +00:00
Name = "Left Half",
2017-03-21 06:09:54 +00:00
Anchor = Anchor.Centre,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Both,
2017-08-02 22:49:25 +00:00
RelativePositionAxes = Axes.X,
2017-03-23 06:28:17 +00:00
X = -middle_split / 2,
2017-08-20 12:51:56 +00:00
RimAction = TaikoAction.LeftRim,
CentreAction = TaikoAction.LeftCentre
2017-03-21 06:09:54 +00:00
},
new TaikoHalfDrum(true, sampleMappings)
2017-03-21 06:09:54 +00:00
{
2017-03-21 09:16:14 +00:00
Name = "Right Half",
2017-03-21 06:09:54 +00:00
Anchor = Anchor.Centre,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Both,
2017-08-02 22:49:25 +00:00
RelativePositionAxes = Axes.X,
2017-03-23 06:28:17 +00:00
X = middle_split / 2,
2017-08-20 12:51:56 +00:00
RimAction = TaikoAction.RightRim,
CentreAction = TaikoAction.RightCentre
2017-03-21 06:09:54 +00:00
}
};
}
2017-03-21 09:16:14 +00:00
/// <summary>
/// A half-drum. Contains one centre and one rim hit.
/// </summary>
2017-08-20 12:51:56 +00:00
private class TaikoHalfDrum : Container, IKeyBindingHandler<TaikoAction>
2017-03-21 06:09:54 +00:00
{
/// <summary>
2017-03-23 03:53:38 +00:00
/// The key to be used for the rim of the half-drum.
2017-03-21 06:09:54 +00:00
/// </summary>
2017-08-20 12:51:56 +00:00
public TaikoAction RimAction;
2017-03-23 03:53:38 +00:00
/// <summary>
/// The key to be used for the centre of the half-drum.
/// </summary>
2017-08-20 12:51:56 +00:00
public TaikoAction CentreAction;
2017-03-21 06:09:54 +00:00
2017-03-23 05:37:00 +00:00
private readonly Sprite rim;
private readonly Sprite rimHit;
private readonly Sprite centre;
private readonly Sprite centreHit;
2017-03-21 06:09:54 +00:00
private readonly DrumSampleMapping sampleMappings;
public TaikoHalfDrum(bool flipped, DrumSampleMapping sampleMappings)
2017-03-21 06:09:54 +00:00
{
this.sampleMappings = sampleMappings;
2017-03-21 06:09:54 +00:00
Masking = true;
Children = new Drawable[]
{
2017-03-23 03:53:38 +00:00
rim = new Sprite
2017-03-21 06:09:54 +00:00
{
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both
},
2017-03-23 03:53:38 +00:00
rimHit = new Sprite
2017-03-21 06:09:54 +00:00
{
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Alpha = 0,
2017-09-07 13:46:21 +00:00
Blending = BlendingMode.Additive,
2017-03-21 06:09:54 +00:00
},
2017-03-23 03:53:38 +00:00
centre = new Sprite
2017-03-21 06:09:54 +00:00
{
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.7f)
},
2017-03-23 03:53:38 +00:00
centreHit = new Sprite
2017-03-21 06:09:54 +00:00
{
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.7f),
Alpha = 0,
2017-09-07 13:46:21 +00:00
Blending = BlendingMode.Additive
2017-03-21 06:09:54 +00:00
}
};
}
[BackgroundDependencyLoader]
private void load(TextureStore textures, OsuColour colours)
{
2017-03-23 03:53:38 +00:00
rim.Texture = textures.Get(@"Play/Taiko/taiko-drum-outer");
rimHit.Texture = textures.Get(@"Play/Taiko/taiko-drum-outer-hit");
centre.Texture = textures.Get(@"Play/Taiko/taiko-drum-inner");
centreHit.Texture = textures.Get(@"Play/Taiko/taiko-drum-inner-hit");
2017-03-21 06:09:54 +00:00
2017-03-23 03:53:38 +00:00
rimHit.Colour = colours.Blue;
centreHit.Colour = colours.Pink;
2017-03-21 06:09:54 +00:00
}
2017-08-20 12:51:56 +00:00
public bool OnPressed(TaikoAction action)
2017-03-21 06:09:54 +00:00
{
2017-03-23 06:28:17 +00:00
Drawable target = null;
2017-04-04 23:58:17 +00:00
Drawable back = null;
2017-03-23 06:28:17 +00:00
var drumSample = sampleMappings.SampleAt(Time.Current);
2017-08-20 12:51:56 +00:00
if (action == CentreAction)
2017-04-04 23:58:17 +00:00
{
2017-03-23 06:28:17 +00:00
target = centreHit;
2017-04-04 23:58:17 +00:00
back = centre;
drumSample.Centre?.Play();
2017-04-04 23:58:17 +00:00
}
2017-08-20 12:51:56 +00:00
else if (action == RimAction)
2017-04-04 23:58:17 +00:00
{
2017-03-23 06:28:17 +00:00
target = rimHit;
2017-04-04 23:58:17 +00:00
back = rim;
drumSample.Rim?.Play();
2017-04-04 23:58:17 +00:00
}
2017-03-21 06:09:54 +00:00
2017-03-23 06:28:17 +00:00
if (target != null)
2017-03-21 06:09:54 +00:00
{
2017-04-04 23:58:17 +00:00
const float scale_amount = 0.05f;
const float alpha_amount = 0.5f;
const float down_time = 40;
const float up_time = 1000;
2017-07-22 18:50:25 +00:00
back.ScaleTo(target.Scale.X - scale_amount, down_time, Easing.OutQuint)
2017-07-17 15:16:15 +00:00
.Then()
2017-07-22 18:50:25 +00:00
.ScaleTo(1, up_time, Easing.OutQuint);
2017-07-17 15:16:15 +00:00
target.Animate(
2017-07-22 18:50:25 +00:00
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)
2017-07-17 15:16:15 +00:00
).Then(
2017-07-22 18:50:25 +00:00
t => t.ScaleTo(1, up_time, Easing.OutQuint),
t => t.FadeOut(up_time, Easing.OutQuint)
2017-07-17 15:16:15 +00:00
);
2017-03-21 06:09:54 +00:00
}
return false;
}
2017-08-20 12:51:56 +00:00
public bool OnReleased(TaikoAction action) => false;
2017-03-21 06:09:54 +00:00
}
}
}