mirror of
https://github.com/ppy/osu.git
synced 2025-03-21 23:20:16 +08:00
Setup basics for control and test
This commit is contained in:
parent
64a371638e
commit
ce7be940e2
94
osu.Game.Tests/Visual/Editing/TestSceneTapTimingControl.cs
Normal file
94
osu.Game.Tests/Visual/Editing/TestSceneTapTimingControl.cs
Normal file
@ -0,0 +1,94 @@
|
||||
// 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 System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps.ControlPoints;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Screens.Edit;
|
||||
using osu.Game.Screens.Edit.Timing;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Editing
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestSceneTapTimingControl : EditorClockTestScene
|
||||
{
|
||||
[Cached(typeof(EditorBeatmap))]
|
||||
[Cached(typeof(IBeatSnapProvider))]
|
||||
private readonly EditorBeatmap editorBeatmap;
|
||||
|
||||
[Cached]
|
||||
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
|
||||
|
||||
[Cached]
|
||||
private Bindable<ControlPointGroup> selectedGroup = new Bindable<ControlPointGroup>();
|
||||
|
||||
private TapTimingControl control;
|
||||
|
||||
public TestSceneTapTimingControl()
|
||||
{
|
||||
editorBeatmap = new EditorBeatmap(CreateBeatmap(new OsuRuleset().RulesetInfo));
|
||||
selectedGroup.Value = editorBeatmap.ControlPointInfo.Groups.First();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestTapThenReset()
|
||||
{
|
||||
AddStep("click tap button", () =>
|
||||
{
|
||||
control.ChildrenOfType<RoundedButton>()
|
||||
.First(b => b.Text == "Tap to beat")
|
||||
.TriggerClick();
|
||||
});
|
||||
|
||||
AddUntilStep("wait for track playing", () => Clock.IsRunning);
|
||||
|
||||
AddStep("click reset button", () =>
|
||||
{
|
||||
control.ChildrenOfType<RoundedButton>()
|
||||
.First(b => b.Text == "Reset")
|
||||
.TriggerClick();
|
||||
});
|
||||
|
||||
AddUntilStep("wait for track stopped", () => !Clock.IsRunning);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBasic()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Beatmap.Value = CreateWorkingBeatmap(editorBeatmap.PlayableBeatmap);
|
||||
Beatmap.Disabled = true;
|
||||
|
||||
Child = new Container
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Width = 400,
|
||||
Scale = new Vector2(1.5f),
|
||||
Child = control = new TapTimingControl(),
|
||||
};
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
Beatmap.Disabled = false;
|
||||
base.Dispose(isDisposing);
|
||||
}
|
||||
}
|
||||
}
|
@ -41,7 +41,8 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
|
||||
protected const float CONTENT_PADDING_VERTICAL = 10;
|
||||
protected const float CONTENT_PADDING_HORIZONTAL = 15;
|
||||
protected const float CORNER_RADIUS = 15;
|
||||
|
||||
public const float CORNER_RADIUS = 15;
|
||||
|
||||
/// <summary>
|
||||
/// The component that is being displayed.
|
||||
|
189
osu.Game/Screens/Edit/Timing/TapTimingControl.cs
Normal file
189
osu.Game/Screens/Edit/Timing/TapTimingControl.cs
Normal file
@ -0,0 +1,189 @@
|
||||
// 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 System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
using osu.Game.Overlays;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Timing
|
||||
{
|
||||
public class TapTimingControl : CompositeDrawable
|
||||
{
|
||||
[Resolved]
|
||||
private EditorClock editorClock { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OverlayColourProvider colourProvider, OsuColour colours)
|
||||
{
|
||||
Height = 200;
|
||||
RelativeSizeAxes = Axes.X;
|
||||
|
||||
CornerRadius = LabelledDrawable<Drawable>.CORNER_RADIUS;
|
||||
Masking = true;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
Colour = colourProvider.Background4,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
new GridContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RowDimensions = new[]
|
||||
{
|
||||
new Dimension(),
|
||||
new Dimension(GridSizeMode.Absolute, 60),
|
||||
},
|
||||
Content = new[]
|
||||
{
|
||||
new Drawable[]
|
||||
{
|
||||
new Metronome()
|
||||
},
|
||||
new Drawable[]
|
||||
{
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding(10),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new RoundedButton
|
||||
{
|
||||
Text = "Reset",
|
||||
BackgroundColour = colours.Pink,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Width = 0.3f,
|
||||
Action = reset,
|
||||
},
|
||||
new RoundedButton
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
Text = "Tap to beat",
|
||||
RelativeSizeAxes = Axes.X,
|
||||
BackgroundColour = colourProvider.Background1,
|
||||
Width = 0.68f,
|
||||
Action = tap,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private void tap()
|
||||
{
|
||||
if (!editorClock.IsRunning)
|
||||
{
|
||||
editorClock.Seek(0);
|
||||
editorClock.Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void reset()
|
||||
{
|
||||
editorClock.Stop();
|
||||
}
|
||||
|
||||
private class Metronome : BeatSyncedContainer
|
||||
{
|
||||
private Container swing;
|
||||
private Box weight;
|
||||
private OsuSpriteText bpm;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OverlayColourProvider overlayColourProvider)
|
||||
{
|
||||
Margin = new MarginPadding(10);
|
||||
AutoSizeAxes = Axes.Both;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new Triangle
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(80, 120),
|
||||
Colour = overlayColourProvider.Background1,
|
||||
},
|
||||
new Circle
|
||||
{
|
||||
Y = -25,
|
||||
Anchor = Anchor.BottomCentre,
|
||||
Origin = Anchor.Centre,
|
||||
Colour = overlayColourProvider.Content2,
|
||||
Size = new Vector2(10)
|
||||
},
|
||||
bpm = new OsuSpriteText
|
||||
{
|
||||
Colour = overlayColourProvider.Content1,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
},
|
||||
swing = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Y = -25,
|
||||
Height = 0.8f,
|
||||
Anchor = Anchor.BottomCentre,
|
||||
Origin = Anchor.BottomCentre,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
Colour = overlayColourProvider.Content2,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Anchor = Anchor.BottomCentre,
|
||||
Origin = Anchor.BottomCentre,
|
||||
Width = 4,
|
||||
},
|
||||
weight = new Box
|
||||
{
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.Centre,
|
||||
Colour = overlayColourProvider.Content2,
|
||||
Size = new Vector2(15),
|
||||
RelativePositionAxes = Axes.Y,
|
||||
Y = -0.4f,
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
swing
|
||||
.RotateTo(20, 500, Easing.InOutQuad)
|
||||
.Then()
|
||||
.RotateTo(-20, 500, Easing.InOutQuad)
|
||||
.Loop();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (CurrentTimingPoint == null)
|
||||
return;
|
||||
|
||||
weight.Y = Math.Clamp((float)CurrentTimingPoint.BPM / 480, 0, 0.95f);
|
||||
bpm.Text = $"{CurrentTimingPoint.BPM:F0}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ namespace osu.Game.Screens.Edit.Timing
|
||||
{
|
||||
Flow.AddRange(new Drawable[]
|
||||
{
|
||||
new TapTimingControl(),
|
||||
bpmTextEntry = new BPMTextBox(),
|
||||
timeSignature = new LabelledTimeSignature
|
||||
{
|
||||
@ -96,5 +97,6 @@ namespace osu.Game.Screens.Edit.Timing
|
||||
}
|
||||
|
||||
private static double beatLengthToBpm(double beatLength) => 60000 / beatLength;
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user