From d05947ef481f09749af41d59cb27136a7404a80a Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 15 Mar 2018 18:08:37 +0900 Subject: [PATCH] Pass adjustable clocks to components, rather than relying on the track --- .../Screens/Edit/Components/PlaybackControl.cs | 17 +++++++++++------ .../Edit/Components/TimeInfoContainer.cs | 9 +++++++-- .../Timelines/Summary/Parts/MarkerPart.cs | 11 ++++++++--- .../Timelines/Summary/SummaryTimeline.cs | 5 +++-- osu.Game/Screens/Edit/Editor.cs | 6 +++--- .../Screens/Edit/Screens/Compose/Compose.cs | 9 +-------- 6 files changed, 33 insertions(+), 24 deletions(-) diff --git a/osu.Game/Screens/Edit/Components/PlaybackControl.cs b/osu.Game/Screens/Edit/Components/PlaybackControl.cs index 05e47ef5b1..71154006ce 100644 --- a/osu.Game/Screens/Edit/Components/PlaybackControl.cs +++ b/osu.Game/Screens/Edit/Components/PlaybackControl.cs @@ -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 diff --git a/osu.Game/Screens/Edit/Components/TimeInfoContainer.cs b/osu.Game/Screens/Edit/Components/TimeInfoContainer.cs index 9a78e6e189..6bbaad432b 100644 --- a/osu.Game/Screens/Edit/Components/TimeInfoContainer.cs +++ b/osu.Game/Screens/Edit/Components/TimeInfoContainer.cs @@ -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"); } } } diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/MarkerPart.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/MarkerPart.cs index c7f40327a9..b249713581 100644 --- a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/MarkerPart.cs +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/MarkerPart.cs @@ -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) diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs index 8a472dc357..9921c24083 100644 --- a/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs @@ -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, diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 1a145478eb..cc7f77e770 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -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 }, } }, } diff --git a/osu.Game/Screens/Edit/Screens/Compose/Compose.cs b/osu.Game/Screens/Edit/Screens/Compose/Compose.cs index b0fad58084..9a720e1608 100644 --- a/osu.Game/Screens/Edit/Screens/Compose/Compose.cs +++ b/osu.Game/Screens/Edit/Screens/Compose/Compose.cs @@ -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.");