From e25d1f69826b62a3765521ab19bf822ad14dd14f Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 19 Mar 2018 16:27:52 +0900 Subject: [PATCH] Pass down editor clocks through DI --- .../Edit/OsuHitObjectComposer.cs | 5 +- osu.Game.Rulesets.Osu/OsuRuleset.cs | 3 +- .../Visual/TestCaseEditorCompose.cs | 10 ++- .../Visual/TestCaseEditorSeekSnapping.cs | 13 +++- .../Visual/TestCaseEditorSelectionLayer.cs | 9 ++- .../Visual/TestCaseEditorSummaryTimeline.cs | 75 ++++--------------- .../Visual/TestCasePlaybackControl.cs | 11 ++- osu.Game/Rulesets/Edit/HitObjectComposer.cs | 11 ++- osu.Game/Rulesets/Ruleset.cs | 3 +- .../Edit/Components/PlaybackControl.cs | 7 +- .../Edit/Components/TimeInfoContainer.cs | 14 ++-- .../Timelines/Summary/SummaryTimeline.cs | 16 ++-- osu.Game/Screens/Edit/Editor.cs | 18 +++-- .../Screens/Edit/Screens/Compose/Compose.cs | 12 +-- 14 files changed, 91 insertions(+), 116 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs index 77f48d704e..026c85d909 100644 --- a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs +++ b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using osu.Framework.Graphics; -using osu.Framework.Timing; using osu.Game.Beatmaps; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit.Tools; @@ -18,8 +17,8 @@ namespace osu.Game.Rulesets.Osu.Edit { public class OsuHitObjectComposer : HitObjectComposer { - public OsuHitObjectComposer(Ruleset ruleset, IAdjustableClock adjustableClock, IFrameBasedClock framedClock) - : base(ruleset, adjustableClock, framedClock) + public OsuHitObjectComposer(Ruleset ruleset) + : base(ruleset) { } diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index 5dcc8e8a6e..d407835a96 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -13,7 +13,6 @@ using System.Linq; using osu.Framework.Graphics; using osu.Game.Overlays.Settings; using osu.Framework.Input.Bindings; -using osu.Framework.Timing; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Osu.Scoring; using osu.Game.Rulesets.Osu.Edit; @@ -138,7 +137,7 @@ namespace osu.Game.Rulesets.Osu public override PerformanceCalculator CreatePerformanceCalculator(Beatmap beatmap, Score score) => new OsuPerformanceCalculator(this, beatmap, score); - public override HitObjectComposer CreateHitObjectComposer(IAdjustableClock adjustableClock, IFrameBasedClock framedClock) => new OsuHitObjectComposer(this, adjustableClock, framedClock); + public override HitObjectComposer CreateHitObjectComposer() => new OsuHitObjectComposer(this); public override string Description => "osu!"; diff --git a/osu.Game.Tests/Visual/TestCaseEditorCompose.cs b/osu.Game.Tests/Visual/TestCaseEditorCompose.cs index 945c3c3901..5fd0f96f4a 100644 --- a/osu.Game.Tests/Visual/TestCaseEditorCompose.cs +++ b/osu.Game.Tests/Visual/TestCaseEditorCompose.cs @@ -13,13 +13,21 @@ namespace osu.Game.Tests.Visual [TestFixture] public class TestCaseEditorCompose : OsuTestCase { + private DependencyContainer dependencies; + + protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) + => dependencies = new DependencyContainer(parent); + [BackgroundDependencyLoader] private void load(OsuGameBase osuGame) { osuGame.Beatmap.Value = new TestWorkingBeatmap(new OsuRuleset().RulesetInfo); var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; - var compose = new Compose(clock, clock); + dependencies.CacheAs(clock); + dependencies.CacheAs(clock); + + var compose = new Compose(); compose.Beatmap.BindTo(osuGame.Beatmap); Child = compose; diff --git a/osu.Game.Tests/Visual/TestCaseEditorSeekSnapping.cs b/osu.Game.Tests/Visual/TestCaseEditorSeekSnapping.cs index 3b4b31c92a..bfdb39dd5e 100644 --- a/osu.Game.Tests/Visual/TestCaseEditorSeekSnapping.cs +++ b/osu.Game.Tests/Visual/TestCaseEditorSeekSnapping.cs @@ -33,10 +33,17 @@ namespace osu.Game.Tests.Visual private DecoupleableInterpolatingFramedClock clock; + private DependencyContainer dependencies; + + protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) + => dependencies = new DependencyContainer(parent); + [BackgroundDependencyLoader] private void load(OsuGameBase osuGame) { clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; + dependencies.CacheAs(clock); + dependencies.CacheAs(clock); var testBeatmap = new Beatmap { @@ -67,7 +74,7 @@ namespace osu.Game.Tests.Visual RelativeSizeAxes = Axes.Both, Content = new[] { - new Drawable[] { composer = new TestHitObjectComposer(new OsuRuleset(), clock, clock) }, + new Drawable[] { composer = new TestHitObjectComposer(new OsuRuleset()) }, new Drawable[] { new TimingPointVisualiser(testBeatmap, track) { Clock = clock } }, }, RowDimensions = new[] @@ -338,8 +345,8 @@ namespace osu.Game.Tests.Visual private class TestHitObjectComposer : HitObjectComposer { - public TestHitObjectComposer(Ruleset ruleset, IAdjustableClock adjustableClock, IFrameBasedClock framedClock) - : base(ruleset, adjustableClock, framedClock) + public TestHitObjectComposer(Ruleset ruleset) + : base(ruleset) { } diff --git a/osu.Game.Tests/Visual/TestCaseEditorSelectionLayer.cs b/osu.Game.Tests/Visual/TestCaseEditorSelectionLayer.cs index 79c722be40..bbbfef477a 100644 --- a/osu.Game.Tests/Visual/TestCaseEditorSelectionLayer.cs +++ b/osu.Game.Tests/Visual/TestCaseEditorSelectionLayer.cs @@ -35,6 +35,11 @@ namespace osu.Game.Tests.Visual typeof(SliderCircleMask) }; + private DependencyContainer dependencies; + + protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) + => dependencies = new DependencyContainer(parent); + [BackgroundDependencyLoader] private void load(OsuGameBase osuGame) { @@ -61,8 +66,10 @@ namespace osu.Game.Tests.Visual }); var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; + dependencies.CacheAs(clock); + dependencies.CacheAs(clock); - Child = new OsuHitObjectComposer(new OsuRuleset(), clock, clock); + Child = new OsuHitObjectComposer(new OsuRuleset()); } } } diff --git a/osu.Game.Tests/Visual/TestCaseEditorSummaryTimeline.cs b/osu.Game.Tests/Visual/TestCaseEditorSummaryTimeline.cs index 6e4b0c2a72..bbe2956c5d 100644 --- a/osu.Game.Tests/Visual/TestCaseEditorSummaryTimeline.cs +++ b/osu.Game.Tests/Visual/TestCaseEditorSummaryTimeline.cs @@ -4,36 +4,41 @@ using System; using System.Collections.Generic; using NUnit.Framework; -using osu.Framework.Audio.Track; -using osu.Framework.Graphics.Textures; +using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Game.Beatmaps; -using osu.Game.Beatmaps.ControlPoints; using OpenTK; using osu.Game.Screens.Edit.Components.Timelines.Summary; using osu.Framework.Configuration; using osu.Framework.Timing; +using osu.Game.Rulesets.Osu; +using osu.Game.Tests.Beatmaps; namespace osu.Game.Tests.Visual { [TestFixture] public class TestCaseEditorSummaryTimeline : OsuTestCase { - private const int length = 60000; - private readonly Random random; - public override IReadOnlyList RequiredTypes => new[] { typeof(SummaryTimeline) }; private readonly Bindable beatmap = new Bindable(); - public TestCaseEditorSummaryTimeline() + private DependencyContainer dependencies; + + protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) + => dependencies = new DependencyContainer(parent); + + [BackgroundDependencyLoader] + private void load() { - random = new Random(1337); + beatmap.Value = new TestWorkingBeatmap(new OsuRuleset().RulesetInfo); var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; + dependencies.CacheAs(clock); + dependencies.CacheAs(clock); SummaryTimeline summaryTimeline; - Add(summaryTimeline = new SummaryTimeline(clock) + Add(summaryTimeline = new SummaryTimeline { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -41,58 +46,6 @@ namespace osu.Game.Tests.Visual }); summaryTimeline.Beatmap.BindTo(beatmap); - - AddStep("New beatmap", newBeatmap); - - newBeatmap(); - } - - private void newBeatmap() - { - var b = new Beatmap(); - - for (int i = 0; i < random.Next(1, 10); i++) - b.ControlPointInfo.TimingPoints.Add(new TimingControlPoint { Time = random.Next(0, length) }); - - for (int i = 0; i < random.Next(1, 5); i++) - b.ControlPointInfo.DifficultyPoints.Add(new DifficultyControlPoint { Time = random.Next(0, length) }); - - for (int i = 0; i < random.Next(1, 5); i++) - b.ControlPointInfo.EffectPoints.Add(new EffectControlPoint { Time = random.Next(0, length) }); - - for (int i = 0; i < random.Next(1, 5); i++) - b.ControlPointInfo.SamplePoints.Add(new SampleControlPoint { Time = random.Next(0, length) }); - - b.BeatmapInfo.Bookmarks = new int[random.Next(10, 30)]; - for (int i = 0; i < b.BeatmapInfo.Bookmarks.Length; i++) - b.BeatmapInfo.Bookmarks[i] = random.Next(0, length); - - beatmap.Value = new TestWorkingBeatmap(b); - } - - private class TestWorkingBeatmap : WorkingBeatmap - { - private readonly Beatmap beatmap; - - public TestWorkingBeatmap(Beatmap beatmap) - : base(beatmap.BeatmapInfo) - { - this.beatmap = beatmap; - } - - protected override Texture GetBackground() => null; - - protected override Beatmap GetBeatmap() => beatmap; - - protected override Track GetTrack() => new TestTrack(); - - private class TestTrack : TrackVirtual - { - public TestTrack() - { - Length = length; - } - } } } } diff --git a/osu.Game.Tests/Visual/TestCasePlaybackControl.cs b/osu.Game.Tests/Visual/TestCasePlaybackControl.cs index 37bf38bbc6..33a801e98f 100644 --- a/osu.Game.Tests/Visual/TestCasePlaybackControl.cs +++ b/osu.Game.Tests/Visual/TestCasePlaybackControl.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using NUnit.Framework; +using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Timing; using osu.Game.Beatmaps; @@ -14,16 +15,24 @@ namespace osu.Game.Tests.Visual [TestFixture] public class TestCasePlaybackControl : OsuTestCase { + private DependencyContainer dependencies; + + protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) + => dependencies = new DependencyContainer(parent); + public TestCasePlaybackControl() { var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; + dependencies.CacheAs(clock); + dependencies.CacheAs(clock); - var playback = new PlaybackControl(clock) + var playback = new PlaybackControl { Anchor = Anchor.Centre, Origin = Anchor.Centre, Size = new Vector2(200,100) }; + playback.Beatmap.Value = new TestWorkingBeatmap(new Beatmap()); Add(playback); diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index c2a286c6dd..ae1c8af1a4 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -32,21 +32,20 @@ namespace osu.Game.Rulesets.Edit private readonly Bindable beatmap = new Bindable(); - private readonly IAdjustableClock adjustableClock; - private readonly IFrameBasedClock framedClock; + private IAdjustableClock adjustableClock; - protected HitObjectComposer(Ruleset ruleset, IAdjustableClock adjustableClock, IFrameBasedClock framedClock) + protected HitObjectComposer(Ruleset ruleset) { this.ruleset = ruleset; - this.adjustableClock = adjustableClock; - this.framedClock = framedClock; RelativeSizeAxes = Axes.Both; } [BackgroundDependencyLoader] - private void load(OsuGameBase osuGame) + private void load(OsuGameBase osuGame, IAdjustableClock adjustableClock, IFrameBasedClock framedClock) { + this.adjustableClock = adjustableClock; + beatmap.BindTo(osuGame.Beatmap); try diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index fc0c7966c6..cba849a491 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Graphics; using osu.Framework.Input.Bindings; -using osu.Framework.Timing; using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Overlays.Settings; @@ -54,7 +53,7 @@ namespace osu.Game.Rulesets public virtual PerformanceCalculator CreatePerformanceCalculator(Beatmap beatmap, Score score) => null; - public virtual HitObjectComposer CreateHitObjectComposer(IAdjustableClock adjustableClock, IFrameBasedClock framedClock) => null; + public virtual HitObjectComposer CreateHitObjectComposer() => null; public virtual Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.fa_question_circle }; diff --git a/osu.Game/Screens/Edit/Components/PlaybackControl.cs b/osu.Game/Screens/Edit/Components/PlaybackControl.cs index 71154006ce..fe2549d300 100644 --- a/osu.Game/Screens/Edit/Components/PlaybackControl.cs +++ b/osu.Game/Screens/Edit/Components/PlaybackControl.cs @@ -18,11 +18,12 @@ namespace osu.Game.Screens.Edit.Components { public class PlaybackControl : BottomBarContainer { - private readonly IconButton playButton; + private IconButton playButton; - private readonly IAdjustableClock adjustableClock; + private IAdjustableClock adjustableClock; - public PlaybackControl(IAdjustableClock adjustableClock) + [BackgroundDependencyLoader] + private void load(IAdjustableClock adjustableClock) { this.adjustableClock = adjustableClock; diff --git a/osu.Game/Screens/Edit/Components/TimeInfoContainer.cs b/osu.Game/Screens/Edit/Components/TimeInfoContainer.cs index 6bbaad432b..5a3b6c652b 100644 --- a/osu.Game/Screens/Edit/Components/TimeInfoContainer.cs +++ b/osu.Game/Screens/Edit/Components/TimeInfoContainer.cs @@ -4,21 +4,19 @@ using osu.Framework.Graphics; using osu.Game.Graphics.Sprites; using System; +using osu.Framework.Allocation; using osu.Framework.Timing; namespace osu.Game.Screens.Edit.Components { public class TimeInfoContainer : BottomBarContainer { - private const int count_duration = 150; - private readonly OsuSpriteText trackTimer; - private readonly IAdjustableClock adjustableClock; + private IAdjustableClock adjustableClock; - public TimeInfoContainer(IAdjustableClock adjustableClock) + public TimeInfoContainer() { - this.adjustableClock = adjustableClock; Children = new Drawable[] { @@ -33,6 +31,12 @@ namespace osu.Game.Screens.Edit.Components }; } + [BackgroundDependencyLoader] + private void load(IAdjustableClock adjustableClock) + { + this.adjustableClock = adjustableClock; + } + protected override void Update() { base.Update(); diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs index 9921c24083..0e80c13257 100644 --- a/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs @@ -17,13 +17,12 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary /// public class SummaryTimeline : BottomBarContainer { - private readonly Drawable timelineBar; - - public SummaryTimeline(IAdjustableClock adjustableClock) + [BackgroundDependencyLoader] + private void load(OsuColour colours, IAdjustableClock adjustableClock) { TimelinePart markerPart, controlPointPart, bookmarkPart, breakPart; - Children = new[] + Children = new Drawable[] { markerPart = new MarkerPart(adjustableClock) { RelativeSizeAxes = Axes.Both }, controlPointPart = new ControlPointPart @@ -40,9 +39,10 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary RelativeSizeAxes = Axes.Both, Height = 0.35f }, - timelineBar = new Container + new Container { RelativeSizeAxes = Axes.Both, + Colour = colours.Gray5, Children = new Drawable[] { new Circle @@ -81,11 +81,5 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary bookmarkPart.Beatmap.BindTo(Beatmap); breakPart.Beatmap.BindTo(Beatmap); } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - timelineBar.Colour = colours.Gray5; - } } } diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index cc7f77e770..8b651000fd 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -32,16 +32,22 @@ namespace osu.Game.Screens.Edit private EditorScreen currentScreen; - private DecoupleableInterpolatingFramedClock adjustableClock; + private DependencyContainer dependencies; + + protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) + => dependencies = new DependencyContainer(parent); [BackgroundDependencyLoader] private void load(OsuColour colours) { // TODO: should probably be done at a RulesetContainer level to share logic with Player. var sourceClock = (IAdjustableClock)Beatmap.Value.Track ?? new StopwatchClock(); - adjustableClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; + var adjustableClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; adjustableClock.ChangeSource(sourceClock); + dependencies.CacheAs(adjustableClock); + dependencies.CacheAs(adjustableClock); + EditorMenuBar menuBar; TimeInfoContainer timeInfo; SummaryTimeline timeline; @@ -115,9 +121,9 @@ namespace osu.Game.Screens.Edit { RelativeSizeAxes = Axes.Both, Padding = new MarginPadding { Right = 10 }, - Child = timeInfo = new TimeInfoContainer(adjustableClock) { RelativeSizeAxes = Axes.Both }, + Child = timeInfo = new TimeInfoContainer { RelativeSizeAxes = Axes.Both }, }, - timeline = new SummaryTimeline(adjustableClock) + timeline = new SummaryTimeline { RelativeSizeAxes = Axes.Both, }, @@ -125,7 +131,7 @@ namespace osu.Game.Screens.Edit { RelativeSizeAxes = Axes.Both, Padding = new MarginPadding { Left = 10 }, - Child = playback = new PlaybackControl(adjustableClock) { RelativeSizeAxes = Axes.Both }, + Child = playback = new PlaybackControl { RelativeSizeAxes = Axes.Both }, } }, } @@ -156,7 +162,7 @@ namespace osu.Game.Screens.Edit switch (mode) { case EditorScreenMode.Compose: - currentScreen = new Compose(adjustableClock, adjustableClock); + currentScreen = new Compose(); break; case EditorScreenMode.Design: currentScreen = new Design(); diff --git a/osu.Game/Screens/Edit/Screens/Compose/Compose.cs b/osu.Game/Screens/Edit/Screens/Compose/Compose.cs index 9a720e1608..861a08fb07 100644 --- a/osu.Game/Screens/Edit/Screens/Compose/Compose.cs +++ b/osu.Game/Screens/Edit/Screens/Compose/Compose.cs @@ -8,7 +8,6 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Logging; -using osu.Framework.Timing; using osu.Game.Screens.Edit.Screens.Compose.Timeline; namespace osu.Game.Screens.Edit.Screens.Compose @@ -20,15 +19,6 @@ namespace osu.Game.Screens.Edit.Screens.Compose private Container composerContainer; - private readonly IAdjustableClock adjustableClock; - private readonly IFrameBasedClock framedClock; - - public Compose(IAdjustableClock adjustableClock, IFrameBasedClock framedClock) - { - this.adjustableClock = adjustableClock; - this.framedClock = framedClock; - } - [BackgroundDependencyLoader] private void load() { @@ -95,7 +85,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose return; } - var composer = ruleset.CreateHitObjectComposer(adjustableClock, framedClock); + var composer = ruleset.CreateHitObjectComposer(); if (composer == null) { Logger.Log($"Ruleset {ruleset.Description} doesn't support hitobject composition.");