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.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
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 : TableContainer
|
|
|
|
{
|
|
|
|
private const float horizontal_inset = 20;
|
|
|
|
private const float row_height = 25;
|
|
|
|
private const int text_size = 14;
|
|
|
|
|
|
|
|
private readonly FillFlowContainer backgroundFlow;
|
|
|
|
|
|
|
|
[Resolved]
|
2019-10-25 19:13:22 +08:00
|
|
|
private Bindable<ControlPointGroup> selectedGroup { get; set; }
|
2019-10-18 16:59:54 +08:00
|
|
|
|
|
|
|
public ControlPointTable()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
Padding = new MarginPadding { Horizontal = horizontal_inset };
|
|
|
|
RowSize = new Dimension(GridSizeMode.Absolute, row_height);
|
|
|
|
|
|
|
|
AddInternal(backgroundFlow = new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Depth = 1f,
|
|
|
|
Padding = new MarginPadding { Horizontal = -horizontal_inset },
|
|
|
|
Margin = new MarginPadding { Top = row_height }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-25 19:13:22 +08:00
|
|
|
public IEnumerable<ControlPointGroup> ControlGroups
|
2019-10-18 16:59:54 +08:00
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
Content = null;
|
|
|
|
backgroundFlow.Clear();
|
|
|
|
|
|
|
|
if (value?.Any() != true)
|
|
|
|
return;
|
|
|
|
|
2019-10-25 19:13:22 +08:00
|
|
|
foreach (var group in value)
|
2019-10-18 16:59:54 +08:00
|
|
|
{
|
2019-10-27 12:31:23 +08:00
|
|
|
backgroundFlow.Add(new RowBackground(group));
|
2019-10-18 16:59:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Columns = createHeaders();
|
2019-10-25 19:13:22 +08:00
|
|
|
Content = value.Select((g, i) => createContent(i, g)).ToArray().ToRectangular();
|
2019-10-18 16:59:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private TableColumn[] createHeaders()
|
|
|
|
{
|
|
|
|
var columns = new List<TableColumn>
|
|
|
|
{
|
|
|
|
new TableColumn(string.Empty, Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
|
2019-10-23 10:22:55 +08:00
|
|
|
new TableColumn("Time", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
|
2019-10-18 16:59:54 +08:00
|
|
|
new TableColumn("Attributes", Anchor.Centre),
|
|
|
|
};
|
|
|
|
|
|
|
|
return columns.ToArray();
|
|
|
|
}
|
|
|
|
|
2019-10-25 19:13:22 +08:00
|
|
|
private Drawable[] createContent(int index, ControlPointGroup group) => new Drawable[]
|
2019-10-18 16:59:54 +08:00
|
|
|
{
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = $"#{index + 1}",
|
|
|
|
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold),
|
|
|
|
Margin = new MarginPadding(10)
|
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
2019-10-25 19:13:22 +08:00
|
|
|
Text = $"{group.Time:n0}ms",
|
2019-10-18 16:59:54 +08:00
|
|
|
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold)
|
|
|
|
},
|
2019-10-27 14:19:36 +08:00
|
|
|
new ControlGroupAttributes(group),
|
2019-10-18 16:59:54 +08:00
|
|
|
};
|
|
|
|
|
2019-10-27 14:19:36 +08:00
|
|
|
private class ControlGroupAttributes : CompositeDrawable
|
2019-10-18 16:59:54 +08:00
|
|
|
{
|
2019-10-27 14:19:36 +08:00
|
|
|
private readonly IBindableList<ControlPoint> controlPoints;
|
2019-10-18 16:59:54 +08:00
|
|
|
|
2019-10-27 14:19:36 +08:00
|
|
|
private readonly FillFlowContainer fill;
|
2019-10-18 16:59:54 +08:00
|
|
|
|
2019-10-27 14:19:36 +08:00
|
|
|
public ControlGroupAttributes(ControlPointGroup group)
|
|
|
|
{
|
|
|
|
InternalChild = fill = new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Padding = new MarginPadding(10),
|
|
|
|
Spacing = new Vector2(2)
|
|
|
|
};
|
|
|
|
|
|
|
|
controlPoints = group.ControlPoints.GetBoundCopy();
|
|
|
|
controlPoints.ItemsAdded += _ => createChildren();
|
|
|
|
controlPoints.ItemsRemoved += _ => createChildren();
|
2019-10-18 16:59:54 +08:00
|
|
|
|
2019-10-27 14:19:36 +08:00
|
|
|
createChildren();
|
|
|
|
}
|
2019-10-18 16:59:54 +08:00
|
|
|
|
2019-10-27 14:19:36 +08:00
|
|
|
private void createChildren()
|
|
|
|
{
|
|
|
|
fill.ChildrenEnumerable = controlPoints.Select(createAttribute).Where(c => c != null);
|
2019-10-18 16:59:54 +08:00
|
|
|
}
|
|
|
|
|
2019-10-27 14:19:36 +08:00
|
|
|
private Drawable createAttribute(ControlPoint controlPoint)
|
|
|
|
{
|
|
|
|
switch (controlPoint)
|
|
|
|
{
|
|
|
|
case TimingControlPoint timing:
|
2019-10-28 15:20:54 +08:00
|
|
|
return new RowAttribute("timing", () => $"{60000 / timing.BeatLength:n1}bpm {timing.TimeSignature}");
|
2019-10-27 14:19:36 +08:00
|
|
|
|
|
|
|
case DifficultyControlPoint difficulty:
|
|
|
|
|
2019-10-28 15:20:54 +08:00
|
|
|
return new RowAttribute("difficulty", () => $"{difficulty.SpeedMultiplier:n2}x");
|
2019-10-27 14:19:36 +08:00
|
|
|
|
|
|
|
case EffectControlPoint effect:
|
2019-10-28 15:20:54 +08:00
|
|
|
return new RowAttribute("effect", () => $"{(effect.KiaiMode ? "Kiai " : "")}{(effect.OmitFirstBarLine ? "NoBarLine " : "")}");
|
2019-10-27 14:19:36 +08:00
|
|
|
|
|
|
|
case SampleControlPoint sample:
|
2019-10-28 15:20:54 +08:00
|
|
|
return new RowAttribute("sample", () => $"{sample.SampleBank} {sample.SampleVolume}%");
|
2019-10-27 14:19:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2019-10-18 16:59:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override Drawable CreateHeader(int index, TableColumn column) => new HeaderText(column?.Header ?? string.Empty);
|
|
|
|
|
|
|
|
private class HeaderText : OsuSpriteText
|
|
|
|
{
|
|
|
|
public HeaderText(string text)
|
|
|
|
{
|
|
|
|
Text = text.ToUpper();
|
|
|
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Black);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class RowBackground : OsuClickableContainer
|
|
|
|
{
|
2019-10-27 12:31:23 +08:00
|
|
|
private readonly ControlPointGroup controlGroup;
|
2019-10-18 16:59:54 +08:00
|
|
|
private const int fade_duration = 100;
|
|
|
|
|
|
|
|
private readonly Box hoveredBackground;
|
|
|
|
|
2019-10-27 12:31:23 +08:00
|
|
|
[Resolved]
|
|
|
|
private Bindable<ControlPointGroup> selectedGroup { get; set; }
|
|
|
|
|
|
|
|
public RowBackground(ControlPointGroup controlGroup)
|
2019-10-18 16:59:54 +08:00
|
|
|
{
|
2019-10-27 12:31:23 +08:00
|
|
|
this.controlGroup = controlGroup;
|
2019-10-18 16:59:54 +08:00
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
Height = 25;
|
|
|
|
|
|
|
|
AlwaysPresent = true;
|
|
|
|
|
|
|
|
CornerRadius = 3;
|
|
|
|
Masking = true;
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
hoveredBackground = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0,
|
|
|
|
},
|
|
|
|
};
|
2019-10-27 12:31:23 +08:00
|
|
|
|
|
|
|
Action = () => selectedGroup.Value = controlGroup;
|
2019-10-18 16:59:54 +08:00
|
|
|
}
|
|
|
|
|
2019-10-27 12:31:23 +08:00
|
|
|
private Color4 colourHover;
|
|
|
|
private Color4 colourSelected;
|
|
|
|
|
2019-10-18 16:59:54 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
2019-10-27 12:31:23 +08:00
|
|
|
hoveredBackground.Colour = colourHover = colours.BlueDarker;
|
|
|
|
colourSelected = colours.YellowDarker;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2019-10-27 15:13:24 +08:00
|
|
|
selectedGroup.BindValueChanged(group => { Selected = controlGroup == group.NewValue; }, true);
|
2019-10-27 12:31:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private bool selected;
|
|
|
|
|
|
|
|
protected bool Selected
|
|
|
|
{
|
|
|
|
get => selected;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value == selected)
|
|
|
|
return;
|
|
|
|
|
|
|
|
selected = value;
|
|
|
|
updateState();
|
|
|
|
}
|
2019-10-18 16:59:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
2019-10-27 12:31:23 +08:00
|
|
|
updateState();
|
2019-10-18 16:59:54 +08:00
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
2019-10-27 12:31:23 +08:00
|
|
|
updateState();
|
2019-10-18 16:59:54 +08:00
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
2019-10-27 12:31:23 +08:00
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
{
|
|
|
|
hoveredBackground.FadeColour(selected ? colourSelected : colourHover, 450, Easing.OutQuint);
|
|
|
|
|
|
|
|
if (selected || IsHovered)
|
|
|
|
hoveredBackground.FadeIn(fade_duration, Easing.OutQuint);
|
|
|
|
else
|
|
|
|
hoveredBackground.FadeOut(fade_duration, Easing.OutQuint);
|
|
|
|
}
|
2019-10-18 16:59:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|