2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-20 20:59:32 +08:00
|
|
|
|
using System;
|
2022-02-13 21:37:37 +08:00
|
|
|
|
using System.Diagnostics;
|
2018-03-20 19:09:55 +08:00
|
|
|
|
using System.Linq;
|
2022-02-13 21:37:37 +08:00
|
|
|
|
using Humanizer;
|
2018-03-19 18:46:26 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2022-02-13 23:27:12 +08:00
|
|
|
|
using osu.Framework.Extensions;
|
2018-03-19 18:46:26 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-02-13 23:27:12 +08:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2018-03-19 18:46:26 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-03-19 18:49:57 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-03-20 19:09:55 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2023-06-07 16:15:13 +08:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-03-19 18:46:26 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2022-02-13 23:27:12 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2022-02-13 21:37:37 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-03-19 18:46:26 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-02-13 23:27:12 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
2023-06-07 16:15:13 +08:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2022-05-24 15:50:16 +08:00
|
|
|
|
using osu.Game.Overlays;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
using osuTK.Input;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-06 17:28:22 +08:00
|
|
|
|
namespace osu.Game.Screens.Edit.Compose.Components
|
2018-03-19 18:46:26 +08:00
|
|
|
|
{
|
2023-06-07 16:15:13 +08:00
|
|
|
|
public partial class BeatDivisorControl : CompositeDrawable, IKeyBindingHandler<GlobalAction>
|
2018-03-19 18:46:26 +08:00
|
|
|
|
{
|
2023-06-01 15:40:33 +08:00
|
|
|
|
private int? lastCustomDivisor;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-07-14 13:02:48 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private BindableBeatDivisor beatDivisor { get; set; } = null!;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-20 12:57:25 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2022-05-24 15:50:16 +08:00
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
2018-03-20 12:57:25 +08:00
|
|
|
|
{
|
2018-03-19 18:46:26 +08:00
|
|
|
|
Masking = true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-19 18:46:26 +08:00
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
2022-05-24 15:50:16 +08:00
|
|
|
|
Name = "Main background",
|
2018-03-19 18:46:26 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-05-24 15:50:16 +08:00
|
|
|
|
Colour = colourProvider.Background3,
|
2018-03-19 18:46:26 +08:00
|
|
|
|
},
|
|
|
|
|
new GridContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Content = new[]
|
|
|
|
|
{
|
|
|
|
|
new Drawable[]
|
|
|
|
|
{
|
2018-03-21 15:04:43 +08:00
|
|
|
|
new Container
|
2018-03-19 18:46:26 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2018-03-21 15:04:43 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
2022-05-24 15:50:16 +08:00
|
|
|
|
Name = "Tick area background",
|
2018-03-21 15:04:43 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-05-24 15:50:16 +08:00
|
|
|
|
Colour = colourProvider.Background5,
|
2018-03-21 15:04:43 +08:00
|
|
|
|
},
|
2022-02-13 22:50:40 +08:00
|
|
|
|
new TickSliderBar(beatDivisor)
|
2018-03-21 15:04:43 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-19 18:46:26 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-05-24 15:50:16 +08:00
|
|
|
|
Colour = colourProvider.Background3
|
2018-03-19 18:46:26 +08:00
|
|
|
|
},
|
2024-02-21 04:18:37 +08:00
|
|
|
|
new GridContainer
|
2018-03-19 18:46:26 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2024-02-21 04:18:37 +08:00
|
|
|
|
Content = new[]
|
2018-03-19 18:46:26 +08:00
|
|
|
|
{
|
2024-02-21 04:18:37 +08:00
|
|
|
|
new Drawable[]
|
2018-03-19 18:46:26 +08:00
|
|
|
|
{
|
2024-02-21 04:18:37 +08:00
|
|
|
|
new ChevronButton
|
2018-03-19 18:46:26 +08:00
|
|
|
|
{
|
2024-02-21 04:18:37 +08:00
|
|
|
|
Icon = FontAwesome.Solid.ChevronLeft,
|
|
|
|
|
Action = beatDivisor.SelectPrevious
|
2018-03-19 18:46:26 +08:00
|
|
|
|
},
|
2024-02-21 04:18:37 +08:00
|
|
|
|
new DivisorDisplay { BeatDivisor = { BindTarget = beatDivisor } },
|
|
|
|
|
new ChevronButton
|
|
|
|
|
{
|
|
|
|
|
Icon = FontAwesome.Solid.ChevronRight,
|
|
|
|
|
Action = beatDivisor.SelectNext
|
|
|
|
|
}
|
2018-03-19 18:46:26 +08:00
|
|
|
|
},
|
2024-02-21 04:18:37 +08:00
|
|
|
|
},
|
|
|
|
|
ColumnDimensions = new[]
|
|
|
|
|
{
|
|
|
|
|
new Dimension(GridSizeMode.Absolute, 20),
|
|
|
|
|
new Dimension(),
|
|
|
|
|
new Dimension(GridSizeMode.Absolute, 20)
|
2018-03-19 18:46:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2018-03-21 15:04:43 +08:00
|
|
|
|
new Drawable[]
|
2022-02-13 21:37:37 +08:00
|
|
|
|
{
|
2024-02-21 04:18:37 +08:00
|
|
|
|
new GridContainer
|
2022-02-13 21:37:37 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2024-02-21 04:18:37 +08:00
|
|
|
|
Content = new[]
|
2022-02-13 21:37:37 +08:00
|
|
|
|
{
|
2024-02-21 04:18:37 +08:00
|
|
|
|
new Drawable[]
|
2022-02-13 21:37:37 +08:00
|
|
|
|
{
|
2024-02-21 04:18:37 +08:00
|
|
|
|
new ChevronButton
|
2022-02-13 21:37:37 +08:00
|
|
|
|
{
|
2024-02-21 04:18:37 +08:00
|
|
|
|
Icon = FontAwesome.Solid.ChevronLeft,
|
|
|
|
|
Action = () => cycleDivisorType(-1)
|
|
|
|
|
},
|
|
|
|
|
new DivisorTypeText { BeatDivisor = { BindTarget = beatDivisor } },
|
|
|
|
|
new ChevronButton
|
|
|
|
|
{
|
|
|
|
|
Icon = FontAwesome.Solid.ChevronRight,
|
|
|
|
|
Action = () => cycleDivisorType(1)
|
2022-02-13 21:37:37 +08:00
|
|
|
|
}
|
2024-02-21 04:18:37 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
ColumnDimensions = new[]
|
|
|
|
|
{
|
|
|
|
|
new Dimension(GridSizeMode.Absolute, 20),
|
|
|
|
|
new Dimension(),
|
|
|
|
|
new Dimension(GridSizeMode.Absolute, 20)
|
2022-02-13 21:37:37 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-10-13 14:47:54 +08:00
|
|
|
|
new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new TextFlowContainer(s => s.Font = s.Font.With(size: 14))
|
|
|
|
|
{
|
|
|
|
|
Padding = new MarginPadding { Horizontal = 15, Vertical = 8 },
|
|
|
|
|
Text = "beat snap",
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
TextAnchor = Anchor.TopCentre,
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-03-19 18:46:26 +08:00
|
|
|
|
},
|
|
|
|
|
RowDimensions = new[]
|
|
|
|
|
{
|
2018-03-22 19:11:55 +08:00
|
|
|
|
new Dimension(GridSizeMode.Absolute, 30),
|
2022-02-13 21:37:37 +08:00
|
|
|
|
new Dimension(GridSizeMode.Absolute, 20),
|
|
|
|
|
new Dimension(GridSizeMode.Absolute, 15)
|
2018-03-19 18:46:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-03-19 18:55:49 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-06-01 15:40:33 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
beatDivisor.ValidDivisors.BindValueChanged(valid =>
|
|
|
|
|
{
|
|
|
|
|
if (valid.NewValue.Type == BeatDivisorType.Custom)
|
|
|
|
|
lastCustomDivisor = valid.NewValue.Presets.Last();
|
|
|
|
|
}, true);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-13 21:37:37 +08:00
|
|
|
|
private void cycleDivisorType(int direction)
|
|
|
|
|
{
|
2023-06-01 15:40:33 +08:00
|
|
|
|
int totalTypes = Enum.GetValues<BeatDivisorType>().Length;
|
|
|
|
|
BeatDivisorType currentType = beatDivisor.ValidDivisors.Value.Type;
|
|
|
|
|
|
2022-02-13 21:37:37 +08:00
|
|
|
|
Debug.Assert(Math.Abs(direction) == 1);
|
2022-02-13 22:50:40 +08:00
|
|
|
|
|
2023-06-01 15:40:33 +08:00
|
|
|
|
cycleOnce();
|
|
|
|
|
|
|
|
|
|
if (lastCustomDivisor == null && currentType == BeatDivisorType.Custom)
|
|
|
|
|
cycleOnce();
|
|
|
|
|
|
|
|
|
|
switch (currentType)
|
2022-02-13 22:50:40 +08:00
|
|
|
|
{
|
|
|
|
|
case BeatDivisorType.Common:
|
2024-01-24 21:01:41 +08:00
|
|
|
|
beatDivisor.SetArbitraryDivisor(4, true);
|
2022-02-13 22:50:40 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BeatDivisorType.Triplets:
|
2024-01-24 21:01:41 +08:00
|
|
|
|
beatDivisor.SetArbitraryDivisor(6, true);
|
2022-02-13 22:50:40 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BeatDivisorType.Custom:
|
2023-06-01 15:40:33 +08:00
|
|
|
|
Debug.Assert(lastCustomDivisor != null);
|
|
|
|
|
beatDivisor.SetArbitraryDivisor(lastCustomDivisor.Value);
|
2022-02-13 22:50:40 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2023-06-01 15:40:33 +08:00
|
|
|
|
|
|
|
|
|
void cycleOnce() => currentType = (BeatDivisorType)(((int)currentType + totalTypes + direction) % totalTypes);
|
2022-02-13 21:37:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-24 14:20:15 +08:00
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
|
|
|
|
{
|
|
|
|
|
if (e.ShiftPressed && e.Key >= Key.Number1 && e.Key <= Key.Number9)
|
|
|
|
|
{
|
|
|
|
|
beatDivisor.SetArbitraryDivisor(e.Key - Key.Number0);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.OnKeyDown(e);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-08 05:28:27 +08:00
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
2023-06-07 16:15:13 +08:00
|
|
|
|
{
|
|
|
|
|
switch (e.Action)
|
|
|
|
|
{
|
|
|
|
|
case GlobalAction.EditorCycleNextBeatSnapDivisor:
|
2023-06-07 23:53:58 +08:00
|
|
|
|
beatDivisor.SelectNext();
|
2023-06-07 16:15:13 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case GlobalAction.EditorCyclePreviousBeatSnapDivisor:
|
2023-06-07 23:53:58 +08:00
|
|
|
|
beatDivisor.SelectPrevious();
|
2023-06-07 16:15:13 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 02:23:02 +08:00
|
|
|
|
internal partial class DivisorDisplay : OsuAnimatedButton, IHasPopover
|
2018-03-19 18:49:57 +08:00
|
|
|
|
{
|
2022-02-13 23:27:12 +08:00
|
|
|
|
public BindableBeatDivisor BeatDivisor { get; } = new BindableBeatDivisor();
|
|
|
|
|
|
|
|
|
|
private readonly OsuSpriteText divisorText;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-02-13 23:27:12 +08:00
|
|
|
|
public DivisorDisplay()
|
2023-08-17 16:07:02 +08:00
|
|
|
|
: base(HoverSampleSet.Default)
|
2018-03-19 18:49:57 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
|
Origin = Anchor.Centre;
|
2022-02-13 23:27:12 +08:00
|
|
|
|
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
Add(divisorText = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Font = OsuFont.Default.With(size: 20),
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Horizontal = 5
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Action = this.ShowPopover;
|
2018-03-19 18:49:57 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-19 19:14:34 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2018-03-20 12:57:25 +08:00
|
|
|
|
private void load(OsuColour colours)
|
2018-03-19 19:14:34 +08:00
|
|
|
|
{
|
2022-02-13 23:27:12 +08:00
|
|
|
|
divisorText.Colour = colours.BlueLighter;
|
2018-03-19 19:14:34 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-19 18:49:57 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2022-02-13 23:27:12 +08:00
|
|
|
|
updateState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
|
{
|
|
|
|
|
BeatDivisor.BindValueChanged(val => divisorText.Text = $"1/{val.NewValue}", true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Popover GetPopover() => new CustomDivisorPopover
|
|
|
|
|
{
|
|
|
|
|
BeatDivisor = { BindTarget = BeatDivisor }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 02:23:02 +08:00
|
|
|
|
internal partial class CustomDivisorPopover : OsuPopover
|
2022-02-13 23:27:12 +08:00
|
|
|
|
{
|
|
|
|
|
public BindableBeatDivisor BeatDivisor { get; } = new BindableBeatDivisor();
|
|
|
|
|
|
|
|
|
|
private readonly OsuNumberBox divisorTextBox;
|
|
|
|
|
|
|
|
|
|
public CustomDivisorPopover()
|
|
|
|
|
{
|
|
|
|
|
Child = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Width = 150,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Spacing = new Vector2(10),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2023-10-31 15:38:22 +08:00
|
|
|
|
divisorTextBox = new AutoSelectTextBox
|
2022-02-13 23:27:12 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
PlaceholderText = "Beat divisor"
|
|
|
|
|
},
|
|
|
|
|
new OsuTextFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2022-02-28 14:26:09 +08:00
|
|
|
|
Text = "Related divisors will be added to the list of presets."
|
2022-02-13 23:27:12 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
BeatDivisor.BindValueChanged(_ => updateState(), true);
|
2023-06-01 15:40:33 +08:00
|
|
|
|
divisorTextBox.OnCommit += (_, _) => setPresetsFromTextBoxEntry();
|
2022-02-13 23:27:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 15:40:33 +08:00
|
|
|
|
private void setPresetsFromTextBoxEntry()
|
2022-02-13 23:27:12 +08:00
|
|
|
|
{
|
|
|
|
|
if (!int.TryParse(divisorTextBox.Text, out int divisor) || divisor < 1 || divisor > 64)
|
|
|
|
|
{
|
|
|
|
|
updateState();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-24 14:20:15 +08:00
|
|
|
|
BeatDivisor.SetArbitraryDivisor(divisor);
|
2022-02-28 14:21:01 +08:00
|
|
|
|
|
|
|
|
|
this.HidePopover();
|
2022-02-13 23:27:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
|
{
|
|
|
|
|
divisorTextBox.Text = BeatDivisor.Value.ToString();
|
2022-02-13 21:37:37 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private partial class DivisorTypeText : OsuSpriteText
|
|
|
|
|
{
|
2022-02-13 22:50:40 +08:00
|
|
|
|
public BindableBeatDivisor BeatDivisor { get; } = new BindableBeatDivisor();
|
2022-02-13 21:37:37 +08:00
|
|
|
|
|
|
|
|
|
public DivisorTypeText()
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
|
|
|
|
|
Font = OsuFont.Default.With(size: 14);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2022-02-13 22:50:40 +08:00
|
|
|
|
BeatDivisor.ValidDivisors.BindValueChanged(val => Text = val.NewValue.Type.Humanize(LetterCasing.LowerCase), true);
|
2018-03-19 18:49:57 +08:00
|
|
|
|
}
|
2018-03-19 18:46:26 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-02-28 02:23:02 +08:00
|
|
|
|
internal partial class ChevronButton : IconButton
|
2018-03-19 18:46:26 +08:00
|
|
|
|
{
|
2022-02-13 21:37:37 +08:00
|
|
|
|
public ChevronButton()
|
2018-03-19 18:46:26 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
|
Origin = Anchor.Centre;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-19 19:14:13 +08:00
|
|
|
|
// Small offset to look a bit better centered along with the divisor text
|
|
|
|
|
Y = 1;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-14 12:40:32 +08:00
|
|
|
|
Size = new Vector2(20);
|
2018-03-19 19:14:34 +08:00
|
|
|
|
IconScale = new Vector2(0.6f);
|
2018-03-19 18:46:26 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-19 18:46:26 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
IconColour = Color4.Black;
|
|
|
|
|
HoverColour = colours.Gray7;
|
|
|
|
|
FlashColour = colours.Gray9;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-20 19:09:55 +08:00
|
|
|
|
private partial class TickSliderBar : SliderBar<int>
|
2018-03-19 19:20:29 +08:00
|
|
|
|
{
|
2023-06-01 15:28:47 +08:00
|
|
|
|
private Marker marker = null!;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-08-30 16:34:02 +08:00
|
|
|
|
[Resolved]
|
2023-06-01 15:28:47 +08:00
|
|
|
|
private OsuColour colours { get; set; } = null!;
|
2019-08-30 16:34:02 +08:00
|
|
|
|
|
2018-03-20 21:25:15 +08:00
|
|
|
|
private readonly BindableBeatDivisor beatDivisor;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-02-13 22:50:40 +08:00
|
|
|
|
public TickSliderBar(BindableBeatDivisor beatDivisor)
|
2018-03-19 19:20:29 +08:00
|
|
|
|
{
|
2018-03-20 21:25:15 +08:00
|
|
|
|
CurrentNumber.BindTo(this.beatDivisor = beatDivisor);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-05-23 23:59:07 +08:00
|
|
|
|
RangePadding = 5;
|
|
|
|
|
Padding = new MarginPadding { Horizontal = RangePadding };
|
2018-03-19 19:20:29 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-02-13 22:50:40 +08:00
|
|
|
|
protected override void LoadComplete()
|
2018-03-19 19:20:29 +08:00
|
|
|
|
{
|
2022-02-13 22:50:40 +08:00
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
beatDivisor.ValidDivisors.BindValueChanged(_ => updateDivisors(), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateDivisors()
|
|
|
|
|
{
|
|
|
|
|
ClearInternal();
|
|
|
|
|
CurrentNumber.ValueChanged -= moveMarker;
|
|
|
|
|
|
2023-05-24 00:45:49 +08:00
|
|
|
|
int largestDivisor = beatDivisor.ValidDivisors.Value.Presets.Last();
|
2023-05-24 12:49:29 +08:00
|
|
|
|
|
2023-05-23 18:57:25 +08:00
|
|
|
|
for (int tickIndex = 0; tickIndex <= largestDivisor; tickIndex++)
|
2018-03-19 19:20:29 +08:00
|
|
|
|
{
|
2023-05-23 21:05:38 +08:00
|
|
|
|
int divisor = BindableBeatDivisor.GetDivisorForBeatIndex(tickIndex, largestDivisor, (int[])beatDivisor.ValidDivisors.Value.Presets);
|
2023-05-23 20:30:35 +08:00
|
|
|
|
bool isSolidTick = divisor * (largestDivisor - tickIndex) == largestDivisor;
|
2023-05-23 21:11:27 +08:00
|
|
|
|
|
2023-05-24 12:49:29 +08:00
|
|
|
|
AddInternal(new Tick(divisor, isSolidTick)
|
2018-03-19 19:20:29 +08:00
|
|
|
|
{
|
2022-05-24 15:50:16 +08:00
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativePositionAxes = Axes.Both,
|
|
|
|
|
Colour = BindableBeatDivisor.GetColourFor(divisor, colours),
|
2023-05-23 18:57:25 +08:00
|
|
|
|
X = tickIndex / (float)largestDivisor,
|
2018-03-19 19:20:29 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-20 20:31:17 +08:00
|
|
|
|
AddInternal(marker = new Marker());
|
2022-02-13 22:50:40 +08:00
|
|
|
|
CurrentNumber.ValueChanged += moveMarker;
|
|
|
|
|
CurrentNumber.TriggerChange();
|
2019-11-08 16:23:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-13 22:50:40 +08:00
|
|
|
|
private void moveMarker(ValueChangedEvent<int> divisor)
|
2019-11-08 16:23:47 +08:00
|
|
|
|
{
|
2022-02-13 22:50:40 +08:00
|
|
|
|
marker.MoveToX(getMappedPosition(divisor.NewValue), 100, Easing.OutQuint);
|
2023-05-23 18:57:25 +08:00
|
|
|
|
|
2023-05-24 12:49:29 +08:00
|
|
|
|
foreach (Tick tick in InternalChildren.OfType<Tick>().Where(t => !t.AlwaysDisplayed))
|
2023-05-23 18:57:25 +08:00
|
|
|
|
{
|
2023-05-24 12:49:29 +08:00
|
|
|
|
tick.FadeTo(divisor.NewValue % tick.Divisor == 0 ? 0.2f : 0f, 100, Easing.OutQuint);
|
2023-05-23 18:57:25 +08:00
|
|
|
|
}
|
2018-03-19 19:20:29 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-20 19:09:55 +08:00
|
|
|
|
protected override void UpdateValue(float value)
|
2018-03-19 19:20:29 +08:00
|
|
|
|
{
|
2018-03-20 21:25:15 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-09-26 13:01:15 +08:00
|
|
|
|
public override bool HandleNonPositionalInput => IsHovered && !CurrentNumber.Disabled;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
2018-03-20 21:25:15 +08:00
|
|
|
|
{
|
2018-10-02 11:02:47 +08:00
|
|
|
|
switch (e.Key)
|
2018-03-20 21:25:15 +08:00
|
|
|
|
{
|
|
|
|
|
case Key.Right:
|
2023-06-07 23:53:58 +08:00
|
|
|
|
beatDivisor.SelectNext();
|
2019-02-21 17:56:34 +08:00
|
|
|
|
OnUserChange(Current.Value);
|
2018-03-20 21:25:15 +08:00
|
|
|
|
return true;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2018-03-20 21:25:15 +08:00
|
|
|
|
case Key.Left:
|
2023-06-07 23:53:58 +08:00
|
|
|
|
beatDivisor.SelectPrevious();
|
2019-02-21 17:56:34 +08:00
|
|
|
|
OnUserChange(Current.Value);
|
2018-03-20 21:25:15 +08:00
|
|
|
|
return true;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2018-03-20 21:25:15 +08:00
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-03-19 19:20:29 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
2018-03-20 20:31:17 +08:00
|
|
|
|
{
|
|
|
|
|
marker.Active = true;
|
2022-05-24 15:51:21 +08:00
|
|
|
|
handleMouseInput(e.ScreenSpaceMousePosition);
|
2018-10-02 11:02:47 +08:00
|
|
|
|
return base.OnMouseDown(e);
|
2018-03-20 20:31:17 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-20 17:17:21 +08:00
|
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
2018-03-20 20:31:17 +08:00
|
|
|
|
{
|
|
|
|
|
marker.Active = false;
|
2020-01-20 17:17:21 +08:00
|
|
|
|
base.OnMouseUp(e);
|
2018-03-20 20:31:17 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
2018-03-20 20:31:17 +08:00
|
|
|
|
{
|
2018-09-19 19:52:57 +08:00
|
|
|
|
handleMouseInput(e.ScreenSpaceMousePosition);
|
2018-03-20 20:31:17 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-20 17:17:21 +08:00
|
|
|
|
protected override void OnDrag(DragEvent e)
|
2018-03-20 20:31:17 +08:00
|
|
|
|
{
|
2018-09-19 19:52:57 +08:00
|
|
|
|
handleMouseInput(e.ScreenSpaceMousePosition);
|
2018-03-20 20:31:17 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-03-18 04:27:11 +08:00
|
|
|
|
protected override void OnDragEnd(DragEndEvent e)
|
|
|
|
|
{
|
2020-03-18 06:04:03 +08:00
|
|
|
|
handleMouseInput(e.ScreenSpaceMousePosition);
|
2020-03-18 04:27:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-19 19:52:57 +08:00
|
|
|
|
private void handleMouseInput(Vector2 screenSpaceMousePosition)
|
2018-03-20 20:31:17 +08:00
|
|
|
|
{
|
|
|
|
|
// copied from SliderBar so we can do custom spacing logic.
|
2021-10-27 12:04:41 +08:00
|
|
|
|
float xPosition = (ToLocalSpace(screenSpaceMousePosition).X - RangePadding) / UsableWidth;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-12-19 15:42:21 +08:00
|
|
|
|
CurrentNumber.Value = beatDivisor.ValidDivisors.Value.Presets.MinBy(d => Math.Abs(getMappedPosition(d) - xPosition));
|
2019-02-21 17:56:34 +08:00
|
|
|
|
OnUserChange(Current.Value);
|
2018-03-20 20:31:17 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-05-17 15:34:10 +08:00
|
|
|
|
private float getMappedPosition(float divisor) => 1 - 1 / divisor;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-05-24 15:50:16 +08:00
|
|
|
|
private partial class Tick : Circle
|
2018-03-19 19:20:29 +08:00
|
|
|
|
{
|
2023-05-24 12:49:29 +08:00
|
|
|
|
public readonly bool AlwaysDisplayed;
|
|
|
|
|
|
|
|
|
|
public readonly int Divisor;
|
|
|
|
|
|
|
|
|
|
public Tick(int divisor, bool alwaysDisplayed)
|
2018-03-19 19:20:29 +08:00
|
|
|
|
{
|
2023-05-24 12:49:29 +08:00
|
|
|
|
AlwaysDisplayed = alwaysDisplayed;
|
2023-05-23 18:57:25 +08:00
|
|
|
|
Divisor = divisor;
|
2023-05-24 12:49:29 +08:00
|
|
|
|
|
2022-05-24 15:50:16 +08:00
|
|
|
|
Size = new Vector2(6f, 12) * BindableBeatDivisor.GetSize(divisor);
|
2023-05-24 12:49:29 +08:00
|
|
|
|
Alpha = alwaysDisplayed ? 1 : 0;
|
|
|
|
|
|
2018-03-20 20:31:17 +08:00
|
|
|
|
InternalChild = new Box { RelativeSizeAxes = Axes.Both };
|
2018-03-19 19:20:29 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-20 19:09:55 +08:00
|
|
|
|
private partial class Marker : CompositeDrawable
|
|
|
|
|
{
|
2022-05-24 15:50:16 +08:00
|
|
|
|
[Resolved]
|
2023-06-01 15:28:47 +08:00
|
|
|
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-20 19:09:55 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2022-05-24 15:50:16 +08:00
|
|
|
|
private void load()
|
2018-03-20 19:09:55 +08:00
|
|
|
|
{
|
2022-05-24 15:50:16 +08:00
|
|
|
|
Colour = colourProvider.Background3;
|
2022-05-24 17:25:57 +08:00
|
|
|
|
Anchor = Anchor.BottomLeft;
|
|
|
|
|
Origin = Anchor.BottomCentre;
|
|
|
|
|
|
|
|
|
|
Size = new Vector2(8, 6.5f);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-20 19:09:55 +08:00
|
|
|
|
RelativePositionAxes = Axes.X;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-20 19:09:55 +08:00
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
|
{
|
2022-05-24 17:25:57 +08:00
|
|
|
|
new Triangle
|
2018-03-20 19:09:55 +08:00
|
|
|
|
{
|
2022-05-24 17:25:57 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2018-03-20 19:09:55 +08:00
|
|
|
|
EdgeSmoothness = new Vector2(1),
|
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-20 20:31:17 +08:00
|
|
|
|
private bool active;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-03-20 20:31:17 +08:00
|
|
|
|
public bool Active
|
|
|
|
|
{
|
|
|
|
|
get => active;
|
|
|
|
|
set
|
|
|
|
|
{
|
2022-05-24 15:50:16 +08:00
|
|
|
|
this.FadeColour(value ? colourProvider.Background1 : colourProvider.Background3, 500, Easing.OutQuint);
|
2018-03-20 20:31:17 +08:00
|
|
|
|
active = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-20 19:09:55 +08:00
|
|
|
|
}
|
2018-03-19 19:20:29 +08:00
|
|
|
|
}
|
2023-10-31 15:38:22 +08:00
|
|
|
|
|
|
|
|
|
private partial class AutoSelectTextBox : OsuNumberBox
|
|
|
|
|
{
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2024-05-22 21:27:53 +08:00
|
|
|
|
GetContainingFocusManager().ChangeFocus(this);
|
2023-10-31 15:38:22 +08:00
|
|
|
|
SelectAll();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-19 18:46:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|