2022-01-23 01:54:14 +08: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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2022-01-23 01:54:14 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Game.Beatmaps.Timing;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Timing
|
|
|
|
{
|
2022-01-23 15:13:32 +08:00
|
|
|
public class LabelledTimeSignature : LabelledComponent<LabelledTimeSignature.TimeSignatureBox, TimeSignature>
|
2022-01-23 01:54:14 +08:00
|
|
|
{
|
|
|
|
public LabelledTimeSignature()
|
|
|
|
: base(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override TimeSignatureBox CreateComponent() => new TimeSignatureBox();
|
|
|
|
|
2022-01-23 15:13:32 +08:00
|
|
|
public class TimeSignatureBox : CompositeDrawable, IHasCurrentValue<TimeSignature>
|
2022-01-23 01:54:14 +08:00
|
|
|
{
|
|
|
|
private readonly BindableWithCurrent<TimeSignature> current = new BindableWithCurrent<TimeSignature>(TimeSignature.SimpleQuadruple);
|
|
|
|
|
|
|
|
public Bindable<TimeSignature> Current
|
|
|
|
{
|
|
|
|
get => current.Current;
|
|
|
|
set => current.Current = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private OsuNumberBox numeratorBox;
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
InternalChild = new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
numeratorBox = new OsuNumberBox
|
|
|
|
{
|
|
|
|
Width = 40,
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
CornerRadius = CORNER_RADIUS,
|
|
|
|
CommitOnFocusLost = true
|
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
2022-01-23 22:20:51 +08:00
|
|
|
Margin = new MarginPadding
|
|
|
|
{
|
|
|
|
Left = 5,
|
|
|
|
Right = CONTENT_PADDING_HORIZONTAL
|
|
|
|
},
|
|
|
|
Text = "/ 4",
|
2022-01-23 01:54:14 +08:00
|
|
|
Font = OsuFont.Default.With(size: 20)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
Current.BindValueChanged(_ => updateFromCurrent(), true);
|
2022-06-24 20:25:23 +08:00
|
|
|
numeratorBox.OnCommit += (_, _) => updateFromNumeratorBox();
|
2022-01-23 01:54:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateFromCurrent()
|
|
|
|
{
|
|
|
|
numeratorBox.Current.Value = Current.Value.Numerator.ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateFromNumeratorBox()
|
|
|
|
{
|
|
|
|
if (int.TryParse(numeratorBox.Current.Value, out int numerator) && numerator > 0)
|
|
|
|
Current.Value = new TimeSignature(numerator);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// trigger `Current` change to restore the numerator box's text to a valid value.
|
|
|
|
Current.TriggerChange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|