2020-01-27 07:00:51 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 08:43:03 +00:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-08-30 08:34:02 +00:00
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-06 09:28:22 +00:00
|
|
|
|
namespace osu.Game.Screens.Edit
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-10-23 05:04:06 +00:00
|
|
|
|
public class BindableBeatDivisor : BindableInt
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => base.Value;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (!VALID_DIVISORS.Contains(value))
|
2019-11-08 08:24:02 +00:00
|
|
|
|
{
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
base.Value = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override int DefaultMinValue => VALID_DIVISORS.First();
|
|
|
|
|
protected override int DefaultMaxValue => VALID_DIVISORS.Last();
|
|
|
|
|
protected override int DefaultPrecision => 1;
|
2019-08-30 08:34:02 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieves the appropriate colour for a beat divisor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="beatDivisor">The beat divisor.</param>
|
|
|
|
|
/// <param name="colours">The set of colours.</param>
|
|
|
|
|
/// <returns>The applicable colour from <paramref name="colours"/> for <paramref name="beatDivisor"/>.</returns>
|
2019-08-31 12:32:02 +00:00
|
|
|
|
public static ColourInfo GetColourFor(int beatDivisor, OsuColour colours)
|
2019-08-30 08:34:02 +00:00
|
|
|
|
{
|
|
|
|
|
switch (beatDivisor)
|
|
|
|
|
{
|
2020-01-27 06:57:55 +00:00
|
|
|
|
case 1:
|
|
|
|
|
return Color4.White;
|
|
|
|
|
|
2019-08-30 08:34:02 +00:00
|
|
|
|
case 2:
|
2020-01-27 06:57:55 +00:00
|
|
|
|
return colours.Red;
|
2019-08-30 08:34:02 +00:00
|
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
return colours.Blue;
|
|
|
|
|
|
|
|
|
|
case 8:
|
2020-01-27 06:57:55 +00:00
|
|
|
|
return colours.Yellow;
|
2019-08-30 08:34:02 +00:00
|
|
|
|
|
|
|
|
|
case 16:
|
|
|
|
|
return colours.PurpleDark;
|
|
|
|
|
|
|
|
|
|
case 3:
|
2020-01-27 06:57:55 +00:00
|
|
|
|
return colours.Purple;
|
2019-08-30 08:34:02 +00:00
|
|
|
|
|
|
|
|
|
case 6:
|
2020-01-27 06:57:55 +00:00
|
|
|
|
return colours.YellowDark;
|
2019-08-30 08:34:02 +00:00
|
|
|
|
|
|
|
|
|
case 12:
|
|
|
|
|
return colours.YellowDarker;
|
|
|
|
|
|
|
|
|
|
default:
|
2020-01-27 06:57:55 +00:00
|
|
|
|
return Color4.Red;
|
2019-08-30 08:34:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-27 07:00:51 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieves the applicable divisor for a specific beat index.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="index">The 0-based beat index.</param>
|
|
|
|
|
/// <param name="beatDivisor">The beat divisor.</param>
|
|
|
|
|
/// <returns>The applicable divisor.</returns>
|
|
|
|
|
public static int GetDivisorForBeatIndex(int index, int beatDivisor)
|
|
|
|
|
{
|
|
|
|
|
int beat = index % beatDivisor;
|
|
|
|
|
|
2020-01-28 07:04:13 +00:00
|
|
|
|
foreach (var divisor in BindableBeatDivisor.VALID_DIVISORS)
|
2020-01-27 07:00:51 +00:00
|
|
|
|
{
|
|
|
|
|
if ((beat * divisor) % beatDivisor == 0)
|
|
|
|
|
return divisor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|