Add basic hitobject display to timeline

This commit is contained in:
Dean Herbert 2019-12-05 19:31:40 +09:00
parent e213b338ce
commit e225b0032a
3 changed files with 115 additions and 7 deletions

View File

@ -13,6 +13,10 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Compose.Components.Timeline;
using osuTK;
using osuTK.Graphics;
@ -25,11 +29,23 @@ namespace osu.Game.Tests.Visual.Editor
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(TimelineArea),
typeof(TimelineHitObjectDisplay),
typeof(Timeline),
typeof(TimelineButton),
typeof(CentreMarker)
};
[Cached(typeof(IEditorBeatmap))]
private readonly EditorBeatmap<OsuHitObject> editorBeatmap;
public TestSceneEditorComposeTimeline()
{
editorBeatmap = new EditorBeatmap<OsuHitObject>(
(Beatmap<OsuHitObject>)
CreateWorkingBeatmap(new OsuRuleset().RulesetInfo).GetPlayableBeatmap(new OsuRuleset().RulesetInfo, new Mod[] { })
);
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{

View File

@ -36,14 +36,21 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
this.adjustableClock = adjustableClock;
Child = waveform = new WaveformGraph
Children = new Drawable[]
{
RelativeSizeAxes = Axes.Both,
Colour = colours.Blue.Opacity(0.2f),
LowColour = colours.BlueLighter,
MidColour = colours.BlueDark,
HighColour = colours.BlueDarker,
Depth = float.MaxValue
waveform = new WaveformGraph
{
RelativeSizeAxes = Axes.Both,
Colour = colours.Blue.Opacity(0.2f),
LowColour = colours.BlueLighter,
MidColour = colours.BlueDark,
HighColour = colours.BlueDarker,
Depth = float.MaxValue
},
new TimelineHitObjectDisplay
{
RelativeSizeAxes = Axes.Both,
},
};
// We don't want the centre marker to scroll

View File

@ -0,0 +1,85 @@
// 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.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Screens.Edit.Components.Timelines.Summary.Parts;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
internal class TimelineHitObjectDisplay : TimelinePart
{
[Resolved]
private IEditorBeatmap beatmap { get; set; }
[BackgroundDependencyLoader]
private void load()
{
foreach (var h in beatmap.HitObjects)
add(h);
beatmap.HitObjectAdded += add;
beatmap.HitObjectRemoved += remove;
}
private void remove(HitObject h)
{
foreach (var d in InternalChildren.OfType<TimelineHitObjectRepresentation>().Where(c => c.HitObject == h))
d.Expire();
}
private void add(HitObject h)
{
Add(new TimelineHitObjectRepresentation(h));
}
private class TimelineHitObjectRepresentation : CompositeDrawable
{
public readonly HitObject HitObject;
public TimelineHitObjectRepresentation(HitObject hitObject)
{
this.HitObject = hitObject;
Anchor = Anchor.CentreLeft;
Origin = Anchor.CentreLeft;
Width = (float)(hitObject.GetEndTime() - hitObject.StartTime);
X = (float)hitObject.StartTime;
RelativePositionAxes = Axes.X;
RelativeSizeAxes = Axes.X;
AddInternal(new Circle
{
Size = new Vector2(16),
Anchor = Anchor.CentreLeft,
Origin = Anchor.Centre,
RelativePositionAxes = Axes.X,
AlwaysPresent = true,
Colour = Color4.White,
});
if (hitObject is IHasEndTime)
{
AddInternal(new Box
{
Size = new Vector2(1, 5),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativePositionAxes = Axes.X,
RelativeSizeAxes = Axes.X,
Colour = Color4.White,
});
}
}
}
}
}