1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-20 00:52:56 +08:00

Add simple carousel divisor type selector

This commit is contained in:
Bartłomiej Dach 2022-02-13 14:37:37 +01:00
parent 6eb79c37d8
commit 36137e0619
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
2 changed files with 112 additions and 14 deletions

View File

@ -2,7 +2,9 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Diagnostics;
using System.Linq; using System.Linq;
using Humanizer;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
@ -14,6 +16,7 @@ using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -24,6 +27,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
public class BeatDivisorControl : CompositeDrawable public class BeatDivisorControl : CompositeDrawable
{ {
private readonly BindableBeatDivisor beatDivisor = new BindableBeatDivisor(); private readonly BindableBeatDivisor beatDivisor = new BindableBeatDivisor();
private readonly Bindable<BeatDivisorType> divisorType = new Bindable<BeatDivisorType>();
public BeatDivisorControl(BindableBeatDivisor beatDivisor) public BeatDivisorControl(BindableBeatDivisor beatDivisor)
{ {
@ -84,7 +88,6 @@ namespace osu.Game.Screens.Edit.Compose.Components
new Container new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = 5 },
Child = new GridContainer Child = new GridContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
@ -92,13 +95,13 @@ namespace osu.Game.Screens.Edit.Compose.Components
{ {
new Drawable[] new Drawable[]
{ {
new DivisorButton new ChevronButton
{ {
Icon = FontAwesome.Solid.ChevronLeft, Icon = FontAwesome.Solid.ChevronLeft,
Action = beatDivisor.Previous Action = beatDivisor.Previous
}, },
new DivisorText(beatDivisor), new DivisorText { BeatDivisor = { BindTarget = beatDivisor } },
new DivisorButton new ChevronButton
{ {
Icon = FontAwesome.Solid.ChevronRight, Icon = FontAwesome.Solid.ChevronRight,
Action = beatDivisor.Next Action = beatDivisor.Next
@ -121,29 +124,80 @@ namespace osu.Game.Screens.Edit.Compose.Components
new TextFlowContainer(s => s.Font = s.Font.With(size: 14)) new TextFlowContainer(s => s.Font = s.Font.With(size: 14))
{ {
Padding = new MarginPadding { Horizontal = 15 }, Padding = new MarginPadding { Horizontal = 15 },
Text = "beat snap divisor", Text = "beat snap",
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
TextAnchor = Anchor.TopCentre TextAnchor = Anchor.TopCentre
}, },
},
new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colours.Gray4
},
new Container
{
RelativeSizeAxes = Axes.Both,
Child = new GridContainer
{
RelativeSizeAxes = Axes.Both,
Content = new[]
{
new Drawable[]
{
new ChevronButton
{
Icon = FontAwesome.Solid.ChevronLeft,
Action = () => cycleDivisorType(-1)
},
new DivisorTypeText { BeatDivisorType = { BindTarget = divisorType } },
new ChevronButton
{
Icon = FontAwesome.Solid.ChevronRight,
Action = () => cycleDivisorType(1)
} }
}, },
},
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.Absolute, 20),
new Dimension(),
new Dimension(GridSizeMode.Absolute, 20)
}
}
}
}
}
},
},
RowDimensions = new[] RowDimensions = new[]
{ {
new Dimension(GridSizeMode.Absolute, 30), new Dimension(GridSizeMode.Absolute, 30),
new Dimension(GridSizeMode.Absolute, 25), new Dimension(GridSizeMode.Absolute, 20),
new Dimension(GridSizeMode.Absolute, 15)
} }
} }
}; };
} }
private void cycleDivisorType(int direction)
{
Debug.Assert(Math.Abs(direction) == 1);
divisorType.Value = (BeatDivisorType)(((int)divisorType.Value + direction) % (int)(BeatDivisorType.Last + 1));
}
private class DivisorText : SpriteText private class DivisorText : SpriteText
{ {
private readonly Bindable<int> beatDivisor = new Bindable<int>(); public Bindable<int> BeatDivisor { get; } = new Bindable<int>();
public DivisorText(BindableBeatDivisor beatDivisor) public DivisorText()
{ {
this.beatDivisor.BindTo(beatDivisor);
Anchor = Anchor.Centre; Anchor = Anchor.Centre;
Origin = Anchor.Centre; Origin = Anchor.Centre;
} }
@ -157,13 +211,32 @@ namespace osu.Game.Screens.Edit.Compose.Components
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
beatDivisor.BindValueChanged(val => Text = $"1/{val.NewValue}", true); BeatDivisor.BindValueChanged(val => Text = $"1/{val.NewValue}", true);
} }
} }
private class DivisorButton : IconButton private class DivisorTypeText : OsuSpriteText
{ {
public DivisorButton() public Bindable<BeatDivisorType> BeatDivisorType { get; } = new Bindable<BeatDivisorType>();
public DivisorTypeText()
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
Font = OsuFont.Default.With(size: 14);
}
protected override void LoadComplete()
{
base.LoadComplete();
BeatDivisorType.BindValueChanged(val => Text = val.NewValue.Humanize(LetterCasing.LowerCase), true);
}
}
private class ChevronButton : IconButton
{
public ChevronButton()
{ {
Anchor = Anchor.Centre; Anchor = Anchor.Centre;
Origin = Anchor.Centre; Origin = Anchor.Centre;

View File

@ -0,0 +1,25 @@
// 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.
namespace osu.Game.Screens.Edit.Compose.Components
{
public enum BeatDivisorType
{
/// <summary>
/// Most common divisors, all with denominators being powers of two.
/// </summary>
Common,
/// <summary>
/// Divisors with denominators divisible by 3.
/// </summary>
Triplets,
/// <summary>
/// Fully arbitrary/custom beat divisors.
/// </summary>
Custom,
Last = Custom
}
}