Move beat divisor colour retrieval to BindableBeatDivisor

This commit is contained in:
smoogipoo 2019-08-30 17:34:02 +09:00
parent 03ce8da5dd
commit 40729356fa
2 changed files with 45 additions and 41 deletions

View File

@ -4,6 +4,9 @@
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
{
@ -35,5 +38,41 @@ namespace osu.Game.Screens.Edit
protected override int DefaultMinValue => VALID_DIVISORS.First();
protected override int DefaultMaxValue => VALID_DIVISORS.Last();
protected override int DefaultPrecision => 1;
/// <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>
public 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;
}
}
}
}

View File

@ -188,6 +188,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
{
private Marker marker;
[Resolved]
private OsuColour colours { get; set; }
private readonly BindableBeatDivisor beatDivisor;
private readonly int[] availableDivisors;
@ -204,11 +207,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
{
foreach (var t in availableDivisors)
{
AddInternal(new Tick(t)
AddInternal(new Tick
{
Anchor = Anchor.TopLeft,
Origin = Anchor.TopCentre,
RelativePositionAxes = Axes.X,
Colour = beatDivisor.GetColourFor(t, colours),
X = getMappedPosition(t)
});
}
@ -284,11 +288,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
private class Tick : CompositeDrawable
{
private readonly int divisor;
public Tick(int divisor)
public Tick()
{
this.divisor = divisor;
Size = new Vector2(2.5f, 10);
InternalChild = new Box { RelativeSizeAxes = Axes.Both };
@ -296,42 +297,6 @@ namespace osu.Game.Screens.Edit.Compose.Components
CornerRadius = 0.5f;
Masking = true;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Colour = getColourForDivisor(divisor, colours);
}
private ColourInfo getColourForDivisor(int divisor, OsuColour colours)
{
switch (divisor)
{
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;
}
}
}
private class Marker : CompositeDrawable