1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 20:38:33 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/UI/InputDrum.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

209 lines
7.7 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
2022-06-17 15:37:17 +08:00
#nullable disable
2017-03-23 14:28:17 +08:00
using System;
2017-03-21 14:09:54 +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;
2017-08-20 20:51:56 +08:00
using osu.Framework.Input.Bindings;
2021-09-16 17:26:12 +08:00
using osu.Framework.Input.Events;
2017-03-21 14:09:54 +08:00
using osu.Game.Graphics;
using osu.Game.Screens.Ranking;
using osu.Game.Skinning;
using osuTK;
2018-04-13 17:19:50 +08:00
2017-04-18 15:05:58 +08:00
namespace osu.Game.Rulesets.Taiko.UI
2017-03-21 14:09:54 +08:00
{
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
{
private const float middle_split = 0.025f;
2018-04-13 17:19:50 +08:00
public InputDrum()
2017-03-21 14:09:54 +08:00
{
AutoSizeAxes = Axes.X;
RelativeSizeAxes = Axes.Y;
}
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader]
private void load()
{
2020-07-26 21:15:01 +08:00
Children = new Drawable[]
2017-03-21 14:09:54 +08:00
{
new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.InputDrum), _ => new DefaultInputDrum())
{
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
},
};
}
private class DefaultInputDrum : AspectContainer
{
public DefaultInputDrum()
{
RelativeSizeAxes = Axes.Y;
}
[BackgroundDependencyLoader]
private void load()
{
InternalChild = new Container
2017-03-21 14:09:54 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2020-07-26 21:15:01 +08:00
RelativeSizeAxes = Axes.Both,
Scale = new Vector2(0.9f),
Children = new[]
{
new TaikoHalfDrum(false)
2020-07-26 21:15:01 +08:00
{
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)
2020-07-26 21:15:01 +08:00
{
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
2017-03-21 14:09:54 +08:00
/// <summary>
/// A half-drum. Contains one centre and one rim hit.
2017-03-21 14:09:54 +08:00
/// </summary>
private class TaikoHalfDrum : Container, IKeyBindingHandler<TaikoAction>
{
/// <summary>
/// The key to be used for the rim of the half-drum.
/// </summary>
public TaikoAction RimAction;
2018-04-13 17:19:50 +08:00
/// <summary>
/// The key to be used for the centre of the half-drum.
/// </summary>
public TaikoAction CentreAction;
2018-04-13 17:19:50 +08:00
private readonly Sprite rim;
private readonly Sprite rimHit;
private readonly Sprite centre;
private readonly Sprite centreHit;
2018-04-13 17:19:50 +08:00
public TaikoHalfDrum(bool flipped)
2017-03-21 14:09:54 +08:00
{
Masking = true;
2018-04-13 17:19:50 +08:00
Children = new Drawable[]
2017-03-21 14:09:54 +08:00
{
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,
Blending = BlendingParameters.Additive,
},
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,
Blending = BlendingParameters.Additive
}
};
}
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader]
private void load(TextureStore textures, OsuColour colours)
2017-04-05 07:58:17 +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;
2017-04-05 07:58:17 +08:00
}
public bool OnPressed(KeyBindingPressEvent<TaikoAction> e)
2017-04-05 07:58:17 +08:00
{
Drawable target = null;
Drawable back = null;
if (e.Action == CentreAction)
2017-03-21 14:09:54 +08:00
{
target = centreHit;
back = centre;
}
else if (e.Action == RimAction)
{
target = rimHit;
back = rim;
}
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)
);
}
2018-04-13 17:19:50 +08:00
return false;
2017-04-05 07:58:17 +08:00
}
2018-04-13 17:19:50 +08:00
public void OnReleased(KeyBindingReleaseEvent<TaikoAction> e)
2017-03-21 14:09:54 +08:00
{
}
}
2017-03-21 14:09:54 +08:00
}
}
}