1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 18:42:56 +08:00

Update colours of all overlay components in one swoop (based off combo colour)

This commit is contained in:
Dean Herbert 2021-04-13 19:24:20 +09:00
parent 495fdd8d65
commit b2c17979de

View File

@ -31,6 +31,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
private const float shadow_radius = 5; private const float shadow_radius = 5;
private const float circle_size = 38; private const float circle_size = 38;
private Container repeatsContainer;
public Action<DragEvent> OnDragHandled; public Action<DragEvent> OnDragHandled;
[UsedImplicitly] [UsedImplicitly]
@ -41,7 +43,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
private readonly Drawable circle; private readonly Drawable circle;
private readonly Container mainComponents; private readonly Container colouredComponents;
private readonly OsuSpriteText comboIndexText; private readonly OsuSpriteText comboIndexText;
[Resolved] [Resolved]
@ -59,39 +61,37 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
RelativePositionAxes = Axes.X; RelativePositionAxes = Axes.X;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; Height = circle_size;
AddRangeInternal(new Drawable[] AddRangeInternal(new[]
{ {
mainComponents = new Container circle = new ExtendableCircle
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
colouredComponents = new Container
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.Both,
AutoSizeAxes = Axes.Y, Children = new Drawable[]
}, {
comboIndexText = new OsuSpriteText comboIndexText = new OsuSpriteText
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Y = -1, Y = -1,
Font = OsuFont.Default.With(size: circle_size * 0.5f, weight: FontWeight.Regular), Font = OsuFont.Default.With(size: circle_size * 0.5f, weight: FontWeight.Regular),
},
}
}, },
}); });
circle = new ExtendableCircle
{
RelativeSizeAxes = Axes.X,
Size = new Vector2(1, circle_size),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
};
mainComponents.Add(circle);
if (hitObject is IHasDuration) if (hitObject is IHasDuration)
{ {
mainComponents.Add(new DragArea(hitObject) colouredComponents.Add(new DragArea(hitObject)
{ {
OnDragHandled = e => OnDragHandled?.Invoke(e) OnDragHandled = e => OnDragHandled?.Invoke(e)
}); });
@ -127,15 +127,15 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
var comboColour = combo.GetComboColour(comboColours); var comboColour = combo.GetComboColour(comboColours);
if (HitObject is IHasDuration) if (HitObject is IHasDuration)
mainComponents.Colour = ColourInfo.GradientHorizontal(comboColour, comboColour.Lighten(0.4f)); circle.Colour = ColourInfo.GradientHorizontal(comboColour, comboColour.Lighten(0.4f));
else else
mainComponents.Colour = comboColour; circle.Colour = comboColour;
var col = mainComponents.Colour.TopLeft.Linear; var col = circle.Colour.TopLeft.Linear;
float brightness = col.R + col.G + col.B; float brightness = col.R + col.G + col.B;
// decide the combo index colour based on brightness? // decide the combo index colour based on brightness?
comboIndexText.Colour = brightness > 0.5f ? Color4.Black : Color4.White; colouredComponents.Colour = OsuColour.Gray(brightness > 0.5f ? 0.2f : 0.9f);
} }
protected override void Update() protected override void Update()
@ -155,13 +155,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
} }
} }
private Container repeatsContainer;
private void updateRepeats(IHasRepeats repeats) private void updateRepeats(IHasRepeats repeats)
{ {
repeatsContainer?.Expire(); repeatsContainer?.Expire();
mainComponents.Add(repeatsContainer = new Container colouredComponents.Add(repeatsContainer = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
}); });
@ -170,7 +168,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{ {
repeatsContainer.Add(new Circle repeatsContainer.Add(new Circle
{ {
Size = new Vector2(circle_size / 2), Size = new Vector2(circle_size / 3),
Alpha = 0.2f,
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.Centre, Origin = Anchor.Centre,
RelativePositionAxes = Axes.X, RelativePositionAxes = Axes.X,
@ -224,7 +223,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
Origin = Anchor.Centre; Origin = Anchor.Centre;
RelativePositionAxes = Axes.X; RelativePositionAxes = Axes.X;
RelativeSizeAxes = Axes.Y; RelativeSizeAxes = Axes.Y;
Colour = OsuColour.Gray(0.2f);
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
@ -351,7 +349,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
/// <summary> /// <summary>
/// A circle with externalised end caps so it can take up the full width of a relative width area. /// A circle with externalised end caps so it can take up the full width of a relative width area.
/// TODO: figure how to do this with a single circle to avoid pixel-misaligned edges.
/// </summary> /// </summary>
public class ExtendableCircle : Container public class ExtendableCircle : Container
{ {
@ -391,7 +388,9 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
Colour = Color4.Black.Opacity(0.4f) Colour = Color4.Black.Opacity(0.4f)
}; };
const float fudge = 0.97f; // TODO: figure how to do this whole thing with a single circle to avoid pixel-misaligned edges.
// just working with what i can make work for the time being..
const float fudge = 0.4f;
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
@ -400,7 +399,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Height = fudge, Padding = new MarginPadding { Vertical = fudge },
Masking = true, Masking = true,
AlwaysPresent = true, AlwaysPresent = true,
EdgeEffect = effect, EdgeEffect = effect,
@ -418,12 +417,16 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
Size = new Vector2(circle_size) Size = new Vector2(circle_size)
}, },
new Box new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Vertical = fudge },
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Height = fudge, Children = new Drawable[]
{
new Box { RelativeSizeAxes = Axes.Both, }
}
}, },
}; };
} }