1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 02:42:54 +08:00

Bind to the screen Beatmap instead of the game-wide Beatmap

This commit is contained in:
smoogipoo 2017-09-26 17:56:16 +09:00
parent 3937ebdc3d
commit c578509a20
5 changed files with 125 additions and 108 deletions

View File

@ -7,7 +7,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Game.Beatmaps;
using osu.Game.Graphics; using osu.Game.Graphics;
namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
@ -17,8 +16,6 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
/// </summary> /// </summary>
internal class MarkerPart : TimelinePart internal class MarkerPart : TimelinePart
{ {
private WorkingBeatmap beatmap;
private readonly Drawable marker; private readonly Drawable marker;
public MarkerPart() public MarkerPart()
@ -32,11 +29,6 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
marker.Colour = colours.Red; marker.Colour = colours.Red;
} }
protected override void LoadBeatmap(WorkingBeatmap beatmap)
{
this.beatmap = beatmap;
}
protected override bool OnDragStart(InputState state) => true; protected override bool OnDragStart(InputState state) => true;
protected override bool OnDragEnd(InputState state) => true; protected override bool OnDragEnd(InputState state) => true;
protected override bool OnDrag(InputState state) protected override bool OnDrag(InputState state)
@ -57,16 +49,22 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
/// <param name="screenPosition">The position in screen coordinates.</param> /// <param name="screenPosition">The position in screen coordinates.</param>
private void seekToPosition(Vector2 screenPosition) private void seekToPosition(Vector2 screenPosition)
{ {
if (Beatmap.Value == null)
return;
float markerPos = MathHelper.Clamp(ToLocalSpace(screenPosition).X, 0, DrawWidth); float markerPos = MathHelper.Clamp(ToLocalSpace(screenPosition).X, 0, DrawWidth);
seekTo(markerPos / DrawWidth * beatmap.Track.Length); seekTo(markerPos / DrawWidth * Beatmap.Value.Track.Length);
} }
private void seekTo(double time) => beatmap.Track.Seek(time); private void seekTo(double time) => Beatmap.Value?.Track.Seek(time);
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
marker.X = (float)beatmap.Track.CurrentTime;
if (Beatmap.Value == null)
return;
marker.X = (float)Beatmap.Value.Track.CurrentTime;
} }
private class MarkerVisualisation : CompositeDrawable private class MarkerVisualisation : CompositeDrawable
@ -80,27 +78,27 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
AutoSizeAxes = Axes.X; AutoSizeAxes = Axes.X;
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
new Triangle new Triangle
{ {
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.BottomCentre, Origin = Anchor.BottomCentre,
Scale = new Vector2(1, -1), Scale = new Vector2(1, -1),
Size = new Vector2(10, 5), Size = new Vector2(10, 5),
}, },
new Triangle new Triangle
{ {
Anchor = Anchor.BottomCentre, Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre, Origin = Anchor.BottomCentre,
Size = new Vector2(10, 5) Size = new Vector2(10, 5)
}, },
new Box new Box
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
Width = 2, Width = 2,
EdgeSmoothness = new Vector2(1, 0) EdgeSmoothness = new Vector2(1, 0)
} }
}; };
} }

View File

@ -3,7 +3,7 @@
using System; using System;
using OpenTK; using OpenTK;
using osu.Framework.Allocation; using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -15,29 +15,26 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
/// </summary> /// </summary>
internal abstract class TimelinePart : CompositeDrawable internal abstract class TimelinePart : CompositeDrawable
{ {
public Bindable<WorkingBeatmap> Beatmap = new Bindable<WorkingBeatmap>();
private readonly Container timeline; private readonly Container timeline;
protected TimelinePart() protected TimelinePart()
{ {
AddInternal(timeline = new Container { RelativeSizeAxes = Axes.Both }); AddInternal(timeline = new Container { RelativeSizeAxes = Axes.Both });
}
[BackgroundDependencyLoader] Beatmap.ValueChanged += b =>
private void load(OsuGameBase osuGame)
{
osuGame.Beatmap.ValueChanged += b =>
{ {
timeline.Clear(); timeline.Clear();
timeline.RelativeChildSize = new Vector2((float)Math.Max(1, b.Track.Length), 1); timeline.RelativeChildSize = new Vector2((float)Math.Max(1, b.Track.Length), 1);
LoadBeatmap(b); LoadBeatmap(b);
}; };
timeline.RelativeChildSize = new Vector2((float)Math.Max(1, osuGame.Beatmap.Value.Track.Length), 1);
LoadBeatmap(osuGame.Beatmap);
} }
protected void Add(Drawable visualisation) => timeline.Add(visualisation); protected void Add(Drawable visualisation) => timeline.Add(visualisation);
protected abstract void LoadBeatmap(WorkingBeatmap beatmap); protected virtual void LoadBeatmap(WorkingBeatmap beatmap)
{
}
} }
} }

View File

@ -3,9 +3,11 @@
using OpenTK; using OpenTK;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Screens.Edit.Components.Timelines.Summary.Parts; using osu.Game.Screens.Edit.Components.Timelines.Summary.Parts;
@ -19,6 +21,8 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary
private const float corner_radius = 5; private const float corner_radius = 5;
private const float contents_padding = 15; private const float contents_padding = 15;
public Bindable<WorkingBeatmap> Beatmap = new Bindable<WorkingBeatmap>();
private readonly Drawable background; private readonly Drawable background;
private readonly Drawable timelineBar; private readonly Drawable timelineBar;
@ -28,67 +32,74 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary
Masking = true; Masking = true;
CornerRadius = corner_radius; CornerRadius = corner_radius;
TimelinePart markerPart, controlPointPart, bookmarkPart, breakPart;
InternalChildren = new[] InternalChildren = new[]
{ {
background = new Box { RelativeSizeAxes = Axes.Both }, background = new Box { RelativeSizeAxes = Axes.Both },
new Container new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = contents_padding, Right = contents_padding },
Children = new[]
{ {
RelativeSizeAxes = Axes.Both, markerPart = new MarkerPart { RelativeSizeAxes = Axes.Both },
Padding = new MarginPadding { Left = contents_padding, Right = contents_padding }, controlPointPart = new ControlPointPart
Children = new[]
{ {
new MarkerPart { RelativeSizeAxes = Axes.Both }, Anchor = Anchor.Centre,
new ControlPointPart Origin = Anchor.BottomCentre,
RelativeSizeAxes = Axes.Both,
Height = 0.35f
},
bookmarkPart = new BookmarkPart
{
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.Both,
Height = 0.35f
},
timelineBar = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{ {
Anchor = Anchor.Centre, new Circle
Origin = Anchor.BottomCentre,
RelativeSizeAxes = Axes.Both,
Height = 0.35f
},
new BookmarkPart
{
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.Both,
Height = 0.35f
},
timelineBar = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{ {
new Circle Anchor = Anchor.CentreLeft,
{ Origin = Anchor.CentreRight,
Anchor = Anchor.CentreLeft, Size = new Vector2(5)
Origin = Anchor.CentreRight, },
Size = new Vector2(5) new Box
}, {
new Box Anchor = Anchor.CentreLeft,
{ Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft, RelativeSizeAxes = Axes.X,
Origin = Anchor.CentreLeft, Height = 1,
RelativeSizeAxes = Axes.X, EdgeSmoothness = new Vector2(0, 1),
Height = 1, },
EdgeSmoothness = new Vector2(0, 1), new Circle
}, {
new Circle Anchor = Anchor.CentreRight,
{ Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreRight, Size = new Vector2(5)
Origin = Anchor.CentreLeft, },
Size = new Vector2(5)
},
}
},
new BreakPart
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Height = 0.25f
} }
},
breakPart = new BreakPart
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Height = 0.25f
} }
} }
}; }
};
markerPart.Beatmap.BindTo(Beatmap);
controlPointPart.Beatmap.BindTo(Beatmap);
bookmarkPart.Beatmap.BindTo(Beatmap);
breakPart.Beatmap.BindTo(Beatmap);
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]

View File

@ -190,6 +190,7 @@ namespace osu.Game.Screens.Edit
} }
}); });
SummaryTimeline summaryTimeline;
Add(new Container Add(new Container
{ {
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
@ -211,7 +212,7 @@ namespace osu.Game.Screens.Edit
Spacing = new Vector2(10, 0), Spacing = new Vector2(10, 0),
Children = new[] Children = new[]
{ {
new SummaryTimeline summaryTimeline = new SummaryTimeline
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -223,6 +224,8 @@ namespace osu.Game.Screens.Edit
} }
} }
}); });
summaryTimeline.Beatmap.BindTo(Beatmap);
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]

View File

@ -3,7 +3,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Audio.Track; using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -11,6 +10,7 @@ using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using OpenTK; using OpenTK;
using osu.Game.Screens.Edit.Components.Timelines.Summary; using osu.Game.Screens.Edit.Components.Timelines.Summary;
using osu.Framework.Configuration;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
{ {
@ -21,40 +21,48 @@ namespace osu.Game.Tests.Visual
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(SummaryTimeline) }; public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(SummaryTimeline) };
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
public TestCaseEditorSummaryTimeline() public TestCaseEditorSummaryTimeline()
{ {
random = new Random(1337); random = new Random(1337);
Add(new SummaryTimeline SummaryTimeline summaryTimeline;
Add(summaryTimeline = new SummaryTimeline
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Size = new Vector2(500, 50) Size = new Vector2(500, 50)
}); });
summaryTimeline.Beatmap.BindTo(beatmap);
AddStep("New beatmap", newBeatmap);
newBeatmap();
} }
[BackgroundDependencyLoader] private void newBeatmap()
private void load(OsuGameBase osuGame)
{ {
var beatmap = new Beatmap(); var b = new Beatmap();
for (int i = 0; i < random.Next(1, 10); i++) for (int i = 0; i < random.Next(1, 10); i++)
beatmap.ControlPointInfo.TimingPoints.Add(new TimingControlPoint { Time = random.Next(0, length) }); b.ControlPointInfo.TimingPoints.Add(new TimingControlPoint { Time = random.Next(0, length) });
for (int i = 0; i < random.Next(1, 5); i++) for (int i = 0; i < random.Next(1, 5); i++)
beatmap.ControlPointInfo.DifficultyPoints.Add(new DifficultyControlPoint { Time = random.Next(0, length) }); b.ControlPointInfo.DifficultyPoints.Add(new DifficultyControlPoint { Time = random.Next(0, length) });
for (int i = 0; i < random.Next(1, 5); i++) for (int i = 0; i < random.Next(1, 5); i++)
beatmap.ControlPointInfo.EffectPoints.Add(new EffectControlPoint { Time = random.Next(0, length) }); b.ControlPointInfo.EffectPoints.Add(new EffectControlPoint { Time = random.Next(0, length) });
for (int i = 0; i < random.Next(1, 5); i++) for (int i = 0; i < random.Next(1, 5); i++)
beatmap.ControlPointInfo.SoundPoints.Add(new SoundControlPoint { Time = random.Next(0, length) }); b.ControlPointInfo.SoundPoints.Add(new SoundControlPoint { Time = random.Next(0, length) });
beatmap.BeatmapInfo.Bookmarks = new int[random.Next(10, 30)]; b.BeatmapInfo.Bookmarks = new int[random.Next(10, 30)];
for (int i = 0; i < beatmap.BeatmapInfo.Bookmarks.Length; i++) for (int i = 0; i < b.BeatmapInfo.Bookmarks.Length; i++)
beatmap.BeatmapInfo.Bookmarks[i] = random.Next(0, length); b.BeatmapInfo.Bookmarks[i] = random.Next(0, length);
osuGame.Beatmap.Value = new TestWorkingBeatmap(beatmap); beatmap.Value = new TestWorkingBeatmap(b);
} }
private class TestWorkingBeatmap : WorkingBeatmap private class TestWorkingBeatmap : WorkingBeatmap