1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 05:27:23 +08:00

Pass adjustable clocks to components, rather than relying on the track

This commit is contained in:
smoogipoo 2018-03-15 18:08:37 +09:00
parent c8f6a6980b
commit d05947ef48
6 changed files with 33 additions and 24 deletions

View File

@ -9,6 +9,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Framework.Timing;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
@ -19,8 +20,12 @@ namespace osu.Game.Screens.Edit.Components
{
private readonly IconButton playButton;
public PlaybackControl()
private readonly IAdjustableClock adjustableClock;
public PlaybackControl(IAdjustableClock adjustableClock)
{
this.adjustableClock = adjustableClock;
PlaybackTabControl tabs;
Children = new Drawable[]
@ -54,22 +59,22 @@ namespace osu.Game.Screens.Edit.Components
}
};
tabs.Current.ValueChanged += newValue => Track.Tempo.Value = newValue;
tabs.Current.ValueChanged += newValue => Beatmap.Value.Track.Tempo.Value = newValue;
}
private void togglePause()
{
if (Track.IsRunning)
Track.Stop();
if (adjustableClock.IsRunning)
adjustableClock.Stop();
else
Track.Start();
adjustableClock.Start();
}
protected override void Update()
{
base.Update();
playButton.Icon = Track.IsRunning ? FontAwesome.fa_pause_circle_o : FontAwesome.fa_play_circle_o;
playButton.Icon = adjustableClock.IsRunning ? FontAwesome.fa_pause_circle_o : FontAwesome.fa_play_circle_o;
}
private class PlaybackTabControl : OsuTabControl<double>

View File

@ -4,6 +4,7 @@
using osu.Framework.Graphics;
using osu.Game.Graphics.Sprites;
using System;
using osu.Framework.Timing;
namespace osu.Game.Screens.Edit.Components
{
@ -13,8 +14,12 @@ namespace osu.Game.Screens.Edit.Components
private readonly OsuSpriteText trackTimer;
public TimeInfoContainer()
private readonly IAdjustableClock adjustableClock;
public TimeInfoContainer(IAdjustableClock adjustableClock)
{
this.adjustableClock = adjustableClock;
Children = new Drawable[]
{
trackTimer = new OsuSpriteText
@ -32,7 +37,7 @@ namespace osu.Game.Screens.Edit.Components
{
base.Update();
trackTimer.Text = TimeSpan.FromMilliseconds(Track.CurrentTime).ToString(@"mm\:ss\:fff");
trackTimer.Text = TimeSpan.FromMilliseconds(adjustableClock.CurrentTime).ToString(@"mm\:ss\:fff");
}
}
}

View File

@ -7,6 +7,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
@ -19,8 +20,12 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
{
private readonly Drawable marker;
public MarkerPart()
private readonly IAdjustableClock adjustableClock;
public MarkerPart(IAdjustableClock adjustableClock)
{
this.adjustableClock = adjustableClock;
Add(marker = new MarkerVisualisation());
}
@ -53,12 +58,12 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
seekTo(markerPos / DrawWidth * Beatmap.Value.Track.Length);
}
private void seekTo(double time) => Beatmap.Value?.Track.Seek(time);
private void seekTo(double time) => adjustableClock.Seek(time);
protected override void Update()
{
base.Update();
marker.X = (float)(Beatmap.Value?.Track.CurrentTime ?? 0);
marker.X = (float)adjustableClock.CurrentTime;
}
protected override void LoadBeatmap(WorkingBeatmap beatmap)

View File

@ -6,6 +6,7 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Timing;
using osu.Game.Graphics;
using osu.Game.Screens.Edit.Components.Timelines.Summary.Parts;
@ -18,13 +19,13 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary
{
private readonly Drawable timelineBar;
public SummaryTimeline()
public SummaryTimeline(IAdjustableClock adjustableClock)
{
TimelinePart markerPart, controlPointPart, bookmarkPart, breakPart;
Children = new[]
{
markerPart = new MarkerPart { RelativeSizeAxes = Axes.Both },
markerPart = new MarkerPart(adjustableClock) { RelativeSizeAxes = Axes.Both },
controlPointPart = new ControlPointPart
{
Anchor = Anchor.Centre,

View File

@ -115,9 +115,9 @@ namespace osu.Game.Screens.Edit
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Right = 10 },
Child = timeInfo = new TimeInfoContainer { RelativeSizeAxes = Axes.Both },
Child = timeInfo = new TimeInfoContainer(adjustableClock) { RelativeSizeAxes = Axes.Both },
},
timeline = new SummaryTimeline
timeline = new SummaryTimeline(adjustableClock)
{
RelativeSizeAxes = Axes.Both,
},
@ -125,7 +125,7 @@ namespace osu.Game.Screens.Edit
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = 10 },
Child = playback = new PlaybackControl { RelativeSizeAxes = Axes.Both },
Child = playback = new PlaybackControl(adjustableClock) { RelativeSizeAxes = Axes.Both },
}
},
}

View File

@ -9,7 +9,6 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Logging;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Screens.Edit.Screens.Compose.Timeline;
namespace osu.Game.Screens.Edit.Screens.Compose
@ -87,14 +86,8 @@ namespace osu.Game.Screens.Edit.Screens.Compose
};
timeline.Beatmap.BindTo(Beatmap);
Beatmap.ValueChanged += beatmapChanged;
}
private void beatmapChanged(WorkingBeatmap newBeatmap)
{
composerContainer.Clear();
var ruleset = newBeatmap.BeatmapInfo.Ruleset?.CreateInstance();
var ruleset = Beatmap.Value.BeatmapInfo.Ruleset?.CreateInstance();
if (ruleset == null)
{
Logger.Log("Beatmap doesn't have a ruleset assigned.");