From 5265d33c126c612a787bed98fa1c665d061c78c0 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 6 Feb 2024 23:32:54 +0900 Subject: [PATCH] Make coverage into a bindable --- .../TestScenePlayfieldCoveringContainer.cs | 12 ++++---- .../Mods/ManiaModPlayfieldCover.cs | 2 +- .../UI/PlayfieldCoveringWrapper.cs | 28 +++++++++++-------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/osu.Game.Rulesets.Mania.Tests/TestScenePlayfieldCoveringContainer.cs b/osu.Game.Rulesets.Mania.Tests/TestScenePlayfieldCoveringContainer.cs index 2a8dc715f9..341d52afcf 100644 --- a/osu.Game.Rulesets.Mania.Tests/TestScenePlayfieldCoveringContainer.cs +++ b/osu.Game.Rulesets.Mania.Tests/TestScenePlayfieldCoveringContainer.cs @@ -39,18 +39,18 @@ public TestScenePlayfieldCoveringContainer() public void TestScrollingDownwards() { AddStep("set down scroll", () => scrollingContainer.Direction = ScrollingDirection.Down); - AddStep("set coverage = 0.5", () => cover.Coverage = 0.5f); - AddStep("set coverage = 0.8f", () => cover.Coverage = 0.8f); - AddStep("set coverage = 0.2f", () => cover.Coverage = 0.2f); + AddStep("set coverage = 0.5", () => cover.Coverage.Value = 0.5f); + AddStep("set coverage = 0.8f", () => cover.Coverage.Value = 0.8f); + AddStep("set coverage = 0.2f", () => cover.Coverage.Value = 0.2f); } [Test] public void TestScrollingUpwards() { AddStep("set up scroll", () => scrollingContainer.Direction = ScrollingDirection.Up); - AddStep("set coverage = 0.5", () => cover.Coverage = 0.5f); - AddStep("set coverage = 0.8f", () => cover.Coverage = 0.8f); - AddStep("set coverage = 0.2f", () => cover.Coverage = 0.2f); + AddStep("set coverage = 0.5", () => cover.Coverage.Value = 0.5f); + AddStep("set coverage = 0.8f", () => cover.Coverage.Value = 0.8f); + AddStep("set coverage = 0.2f", () => cover.Coverage.Value = 0.2f); } } } diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModPlayfieldCover.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModPlayfieldCover.cs index bc76c5cfe9..18c3ecc073 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModPlayfieldCover.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModPlayfieldCover.cs @@ -41,7 +41,7 @@ public virtual void ApplyToDrawableRuleset(DrawableRuleset drawa { c.RelativeSizeAxes = Axes.Both; c.Direction = ExpandDirection; - c.Coverage = Coverage.Value; + c.Coverage.BindTo(Coverage); })); } } diff --git a/osu.Game.Rulesets.Mania/UI/PlayfieldCoveringWrapper.cs b/osu.Game.Rulesets.Mania/UI/PlayfieldCoveringWrapper.cs index 92f471e36b..0956b2f98f 100644 --- a/osu.Game.Rulesets.Mania/UI/PlayfieldCoveringWrapper.cs +++ b/osu.Game.Rulesets.Mania/UI/PlayfieldCoveringWrapper.cs @@ -19,6 +19,11 @@ namespace osu.Game.Rulesets.Mania.UI /// public partial class PlayfieldCoveringWrapper : CompositeDrawable { + /// + /// The relative area that should be completely covered. This does not include the fade. + /// + public readonly BindableFloat Coverage = new BindableFloat(); + /// /// The complete cover, including gradient and fill. /// @@ -94,21 +99,20 @@ private void load(IScrollingInfo scrollingInfo) scrollDirection.BindValueChanged(onScrollDirectionChanged, true); } + protected override void LoadComplete() + { + base.LoadComplete(); + + Coverage.BindValueChanged(c => + { + filled.Height = c.NewValue; + gradient.Y = -c.NewValue; + }, true); + } + private void onScrollDirectionChanged(ValueChangedEvent direction) => cover.Rotation = direction.NewValue == ScrollingDirection.Up ? 0 : 180f; - /// - /// The relative area that should be completely covered. This does not include the fade. - /// - public float Coverage - { - set - { - filled.Height = value; - gradient.Y = -value; - } - } - /// /// The direction in which the cover expands. ///