Add new display for timing row attributes

This commit is contained in:
Dean Herbert 2021-04-19 15:06:07 +09:00
parent f4baff9e04
commit a10a8680d0
6 changed files with 170 additions and 30 deletions

View File

@ -1,11 +1,16 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.ComponentModel;
namespace osu.Game.Beatmaps.Timing namespace osu.Game.Beatmaps.Timing
{ {
public enum TimeSignatures public enum TimeSignatures
{ {
[Description("4/4")]
SimpleQuadruple = 4, SimpleQuadruple = 4,
[Description("3/4")]
SimpleTriple = 3 SimpleTriple = 3
} }
} }

View File

@ -20,7 +20,7 @@ namespace osu.Game.Screens.Edit
protected const float ROW_HEIGHT = 25; protected const float ROW_HEIGHT = 25;
protected const int TEXT_SIZE = 14; public const int TEXT_SIZE = 14;
protected readonly FillFlowContainer<RowBackground> BackgroundFlow; protected readonly FillFlowContainer<RowBackground> BackgroundFlow;

View File

@ -12,6 +12,7 @@ using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Extensions; using osu.Game.Extensions;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Edit.Timing.RowAttributes;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -119,7 +120,12 @@ namespace osu.Game.Screens.Edit.Timing
private void createChildren() private void createChildren()
{ {
fill.ChildrenEnumerable = controlPoints.Select(createAttribute).Where(c => c != null); fill.ChildrenEnumerable = controlPoints
.Select(createAttribute)
.Where(c => c != null)
// arbitrary ordering to make timing points first.
// probably want to explicitly define order in the future.
.OrderByDescending(c => c.GetType().Name);
} }
private Drawable createAttribute(ControlPoint controlPoint) private Drawable createAttribute(ControlPoint controlPoint)
@ -129,20 +135,19 @@ namespace osu.Game.Screens.Edit.Timing
switch (controlPoint) switch (controlPoint)
{ {
case TimingControlPoint timing: case TimingControlPoint timing:
return new RowAttribute("timing", () => $"{60000 / timing.BeatLength:n1}bpm {timing.TimeSignature}", colour); return new TimingRowAttribute(timing);
case DifficultyControlPoint difficulty: case DifficultyControlPoint difficulty:
return new EmptyRowAttribute("difficulty", () => $"{difficulty.SpeedMultiplier:n2}x", colour);
return new RowAttribute("difficulty", () => $"{difficulty.SpeedMultiplier:n2}x", colour);
case EffectControlPoint effect: case EffectControlPoint effect:
return new RowAttribute("effect", () => string.Join(" ", return new EmptyRowAttribute("effect", () => string.Join(" ",
effect.KiaiMode ? "Kiai" : string.Empty, effect.KiaiMode ? "Kiai" : string.Empty,
effect.OmitFirstBarLine ? "NoBarLine" : string.Empty effect.OmitFirstBarLine ? "NoBarLine" : string.Empty
).Trim(), colour); ).Trim(), colour);
case SampleControlPoint sample: case SampleControlPoint sample:
return new RowAttribute("sample", () => $"{sample.SampleBank} {sample.SampleVolume}%", colour); return new EmptyRowAttribute("sample", () => $"{sample.SampleBank} {sample.SampleVolume}%", colour);
} }
return null; return null;

View File

@ -1,33 +1,31 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osuTK.Graphics; using osu.Game.Overlays;
using osuTK;
namespace osu.Game.Screens.Edit.Timing namespace osu.Game.Screens.Edit.Timing
{ {
public class RowAttribute : CompositeDrawable, IHasTooltip public class RowAttribute : CompositeDrawable
{ {
private readonly string header; private readonly ControlPoint point;
private readonly Func<string> content;
private readonly Color4 colour;
public RowAttribute(string header, Func<string> content, Color4 colour) protected FillFlowContainer Content { get; private set; }
public RowAttribute(ControlPoint point)
{ {
this.header = header; this.point = point;
this.content = content;
this.colour = colour;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours, OverlayColourProvider overlayColours)
{ {
AutoSizeAxes = Axes.X; AutoSizeAxes = Axes.X;
@ -43,21 +41,45 @@ namespace osu.Game.Screens.Edit.Timing
{ {
new Box new Box
{ {
Colour = colour, Colour = overlayColours.Background4,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
}, },
new OsuSpriteText Content = new FillFlowContainer
{ {
Padding = new MarginPadding(2), RelativeSizeAxes = Axes.Y,
Anchor = Anchor.Centre, AutoSizeAxes = Axes.X,
Origin = Anchor.Centre, Direction = FillDirection.Horizontal,
Font = OsuFont.Default.With(weight: FontWeight.SemiBold, size: 12), Margin = new MarginPadding { Right = 5 },
Text = header, Spacing = new Vector2(5),
Colour = colours.Gray0 Children = new Drawable[]
}, {
new Container
{
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Children = new Drawable[]
{
new Box
{
Colour = point.GetRepresentingColour(colours),
RelativeSizeAxes = Axes.Both,
},
new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Padding = new MarginPadding(3),
Font = OsuFont.Default.With(weight: FontWeight.SemiBold, size: 12),
Text = point.GetType().Name.Replace("ControlPoint", string.Empty).ToLowerInvariant(),
Colour = colours.Gray0
},
},
},
},
}
}; };
} }
public string TooltipText => content();
} }
} }

View File

@ -0,0 +1,63 @@
// 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.
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osuTK.Graphics;
namespace osu.Game.Screens.Edit.Timing.RowAttributes
{
public class EmptyRowAttribute : CompositeDrawable, IHasTooltip
{
private readonly string header;
private readonly Func<string> content;
private readonly Color4 colour;
public EmptyRowAttribute(string header, Func<string> content, Color4 colour)
{
this.header = header;
this.content = content;
this.colour = colour;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AutoSizeAxes = Axes.X;
Height = 20;
Anchor = Anchor.CentreLeft;
Origin = Anchor.CentreLeft;
Masking = true;
CornerRadius = 5;
InternalChildren = new Drawable[]
{
new Box
{
Colour = colour,
RelativeSizeAxes = Axes.Both,
},
new OsuSpriteText
{
Padding = new MarginPadding(2),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.Default.With(weight: FontWeight.SemiBold, size: 12),
Text = header,
Colour = colours.Gray0
},
};
}
public string TooltipText => content();
}
}

View File

@ -0,0 +1,45 @@
// 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.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Beatmaps.Timing;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
namespace osu.Game.Screens.Edit.Timing.RowAttributes
{
internal class TimingRowAttribute : RowAttribute
{
private readonly BindableNumber<double> beatLength;
private readonly Bindable<TimeSignatures> timeSignature;
private OsuSpriteText text;
public TimingRowAttribute(TimingControlPoint timing)
: base(timing)
{
timeSignature = timing.TimeSignatureBindable.GetBoundCopy();
beatLength = timing.BeatLengthBindable.GetBoundCopy();
}
[BackgroundDependencyLoader]
private void load()
{
Content.Add(text = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: EditorTable.TEXT_SIZE, weight: FontWeight.Regular),
});
timeSignature.BindValueChanged(_ => updateText());
beatLength.BindValueChanged(_ => updateText(), true);
}
private void updateText() =>
text.Text = $"{60000 / beatLength.Value:n1}bpm {timeSignature.Value.GetDescription()}";
}
}