Skip to content

Commit

Permalink
Allow toggling SVs in the editor
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Aug 15, 2023
1 parent ec9e7f1 commit 9ce84e6
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 50 deletions.
3 changes: 1 addition & 2 deletions osu.Game.Rulesets.Catch/UI/DrawableCatchRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ namespace osu.Game.Rulesets.Catch.UI
{
public partial class DrawableCatchRuleset : DrawableScrollingRuleset<CatchHitObject>
{
protected override ScrollVisualisationMethod VisualisationMethod => ScrollVisualisationMethod.Constant;

protected override bool UserScrollSpeedAdjustment => false;

public DrawableCatchRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList<Mod>? mods = null)
: base(ruleset, beatmap, mods)
{
Direction.Value = ScrollingDirection.Down;
TimeRange.Value = GetTimeRange(beatmap.Difficulty.ApproachRate);
VisualisationMethod = ScrollVisualisationMethod.Constant;
}

[BackgroundDependencyLoader]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private class TestScrollingInfo : IScrollingInfo

IBindable<ScrollingDirection> IScrollingInfo.Direction => Direction;
IBindable<double> IScrollingInfo.TimeRange { get; } = new Bindable<double>(5000);
IScrollAlgorithm IScrollingInfo.Algorithm { get; } = new ConstantScrollAlgorithm();
IBindable<IScrollAlgorithm> IScrollingInfo.Algorithm { get; } = new Bindable<IScrollAlgorithm>(new ConstantScrollAlgorithm());
}
}
}
17 changes: 16 additions & 1 deletion osu.Game.Rulesets.Mania/Edit/DrawableManiaEditorRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// 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;
Expand All @@ -15,12 +17,25 @@ namespace osu.Game.Rulesets.Mania.Edit
{
public partial class DrawableManiaEditorRuleset : DrawableManiaRuleset
{
public readonly IBindable<TernaryState> ShowSpeedChanges = new Bindable<TernaryState>();

public new IScrollingInfo ScrollingInfo => base.ScrollingInfo;

public DrawableManiaEditorRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList<Mod>? mods)
: base(ruleset, beatmap, mods)
{
ScrollMethod = ScrollVisualisationMethod.Constant;
}

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)
Expand Down
28 changes: 27 additions & 1 deletion osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
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;
Expand All @@ -16,13 +21,16 @@
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<ManiaHitObject>
{
private readonly Bindable<TernaryState> showSpeedChanges = new Bindable<TernaryState>();

private DrawableManiaEditorRuleset drawableRuleset;
private ManiaBeatSnapGrid beatSnapGrid;
private InputManager inputManager;
Expand All @@ -36,6 +44,21 @@ public ManiaHitObjectComposer(Ruleset ruleset)
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()
Expand All @@ -59,7 +82,10 @@ protected override Playfield PlayfieldAtScreenSpacePosition(Vector2 screenSpaceP

protected override DrawableRuleset<ManiaHitObject> CreateDrawableRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList<Mod> mods = null)
{
drawableRuleset = new DrawableManiaEditorRuleset(ruleset, beatmap, mods);
drawableRuleset = new DrawableManiaEditorRuleset(ruleset, beatmap, mods)
{
ShowSpeedChanges = { BindTarget = showSpeedChanges }
};

// 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);
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Mania/Mods/ManiaModConstantSpeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ManiaModConstantSpeed : Mod, IApplicableToDrawableRuleset<ManiaHitO
public void ApplyToDrawableRuleset(DrawableRuleset<ManiaHitObject> drawableRuleset)
{
var maniaRuleset = (DrawableManiaRuleset)drawableRuleset;
maniaRuleset.ScrollMethod = ScrollVisualisationMethod.Constant;
maniaRuleset.VisualisationMethod = ScrollVisualisationMethod.Constant;
}
}
}
17 changes: 3 additions & 14 deletions osu.Game.Rulesets.Mania/UI/DrawableManiaRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#nullable disable

using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
Expand Down Expand Up @@ -52,22 +51,12 @@ public partial class DrawableManiaRuleset : DrawableScrollingRuleset<ManiaHitObj

protected new ManiaRulesetConfigManager Config => (ManiaRulesetConfigManager)base.Config;

public ScrollVisualisationMethod ScrollMethod
public new ScrollVisualisationMethod VisualisationMethod
{
get => scrollMethod;
set
{
if (IsLoaded)
throw new InvalidOperationException($"Can't alter {nameof(ScrollMethod)} after ruleset is already loaded");

scrollMethod = value;
}
get => base.VisualisationMethod;
set => base.VisualisationMethod = value;
}

private ScrollVisualisationMethod scrollMethod = ScrollVisualisationMethod.Sequential;

protected override ScrollVisualisationMethod VisualisationMethod => scrollMethod;

private readonly Bindable<ManiaScrollingDirection> configDirection = new Bindable<ManiaScrollingDirection>();
private readonly BindableInt configScrollSpeed = new BindableInt();
private double smoothTimeRange;
Expand Down
3 changes: 1 addition & 2 deletions osu.Game.Rulesets.Taiko/UI/DrawableTaikoRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public partial class DrawableTaikoRuleset : DrawableScrollingRuleset<TaikoHitObj

public new TaikoInputManager KeyBindingInputManager => (TaikoInputManager)base.KeyBindingInputManager;

protected override ScrollVisualisationMethod VisualisationMethod => ScrollVisualisationMethod.Overlapping;

protected override bool UserScrollSpeedAdjustment => false;

private SkinnableDrawable scroller;
Expand All @@ -45,6 +43,7 @@ public DrawableTaikoRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList<Mod
: base(ruleset, beatmap, mods)
{
Direction.Value = ScrollingDirection.Left;
VisualisationMethod = ScrollVisualisationMethod.Overlapping;
}

[BackgroundDependencyLoader]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,13 @@ private partial class TestDrawableScrollingRuleset : DrawableScrollingRuleset<Te

protected override bool RelativeScaleBeatLengths => RelativeScaleBeatLengthsOverride;

protected override ScrollVisualisationMethod VisualisationMethod => ScrollVisualisationMethod.Overlapping;

public new Bindable<double> TimeRange => base.TimeRange;

public TestDrawableScrollingRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList<Mod> mods = null)
: base(ruleset, beatmap, mods)
{
TimeRange.Value = time_range;
VisualisationMethod = ScrollVisualisationMethod.Overlapping;
}

public override DrawableHitObject<TestHitObject> CreateDrawableRepresentation(TestHitObject h)
Expand Down
51 changes: 34 additions & 17 deletions osu.Game/Rulesets/UI/Scrolling/DrawableScrollingRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ public abstract partial class DrawableScrollingRuleset<TObject> : DrawableRulese
MaxValue = time_span_max
};

protected virtual ScrollVisualisationMethod VisualisationMethod => ScrollVisualisationMethod.Sequential;

ScrollVisualisationMethod IDrawableScrollingRuleset.VisualisationMethod => VisualisationMethod;

/// <summary>
Expand Down Expand Up @@ -99,20 +97,7 @@ protected DrawableScrollingRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyL
[BackgroundDependencyLoader]
private void load()
{
switch (VisualisationMethod)
{
case ScrollVisualisationMethod.Sequential:
scrollingInfo.Algorithm = new SequentialScrollAlgorithm(ControlPoints);
break;

case ScrollVisualisationMethod.Overlapping:
scrollingInfo.Algorithm = new OverlappingScrollAlgorithm(ControlPoints);
break;

case ScrollVisualisationMethod.Constant:
scrollingInfo.Algorithm = new ConstantScrollAlgorithm();
break;
}
updateScrollAlgorithm();

double lastObjectTime = Beatmap.HitObjects.Any() ? Beatmap.GetLastObjectTime() : double.MaxValue;
double baseBeatLength = TimingControlPoint.DEFAULT_BEAT_LENGTH;
Expand Down Expand Up @@ -178,6 +163,36 @@ protected override void LoadComplete()
throw new ArgumentException($"{nameof(Playfield)} must be a {nameof(ScrollingPlayfield)} when using {nameof(DrawableScrollingRuleset<TObject>)}.");
}

private ScrollVisualisationMethod visualisationMethod = ScrollVisualisationMethod.Sequential;

protected ScrollVisualisationMethod VisualisationMethod
{
get => visualisationMethod;
set
{
visualisationMethod = value;
updateScrollAlgorithm();
}
}

private void updateScrollAlgorithm()
{
switch (VisualisationMethod)
{
case ScrollVisualisationMethod.Sequential:
scrollingInfo.Algorithm.Value = new SequentialScrollAlgorithm(ControlPoints);
break;

case ScrollVisualisationMethod.Overlapping:
scrollingInfo.Algorithm.Value = new OverlappingScrollAlgorithm(ControlPoints);
break;

case ScrollVisualisationMethod.Constant:
scrollingInfo.Algorithm.Value = new ConstantScrollAlgorithm();
break;
}
}

/// <summary>
/// Adjusts the scroll speed of <see cref="HitObject"/>s.
/// </summary>
Expand Down Expand Up @@ -217,7 +232,9 @@ private class LocalScrollingInfo : IScrollingInfo

public IBindable<double> TimeRange { get; } = new BindableDouble();

public IScrollAlgorithm Algorithm { get; set; }
public readonly Bindable<IScrollAlgorithm> Algorithm = new Bindable<IScrollAlgorithm>(new ConstantScrollAlgorithm());

IBindable<IScrollAlgorithm> IScrollingInfo.Algorithm => Algorithm;
}
}
}
4 changes: 2 additions & 2 deletions osu.Game/Rulesets/UI/Scrolling/IScrollingInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public interface IScrollingInfo
IBindable<ScrollingDirection> Direction { get; }

/// <summary>
///
/// The span of time that is visible by the length of the scrolling axes.
/// </summary>
IBindable<double> TimeRange { get; }

/// <summary>
/// The algorithm which controls <see cref="HitObject"/> positions and sizes.
/// </summary>
IScrollAlgorithm Algorithm { get; }
IBindable<IScrollAlgorithm> Algorithm { get; }
}
}
14 changes: 9 additions & 5 deletions osu.Game/Rulesets/UI/Scrolling/ScrollingHitObjectContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.UI.Scrolling.Algorithms;
using osuTK;

namespace osu.Game.Rulesets.UI.Scrolling
Expand All @@ -21,6 +22,7 @@ public partial class ScrollingHitObjectContainer : HitObjectContainer
{
private readonly IBindable<double> timeRange = new BindableDouble();
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
private readonly IBindable<IScrollAlgorithm> algorithm = new Bindable<IScrollAlgorithm>();

/// <summary>
/// Whether the scrolling direction is horizontal or vertical.
Expand Down Expand Up @@ -59,9 +61,11 @@ private void load()
{
direction.BindTo(scrollingInfo.Direction);
timeRange.BindTo(scrollingInfo.TimeRange);
algorithm.BindTo(scrollingInfo.Algorithm);

direction.ValueChanged += _ => layoutCache.Invalidate();
timeRange.ValueChanged += _ => layoutCache.Invalidate();
algorithm.ValueChanged += _ => layoutCache.Invalidate();
}

/// <summary>
Expand All @@ -73,7 +77,7 @@ private void load()
public double TimeAtPosition(float localPosition, double currentTime)
{
float scrollPosition = axisInverted ? -localPosition : localPosition;
return scrollingInfo.Algorithm.TimeAt(scrollPosition, currentTime, timeRange.Value, scrollLength);
return algorithm.Value.TimeAt(scrollPosition, currentTime, timeRange.Value, scrollLength);
}

/// <summary>
Expand All @@ -95,7 +99,7 @@ public double TimeAtScreenSpacePosition(Vector2 screenSpacePosition)
/// </summary>
public float PositionAtTime(double time, double currentTime, double? originTime = null)
{
float scrollPosition = scrollingInfo.Algorithm.PositionAt(time, currentTime, timeRange.Value, scrollLength, originTime);
float scrollPosition = algorithm.Value.PositionAt(time, currentTime, timeRange.Value, scrollLength, originTime);
return axisInverted ? -scrollPosition : scrollPosition;
}

Expand All @@ -122,7 +126,7 @@ public Vector2 ScreenSpacePositionAtTime(double time)
/// </summary>
public float LengthAtTime(double startTime, double endTime)
{
return scrollingInfo.Algorithm.GetLength(startTime, endTime, timeRange.Value, scrollLength);
return algorithm.Value.GetLength(startTime, endTime, timeRange.Value, scrollLength);
}

private float scrollLength => scrollingAxis == Direction.Horizontal ? DrawWidth : DrawHeight;
Expand Down Expand Up @@ -169,7 +173,7 @@ protected override void Update()
foreach (var entry in Entries)
setComputedLifetimeStart(entry);

scrollingInfo.Algorithm.Reset();
algorithm.Value.Reset();

layoutCache.Validate();
}
Expand Down Expand Up @@ -224,7 +228,7 @@ private double computeDisplayStartTime(HitObjectLifetimeEntry entry)
break;
}

return scrollingInfo.Algorithm.GetDisplayStartTime(entry.HitObject.StartTime, startOffset, timeRange.Value, scrollLength);
return algorithm.Value.GetDisplayStartTime(entry.HitObject.StartTime, startOffset, timeRange.Value, scrollLength);
}

private void setComputedLifetimeStart(HitObjectLifetimeEntry entry)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace osu.Game.Screens.Edit.Components.TernaryButtons
{
internal partial class DrawableTernaryButton : OsuButton
public partial class DrawableTernaryButton : OsuButton
{
private Color4 defaultBackgroundColour;
private Color4 defaultIconColour;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Tests/Visual/ScrollingTestContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class TestScrollingInfo : IScrollingInfo
IBindable<double> IScrollingInfo.TimeRange => TimeRange;

public readonly TestScrollAlgorithm Algorithm = new TestScrollAlgorithm();
IScrollAlgorithm IScrollingInfo.Algorithm => Algorithm;
IBindable<IScrollAlgorithm> IScrollingInfo.Algorithm => new Bindable<IScrollAlgorithm>(Algorithm);
}

public class TestScrollAlgorithm : IScrollAlgorithm
Expand Down

0 comments on commit 9ce84e6

Please sign in to comment.