From 5ecbc5612c8a75b8a7a14b4ac807ef726cf64afe Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 19 Mar 2018 20:30:07 +0900 Subject: [PATCH] Integrate with dependency injection --- .../Visual/TestCaseBeatSnapVisualiser.cs | 7 ++++ .../Screens/Compose/BindableBeatDivisor.cs | 15 +++++++ .../Screens/Edit/Screens/Compose/Compose.cs | 9 +++++ .../Screens/Compose/DrawableBeatDivisor.cs | 40 +++++++++---------- osu.Game/osu.Game.csproj | 1 + 5 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 osu.Game/Screens/Edit/Screens/Compose/BindableBeatDivisor.cs diff --git a/osu.Game.Tests/Visual/TestCaseBeatSnapVisualiser.cs b/osu.Game.Tests/Visual/TestCaseBeatSnapVisualiser.cs index a17b2328ba..d72b59f5c5 100644 --- a/osu.Game.Tests/Visual/TestCaseBeatSnapVisualiser.cs +++ b/osu.Game.Tests/Visual/TestCaseBeatSnapVisualiser.cs @@ -17,9 +17,16 @@ namespace osu.Game.Tests.Visual typeof(BeatSnapVisualiser) }; + private DependencyContainer dependencies; + + protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) + => dependencies = new DependencyContainer(parent); + [BackgroundDependencyLoader] private void load() { + dependencies.Cache(new BindableBeatDivisor()); + Child = new BeatSnapVisualiser { Anchor = Anchor.Centre, diff --git a/osu.Game/Screens/Edit/Screens/Compose/BindableBeatDivisor.cs b/osu.Game/Screens/Edit/Screens/Compose/BindableBeatDivisor.cs new file mode 100644 index 0000000000..eb68bce71b --- /dev/null +++ b/osu.Game/Screens/Edit/Screens/Compose/BindableBeatDivisor.cs @@ -0,0 +1,15 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Configuration; + +namespace osu.Game.Screens.Edit.Screens.Compose +{ + public class BindableBeatDivisor : Bindable + { + public BindableBeatDivisor() + : base(1) + { + } + } +} diff --git a/osu.Game/Screens/Edit/Screens/Compose/Compose.cs b/osu.Game/Screens/Edit/Screens/Compose/Compose.cs index d32dc92ce5..c044c949e8 100644 --- a/osu.Game/Screens/Edit/Screens/Compose/Compose.cs +++ b/osu.Game/Screens/Edit/Screens/Compose/Compose.cs @@ -17,11 +17,20 @@ namespace osu.Game.Screens.Edit.Screens.Compose private const float vertical_margins = 10; private const float horizontal_margins = 20; + private readonly BindableBeatDivisor beatDivisor = new BindableBeatDivisor(); + private Container composerContainer; + private DependencyContainer dependencies; + + protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) + => dependencies = new DependencyContainer(parent); + [BackgroundDependencyLoader] private void load() { + dependencies.Cache(beatDivisor); + ScrollableTimeline timeline; Children = new Drawable[] { diff --git a/osu.Game/Screens/Edit/Screens/Compose/DrawableBeatDivisor.cs b/osu.Game/Screens/Edit/Screens/Compose/DrawableBeatDivisor.cs index 5e2601ca50..af028763a0 100644 --- a/osu.Game/Screens/Edit/Screens/Compose/DrawableBeatDivisor.cs +++ b/osu.Game/Screens/Edit/Screens/Compose/DrawableBeatDivisor.cs @@ -19,15 +19,14 @@ namespace osu.Game.Screens.Edit.Screens.Compose { private static readonly int[] available_divisors = { 1, 2, 3, 4, 6, 8, 12, 16 }; - public readonly Bindable Divisor = new Bindable(1); + private readonly Bindable beatDivisor = new Bindable(1); private int currentDivisorIndex; - private TickContainer tickContainer; - private DivisorText text; - [BackgroundDependencyLoader] - private void load(OsuColour colours) + private void load(OsuColour colours, BindableBeatDivisor beatDivisor) { + this.beatDivisor.BindTo(beatDivisor); + Masking = true; CornerRadius = 5; @@ -46,7 +45,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose { new Drawable[] { - tickContainer = new TickContainer(1, 2, 3, 4, 6, 8, 12, 16) + new TickContainer(1, 2, 3, 4, 6, 8, 12, 16) { RelativeSizeAxes = Axes.Both, Padding = new MarginPadding { Horizontal = 5 } @@ -80,7 +79,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose Icon = FontAwesome.fa_chevron_left, Action = selectPrevious }, - text = new DivisorText(), + new DivisorText(), new DivisorButton { Icon = FontAwesome.fa_chevron_right, @@ -116,28 +115,25 @@ namespace osu.Game.Screens.Edit.Screens.Compose } } }; - - tickContainer.Divisor.BindTo(Divisor); - text.Divisor.BindTo(Divisor); } private void selectPrevious() { if (currentDivisorIndex == 0) return; - Divisor.Value = available_divisors[--currentDivisorIndex]; + beatDivisor.Value = available_divisors[--currentDivisorIndex]; } private void selectNext() { if (currentDivisorIndex == available_divisors.Length - 1) return; - Divisor.Value = available_divisors[++currentDivisorIndex]; + beatDivisor.Value = available_divisors[++currentDivisorIndex]; } private class DivisorText : SpriteText { - public readonly Bindable Divisor = new Bindable(); + private readonly Bindable beatDivisor = new Bindable(); public DivisorText() { @@ -146,8 +142,10 @@ namespace osu.Game.Screens.Edit.Screens.Compose } [BackgroundDependencyLoader] - private void load(OsuColour colours) + private void load(OsuColour colours, BindableBeatDivisor beatDivisor) { + this.beatDivisor.BindTo(beatDivisor); + Colour = colours.BlueLighter; } @@ -155,11 +153,11 @@ namespace osu.Game.Screens.Edit.Screens.Compose { base.LoadComplete(); - Divisor.ValueChanged += v => updateText(); + beatDivisor.ValueChanged += v => updateText(); updateText(); } - private void updateText() => Text = $"1/{Divisor.Value}"; + private void updateText() => Text = $"1/{beatDivisor.Value}"; } private class DivisorButton : IconButton @@ -187,7 +185,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose private class TickContainer : CompositeDrawable { - public readonly BindableInt Divisor = new BindableInt(); + private readonly Bindable beatDivisor = new Bindable(); public new MarginPadding Padding { @@ -206,8 +204,10 @@ namespace osu.Game.Screens.Edit.Screens.Compose } [BackgroundDependencyLoader] - private void load(OsuColour colours) + private void load(OsuColour colours, BindableBeatDivisor beatDivisor) { + this.beatDivisor.BindTo(beatDivisor); + InternalChild = marker = new EquilateralTriangle { Anchor = Anchor.BottomLeft, @@ -234,11 +234,11 @@ namespace osu.Game.Screens.Edit.Screens.Compose { base.LoadComplete(); - Divisor.ValueChanged += v => updatePosition(); + beatDivisor.ValueChanged += v => updatePosition(); updatePosition(); } - private void updatePosition() => marker.MoveToX(getTickPosition(Array.IndexOf(availableDivisors, Divisor.Value)), 100, Easing.OutQuint); + private void updatePosition() => marker.MoveToX(getTickPosition(Array.IndexOf(availableDivisors, beatDivisor.Value)), 100, Easing.OutQuint); private float getTickPosition(int index) => (index + 1) * tickSpacing; diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 8bdefbfeb5..42f58e9eee 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -380,6 +380,7 @@ +