1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 21:47:25 +08:00
osu-lazer/osu.Game/Screens/Edit/Timing/ControlPointTable.cs

158 lines
5.2 KiB
C#
Raw Normal View History

2019-10-18 16:59:54 +08:00
// 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.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Extensions;
2019-10-18 16:59:54 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Edit.Timing.RowAttributes;
2019-10-18 16:59:54 +08:00
using osuTK;
2019-10-27 12:31:23 +08:00
using osuTK.Graphics;
2019-10-18 16:59:54 +08:00
namespace osu.Game.Screens.Edit.Timing
{
public class ControlPointTable : EditorTable
2019-10-18 16:59:54 +08:00
{
[Resolved]
private Bindable<ControlPointGroup> selectedGroup { get; set; }
2019-10-18 16:59:54 +08:00
[Resolved]
private EditorClock clock { get; set; }
public IEnumerable<ControlPointGroup> ControlGroups
2019-10-18 16:59:54 +08:00
{
set
{
Content = null;
BackgroundFlow.Clear();
2019-10-18 16:59:54 +08:00
if (value?.Any() != true)
return;
foreach (var group in value)
2019-10-18 16:59:54 +08:00
{
BackgroundFlow.Add(new RowBackground(group)
{
Action = () =>
{
selectedGroup.Value = group;
clock.SeekSmoothlyTo(group.Time);
}
});
2019-10-18 16:59:54 +08:00
}
Columns = createHeaders();
Content = value.Select((g, i) => createContent(i, g)).ToArray().ToRectangular();
2019-10-18 16:59:54 +08:00
}
}
protected override void LoadComplete()
{
base.LoadComplete();
selectedGroup.BindValueChanged(group =>
{
foreach (var b in BackgroundFlow) b.Selected = b.Item == group.NewValue;
}, true);
}
2019-10-18 16:59:54 +08:00
private TableColumn[] createHeaders()
{
var columns = new List<TableColumn>
{
new TableColumn("Time", Anchor.CentreLeft, new Dimension(GridSizeMode.Absolute, 120)),
new TableColumn("Attributes", Anchor.CentreLeft),
2019-10-18 16:59:54 +08:00
};
return columns.ToArray();
}
private Drawable[] createContent(int index, ControlPointGroup group) => new Drawable[]
2019-10-18 16:59:54 +08:00
{
new OsuSpriteText
{
Text = group.Time.ToEditorFormattedString(),
Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Bold)
2019-10-18 16:59:54 +08:00
},
new ControlGroupAttributes(group),
2019-10-18 16:59:54 +08:00
};
private class ControlGroupAttributes : CompositeDrawable
2019-10-18 16:59:54 +08:00
{
private readonly IBindableList<ControlPoint> controlPoints = new BindableList<ControlPoint>();
2019-10-18 16:59:54 +08:00
private readonly FillFlowContainer fill;
2019-10-18 16:59:54 +08:00
public ControlGroupAttributes(ControlPointGroup group)
{
RelativeSizeAxes = Axes.Both;
InternalChild = fill = new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(2)
};
controlPoints.BindTo(group.ControlPoints);
}
[Resolved]
private OsuColour colours { get; set; }
2019-10-18 16:59:54 +08:00
[BackgroundDependencyLoader]
private void load()
{
createChildren();
}
2019-10-18 16:59:54 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
controlPoints.CollectionChanged += (_, __) => createChildren();
}
private void createChildren()
{
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);
2019-10-18 16:59:54 +08:00
}
private Drawable createAttribute(ControlPoint controlPoint)
{
Color4 colour = controlPoint.GetRepresentingColour(colours);
switch (controlPoint)
{
case TimingControlPoint timing:
return new TimingRowAttribute(timing);
case DifficultyControlPoint difficulty:
return new DifficultyRowAttribute(difficulty);
case EffectControlPoint effect:
return new EmptyRowAttribute("effect", () => string.Join(" ",
effect.KiaiMode ? "Kiai" : string.Empty,
effect.OmitFirstBarLine ? "NoBarLine" : string.Empty
).Trim(), colour);
case SampleControlPoint sample:
return new EmptyRowAttribute("sample", () => $"{sample.SampleBank} {sample.SampleVolume}%", colour);
}
return null;
}
2019-10-18 16:59:54 +08:00
}
}
}