From d12f6ea2213da50789f48c9cf3f0e65a55e1ae93 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 1 Jun 2022 18:53:35 +0900 Subject: [PATCH] Add basics of tap button --- .../Visual/Editing/TestSceneTapButton.cs | 48 +++++++ osu.Game/Screens/Edit/Timing/TapButton.cs | 122 ++++++++++++++++++ .../Screens/Edit/Timing/TapTimingControl.cs | 9 ++ 3 files changed, 179 insertions(+) create mode 100644 osu.Game.Tests/Visual/Editing/TestSceneTapButton.cs create mode 100644 osu.Game/Screens/Edit/Timing/TapButton.cs diff --git a/osu.Game.Tests/Visual/Editing/TestSceneTapButton.cs b/osu.Game.Tests/Visual/Editing/TestSceneTapButton.cs new file mode 100644 index 0000000000..d8141619ab --- /dev/null +++ b/osu.Game.Tests/Visual/Editing/TestSceneTapButton.cs @@ -0,0 +1,48 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Game.Overlays; +using osu.Game.Screens.Edit.Timing; +using osuTK; +using osuTK.Input; + +namespace osu.Game.Tests.Visual.Editing +{ + public class TestSceneTapButton : OsuManualInputManagerTestScene + { + private TapButton tapButton; + + [Cached] + private readonly OverlayColourProvider overlayColour = new OverlayColourProvider(OverlayColourScheme.Aquamarine); + + [Test] + public void TestBasic() + { + AddStep("create button", () => + { + Child = tapButton = new TapButton + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Scale = new Vector2(4), + }; + }); + + bool pressed = false; + + AddRepeatStep("Press button", () => + { + InputManager.MoveMouseTo(tapButton); + if (!pressed) + InputManager.PressButton(MouseButton.Left); + else + InputManager.ReleaseButton(MouseButton.Left); + + pressed = !pressed; + }, 100); + } + } +} diff --git a/osu.Game/Screens/Edit/Timing/TapButton.cs b/osu.Game/Screens/Edit/Timing/TapButton.cs new file mode 100644 index 0000000000..59ec966fe0 --- /dev/null +++ b/osu.Game/Screens/Edit/Timing/TapButton.cs @@ -0,0 +1,122 @@ +// Copyright (c) ppy Pty Ltd . 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; +using osu.Framework.Input.Events; +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; + private CircularContainer innerCircle; + private Circle outerCircle; + + private Container scaleContainer; + + [BackgroundDependencyLoader] + private void load() + { + Size = new Vector2(SIZE); + + const float ring_width = 20; + const float light_padding = 3; + + InternalChild = scaleContainer = new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + Children = new Drawable[] + { + outerCircle = new Circle + { + RelativeSizeAxes = Axes.Both, + Colour = colourProvider.Background3 + }, + 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, + }, + } + }, + innerCircle = new CircularContainer + { + Size = new Vector2(SIZE - ring_width + light_padding), + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Masking = true, + BorderThickness = light_padding, + BorderColour = colourProvider.Background3, + Children = new Drawable[] + { + new Box + { + Colour = colourProvider.Background2, + RelativeSizeAxes = Axes.Both, + AlwaysPresent = true, + }, + } + }, + hoverLayer = new Circle + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.White.Opacity(0.01f), + Blending = BlendingParameters.Additive, + Alpha = 0, + }, + } + }; + } + + 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) + { + scaleContainer.ScaleTo(0.98f, 200, Easing.OutQuint); + innerCircle.ScaleTo(0.95f, 200, Easing.OutQuint); + return base.OnMouseDown(e); + } + + protected override void OnMouseUp(MouseUpEvent e) + { + scaleContainer.ScaleTo(1, 1200, Easing.OutQuint); + innerCircle.ScaleTo(1, 1200, Easing.OutQuint); + base.OnMouseUp(e); + } + } +} diff --git a/osu.Game/Screens/Edit/Timing/TapTimingControl.cs b/osu.Game/Screens/Edit/Timing/TapTimingControl.cs index 990f8d2ce0..20d6c656ff 100644 --- a/osu.Game/Screens/Edit/Timing/TapTimingControl.cs +++ b/osu.Game/Screens/Edit/Timing/TapTimingControl.cs @@ -50,6 +50,7 @@ namespace osu.Game.Screens.Edit.Timing new Dimension(GridSizeMode.Absolute, 200), new Dimension(GridSizeMode.Absolute, 60), new Dimension(GridSizeMode.Absolute, 60), + new Dimension(GridSizeMode.Absolute, 120), }, Content = new[] { @@ -141,6 +142,14 @@ namespace osu.Game.Screens.Edit.Timing } } }, + }, + new Drawable[] + { + new TapButton + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + } } } },