1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 13:22:55 +08:00

Pass down editor clocks through DI

This commit is contained in:
smoogipoo 2018-03-19 16:27:52 +09:00
parent abb5dcf678
commit e25d1f6982
14 changed files with 91 additions and 116 deletions

View File

@ -3,7 +3,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Timing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Tools; using osu.Game.Rulesets.Edit.Tools;
@ -18,8 +17,8 @@ namespace osu.Game.Rulesets.Osu.Edit
{ {
public class OsuHitObjectComposer : HitObjectComposer public class OsuHitObjectComposer : HitObjectComposer
{ {
public OsuHitObjectComposer(Ruleset ruleset, IAdjustableClock adjustableClock, IFrameBasedClock framedClock) public OsuHitObjectComposer(Ruleset ruleset)
: base(ruleset, adjustableClock, framedClock) : base(ruleset)
{ {
} }

View File

@ -13,7 +13,6 @@ using System.Linq;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Overlays.Settings; using osu.Game.Overlays.Settings;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Timing;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Osu.Scoring; using osu.Game.Rulesets.Osu.Scoring;
using osu.Game.Rulesets.Osu.Edit; 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 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!"; public override string Description => "osu!";

View File

@ -13,13 +13,21 @@ namespace osu.Game.Tests.Visual
[TestFixture] [TestFixture]
public class TestCaseEditorCompose : OsuTestCase public class TestCaseEditorCompose : OsuTestCase
{ {
private DependencyContainer dependencies;
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
=> dependencies = new DependencyContainer(parent);
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuGameBase osuGame) private void load(OsuGameBase osuGame)
{ {
osuGame.Beatmap.Value = new TestWorkingBeatmap(new OsuRuleset().RulesetInfo); osuGame.Beatmap.Value = new TestWorkingBeatmap(new OsuRuleset().RulesetInfo);
var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false };
var compose = new Compose(clock, clock); dependencies.CacheAs<IAdjustableClock>(clock);
dependencies.CacheAs<IFrameBasedClock>(clock);
var compose = new Compose();
compose.Beatmap.BindTo(osuGame.Beatmap); compose.Beatmap.BindTo(osuGame.Beatmap);
Child = compose; Child = compose;

View File

@ -33,10 +33,17 @@ namespace osu.Game.Tests.Visual
private DecoupleableInterpolatingFramedClock clock; private DecoupleableInterpolatingFramedClock clock;
private DependencyContainer dependencies;
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
=> dependencies = new DependencyContainer(parent);
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuGameBase osuGame) private void load(OsuGameBase osuGame)
{ {
clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false };
dependencies.CacheAs<IAdjustableClock>(clock);
dependencies.CacheAs<IFrameBasedClock>(clock);
var testBeatmap = new Beatmap var testBeatmap = new Beatmap
{ {
@ -67,7 +74,7 @@ namespace osu.Game.Tests.Visual
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Content = new[] 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 } }, new Drawable[] { new TimingPointVisualiser(testBeatmap, track) { Clock = clock } },
}, },
RowDimensions = new[] RowDimensions = new[]
@ -338,8 +345,8 @@ namespace osu.Game.Tests.Visual
private class TestHitObjectComposer : HitObjectComposer private class TestHitObjectComposer : HitObjectComposer
{ {
public TestHitObjectComposer(Ruleset ruleset, IAdjustableClock adjustableClock, IFrameBasedClock framedClock) public TestHitObjectComposer(Ruleset ruleset)
: base(ruleset, adjustableClock, framedClock) : base(ruleset)
{ {
} }

View File

@ -35,6 +35,11 @@ namespace osu.Game.Tests.Visual
typeof(SliderCircleMask) typeof(SliderCircleMask)
}; };
private DependencyContainer dependencies;
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
=> dependencies = new DependencyContainer(parent);
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuGameBase osuGame) private void load(OsuGameBase osuGame)
{ {
@ -61,8 +66,10 @@ namespace osu.Game.Tests.Visual
}); });
var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false };
dependencies.CacheAs<IAdjustableClock>(clock);
dependencies.CacheAs<IFrameBasedClock>(clock);
Child = new OsuHitObjectComposer(new OsuRuleset(), clock, clock); Child = new OsuHitObjectComposer(new OsuRuleset());
} }
} }
} }

View File

@ -4,36 +4,41 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Audio.Track; using osu.Framework.Allocation;
using osu.Framework.Graphics.Textures;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
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; using osu.Framework.Configuration;
using osu.Framework.Timing; using osu.Framework.Timing;
using osu.Game.Rulesets.Osu;
using osu.Game.Tests.Beatmaps;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
{ {
[TestFixture] [TestFixture]
public class TestCaseEditorSummaryTimeline : OsuTestCase public class TestCaseEditorSummaryTimeline : OsuTestCase
{ {
private const int length = 60000;
private readonly Random random;
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(SummaryTimeline) }; public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(SummaryTimeline) };
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>(); private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
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 }; var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false };
dependencies.CacheAs<IAdjustableClock>(clock);
dependencies.CacheAs<IFrameBasedClock>(clock);
SummaryTimeline summaryTimeline; SummaryTimeline summaryTimeline;
Add(summaryTimeline = new SummaryTimeline(clock) Add(summaryTimeline = new SummaryTimeline
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -41,58 +46,6 @@ namespace osu.Game.Tests.Visual
}); });
summaryTimeline.Beatmap.BindTo(beatmap); 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;
}
}
} }
} }
} }

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Timing; using osu.Framework.Timing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -14,16 +15,24 @@ namespace osu.Game.Tests.Visual
[TestFixture] [TestFixture]
public class TestCasePlaybackControl : OsuTestCase public class TestCasePlaybackControl : OsuTestCase
{ {
private DependencyContainer dependencies;
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
=> dependencies = new DependencyContainer(parent);
public TestCasePlaybackControl() public TestCasePlaybackControl()
{ {
var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; var clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false };
dependencies.CacheAs<IAdjustableClock>(clock);
dependencies.CacheAs<IFrameBasedClock>(clock);
var playback = new PlaybackControl(clock) var playback = new PlaybackControl
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Size = new Vector2(200,100) Size = new Vector2(200,100)
}; };
playback.Beatmap.Value = new TestWorkingBeatmap(new Beatmap()); playback.Beatmap.Value = new TestWorkingBeatmap(new Beatmap());
Add(playback); Add(playback);

View File

@ -32,21 +32,20 @@ namespace osu.Game.Rulesets.Edit
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>(); private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
private readonly IAdjustableClock adjustableClock; private IAdjustableClock adjustableClock;
private readonly IFrameBasedClock framedClock;
protected HitObjectComposer(Ruleset ruleset, IAdjustableClock adjustableClock, IFrameBasedClock framedClock) protected HitObjectComposer(Ruleset ruleset)
{ {
this.ruleset = ruleset; this.ruleset = ruleset;
this.adjustableClock = adjustableClock;
this.framedClock = framedClock;
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuGameBase osuGame) private void load(OsuGameBase osuGame, IAdjustableClock adjustableClock, IFrameBasedClock framedClock)
{ {
this.adjustableClock = adjustableClock;
beatmap.BindTo(osuGame.Beatmap); beatmap.BindTo(osuGame.Beatmap);
try try

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Timing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Overlays.Settings; using osu.Game.Overlays.Settings;
@ -54,7 +53,7 @@ namespace osu.Game.Rulesets
public virtual PerformanceCalculator CreatePerformanceCalculator(Beatmap beatmap, Score score) => null; 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 }; public virtual Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.fa_question_circle };

View File

@ -18,11 +18,12 @@ namespace osu.Game.Screens.Edit.Components
{ {
public class PlaybackControl : BottomBarContainer 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; this.adjustableClock = adjustableClock;

View File

@ -4,21 +4,19 @@
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using System; using System;
using osu.Framework.Allocation;
using osu.Framework.Timing; using osu.Framework.Timing;
namespace osu.Game.Screens.Edit.Components namespace osu.Game.Screens.Edit.Components
{ {
public class TimeInfoContainer : BottomBarContainer public class TimeInfoContainer : BottomBarContainer
{ {
private const int count_duration = 150;
private readonly OsuSpriteText trackTimer; private readonly OsuSpriteText trackTimer;
private readonly IAdjustableClock adjustableClock; private IAdjustableClock adjustableClock;
public TimeInfoContainer(IAdjustableClock adjustableClock) public TimeInfoContainer()
{ {
this.adjustableClock = adjustableClock;
Children = new Drawable[] 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() protected override void Update()
{ {
base.Update(); base.Update();

View File

@ -17,13 +17,12 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary
/// </summary> /// </summary>
public class SummaryTimeline : BottomBarContainer public class SummaryTimeline : BottomBarContainer
{ {
private readonly Drawable timelineBar; [BackgroundDependencyLoader]
private void load(OsuColour colours, IAdjustableClock adjustableClock)
public SummaryTimeline(IAdjustableClock adjustableClock)
{ {
TimelinePart markerPart, controlPointPart, bookmarkPart, breakPart; TimelinePart markerPart, controlPointPart, bookmarkPart, breakPart;
Children = new[] Children = new Drawable[]
{ {
markerPart = new MarkerPart(adjustableClock) { RelativeSizeAxes = Axes.Both }, markerPart = new MarkerPart(adjustableClock) { RelativeSizeAxes = Axes.Both },
controlPointPart = new ControlPointPart controlPointPart = new ControlPointPart
@ -40,9 +39,10 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Height = 0.35f Height = 0.35f
}, },
timelineBar = new Container new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = colours.Gray5,
Children = new Drawable[] Children = new Drawable[]
{ {
new Circle new Circle
@ -81,11 +81,5 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary
bookmarkPart.Beatmap.BindTo(Beatmap); bookmarkPart.Beatmap.BindTo(Beatmap);
breakPart.Beatmap.BindTo(Beatmap); breakPart.Beatmap.BindTo(Beatmap);
} }
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
timelineBar.Colour = colours.Gray5;
}
} }
} }

View File

@ -32,16 +32,22 @@ namespace osu.Game.Screens.Edit
private EditorScreen currentScreen; private EditorScreen currentScreen;
private DecoupleableInterpolatingFramedClock adjustableClock; private DependencyContainer dependencies;
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
=> dependencies = new DependencyContainer(parent);
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
// TODO: should probably be done at a RulesetContainer level to share logic with Player. // TODO: should probably be done at a RulesetContainer level to share logic with Player.
var sourceClock = (IAdjustableClock)Beatmap.Value.Track ?? new StopwatchClock(); var sourceClock = (IAdjustableClock)Beatmap.Value.Track ?? new StopwatchClock();
adjustableClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; var adjustableClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false };
adjustableClock.ChangeSource(sourceClock); adjustableClock.ChangeSource(sourceClock);
dependencies.CacheAs<IAdjustableClock>(adjustableClock);
dependencies.CacheAs<IFrameBasedClock>(adjustableClock);
EditorMenuBar menuBar; EditorMenuBar menuBar;
TimeInfoContainer timeInfo; TimeInfoContainer timeInfo;
SummaryTimeline timeline; SummaryTimeline timeline;
@ -115,9 +121,9 @@ namespace osu.Game.Screens.Edit
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Right = 10 }, 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, RelativeSizeAxes = Axes.Both,
}, },
@ -125,7 +131,7 @@ namespace osu.Game.Screens.Edit
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = 10 }, 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) switch (mode)
{ {
case EditorScreenMode.Compose: case EditorScreenMode.Compose:
currentScreen = new Compose(adjustableClock, adjustableClock); currentScreen = new Compose();
break; break;
case EditorScreenMode.Design: case EditorScreenMode.Design:
currentScreen = new Design(); currentScreen = new Design();

View File

@ -8,7 +8,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.Logging; using osu.Framework.Logging;
using osu.Framework.Timing;
using osu.Game.Screens.Edit.Screens.Compose.Timeline; using osu.Game.Screens.Edit.Screens.Compose.Timeline;
namespace osu.Game.Screens.Edit.Screens.Compose namespace osu.Game.Screens.Edit.Screens.Compose
@ -20,15 +19,6 @@ namespace osu.Game.Screens.Edit.Screens.Compose
private Container composerContainer; private Container composerContainer;
private readonly IAdjustableClock adjustableClock;
private readonly IFrameBasedClock framedClock;
public Compose(IAdjustableClock adjustableClock, IFrameBasedClock framedClock)
{
this.adjustableClock = adjustableClock;
this.framedClock = framedClock;
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
@ -95,7 +85,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose
return; return;
} }
var composer = ruleset.CreateHitObjectComposer(adjustableClock, framedClock); var composer = ruleset.CreateHitObjectComposer();
if (composer == null) if (composer == null)
{ {
Logger.Log($"Ruleset {ruleset.Description} doesn't support hitobject composition."); Logger.Log($"Ruleset {ruleset.Description} doesn't support hitobject composition.");