From 37c2b330a235a99fe999be7975c256325fa8c50a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 1 Sep 2023 19:49:57 +0900 Subject: [PATCH] Move toggle implementation to work on all scrolling rulesets automatically --- .../Edit/CatchHitObjectComposer.cs | 1 + .../Mods/TestSceneManiaModConstantSpeed.cs | 2 +- .../Edit/DrawableManiaEditorRuleset.cs | 19 +----- .../Edit/ManiaHitObjectComposer.cs | 30 +-------- .../Edit/TaikoHitObjectComposer.cs | 2 +- .../Edit/DistancedHitObjectComposer.cs | 2 +- osu.Game/Rulesets/Edit/HitObjectComposer.cs | 5 +- .../Edit/ScrollingHitObjectComposer.cs | 62 +++++++++++++++++++ 8 files changed, 73 insertions(+), 50 deletions(-) create mode 100644 osu.Game/Rulesets/Edit/ScrollingHitObjectComposer.cs diff --git a/osu.Game.Rulesets.Catch/Edit/CatchHitObjectComposer.cs b/osu.Game.Rulesets.Catch/Edit/CatchHitObjectComposer.cs index f2877572e8..136a78b343 100644 --- a/osu.Game.Rulesets.Catch/Edit/CatchHitObjectComposer.cs +++ b/osu.Game.Rulesets.Catch/Edit/CatchHitObjectComposer.cs @@ -26,6 +26,7 @@ using osuTK; namespace osu.Game.Rulesets.Catch.Edit { public partial class CatchHitObjectComposer : DistancedHitObjectComposer + // we're also a ScrollingHitObjectComposer candidate, but can't be everything can we? { private const float distance_snap_radius = 50; diff --git a/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModConstantSpeed.cs b/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModConstantSpeed.cs index dc4f660a45..474430414c 100644 --- a/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModConstantSpeed.cs +++ b/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneManiaModConstantSpeed.cs @@ -24,7 +24,7 @@ namespace osu.Game.Rulesets.Mania.Tests.Mods PassCondition = () => { var hitObject = Player.ChildrenOfType().FirstOrDefault(); - return hitObject?.Dependencies.Get().Algorithm is ConstantScrollAlgorithm; + return hitObject?.Dependencies.Get().Algorithm.Value is ConstantScrollAlgorithm; } }); } diff --git a/osu.Game.Rulesets.Mania/Edit/DrawableManiaEditorRuleset.cs b/osu.Game.Rulesets.Mania/Edit/DrawableManiaEditorRuleset.cs index 013dd3dcbd..1741dad5d6 100644 --- a/osu.Game.Rulesets.Mania/Edit/DrawableManiaEditorRuleset.cs +++ b/osu.Game.Rulesets.Mania/Edit/DrawableManiaEditorRuleset.cs @@ -2,23 +2,18 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; -using osu.Framework.Bindables; using osu.Framework.Graphics; -using osuTK; using osu.Game.Beatmaps; -using osu.Game.Configuration; -using osu.Game.Graphics.UserInterface; using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI.Scrolling; +using osuTK; namespace osu.Game.Rulesets.Mania.Edit { public partial class DrawableManiaEditorRuleset : DrawableManiaRuleset { - public readonly IBindable ShowSpeedChanges = new Bindable(); - public new IScrollingInfo ScrollingInfo => base.ScrollingInfo; public DrawableManiaEditorRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList? mods) @@ -26,18 +21,6 @@ namespace osu.Game.Rulesets.Mania.Edit { } - protected override void LoadComplete() - { - base.LoadComplete(); - - ShowSpeedChanges.BindValueChanged(state => - { - VisualisationMethod = state.NewValue == TernaryState.True - ? ScrollVisualisationMethod.Sequential - : ScrollVisualisationMethod.Constant; - }, true); - } - protected override Playfield CreatePlayfield() => new ManiaEditorPlayfield(Beatmap.Stages) { Anchor = Anchor.Centre, diff --git a/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs b/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs index 44e238efac..9bde9485b2 100644 --- a/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs +++ b/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs @@ -6,13 +6,8 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; -using osu.Framework.Bindables; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; using osu.Framework.Input; using osu.Game.Beatmaps; -using osu.Game.Graphics.UserInterface; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit.Tools; using osu.Game.Rulesets.Mania.Objects; @@ -21,16 +16,13 @@ using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI.Scrolling; -using osu.Game.Screens.Edit.Components.TernaryButtons; using osu.Game.Screens.Edit.Compose.Components; using osuTK; namespace osu.Game.Rulesets.Mania.Edit { - public partial class ManiaHitObjectComposer : HitObjectComposer + public partial class ManiaHitObjectComposer : ScrollingHitObjectComposer { - private readonly Bindable showSpeedChanges = new Bindable(); - private DrawableManiaEditorRuleset drawableRuleset; private ManiaBeatSnapGrid beatSnapGrid; private InputManager inputManager; @@ -44,21 +36,6 @@ namespace osu.Game.Rulesets.Mania.Edit private void load() { AddInternal(beatSnapGrid = new ManiaBeatSnapGrid()); - - LeftToolbox.Add(new EditorToolboxGroup("playfield") - { - Child = new FillFlowContainer - { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Direction = FillDirection.Vertical, - Spacing = new Vector2(0, 5), - Children = new[] - { - new DrawableTernaryButton(new TernaryButton(showSpeedChanges, "Show speed changes", () => new SpriteIcon { Icon = FontAwesome.Solid.TachometerAlt })) - } - }, - }); } protected override void LoadComplete() @@ -82,10 +59,7 @@ namespace osu.Game.Rulesets.Mania.Edit protected override DrawableRuleset CreateDrawableRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList mods = null) { - drawableRuleset = new DrawableManiaEditorRuleset(ruleset, beatmap, mods) - { - ShowSpeedChanges = { BindTarget = showSpeedChanges } - }; + drawableRuleset = new DrawableManiaEditorRuleset(ruleset, beatmap, mods); // This is the earliest we can cache the scrolling info to ourselves, before masks are added to the hierarchy and inject it dependencies.CacheAs(drawableRuleset.ScrollingInfo); diff --git a/osu.Game.Rulesets.Taiko/Edit/TaikoHitObjectComposer.cs b/osu.Game.Rulesets.Taiko/Edit/TaikoHitObjectComposer.cs index 3e63d624e7..fbad8c7fad 100644 --- a/osu.Game.Rulesets.Taiko/Edit/TaikoHitObjectComposer.cs +++ b/osu.Game.Rulesets.Taiko/Edit/TaikoHitObjectComposer.cs @@ -9,7 +9,7 @@ using osu.Game.Screens.Edit.Compose.Components; namespace osu.Game.Rulesets.Taiko.Edit { - public partial class TaikoHitObjectComposer : HitObjectComposer + public partial class TaikoHitObjectComposer : ScrollingHitObjectComposer { protected override bool ApplyHorizontalCentering => false; diff --git a/osu.Game/Rulesets/Edit/DistancedHitObjectComposer.cs b/osu.Game/Rulesets/Edit/DistancedHitObjectComposer.cs index 817e8bd5fe..d1db8cb1f1 100644 --- a/osu.Game/Rulesets/Edit/DistancedHitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/DistancedHitObjectComposer.cs @@ -62,7 +62,7 @@ namespace osu.Game.Rulesets.Edit } [BackgroundDependencyLoader] - private void load(OverlayColourProvider colourProvider) + private void load() { RightToolbox.Add(new EditorToolboxGroup("snapping") { diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index c967187b5c..295a016c7b 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -87,6 +87,8 @@ namespace osu.Game.Rulesets.Edit private IBindable hasTiming; private Bindable autoSeekOnPlacement; + protected DrawableRuleset DrawableRuleset { get; private set; } + protected HitObjectComposer(Ruleset ruleset) : base(ruleset) { @@ -104,7 +106,8 @@ namespace osu.Game.Rulesets.Edit try { - drawableRulesetWrapper = new DrawableEditorRulesetWrapper(CreateDrawableRuleset(Ruleset, EditorBeatmap.PlayableBeatmap, new[] { Ruleset.GetAutoplayMod() })) + DrawableRuleset = CreateDrawableRuleset(Ruleset, EditorBeatmap.PlayableBeatmap, new[] { Ruleset.GetAutoplayMod() }); + drawableRulesetWrapper = new DrawableEditorRulesetWrapper(DrawableRuleset) { Clock = EditorClock, ProcessCustomClock = false diff --git a/osu.Game/Rulesets/Edit/ScrollingHitObjectComposer.cs b/osu.Game/Rulesets/Edit/ScrollingHitObjectComposer.cs new file mode 100644 index 0000000000..0340354016 --- /dev/null +++ b/osu.Game/Rulesets/Edit/ScrollingHitObjectComposer.cs @@ -0,0 +1,62 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Game.Configuration; +using osu.Game.Graphics.UserInterface; +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.UI.Scrolling; +using osu.Game.Screens.Edit.Components.TernaryButtons; +using osuTK; + +namespace osu.Game.Rulesets.Edit +{ + public abstract partial class ScrollingHitObjectComposer : HitObjectComposer + where TObject : HitObject + { + private readonly Bindable showSpeedChanges = new Bindable(); + + protected ScrollingHitObjectComposer(Ruleset ruleset) + : base(ruleset) + { + } + + [BackgroundDependencyLoader] + private void load() + { + if (DrawableRuleset is DrawableScrollingRuleset drawableScrollingRuleset) + { + var originalVisualisationMethod = drawableScrollingRuleset.VisualisationMethod; + + if (originalVisualisationMethod != ScrollVisualisationMethod.Constant) + { + LeftToolbox.Add(new EditorToolboxGroup("playfield") + { + Child = new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 5), + Children = new[] + { + new DrawableTernaryButton(new TernaryButton(showSpeedChanges, "Show speed changes", () => new SpriteIcon { Icon = FontAwesome.Solid.TachometerAlt })) + } + }, + }); + + showSpeedChanges.BindValueChanged(state => + { + drawableScrollingRuleset.VisualisationMethod = state.NewValue == TernaryState.True + ? originalVisualisationMethod + : ScrollVisualisationMethod.Constant; + }, true); + } + } + } + } +}