1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 01:52:55 +08:00

Integrate with dependency injection

This commit is contained in:
smoogipoo 2018-03-19 20:30:07 +09:00
parent 46f10b392d
commit 5ecbc5612c
5 changed files with 52 additions and 20 deletions

View File

@ -17,9 +17,16 @@ namespace osu.Game.Tests.Visual
typeof(BeatSnapVisualiser) typeof(BeatSnapVisualiser)
}; };
private DependencyContainer dependencies;
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
=> dependencies = new DependencyContainer(parent);
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
dependencies.Cache(new BindableBeatDivisor());
Child = new BeatSnapVisualiser Child = new BeatSnapVisualiser
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,

View File

@ -0,0 +1,15 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// 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<int>
{
public BindableBeatDivisor()
: base(1)
{
}
}
}

View File

@ -17,11 +17,20 @@ namespace osu.Game.Screens.Edit.Screens.Compose
private const float vertical_margins = 10; private const float vertical_margins = 10;
private const float horizontal_margins = 20; private const float horizontal_margins = 20;
private readonly BindableBeatDivisor beatDivisor = new BindableBeatDivisor();
private Container composerContainer; private Container composerContainer;
private DependencyContainer dependencies;
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
=> dependencies = new DependencyContainer(parent);
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
dependencies.Cache(beatDivisor);
ScrollableTimeline timeline; ScrollableTimeline timeline;
Children = new Drawable[] Children = new Drawable[]
{ {

View File

@ -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 }; private static readonly int[] available_divisors = { 1, 2, 3, 4, 6, 8, 12, 16 };
public readonly Bindable<int> Divisor = new Bindable<int>(1); private readonly Bindable<int> beatDivisor = new Bindable<int>(1);
private int currentDivisorIndex; private int currentDivisorIndex;
private TickContainer tickContainer;
private DivisorText text;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours, BindableBeatDivisor beatDivisor)
{ {
this.beatDivisor.BindTo(beatDivisor);
Masking = true; Masking = true;
CornerRadius = 5; CornerRadius = 5;
@ -46,7 +45,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose
{ {
new Drawable[] 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, RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = 5 } Padding = new MarginPadding { Horizontal = 5 }
@ -80,7 +79,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose
Icon = FontAwesome.fa_chevron_left, Icon = FontAwesome.fa_chevron_left,
Action = selectPrevious Action = selectPrevious
}, },
text = new DivisorText(), new DivisorText(),
new DivisorButton new DivisorButton
{ {
Icon = FontAwesome.fa_chevron_right, 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() private void selectPrevious()
{ {
if (currentDivisorIndex == 0) if (currentDivisorIndex == 0)
return; return;
Divisor.Value = available_divisors[--currentDivisorIndex]; beatDivisor.Value = available_divisors[--currentDivisorIndex];
} }
private void selectNext() private void selectNext()
{ {
if (currentDivisorIndex == available_divisors.Length - 1) if (currentDivisorIndex == available_divisors.Length - 1)
return; return;
Divisor.Value = available_divisors[++currentDivisorIndex]; beatDivisor.Value = available_divisors[++currentDivisorIndex];
} }
private class DivisorText : SpriteText private class DivisorText : SpriteText
{ {
public readonly Bindable<int> Divisor = new Bindable<int>(); private readonly Bindable<int> beatDivisor = new Bindable<int>();
public DivisorText() public DivisorText()
{ {
@ -146,8 +142,10 @@ namespace osu.Game.Screens.Edit.Screens.Compose
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours, BindableBeatDivisor beatDivisor)
{ {
this.beatDivisor.BindTo(beatDivisor);
Colour = colours.BlueLighter; Colour = colours.BlueLighter;
} }
@ -155,11 +153,11 @@ namespace osu.Game.Screens.Edit.Screens.Compose
{ {
base.LoadComplete(); base.LoadComplete();
Divisor.ValueChanged += v => updateText(); beatDivisor.ValueChanged += v => updateText();
updateText(); updateText();
} }
private void updateText() => Text = $"1/{Divisor.Value}"; private void updateText() => Text = $"1/{beatDivisor.Value}";
} }
private class DivisorButton : IconButton private class DivisorButton : IconButton
@ -187,7 +185,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose
private class TickContainer : CompositeDrawable private class TickContainer : CompositeDrawable
{ {
public readonly BindableInt Divisor = new BindableInt(); private readonly Bindable<int> beatDivisor = new Bindable<int>();
public new MarginPadding Padding public new MarginPadding Padding
{ {
@ -206,8 +204,10 @@ namespace osu.Game.Screens.Edit.Screens.Compose
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours, BindableBeatDivisor beatDivisor)
{ {
this.beatDivisor.BindTo(beatDivisor);
InternalChild = marker = new EquilateralTriangle InternalChild = marker = new EquilateralTriangle
{ {
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
@ -234,11 +234,11 @@ namespace osu.Game.Screens.Edit.Screens.Compose
{ {
base.LoadComplete(); base.LoadComplete();
Divisor.ValueChanged += v => updatePosition(); beatDivisor.ValueChanged += v => updatePosition();
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; private float getTickPosition(int index) => (index + 1) * tickSpacing;

View File

@ -380,6 +380,7 @@
<Compile Include="Rulesets\Replays\Types\IConvertibleReplayFrame.cs" /> <Compile Include="Rulesets\Replays\Types\IConvertibleReplayFrame.cs" />
<Compile Include="Rulesets\Scoring\Legacy\LegacyScoreParser.cs" /> <Compile Include="Rulesets\Scoring\Legacy\LegacyScoreParser.cs" />
<Compile Include="Rulesets\UI\JudgementContainer.cs" /> <Compile Include="Rulesets\UI\JudgementContainer.cs" />
<Compile Include="Screens\Edit\Screens\Compose\BindableBeatDivisor.cs" />
<Compile Include="Screens\Edit\Screens\Compose\DrawableBeatDivisor.cs" /> <Compile Include="Screens\Edit\Screens\Compose\DrawableBeatDivisor.cs" />
<Compile Include="Screens\Edit\Screens\Compose\Layers\BorderLayer.cs" /> <Compile Include="Screens\Edit\Screens\Compose\Layers\BorderLayer.cs" />
<Compile Include="Screens\Edit\Screens\Compose\Layers\HitObjectMaskLayer.cs" /> <Compile Include="Screens\Edit\Screens\Compose\Layers\HitObjectMaskLayer.cs" />