1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-06 21:57:19 +08:00

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

203 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 18:19:50 +09:00
2022-06-17 16:37:17 +09:00
#nullable disable
2017-03-23 15:28:17 +09:00
using System;
2017-03-21 15:09:54 +09: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 21:51:56 +09:00
using osu.Framework.Input.Bindings;
2021-09-16 18:26:12 +09:00
using osu.Framework.Input.Events;
2017-03-21 15:09:54 +09:00
using osu.Game.Graphics;
using osu.Game.Rulesets.Taiko.Objects;
using osu.Game.Rulesets.UI;
using osu.Game.Skinning;
using osuTK;
2018-04-13 18:19:50 +09:00
2017-04-18 16:05:58 +09:00
namespace osu.Game.Rulesets.Taiko.UI
2017-03-21 15:09:54 +09:00
{
2017-03-21 18:16:14 +09:00
/// <summary>
/// A component of the playfield that captures input and displays input as a drum.
/// </summary>
2017-03-21 15:09:54 +09:00
internal class InputDrum : Container
{
private const float middle_split = 0.025f;
2018-04-13 18:19:50 +09:00
[Cached]
private DrumSampleTriggerSource sampleTriggerSource;
2018-04-13 18:19:50 +09:00
public InputDrum(HitObjectContainer hitObjectContainer)
2017-03-21 15:09:54 +09:00
{
sampleTriggerSource = new DrumSampleTriggerSource(hitObjectContainer);
2018-04-13 18:19:50 +09:00
2017-08-03 08:19:25 +09:30
RelativeSizeAxes = Axes.Both;
}
2018-04-13 18:19:50 +09:00
[BackgroundDependencyLoader]
private void load()
{
2020-07-26 15:15:01 +02:00
Children = new Drawable[]
2017-03-21 15:09:54 +09:00
{
2020-07-26 15:15:01 +02:00
new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.InputDrum), _ => new Container
2017-03-21 15:09:54 +09:00
{
2020-07-26 15:15:01 +02:00
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fit,
Scale = new Vector2(0.9f),
Children = new Drawable[]
{
2020-07-26 15:15:01 +02: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
}
}
2020-07-26 15:15:01 +02:00
}),
sampleTriggerSource
2020-07-26 15:15:01 +02:00
};
2017-03-21 15:09:54 +09:00
}
2018-04-13 18:19:50 +09:00
2017-03-21 18:16:14 +09:00
/// <summary>
/// A half-drum. Contains one centre and one rim hit.
/// </summary>
2017-08-20 21:51:56 +09:00
private class TaikoHalfDrum : Container, IKeyBindingHandler<TaikoAction>
2017-03-21 15:09:54 +09:00
{
/// <summary>
2017-03-23 12:53:38 +09:00
/// The key to be used for the rim of the half-drum.
2017-03-21 15:09:54 +09:00
/// </summary>
2017-08-20 21:51:56 +09:00
public TaikoAction RimAction;
2018-04-13 18:19:50 +09:00
2017-03-23 12:53:38 +09:00
/// <summary>
/// The key to be used for the centre of the half-drum.
/// </summary>
2017-08-20 21:51:56 +09:00
public TaikoAction CentreAction;
2018-04-13 18:19:50 +09:00
2017-03-23 14:37:00 +09:00
private readonly Sprite rim;
private readonly Sprite rimHit;
private readonly Sprite centre;
private readonly Sprite centreHit;
2018-04-13 18:19:50 +09:00
[Resolved]
private DrumSampleTriggerSource sampleTriggerSource { get; set; }
2018-04-13 18:19:50 +09:00
public TaikoHalfDrum(bool flipped)
2017-03-21 15:09:54 +09:00
{
Masking = true;
2018-04-13 18:19:50 +09:00
2017-03-21 15:09:54 +09:00
Children = new Drawable[]
{
2017-03-23 12:53:38 +09:00
rim = new Sprite
2017-03-21 15:09:54 +09:00
{
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both
},
2017-03-23 12:53:38 +09:00
rimHit = new Sprite
2017-03-21 15:09:54 +09:00
{
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Alpha = 0,
2019-08-21 13:29:50 +09:00
Blending = BlendingParameters.Additive,
2017-03-21 15:09:54 +09:00
},
2017-03-23 12:53:38 +09:00
centre = new Sprite
2017-03-21 15:09:54 +09:00
{
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.7f)
},
2017-03-23 12:53:38 +09:00
centreHit = new Sprite
2017-03-21 15:09:54 +09:00
{
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.7f),
Alpha = 0,
2019-08-21 13:29:50 +09:00
Blending = BlendingParameters.Additive
2017-03-21 15:09:54 +09:00
}
};
}
2018-04-13 18:19:50 +09:00
2017-03-21 15:09:54 +09:00
[BackgroundDependencyLoader]
2018-08-31 07:04:40 +09:00
private void load(TextureStore textures, OsuColour colours)
2017-03-21 15:09:54 +09: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 18:19:50 +09:00
2017-03-23 12:53:38 +09:00
rimHit.Colour = colours.Blue;
centreHit.Colour = colours.Pink;
2017-03-21 15:09:54 +09:00
}
2018-04-13 18:19:50 +09:00
2021-09-16 18:26:12 +09:00
public bool OnPressed(KeyBindingPressEvent<TaikoAction> e)
2017-03-21 15:09:54 +09:00
{
2017-03-23 15:28:17 +09:00
Drawable target = null;
2017-04-05 08:58:17 +09:00
Drawable back = null;
2018-04-13 18:19:50 +09:00
2021-09-16 18:26:12 +09:00
if (e.Action == CentreAction)
2017-04-05 08:58:17 +09:00
{
2017-03-23 15:28:17 +09:00
target = centreHit;
2017-04-05 08:58:17 +09:00
back = centre;
2018-04-13 18:19:50 +09:00
sampleTriggerSource.Play(HitType.Centre);
2017-04-05 08:58:17 +09:00
}
2021-09-16 18:26:12 +09:00
else if (e.Action == RimAction)
2017-04-05 08:58:17 +09:00
{
2017-03-23 15:28:17 +09:00
target = rimHit;
2017-04-05 08:58:17 +09:00
back = rim;
2018-04-13 18:19:50 +09:00
sampleTriggerSource.Play(HitType.Rim);
2017-04-05 08:58:17 +09:00
}
2018-04-13 18:19:50 +09:00
2017-03-23 15:28:17 +09:00
if (target != null)
2017-03-21 15:09:54 +09:00
{
2017-04-05 08:58:17 +09:00
const float scale_amount = 0.05f;
const float alpha_amount = 0.5f;
2018-04-13 18:19:50 +09:00
2017-04-05 08:58:17 +09:00
const float down_time = 40;
const float up_time = 1000;
2018-04-13 18:19:50 +09:00
2017-07-22 20:50:25 +02:00
back.ScaleTo(target.Scale.X - scale_amount, down_time, Easing.OutQuint)
2017-07-17 18:16:15 +03:00
.Then()
2017-07-22 20:50:25 +02:00
.ScaleTo(1, up_time, Easing.OutQuint);
2018-04-13 18:19:50 +09:00
2017-07-17 18:16:15 +03:00
target.Animate(
2017-07-22 20:50:25 +02: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 18:16:15 +03:00
).Then(
2017-07-22 20:50:25 +02:00
t => t.ScaleTo(1, up_time, Easing.OutQuint),
t => t.FadeOut(up_time, Easing.OutQuint)
2017-07-17 18:16:15 +03:00
);
2017-03-21 15:09:54 +09:00
}
2018-04-13 18:19:50 +09:00
2017-03-21 15:09:54 +09:00
return false;
}
2018-04-13 18:19:50 +09:00
2021-09-16 18:26:12 +09:00
public void OnReleased(KeyBindingReleaseEvent<TaikoAction> e)
{
}
2017-03-21 15:09:54 +09:00
}
}
}