bind laneCover direction to scroll direction

This commit is contained in:
LastExceed 2020-07-14 16:43:15 +02:00
parent 921939f97a
commit 25fb49d59f

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Colour;
@ -40,7 +41,7 @@ namespace osu.Game.Rulesets.Mania.Mods
Children = new Drawable[] Children = new Drawable[]
{ {
hoc, hoc,
new LaneCover(false) new LaneCover
{ {
Coverage = 0.5f, Coverage = 0.5f,
RelativeSizeAxes = Axes.Both RelativeSizeAxes = Axes.Both
@ -54,8 +55,10 @@ namespace osu.Game.Rulesets.Mania.Mods
{ {
private readonly Box gradient; private readonly Box gradient;
private readonly Box filled; private readonly Box filled;
private bool reversed;
private readonly Bindable<ManiaScrollingDirection> scrollDirection = new Bindable<ManiaScrollingDirection>();
public LaneCover(bool reversed) public LaneCover()
{ {
Blending = new BlendingParameters Blending = new BlendingParameters
{ {
@ -80,8 +83,6 @@ namespace osu.Game.Rulesets.Mania.Mods
RelativeSizeAxes = Axes.Both RelativeSizeAxes = Axes.Both
} }
}; };
Reversed = reversed;
} }
private void updateCoverage() private void updateCoverage()
@ -97,6 +98,12 @@ namespace osu.Game.Rulesets.Mania.Mods
); );
} }
private void onScrollDirectionChanged(ValueChangedEvent<ManiaScrollingDirection> valueChangedEvent)
{
reversed = valueChangedEvent.NewValue == ManiaScrollingDirection.Up;
updateCoverage();
}
private float coverage; private float coverage;
public float Coverage public float Coverage
@ -112,28 +119,11 @@ namespace osu.Game.Rulesets.Mania.Mods
} }
} }
private bool reversed;
public bool Reversed
{
set
{
if (reversed == value)
return;
reversed = value;
updateCoverage();
}
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(ManiaRulesetConfigManager configManager) private void load(ManiaRulesetConfigManager configManager)
{ {
var scrollDirection = configManager.GetBindable<ManiaScrollingDirection>(ManiaRulesetSetting.ScrollDirection); scrollDirection.BindTo(configManager.GetBindable<ManiaScrollingDirection>(ManiaRulesetSetting.ScrollDirection));
scrollDirection.BindValueChanged(onScrollDirectionChanged, true);
if (scrollDirection.Value == ManiaScrollingDirection.Up)
Reversed = !reversed;
} }
} }
} }