// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Linq; using osu.Framework.Bindables; using osu.Framework.Graphics.Colour; using osu.Game.Graphics; using osuTK.Graphics; namespace osu.Game.Screens.Edit { public class BindableBeatDivisor : BindableInt { public static readonly int[] VALID_DIVISORS = { 1, 2, 3, 4, 6, 8, 12, 16 }; public BindableBeatDivisor(int value = 1) : base(value) { } public void Next() => Value = VALID_DIVISORS[Math.Min(VALID_DIVISORS.Length - 1, Array.IndexOf(VALID_DIVISORS, Value) + 1)]; public void Previous() => Value = VALID_DIVISORS[Math.Max(0, Array.IndexOf(VALID_DIVISORS, Value) - 1)]; public override int Value { get => base.Value; set { if (!VALID_DIVISORS.Contains(value)) { // If it doesn't match, value will be 0, but will be clamped to the valid range via DefaultMinValue value = Array.FindLast(VALID_DIVISORS, d => d < value); } base.Value = value; } } protected override int DefaultMinValue => VALID_DIVISORS.First(); protected override int DefaultMaxValue => VALID_DIVISORS.Last(); protected override int DefaultPrecision => 1; /// /// Retrieves the appropriate colour for a beat divisor. /// /// The beat divisor. /// The set of colours. /// The applicable colour from for . public static ColourInfo GetColourFor(int beatDivisor, OsuColour colours) { switch (beatDivisor) { case 2: return colours.BlueLight; case 4: return colours.Blue; case 8: return colours.BlueDarker; case 16: return colours.PurpleDark; case 3: return colours.YellowLight; case 6: return colours.Yellow; case 12: return colours.YellowDarker; default: return Color4.White; } } } }