osu/osu.Game/Screens/Edit/Timing/TapButton.cs

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

237 lines
8.2 KiB
C#
Raw Normal View History

2022-06-01 09:53:35 +00:00
// 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.
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2022-06-01 10:45:11 +00:00
using osu.Framework.Graphics.UserInterface;
2022-06-01 09:53:35 +00:00
using osu.Framework.Input.Events;
2022-06-01 10:45:11 +00:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
2022-06-01 09:53:35 +00:00
using osu.Game.Overlays;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Edit.Timing
{
internal class TapButton : CircularContainer
{
public const float SIZE = 100;
[Resolved]
private OverlayColourProvider colourProvider { get; set; }
private Circle hoverLayer;
2022-06-01 10:45:11 +00:00
2022-06-01 09:53:35 +00:00
private CircularContainer innerCircle;
2022-06-01 10:45:11 +00:00
private Box innerCircleHighlight;
private int currentLight;
2022-06-01 09:53:35 +00:00
private Container scaleContainer;
2022-06-01 10:45:11 +00:00
private Container lights;
private const int light_count = 6;
2022-06-01 09:53:35 +00:00
[BackgroundDependencyLoader]
private void load()
{
Size = new Vector2(SIZE);
2022-06-01 10:45:11 +00:00
const float ring_width = 18;
2022-06-01 09:53:35 +00:00
const float light_padding = 3;
InternalChild = scaleContainer = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
2022-06-01 10:45:11 +00:00
new Circle
2022-06-01 09:53:35 +00:00
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background3
},
2022-06-01 10:45:11 +00:00
lights = new Container
{
RelativeSizeAxes = Axes.Both,
},
2022-06-01 09:53:35 +00:00
new CircularContainer
{
RelativeSizeAxes = Axes.Both,
Name = "outer masking",
Masking = true,
BorderThickness = light_padding,
BorderColour = colourProvider.Background3,
Children = new Drawable[]
{
new Box
{
Colour = Color4.Black,
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true,
},
}
},
2022-06-01 10:45:11 +00:00
new Circle
{
Size = new Vector2(SIZE - ring_width * 2 + light_padding * 2),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = colourProvider.Background3,
},
2022-06-01 09:53:35 +00:00
innerCircle = new CircularContainer
{
2022-06-01 10:45:11 +00:00
Size = new Vector2(SIZE - ring_width * 2),
2022-06-01 09:53:35 +00:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Masking = true,
Children = new Drawable[]
{
new Box
{
Colour = colourProvider.Background2,
RelativeSizeAxes = Axes.Both,
2022-06-01 10:45:11 +00:00
},
innerCircleHighlight = new Box
{
Colour = colourProvider.Colour3,
Blending = BlendingParameters.Additive,
RelativeSizeAxes = Axes.Both,
Alpha = 0,
},
new OsuSpriteText
{
Font = OsuFont.Torus.With(size: 20),
Colour = colourProvider.Background1,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "Tap!"
},
hoverLayer = new Circle
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background1.Opacity(0.3f),
Blending = BlendingParameters.Additive,
Alpha = 0,
2022-06-01 09:53:35 +00:00
},
}
},
}
};
2022-06-01 10:45:11 +00:00
for (int i = 0; i < light_count; i++)
{
lights.Add(new Light
{
Rotation = i * (360f / light_count)
});
}
2022-06-01 09:53:35 +00:00
}
2022-06-01 10:45:11 +00:00
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) =>
hoverLayer.ReceivePositionalInputAt(screenSpacePos);
2022-06-01 09:53:35 +00:00
protected override bool OnHover(HoverEvent e)
{
hoverLayer.FadeIn(500, Easing.OutQuint);
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
hoverLayer.FadeOut(500, Easing.OutQuint);
base.OnHoverLost(e);
}
protected override bool OnMouseDown(MouseDownEvent e)
{
2022-06-01 10:45:11 +00:00
const double in_duration = 100;
scaleContainer.ScaleTo(0.99f, in_duration, Easing.OutQuint);
innerCircle.ScaleTo(0.96f, in_duration, Easing.OutQuint);
innerCircleHighlight
.FadeIn(50, Easing.OutQuint)
.FlashColour(Color4.White, 1000, Easing.OutQuint);
lights[currentLight % light_count].Hide();
lights[(currentLight + light_count / 2) % light_count].Hide();
currentLight++;
lights[currentLight % light_count].Show();
lights[(currentLight + light_count / 2) % light_count].Show();
2022-06-01 09:53:35 +00:00
return base.OnMouseDown(e);
}
protected override void OnMouseUp(MouseUpEvent e)
{
2022-06-01 10:45:11 +00:00
const double out_duration = 800;
scaleContainer.ScaleTo(1, out_duration, Easing.OutQuint);
innerCircle.ScaleTo(1, out_duration, Easing.OutQuint);
innerCircleHighlight.FadeOut(out_duration, Easing.OutQuint);
2022-06-01 09:53:35 +00:00
base.OnMouseUp(e);
}
2022-06-01 10:45:11 +00:00
private class Light : CompositeDrawable
{
private CircularProgress fill;
[Resolved]
private OverlayColourProvider colourProvider { get; set; }
[BackgroundDependencyLoader]
private void load()
{
RelativeSizeAxes = Axes.Both;
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
InternalChildren = new Drawable[]
{
new CircularProgress
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(0.99f),
Current = { Value = 1f / light_count - 0.01f },
Colour = colourProvider.Background2,
},
fill = new CircularProgress
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Alpha = 0,
Size = new Vector2(0.99f),
Current = { Value = 1f / light_count - 0.01f },
Colour = colourProvider.Colour1,
Blending = BlendingParameters.Additive
},
};
}
public override void Show()
{
fill
.FadeIn(50, Easing.OutQuint)
.FlashColour(Color4.White, 1000, Easing.OutQuint);
}
public override void Hide()
{
fill
.FadeOut(300, Easing.OutQuint);
}
}
2022-06-01 09:53:35 +00:00
}
}