1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 19:37:51 +08:00
osu-lazer/osu.Game.Modes.Taiko/UI/InputDrum.cs

149 lines
5.2 KiB
C#
Raw Normal View History

2017-03-21 14:09:54 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2017-03-23 14:28:17 +08:00
using System;
2017-03-21 14:09:54 +08:00
using OpenTK;
using OpenTK.Input;
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;
using osu.Game.Graphics;
namespace osu.Game.Modes.Taiko.UI
{
2017-03-21 17:16:14 +08:00
/// <summary>
/// A component of the playfield that captures input and displays input as a drum.
/// </summary>
2017-03-21 14:09:54 +08:00
internal class InputDrum : Container
{
public InputDrum()
{
Size = new Vector2(TaikoPlayfield.PLAYFIELD_HEIGHT);
2017-03-21 14:09:54 +08:00
2017-03-23 14:28:17 +08:00
const float middle_split = 10;
2017-03-21 14:09:54 +08:00
Children = new Drawable[]
{
new TaikoHalfDrum(false)
{
2017-03-21 17:16:14 +08:00
Name = "Left Half",
2017-03-21 14:09:54 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Both,
2017-03-23 14:28:17 +08:00
X = -middle_split / 2,
2017-03-23 11:53:38 +08:00
RimKey = Key.D,
CentreKey = Key.F
2017-03-21 14:09:54 +08:00
},
new TaikoHalfDrum(true)
{
2017-03-21 17:16:14 +08:00
Name = "Right Half",
2017-03-21 14:09:54 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Both,
2017-03-23 14:28:17 +08:00
X = middle_split / 2,
2017-03-21 14:09:54 +08:00
Position = new Vector2(-1f, 0),
2017-03-23 11:53:38 +08:00
RimKey = Key.K,
CentreKey = Key.J
2017-03-21 14:09:54 +08:00
}
};
}
2017-03-21 17:16:14 +08:00
/// <summary>
/// A half-drum. Contains one centre and one rim hit.
/// </summary>
2017-03-21 14:09:54 +08:00
private class TaikoHalfDrum : Container
{
/// <summary>
2017-03-23 11:53:38 +08:00
/// The key to be used for the rim of the half-drum.
2017-03-21 14:09:54 +08:00
/// </summary>
2017-03-23 11:53:38 +08:00
public Key RimKey;
/// <summary>
/// The key to be used for the centre of the half-drum.
/// </summary>
public Key CentreKey;
2017-03-21 14:09:54 +08:00
2017-03-23 13:37:00 +08:00
private readonly Sprite rim;
private readonly Sprite rimHit;
private readonly Sprite centre;
private readonly Sprite centreHit;
2017-03-21 14:09:54 +08:00
public TaikoHalfDrum(bool flipped)
{
Masking = true;
Children = new Drawable[]
{
2017-03-23 11:53:38 +08:00
rim = new Sprite
2017-03-21 14:09:54 +08:00
{
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both
},
2017-03-23 11:53:38 +08:00
rimHit = new Sprite
2017-03-21 14:09:54 +08:00
{
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Alpha = 0,
2017-03-23 14:28:17 +08:00
BlendingMode = BlendingMode.Additive,
2017-03-21 14:09:54 +08:00
},
2017-03-23 11:53:38 +08:00
centre = new Sprite
2017-03-21 14:09:54 +08:00
{
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.7f)
},
2017-03-23 11:53:38 +08:00
centreHit = new Sprite
2017-03-21 14:09:54 +08:00
{
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.7f),
Alpha = 0,
BlendingMode = BlendingMode.Additive
}
};
}
[BackgroundDependencyLoader]
private void load(TextureStore textures, OsuColour colours)
{
2017-03-23 11:53:38 +08: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 14:09:54 +08:00
2017-03-23 11:53:38 +08:00
rimHit.Colour = colours.Blue;
centreHit.Colour = colours.Pink;
2017-03-21 14:09:54 +08:00
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (args.Repeat)
return false;
2017-03-23 14:28:17 +08:00
Drawable target = null;
2017-03-23 11:53:38 +08:00
if (args.Key == CentreKey)
2017-03-23 14:28:17 +08:00
target = centreHit;
else if (args.Key == RimKey)
target = rimHit;
2017-03-21 14:09:54 +08:00
2017-03-23 14:28:17 +08:00
if (target != null)
2017-03-21 14:09:54 +08:00
{
2017-03-23 14:28:17 +08:00
target.FadeTo(Math.Min(target.Alpha + 0.4f, 1), 40, EasingTypes.OutQuint);
target.Delay(40);
2017-03-27 14:49:32 +08:00
target.FadeOut(1000, EasingTypes.OutQuint);
2017-03-21 14:09:54 +08:00
}
return false;
}
}
}
}