diff --git a/osu-framework b/osu-framework index 107c551767..67d89a3601 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 107c5517670ca88dbe8c83a97e37e99ac5742ee6 +Subproject commit 67d89a36016f98c0ede576b859a2ccafe114fce8 diff --git a/osu-resources b/osu-resources index 76656c51f2..f6042e1cb3 160000 --- a/osu-resources +++ b/osu-resources @@ -1 +1 @@ -Subproject commit 76656c51f281e7934159e9ed4414378fef24d130 +Subproject commit f6042e1cb37cfad6c879d0e1245f7880c7fcd5f5 diff --git a/osu.Desktop.Tests/Visual/TestCaseCatcher.cs b/osu.Desktop.Tests/Visual/TestCaseCatcher.cs new file mode 100644 index 0000000000..3f57b5eeb9 --- /dev/null +++ b/osu.Desktop.Tests/Visual/TestCaseCatcher.cs @@ -0,0 +1,35 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Game.Rulesets; +using osu.Game.Rulesets.Catch; +using osu.Game.Rulesets.Catch.UI; +using OpenTK; + +namespace osu.Desktop.Tests.Visual +{ + internal class TestCaseCatcher : OsuTestCase + { + [BackgroundDependencyLoader] + private void load(RulesetStore rulesets) + { + Children = new Drawable[] + { + new CatchInputManager(rulesets.GetRuleset(2)) + { + RelativeSizeAxes = Axes.Both, + Child = new CatcherArea + { + RelativePositionAxes = Axes.Both, + RelativeSizeAxes = Axes.Both, + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Size = new Vector2(1, 0.2f), + } + }, + }; + } + } +} diff --git a/osu.Desktop.Tests/Visual/TestCaseGamefield.cs b/osu.Desktop.Tests/Visual/TestCaseGamefield.cs index 9d61c9ab0c..73c61f5669 100644 --- a/osu.Desktop.Tests/Visual/TestCaseGamefield.cs +++ b/osu.Desktop.Tests/Visual/TestCaseGamefield.cs @@ -11,11 +11,15 @@ using osu.Framework.Timing; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; using osu.Game.Rulesets; +using osu.Game.Rulesets.Catch; using osu.Game.Rulesets.Catch.UI; +using osu.Game.Rulesets.Mania; using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.UI; +using osu.Game.Rulesets.Taiko; using osu.Game.Rulesets.Taiko.UI; using OpenTK; @@ -84,25 +88,25 @@ namespace osu.Desktop.Tests.Visual Clock = new FramedClock(), Children = new Drawable[] { - new OsuHitRenderer(beatmap, false) + new OsuRulesetContainer(new OsuRuleset(new RulesetInfo()), beatmap, false) { Scale = new Vector2(0.5f), Anchor = Anchor.TopLeft, Origin = Anchor.TopLeft }, - new TaikoHitRenderer(beatmap, false) + new TaikoRulesetContainer(new TaikoRuleset(new RulesetInfo()),beatmap, false) { Scale = new Vector2(0.5f), Anchor = Anchor.TopRight, Origin = Anchor.TopRight }, - new CatchHitRenderer(beatmap, false) + new CatchRulesetContainer(new CatchRuleset(new RulesetInfo()),beatmap, false) { Scale = new Vector2(0.5f), Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft }, - new ManiaHitRenderer(beatmap, false) + new ManiaRulesetContainer(new ManiaRuleset(new RulesetInfo()),beatmap, false) { Scale = new Vector2(0.5f), Anchor = Anchor.BottomRight, diff --git a/osu.Desktop.Tests/Visual/TestCaseScrollingHitObjects.cs b/osu.Desktop.Tests/Visual/TestCaseScrollingHitObjects.cs deleted file mode 100644 index efc129a678..0000000000 --- a/osu.Desktop.Tests/Visual/TestCaseScrollingHitObjects.cs +++ /dev/null @@ -1,209 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Framework.Configuration; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.UserInterface; -using osu.Game.Graphics.Sprites; -using osu.Game.Rulesets.Objects; -using osu.Game.Rulesets.Objects.Drawables; -using osu.Game.Rulesets.Timing; -using OpenTK; -using OpenTK.Graphics; - -namespace osu.Desktop.Tests.Visual -{ - public class TestCaseScrollingHitObjects : OsuTestCase - { - public override string Description => "SpeedAdjustmentContainer/DrawableTimingSection"; - - private readonly BindableDouble timeRangeBindable; - private readonly OsuSpriteText bottomLabel; - private readonly SpriteText topTime; - private readonly SpriteText bottomTime; - - public TestCaseScrollingHitObjects() - { - OsuSpriteText timeRangeText; - SpeedAdjustmentCollection adjustmentCollection; - - timeRangeBindable = new BindableDouble(2000) - { - MinValue = 200, - MaxValue = 4000, - }; - - SliderBar timeRange; - Add(timeRange = new BasicSliderBar - { - Size = new Vector2(200, 20), - SelectionColor = Color4.Pink, - KeyboardStep = 100 - }); - - Add(timeRangeText = new OsuSpriteText - { - X = 210, - TextSize = 16, - }); - - timeRange.Current.BindTo(timeRangeBindable); - timeRangeBindable.ValueChanged += v => timeRangeText.Text = $"Visible Range: {v:#,#.#}"; - timeRangeBindable.ValueChanged += v => bottomLabel.Text = $"t minus {v:#,#}"; - - AddRange(new Drawable[] - { - new Container - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Size = new Vector2(100, 500), - Children = new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Alpha = 0.25f - }, - adjustmentCollection = new SpeedAdjustmentCollection(Axes.Y) - { - RelativeSizeAxes = Axes.Both, - VisibleTimeRange = timeRangeBindable, - Masking = true, - }, - new OsuSpriteText - { - Text = "t minus 0", - Margin = new MarginPadding(2), - TextSize = 14, - Anchor = Anchor.TopRight, - }, - bottomLabel = new OsuSpriteText - { - Text = "t minus x", - Margin = new MarginPadding(2), - TextSize = 14, - Anchor = Anchor.BottomRight, - Origin = Anchor.BottomLeft, - }, - topTime = new OsuSpriteText - { - Margin = new MarginPadding(2), - TextSize = 14, - Anchor = Anchor.TopLeft, - Origin = Anchor.TopRight, - }, - bottomTime = new OsuSpriteText - { - Margin = new MarginPadding(2), - TextSize = 14, - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomRight, - }, - } - } - }); - - timeRangeBindable.TriggerChange(); - - adjustmentCollection.Add(new TestSpeedAdjustmentContainer(new MultiplierControlPoint())); - - AddStep("Add hit object", () => adjustmentCollection.Add(new TestDrawableHitObject(new HitObject { StartTime = Time.Current + 2000 }))); - } - - protected override void Update() - { - base.Update(); - - topTime.Text = Time.Current.ToString("#,#"); - bottomTime.Text = (Time.Current + timeRangeBindable.Value).ToString("#,#"); - } - - private class TestSpeedAdjustmentContainer : SpeedAdjustmentContainer - { - public override bool RemoveWhenNotAlive => false; - - public TestSpeedAdjustmentContainer(MultiplierControlPoint controlPoint) - : base(controlPoint) - { - } - - protected override DrawableTimingSection CreateTimingSection() => new TestDrawableTimingSection(ControlPoint); - - private class TestDrawableTimingSection : DrawableTimingSection - { - private readonly MultiplierControlPoint controlPoint; - - public TestDrawableTimingSection(MultiplierControlPoint controlPoint) - { - this.controlPoint = controlPoint; - } - - protected override void Update() - { - base.Update(); - - Y = (float)(controlPoint.StartTime - Time.Current); - } - } - } - - private class TestDrawableHitObject : DrawableHitObject, IScrollingHitObject - { - private readonly Box background; - private const float height = 14; - - public BindableDouble LifetimeOffset { get; } = new BindableDouble(); - - public TestDrawableHitObject(HitObject hitObject) - : base(hitObject) - { - AutoSizeAxes = Axes.Y; - RelativeSizeAxes = Axes.X; - RelativePositionAxes = Axes.Y; - - Y = (float)hitObject.StartTime; - - Children = new Drawable[] - { - background = new Box - { - RelativeSizeAxes = Axes.X, - Height = height, - }, - new Box - { - RelativeSizeAxes = Axes.X, - Colour = Color4.Cyan, - Height = 1, - }, - new OsuSpriteText - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Colour = Color4.Black, - TextSize = height, - Font = @"Exo2.0-BoldItalic", - Text = $"{hitObject.StartTime:#,#}" - } - }; - } - - protected override void LoadComplete() - { - base.LoadComplete(); - this.FadeInFromZero(250, Easing.OutQuint); - } - - protected override void Update() - { - base.Update(); - if (Time.Current >= HitObject.StartTime) - background.Colour = Color4.Red; - } - } - } -} diff --git a/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs new file mode 100644 index 0000000000..43bd921cfc --- /dev/null +++ b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs @@ -0,0 +1,158 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using OpenTK; +using osu.Desktop.Tests.Beatmaps; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Timing; +using osu.Game.Beatmaps; +using osu.Game.Rulesets.Beatmaps; +using osu.Game.Rulesets.Judgements; +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Rulesets.Scoring; +using osu.Game.Rulesets.UI; + +namespace osu.Desktop.Tests.Visual +{ + /// + /// The most minimal implementation of a playfield with scrolling hit objects. + /// + public class TestCaseScrollingPlayfield : OsuTestCase + { + public TestCaseScrollingPlayfield() + { + Clock = new FramedClock(); + + var objects = new List(); + + int time = 1500; + for (int i = 0; i < 50; i++) + { + objects.Add(new TestHitObject { StartTime = time }); + + time += 500; + } + + Beatmap b = new Beatmap + { + HitObjects = objects, + BeatmapInfo = new BeatmapInfo + { + Difficulty = new BeatmapDifficulty(), + Metadata = new BeatmapMetadata() + } + }; + + WorkingBeatmap beatmap = new TestWorkingBeatmap(b); + + TestRulesetContainer horizontalRulesetContainer; + Add(horizontalRulesetContainer = new TestRulesetContainer(Axes.X, beatmap, true)); + + TestRulesetContainer verticalRulesetContainer; + Add(verticalRulesetContainer = new TestRulesetContainer(Axes.Y, beatmap, true)); + + AddStep("Reverse direction", () => + { + horizontalRulesetContainer.Playfield.Reversed.Toggle(); + verticalRulesetContainer.Playfield.Reversed.Toggle(); + }); + } + + private class TestRulesetContainer : ScrollingRulesetContainer + { + private readonly Axes scrollingAxes; + + public TestRulesetContainer(Axes scrollingAxes, WorkingBeatmap beatmap, bool isForCurrentRuleset) + : base(null, beatmap, isForCurrentRuleset) + { + this.scrollingAxes = scrollingAxes; + } + + public new TestPlayfield Playfield => base.Playfield; + + public override ScoreProcessor CreateScoreProcessor() => new TestScoreProcessor(); + + protected override BeatmapConverter CreateBeatmapConverter() => new TestBeatmapConverter(); + + protected override Playfield CreatePlayfield() => new TestPlayfield(scrollingAxes); + + protected override DrawableHitObject GetVisualRepresentation(TestHitObject h) => new DrawableTestHitObject(scrollingAxes, h); + } + + private class TestScoreProcessor : ScoreProcessor + { + protected override void OnNewJudgement(TestJudgement judgement) + { + } + } + + private class TestBeatmapConverter : BeatmapConverter + { + protected override IEnumerable ValidConversionTypes => new[] { typeof(HitObject) }; + + protected override IEnumerable ConvertHitObject(HitObject original, Beatmap beatmap) + { + yield return original as TestHitObject; + } + } + + private class DrawableTestHitObject : DrawableScrollingHitObject + { + public DrawableTestHitObject(Axes scrollingAxes, TestHitObject hitObject) + : base(hitObject) + { + Anchor = scrollingAxes == Axes.Y ? Anchor.TopCentre : Anchor.CentreLeft; + Origin = Anchor.Centre; + + AutoSizeAxes = Axes.Both; + + Add(new Circle + { + Size = new Vector2(50) + }); + } + + protected override TestJudgement CreateJudgement() => new TestJudgement(); + + protected override void UpdateState(ArmedState state) + { + } + } + + private class TestPlayfield : ScrollingPlayfield + { + protected override Container Content => content; + private readonly Container content; + + public TestPlayfield(Axes scrollingAxes) + : base(scrollingAxes) + { + InternalChildren = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Alpha = 0.2f + }, + content = new Container { RelativeSizeAxes = Axes.Both } + }; + } + } + + + private class TestHitObject : HitObject + { + } + + private class TestJudgement : Judgement + { + public override string ResultString { get { throw new NotImplementedException(); } } + public override string MaxResultString { get { throw new NotImplementedException(); } } + } + } +} \ No newline at end of file diff --git a/osu.Desktop.Tests/osu.Desktop.Tests.csproj b/osu.Desktop.Tests/osu.Desktop.Tests.csproj index 9210b5eb3a..8e742f6ece 100644 --- a/osu.Desktop.Tests/osu.Desktop.Tests.csproj +++ b/osu.Desktop.Tests/osu.Desktop.Tests.csproj @@ -71,6 +71,7 @@ + @@ -98,7 +99,7 @@ - + diff --git a/osu.Desktop/osu.Desktop.csproj b/osu.Desktop/osu.Desktop.csproj index 8ffa6b62f7..bbca4145c6 100644 --- a/osu.Desktop/osu.Desktop.csproj +++ b/osu.Desktop/osu.Desktop.csproj @@ -103,6 +103,7 @@ 6 prompt AllRules.ruleset + --tests diff --git a/osu.Game.Rulesets.Catch/Beatmaps/CatchBeatmapConverter.cs b/osu.Game.Rulesets.Catch/Beatmaps/CatchBeatmapConverter.cs index f9859cd244..d6efe45adf 100644 --- a/osu.Game.Rulesets.Catch/Beatmaps/CatchBeatmapConverter.cs +++ b/osu.Game.Rulesets.Catch/Beatmaps/CatchBeatmapConverter.cs @@ -8,6 +8,7 @@ using System; using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Beatmaps; using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Osu.UI; namespace osu.Game.Rulesets.Catch.Beatmaps { @@ -15,9 +16,16 @@ namespace osu.Game.Rulesets.Catch.Beatmaps { protected override IEnumerable ValidConversionTypes { get; } = new[] { typeof(IHasXPosition) }; - protected override IEnumerable ConvertHitObject(HitObject original, Beatmap beatmap) + protected override IEnumerable ConvertHitObject(HitObject obj, Beatmap beatmap) { - yield return null; + if (!(obj is IHasXPosition)) + yield break; + + yield return new Fruit + { + StartTime = obj.StartTime, + Position = ((IHasXPosition)obj).X / OsuPlayfield.BASE_SIZE.X + }; } } } diff --git a/osu.Game.Rulesets.Catch/CatchInputManager.cs b/osu.Game.Rulesets.Catch/CatchInputManager.cs new file mode 100644 index 0000000000..eada5cf532 --- /dev/null +++ b/osu.Game.Rulesets.Catch/CatchInputManager.cs @@ -0,0 +1,32 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Collections.Generic; +using osu.Game.Input; +using OpenTK.Input; + +namespace osu.Game.Rulesets.Catch +{ + public class CatchInputManager : ActionMappingInputManager + { + public CatchInputManager(RulesetInfo ruleset) : base(ruleset) + { + Mappings = new Dictionary + { + { Key.Z, CatchAction.MoveLeft }, + { Key.Left, CatchAction.MoveLeft }, + { Key.X, CatchAction.MoveRight }, + { Key.Right, CatchAction.MoveRight }, + { Key.LShift, CatchAction.Dash }, + { Key.RShift, CatchAction.Dash }, + }; + } + } + + public enum CatchAction + { + MoveLeft, + MoveRight, + Dash + } +} diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs index dc13329bde..8d45ea8fa2 100644 --- a/osu.Game.Rulesets.Catch/CatchRuleset.cs +++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs @@ -18,7 +18,7 @@ namespace osu.Game.Rulesets.Catch { public class CatchRuleset : Ruleset { - public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new CatchHitRenderer(beatmap, isForCurrentRuleset); + public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new CatchRulesetContainer(this, beatmap, isForCurrentRuleset); public override IEnumerable GetModsFor(ModType type) { @@ -102,5 +102,10 @@ namespace osu.Game.Rulesets.Catch public override ScoreProcessor CreateScoreProcessor() => new CatchScoreProcessor(); public override int LegacyID => 2; + + public CatchRuleset(RulesetInfo rulesetInfo) + : base(rulesetInfo) + { + } } } diff --git a/osu.Game.Rulesets.Catch/Objects/Drawable/DrawableFruit.cs b/osu.Game.Rulesets.Catch/Objects/Drawable/DrawableFruit.cs index 3e7d9bd6d7..62e5c094be 100644 --- a/osu.Game.Rulesets.Catch/Objects/Drawable/DrawableFruit.cs +++ b/osu.Game.Rulesets.Catch/Objects/Drawable/DrawableFruit.cs @@ -1,36 +1,128 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using osu.Framework.Allocation; +using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.Textures; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.MathUtils; +using osu.Game.Graphics; +using osu.Game.Rulesets.Catch.Judgements; +using osu.Game.Rulesets.Objects.Drawables; using OpenTK; +using OpenTK.Graphics; namespace osu.Game.Rulesets.Catch.Objects.Drawable { - internal class DrawableFruit : Sprite + public class DrawableFruit : DrawableScrollingHitObject { - //private readonly CatchBaseHit h; + private const float pulp_size = 30; - public DrawableFruit(CatchBaseHit h) + private class Pulp : Circle, IHasAccentColour { - //this.h = h; + public Pulp() + { + Size = new Vector2(pulp_size); - Origin = Anchor.Centre; - Scale = new Vector2(0.1f); - RelativePositionAxes = Axes.Y; - Position = new Vector2(h.Position, -0.1f); + EdgeEffect = new EdgeEffectParameters + { + Type = EdgeEffectType.Glow, + Radius = 5, + Colour = AccentColour.Opacity(0.5f), + }; + } + + public Color4 AccentColour { get; set; } = Color4.White; } - [BackgroundDependencyLoader] - private void load(TextureStore textures) - { - Texture = textures.Get(@"Menu/logo"); - //Transforms.Add(new TransformPosition { StartTime = h.StartTime - 200, EndTime = h.StartTime, StartValue = new Vector2(h.Position, -0.1f), EndValue = new Vector2(h.Position, 0.9f) }); - //Transforms.Add(new TransformAlpha { StartTime = h.StartTime + duration + 200, EndTime = h.StartTime + duration + 400, StartValue = 1, EndValue = 0 }); - Expire(true); + public DrawableFruit(CatchBaseHit h) + : base(h) + { + Origin = Anchor.Centre; + Size = new Vector2(pulp_size * 2, pulp_size * 2.6f); + + RelativePositionAxes = Axes.Both; + X = h.Position; + + Colour = new Color4(RNG.NextSingle(), RNG.NextSingle(), RNG.NextSingle(), 1); + + Rotation = (float)(RNG.NextDouble() - 0.5f) * 40; + } + + public Func CheckPosition; + + [BackgroundDependencyLoader] + private void load() + { + Children = new Framework.Graphics.Drawable[] + { + //todo: share this more + new BufferedContainer + { + RelativeSizeAxes = Axes.Both, + CacheDrawnFrameBuffer = true, + Children = new Framework.Graphics.Drawable[] + { + new Pulp + { + RelativePositionAxes = Axes.Both, + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Scale = new Vector2(0.6f), + }, + new Pulp + { + RelativePositionAxes = Axes.Both, + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Y = -0.08f + }, + new Pulp + { + RelativePositionAxes = Axes.Both, + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + Y = -0.08f + }, + new Pulp + { + RelativePositionAxes = Axes.Both, + Anchor = Anchor.BottomCentre, + Origin = Anchor.BottomCentre, + }, + } + } + }; + } + + protected override CatchJudgement CreateJudgement() => new CatchJudgement(); + + private const float preempt = 1000; + + protected override void CheckJudgement(bool userTriggered) + { + if (Judgement.TimeOffset > 0) + Judgement.Result = CheckPosition?.Invoke(HitObject) ?? false ? HitResult.Hit : HitResult.Miss; + } + + protected override void UpdateState(ArmedState state) + { + using (BeginAbsoluteSequence(HitObject.StartTime - preempt)) + { + // animation + this.FadeIn(200); + } + + switch (state) + { + case ArmedState.Miss: + using (BeginAbsoluteSequence(HitObject.StartTime, true)) + this.FadeOut(250).RotateTo(Rotation * 2, 250, Easing.Out); + break; + } } } } diff --git a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs index 3f29547e46..33c1355823 100644 --- a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs +++ b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs @@ -14,11 +14,19 @@ namespace osu.Game.Rulesets.Catch.Scoring { } - public CatchScoreProcessor(HitRenderer hitRenderer) - : base(hitRenderer) + public CatchScoreProcessor(RulesetContainer rulesetContainer) + : base(rulesetContainer) { } + protected override void Reset() + { + base.Reset(); + + Health.Value = 1; + Accuracy.Value = 1; + } + protected override void OnNewJudgement(CatchJudgement judgement) { } diff --git a/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs b/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs index 8be52150fc..4ea6d180f3 100644 --- a/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs +++ b/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs @@ -2,23 +2,65 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Graphics; -using osu.Framework.Graphics.Shapes; using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.UI; using OpenTK; using osu.Game.Rulesets.Catch.Judgements; +using osu.Framework.Graphics.Containers; +using osu.Game.Rulesets.Catch.Objects.Drawable; +using osu.Game.Rulesets.Objects.Drawables; namespace osu.Game.Rulesets.Catch.UI { - public class CatchPlayfield : Playfield + public class CatchPlayfield : ScrollingPlayfield { - public CatchPlayfield() - { - Size = new Vector2(1, 0.9f); - Anchor = Anchor.BottomCentre; - Origin = Anchor.BottomCentre; + protected override Container Content => content; + private readonly Container content; + private readonly CatcherArea catcherArea; - Add(new Box { RelativeSizeAxes = Axes.Both, Alpha = 0.5f }); + public CatchPlayfield() + : base(Axes.Y) + { + Reversed.Value = true; + + Size = new Vector2(1); + + Anchor = Anchor.TopCentre; + Origin = Anchor.TopCentre; + + InternalChildren = new Drawable[] + { + content = new Container + { + RelativeSizeAxes = Axes.Both, + }, + catcherArea = new CatcherArea + { + RelativeSizeAxes = Axes.Both, + Anchor = Anchor.BottomLeft, + Origin = Anchor.TopLeft, + Height = 0.3f + } + }; + } + + public override void Add(DrawableHitObject h) + { + base.Add(h); + + var fruit = (DrawableFruit)h; + fruit.CheckPosition = catcherArea.CheckIfWeCanCatch; + fruit.OnJudgement += Fruit_OnJudgement; + } + + private void Fruit_OnJudgement(DrawableHitObject obj) + { + if (obj.Judgement.Result == HitResult.Hit) + { + Vector2 screenPosition = obj.ScreenSpaceDrawQuad.Centre; + Remove(obj); + catcherArea.Add(obj, screenPosition); + } } } -} \ No newline at end of file +} diff --git a/osu.Game.Rulesets.Catch/UI/CatchHitRenderer.cs b/osu.Game.Rulesets.Catch/UI/CatchRulesetContainer.cs similarity index 57% rename from osu.Game.Rulesets.Catch/UI/CatchHitRenderer.cs rename to osu.Game.Rulesets.Catch/UI/CatchRulesetContainer.cs index 179440adb3..27cc05c47a 100644 --- a/osu.Game.Rulesets.Catch/UI/CatchHitRenderer.cs +++ b/osu.Game.Rulesets.Catch/UI/CatchRulesetContainer.cs @@ -1,11 +1,13 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Framework.Input; using osu.Game.Beatmaps; using osu.Game.Rulesets.Beatmaps; using osu.Game.Rulesets.Catch.Beatmaps; using osu.Game.Rulesets.Catch.Judgements; using osu.Game.Rulesets.Catch.Objects; +using osu.Game.Rulesets.Catch.Objects.Drawable; using osu.Game.Rulesets.Catch.Scoring; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Scoring; @@ -13,10 +15,10 @@ using osu.Game.Rulesets.UI; namespace osu.Game.Rulesets.Catch.UI { - public class CatchHitRenderer : HitRenderer + public class CatchRulesetContainer : ScrollingRulesetContainer { - public CatchHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) - : base(beatmap, isForCurrentRuleset) + public CatchRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset) + : base(ruleset, beatmap, isForCurrentRuleset) { } @@ -26,6 +28,14 @@ namespace osu.Game.Rulesets.Catch.UI protected override Playfield CreatePlayfield() => new CatchPlayfield(); - protected override DrawableHitObject GetVisualRepresentation(CatchBaseHit h) => null; + protected override PassThroughInputManager CreateActionMappingInputManager() => new CatchInputManager(Ruleset.RulesetInfo); + + protected override DrawableHitObject GetVisualRepresentation(CatchBaseHit h) + { + if (h is Fruit) + return new DrawableFruit(h); + + return null; + } } } diff --git a/osu.Game.Rulesets.Catch/UI/CatcherArea.cs b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs new file mode 100644 index 0000000000..776f2119ab --- /dev/null +++ b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs @@ -0,0 +1,186 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Linq; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Textures; +using osu.Framework.Input; +using osu.Framework.MathUtils; +using osu.Game.Rulesets.Catch.Judgements; +using osu.Game.Rulesets.Catch.Objects; +using osu.Game.Rulesets.Catch.Objects.Drawable; +using osu.Game.Rulesets.Objects.Drawables; +using OpenTK; + +namespace osu.Game.Rulesets.Catch.UI +{ + public class CatcherArea : Container + { + private Catcher catcher; + + public void Add(DrawableHitObject fruit, Vector2 screenPosition) => catcher.AddToStack(fruit, screenPosition); + + public bool CheckIfWeCanCatch(CatchBaseHit obj) => Math.Abs(catcher.Position.X - obj.Position) < catcher.DrawSize.X / DrawSize.X / 2; + + [BackgroundDependencyLoader] + private void load() + { + Children = new Drawable[] + { + catcher = new Catcher + { + RelativePositionAxes = Axes.Both, + Anchor = Anchor.TopLeft, + Origin = Anchor.TopCentre, + X = 0.5f, + } + }; + } + + protected override void Update() + { + base.Update(); + + catcher.Size = new Vector2(DrawSize.Y); + } + + private class Catcher : Container + { + private Texture texture; + + [BackgroundDependencyLoader] + private void load(TextureStore textures) + { + texture = textures.Get(@"Play/Catch/fruit-catcher-idle"); + + Child = createCatcherSprite(); + } + + private int currentDirection; + + private bool dashing; + + protected bool Dashing + { + get { return dashing; } + set + { + if (value == dashing) return; + + dashing = value; + + if (dashing) + Schedule(addAdditiveSprite); + } + } + + private void addAdditiveSprite() + { + if (!dashing) return; + + var additive = createCatcherSprite(); + + additive.RelativePositionAxes = Axes.Both; + additive.BlendingMode = BlendingMode.Additive; + additive.Position = Position; + additive.Scale = Scale; + + ((CatcherArea)Parent).Add(additive); + + additive.FadeTo(0.4f).FadeOut(800, Easing.OutQuint).Expire(); + + Scheduler.AddDelayed(addAdditiveSprite, 50); + } + + private Sprite createCatcherSprite() => new Sprite + { + RelativeSizeAxes = Axes.Both, + FillMode = FillMode.Fit, + Texture = texture, + OriginPosition = new Vector2(DrawWidth / 2, 10) //temporary until the sprite is aligned correctly. + }; + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + { + if (args.Repeat) return true; + + if (state.Data is CatchAction) + { + switch ((CatchAction)state.Data) + { + case CatchAction.MoveLeft: + currentDirection--; + return true; + case CatchAction.MoveRight: + currentDirection++; + return true; + case CatchAction.Dash: + Dashing = true; + return true; + } + } + + return base.OnKeyDown(state, args); + } + + protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) + { + if (state.Data is CatchAction) + { + switch ((CatchAction)state.Data) + { + case CatchAction.MoveLeft: + currentDirection++; + return true; + case CatchAction.MoveRight: + currentDirection--; + return true; + case CatchAction.Dash: + Dashing = false; + return true; + } + } + + return base.OnKeyUp(state, args); + } + + protected override void Update() + { + base.Update(); + + if (currentDirection == 0) return; + + float speed = Dashing ? 1.5f : 1; + + Scale = new Vector2(Math.Sign(currentDirection), 1); + X = (float)MathHelper.Clamp(X + Math.Sign(currentDirection) * Clock.ElapsedFrameTime / 1800 * speed, 0, 1); + } + + public void AddToStack(DrawableHitObject fruit, Vector2 absolutePosition) + { + fruit.RelativePositionAxes = Axes.None; + fruit.Position = new Vector2(ToLocalSpace(absolutePosition).X - DrawSize.X / 2, 0); + + fruit.Anchor = Anchor.TopCentre; + fruit.Origin = Anchor.BottomCentre; + fruit.Scale *= 0.7f; + fruit.LifetimeEnd = double.MaxValue; + fruit.Depth = (float)Time.Current; + + float distance = fruit.DrawSize.X / 2 * fruit.Scale.X; + + while (Children.OfType().Any(f => Vector2.DistanceSquared(f.Position, fruit.Position) < distance * distance)) + { + fruit.X += RNG.Next(-5, 5); + fruit.Y -= RNG.Next(0, 5); + } + + Add(fruit); + } + } + } +} diff --git a/osu.Game.Rulesets.Catch/osu.Game.Rulesets.Catch.csproj b/osu.Game.Rulesets.Catch/osu.Game.Rulesets.Catch.csproj index 83996df41a..79ef5f4ba8 100644 --- a/osu.Game.Rulesets.Catch/osu.Game.Rulesets.Catch.csproj +++ b/osu.Game.Rulesets.Catch/osu.Game.Rulesets.Catch.csproj @@ -38,6 +38,7 @@ True + @@ -50,6 +51,7 @@ + @@ -57,7 +59,8 @@ - + + diff --git a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/HitObjectPatternGenerator.cs b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/HitObjectPatternGenerator.cs index b1ba99d98b..99f55cb98b 100644 --- a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/HitObjectPatternGenerator.cs +++ b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/HitObjectPatternGenerator.cs @@ -33,12 +33,6 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy float positionSeparation = ((positionData?.Position ?? Vector2.Zero) - previousPosition).Length; double timeSeparation = hitObject.StartTime - previousTime; - if (timeSeparation <= 125) - { - // More than 120 BPM - convertType |= PatternType.ForceNotStack; - } - if (timeSeparation <= 80) { // More than 187 BPM @@ -64,7 +58,7 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy // More than 111 BPM stream convertType |= PatternType.Cycle | PatternType.KeepSingle; } - else if (timeSeparation <= 150 & positionSeparation < 20) + else if (timeSeparation <= 150 && positionSeparation < 20) { // More than 100 BPM stream convertType |= PatternType.ForceStack | PatternType.LowProbability; @@ -401,4 +395,4 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy }); } } -} \ No newline at end of file +} diff --git a/osu.Game.Rulesets.Mania/ManiaRuleset.cs b/osu.Game.Rulesets.Mania/ManiaRuleset.cs index a8a89a57e0..50ad6960ae 100644 --- a/osu.Game.Rulesets.Mania/ManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/ManiaRuleset.cs @@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.Mania { public class ManiaRuleset : Ruleset { - public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new ManiaHitRenderer(beatmap, isForCurrentRuleset); + public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new ManiaRulesetContainer(this, beatmap, isForCurrentRuleset); public override IEnumerable GetModsFor(ModType type) { @@ -118,5 +118,10 @@ namespace osu.Game.Rulesets.Mania public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor(); public override int LegacyID => 3; + + public ManiaRuleset(RulesetInfo rulesetInfo) + : base(rulesetInfo) + { + } } } diff --git a/osu.Game.Rulesets.Mania/Mods/IGenerateSpeedAdjustments.cs b/osu.Game.Rulesets.Mania/Mods/IGenerateSpeedAdjustments.cs index f179aa2ff8..954ee3f481 100644 --- a/osu.Game.Rulesets.Mania/Mods/IGenerateSpeedAdjustments.cs +++ b/osu.Game.Rulesets.Mania/Mods/IGenerateSpeedAdjustments.cs @@ -15,9 +15,9 @@ namespace osu.Game.Rulesets.Mania.Mods /// /// Applies this mod to a hit renderer. /// - /// The hit renderer to apply to. + /// The hit renderer to apply to. /// The per-column list of speed adjustments for hit objects. /// The list of speed adjustments for bar lines. - void ApplyToHitRenderer(ManiaHitRenderer hitRenderer, ref List[] hitObjectTimingChanges, ref List barlineTimingChanges); + void ApplyToRulesetContainer(ManiaRulesetContainer rulesetContainer, ref List[] hitObjectTimingChanges, ref List barlineTimingChanges); } } diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs index 1ba8ac4710..a054e0db56 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs @@ -20,12 +20,12 @@ namespace osu.Game.Rulesets.Mania.Mods public override FontAwesome Icon => FontAwesome.fa_sort_desc; - public void ApplyToHitRenderer(ManiaHitRenderer hitRenderer, ref List[] hitObjectTimingChanges, ref List barlineTimingChanges) + public void ApplyToRulesetContainer(ManiaRulesetContainer rulesetContainer, ref List[] hitObjectTimingChanges, ref List barlineTimingChanges) { // We have to generate one speed adjustment per hit object for gravity - foreach (ManiaHitObject obj in hitRenderer.Objects) + foreach (ManiaHitObject obj in rulesetContainer.Objects) { - MultiplierControlPoint controlPoint = hitRenderer.CreateControlPointAt(obj.StartTime); + MultiplierControlPoint controlPoint = rulesetContainer.CreateControlPointAt(obj.StartTime); // Beat length has too large of an effect for gravity, so we'll force it to a constant value for now controlPoint.TimingPoint.BeatLength = 1000; @@ -33,9 +33,9 @@ namespace osu.Game.Rulesets.Mania.Mods } // Like with hit objects, we need to generate one speed adjustment per bar line - foreach (DrawableBarLine barLine in hitRenderer.BarLines) + foreach (DrawableBarLine barLine in rulesetContainer.BarLines) { - var controlPoint = hitRenderer.CreateControlPointAt(barLine.HitObject.StartTime); + var controlPoint = rulesetContainer.CreateControlPointAt(barLine.HitObject.StartTime); // Beat length has too large of an effect for gravity, so we'll force it to a constant value for now controlPoint.TimingPoint.BeatLength = 1000; diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs index cb1352fc4a..10dc607ec3 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs @@ -4,7 +4,6 @@ using OpenTK.Graphics; using OpenTK.Input; using osu.Framework.Configuration; -using osu.Framework.Graphics; using osu.Game.Rulesets.Mania.Judgements; using osu.Game.Rulesets.Objects.Drawables; @@ -27,9 +26,6 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables if (key != null) Key.BindTo(key); - - RelativePositionAxes = Axes.Y; - Y = (float)HitObject.StartTime; } public override Color4 AccentColour diff --git a/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs b/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs index f575342486..63b443319f 100644 --- a/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs +++ b/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs @@ -155,8 +155,8 @@ namespace osu.Game.Rulesets.Mania.Scoring { } - public ManiaScoreProcessor(HitRenderer hitRenderer) - : base(hitRenderer) + public ManiaScoreProcessor(RulesetContainer rulesetContainer) + : base(rulesetContainer) { } diff --git a/osu.Game.Rulesets.Mania/Timing/BasicScrollingDrawableTimingSection.cs b/osu.Game.Rulesets.Mania/Timing/BasicScrollingDrawableTimingSection.cs deleted file mode 100644 index e485581d9f..0000000000 --- a/osu.Game.Rulesets.Mania/Timing/BasicScrollingDrawableTimingSection.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Game.Rulesets.Timing; - -namespace osu.Game.Rulesets.Mania.Timing -{ - /// - /// A which scrolls relative to the control point start time. - /// - internal class BasicScrollingDrawableTimingSection : DrawableTimingSection - { - private readonly MultiplierControlPoint controlPoint; - - public BasicScrollingDrawableTimingSection(MultiplierControlPoint controlPoint) - { - this.controlPoint = controlPoint; - } - - protected override void Update() - { - base.Update(); - - Y = (float)(controlPoint.StartTime - Time.Current); - } - } -} diff --git a/osu.Game.Rulesets.Mania/Timing/GravityScrollingDrawableTimingSection.cs b/osu.Game.Rulesets.Mania/Timing/GravityScrollingContainer.cs similarity index 80% rename from osu.Game.Rulesets.Mania/Timing/GravityScrollingDrawableTimingSection.cs rename to osu.Game.Rulesets.Mania/Timing/GravityScrollingContainer.cs index 730daa9ffd..699acc477b 100644 --- a/osu.Game.Rulesets.Mania/Timing/GravityScrollingDrawableTimingSection.cs +++ b/osu.Game.Rulesets.Mania/Timing/GravityScrollingContainer.cs @@ -6,13 +6,13 @@ using osu.Game.Rulesets.Timing; namespace osu.Game.Rulesets.Mania.Timing { /// - /// A that emulates a form of gravity where hit objects speed up over time. + /// A that emulates a form of gravity where hit objects speed up over time. /// - internal class GravityScrollingDrawableTimingSection : DrawableTimingSection + internal class GravityScrollingContainer : ScrollingContainer { private readonly MultiplierControlPoint controlPoint; - public GravityScrollingDrawableTimingSection(MultiplierControlPoint controlPoint) + public GravityScrollingContainer(MultiplierControlPoint controlPoint) { this.controlPoint = controlPoint; } @@ -51,10 +51,10 @@ namespace osu.Game.Rulesets.Mania.Timing private double acceleration => 1 / VisibleTimeRange; /// - /// Computes the current time relative to , accounting for . + /// Computes the current time relative to , accounting for . /// /// The non-offset time. - /// The current time relative to - . + /// The current time relative to - . private double relativeTimeAt(double time) => Time.Current - time + VisibleTimeRange; } } diff --git a/osu.Game.Rulesets.Mania/Timing/ManiaSpeedAdjustmentContainer.cs b/osu.Game.Rulesets.Mania/Timing/ManiaSpeedAdjustmentContainer.cs index ed22264d74..321b4ee92b 100644 --- a/osu.Game.Rulesets.Mania/Timing/ManiaSpeedAdjustmentContainer.cs +++ b/osu.Game.Rulesets.Mania/Timing/ManiaSpeedAdjustmentContainer.cs @@ -15,15 +15,14 @@ namespace osu.Game.Rulesets.Mania.Timing this.scrollingAlgorithm = scrollingAlgorithm; } - protected override DrawableTimingSection CreateTimingSection() + protected override ScrollingContainer CreateScrollingContainer() { switch (scrollingAlgorithm) { default: - case ScrollingAlgorithm.Basic: - return new BasicScrollingDrawableTimingSection(ControlPoint); + return base.CreateScrollingContainer(); case ScrollingAlgorithm.Gravity: - return new GravityScrollingDrawableTimingSection(ControlPoint); + return new GravityScrollingContainer(ControlPoint); } } } diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index 94cf6a4337..9fbc9ba5e7 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -14,11 +14,13 @@ using osu.Game.Graphics; using osu.Game.Rulesets.Objects.Drawables; using System; using osu.Framework.Configuration; -using osu.Game.Rulesets.Timing; +using osu.Game.Rulesets.UI; +using osu.Game.Rulesets.Mania.Objects; +using osu.Game.Rulesets.Mania.Judgements; namespace osu.Game.Rulesets.Mania.UI { - public class Column : Container, IHasAccentColour + public class Column : ScrollingPlayfield, IHasAccentColour { private const float key_icon_size = 10; private const float key_icon_corner_radius = 3; @@ -30,13 +32,6 @@ namespace osu.Game.Rulesets.Mania.UI private const float column_width = 45; private const float special_column_width = 70; - private readonly BindableDouble visibleTimeRange = new BindableDouble(); - public BindableDouble VisibleTimeRange - { - get { return visibleTimeRange; } - set { visibleTimeRange.BindTo(value); } - } - /// /// The key that will trigger input actions for this column and hit objects contained inside it. /// @@ -46,14 +41,15 @@ namespace osu.Game.Rulesets.Mania.UI private readonly Container hitTargetBar; private readonly Container keyIcon; - private readonly SpeedAdjustmentCollection speedAdjustments; + protected override Container Content => content; + private readonly Container content; public Column() + : base(Axes.Y) { - RelativeSizeAxes = Axes.Y; Width = column_width; - Children = new Drawable[] + InternalChildren = new Drawable[] { background = new Box { @@ -97,11 +93,10 @@ namespace osu.Game.Rulesets.Mania.UI } } }, - speedAdjustments = new SpeedAdjustmentCollection(Axes.Y) + content = new Container { Name = "Hit objects", RelativeSizeAxes = Axes.Both, - VisibleTimeRange = VisibleTimeRange }, // For column lighting, we need to capture input events before the notes new InputTarget @@ -150,6 +145,8 @@ namespace osu.Game.Rulesets.Mania.UI }; } + public override Axes RelativeSizeAxes => Axes.Y; + private bool isSpecial; public bool IsSpecial { @@ -192,11 +189,14 @@ namespace osu.Game.Rulesets.Mania.UI } } - public void Add(SpeedAdjustmentContainer speedAdjustment) => speedAdjustments.Add(speedAdjustment); - public void Add(DrawableHitObject hitObject) + /// + /// Adds a DrawableHitObject to this Playfield. + /// + /// The DrawableHitObject to add. + public override void Add(DrawableHitObject hitObject) { hitObject.AccentColour = AccentColour; - speedAdjustments.Add(hitObject); + HitObjects.Add(hitObject); } private bool onKeyDown(InputState state, KeyDownEventArgs args) diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index 03b6e18856..b836b54fa8 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -15,23 +15,15 @@ using OpenTK.Input; using System.Linq; using System.Collections.Generic; using osu.Game.Rulesets.Objects.Drawables; -using osu.Framework.Input; using osu.Game.Rulesets.Mania.Objects.Drawables; -using osu.Game.Rulesets.Timing; -using osu.Framework.Configuration; using osu.Framework.Graphics.Shapes; namespace osu.Game.Rulesets.Mania.UI { - public class ManiaPlayfield : Playfield + public class ManiaPlayfield : ScrollingPlayfield { public const float HIT_TARGET_POSITION = 50; - private const double time_span_default = 1500; - private const double time_span_min = 50; - private const double time_span_max = 10000; - private const double time_span_step = 50; - /// /// Default column keys, expanding outwards from the middle as more column are added. /// E.g. 2 columns use FJ, 4 columns use DFJK, 6 use SDFJKL, etc... @@ -56,13 +48,8 @@ namespace osu.Game.Rulesets.Mania.UI private readonly FlowContainer columns; public IEnumerable Columns => columns.Children; - private readonly BindableDouble visibleTimeRange = new BindableDouble(time_span_default) - { - MinValue = time_span_min, - MaxValue = time_span_max - }; - - private readonly SpeedAdjustmentCollection barLineContainer; + protected override Container Content => content; + private readonly Container content; private List normalColumnColours = new List(); private Color4 specialColumnColour; @@ -70,13 +57,14 @@ namespace osu.Game.Rulesets.Mania.UI private readonly int columnCount; public ManiaPlayfield(int columnCount) + : base(Axes.Y) { this.columnCount = columnCount; if (columnCount <= 0) throw new ArgumentException("Can't have zero or fewer columns."); - Children = new Drawable[] + InternalChildren = new Drawable[] { new Container { @@ -120,13 +108,12 @@ namespace osu.Game.Rulesets.Mania.UI Padding = new MarginPadding { Top = HIT_TARGET_POSITION }, Children = new[] { - barLineContainer = new SpeedAdjustmentCollection(Axes.Y) + content = new Container { Name = "Bar lines", Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, RelativeSizeAxes = Axes.Y, - VisibleTimeRange = visibleTimeRange // Width is set in the Update method } } @@ -136,7 +123,13 @@ namespace osu.Game.Rulesets.Mania.UI }; for (int i = 0; i < columnCount; i++) - columns.Add(new Column { VisibleTimeRange = visibleTimeRange }); + { + var c = new Column(); + c.VisibleTimeRange.BindTo(VisibleTimeRange); + + columns.Add(c); + AddNested(c); + } } [BackgroundDependencyLoader] @@ -210,37 +203,13 @@ namespace osu.Game.Rulesets.Mania.UI } public override void Add(DrawableHitObject h) => Columns.ElementAt(h.HitObject.Column).Add(h); - public void Add(DrawableBarLine barline) => barLineContainer.Add(barline); - public void Add(SpeedAdjustmentContainer speedAdjustment) => barLineContainer.Add(speedAdjustment); - - protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) - { - if (state.Keyboard.ControlPressed) - { - switch (args.Key) - { - case Key.Minus: - transformVisibleTimeRangeTo(visibleTimeRange + time_span_step, 200, Easing.OutQuint); - break; - case Key.Plus: - transformVisibleTimeRangeTo(visibleTimeRange - time_span_step, 200, Easing.OutQuint); - break; - } - } - - return false; - } - - private void transformVisibleTimeRangeTo(double newTimeRange, double duration = 0, Easing easing = Easing.None) - { - this.TransformTo(nameof(visibleTimeRange), newTimeRange, duration, easing); - } + public void Add(DrawableBarLine barline) => HitObjects.Add(barline); protected override void Update() { // Due to masking differences, it is not possible to get the width of the columns container automatically // While masking on effectively only the Y-axis, so we need to set the width of the bar line container manually - barLineContainer.Width = columns.Width; + content.Width = columns.Width; } } } diff --git a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs b/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs similarity index 57% rename from osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs rename to osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs index b92c0916b1..7f6b19f3bd 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs @@ -17,7 +17,6 @@ using osu.Game.Beatmaps.ControlPoints; using osu.Game.Rulesets.Beatmaps; using osu.Game.Rulesets.Mania.Beatmaps; using osu.Game.Rulesets.Mania.Judgements; -using osu.Game.Rulesets.Mania.Mods; using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Game.Rulesets.Mania.Scoring; @@ -30,7 +29,7 @@ using osu.Game.Rulesets.UI; namespace osu.Game.Rulesets.Mania.UI { - public class ManiaHitRenderer : SpeedAdjustedHitRenderer + public class ManiaRulesetContainer : ScrollingRulesetContainer { /// /// Preferred column count. This will only have an effect during the initialization of the play field. @@ -39,24 +38,9 @@ namespace osu.Game.Rulesets.Mania.UI public IEnumerable BarLines; - /// - /// Per-column timing changes. - /// - private readonly List[] hitObjectSpeedAdjustments; - - /// - /// Bar line timing changes. - /// - private readonly List barLineSpeedAdjustments = new List(); - - public ManiaHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) - : base(beatmap, isForCurrentRuleset) + public ManiaRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset) + : base(ruleset, beatmap, isForCurrentRuleset) { - // Generate the speed adjustment container lists - hitObjectSpeedAdjustments = new List[PreferredColumns]; - for (int i = 0; i < PreferredColumns; i++) - hitObjectSpeedAdjustments[i] = new List(); - // Generate the bar lines double lastObjectTime = (Objects.LastOrDefault() as IHasEndTime)?.EndTime ?? Objects.LastOrDefault()?.StartTime ?? double.MaxValue; @@ -83,30 +67,12 @@ namespace osu.Game.Rulesets.Mania.UI } BarLines = barLines; - - // Generate speed adjustments from mods first - bool useDefaultSpeedAdjustments = true; - - if (Mods != null) - { - foreach (var speedAdjustmentMod in Mods.OfType()) - { - useDefaultSpeedAdjustments = false; - speedAdjustmentMod.ApplyToHitRenderer(this, ref hitObjectSpeedAdjustments, ref barLineSpeedAdjustments); - } - } - - // Generate the default speed adjustments - if (useDefaultSpeedAdjustments) - generateDefaultSpeedAdjustments(); } [BackgroundDependencyLoader] private void load() { - var maniaPlayfield = (ManiaPlayfield)Playfield; - - BarLines.ForEach(maniaPlayfield.Add); + BarLines.ForEach(Playfield.Add); } protected override void ApplyBeatmap() @@ -116,28 +82,6 @@ namespace osu.Game.Rulesets.Mania.UI PreferredColumns = (int)Math.Max(1, Math.Round(Beatmap.BeatmapInfo.Difficulty.CircleSize)); } - protected override void ApplySpeedAdjustments() - { - var maniaPlayfield = (ManiaPlayfield)Playfield; - - for (int i = 0; i < PreferredColumns; i++) - foreach (var change in hitObjectSpeedAdjustments[i]) - maniaPlayfield.Columns.ElementAt(i).Add(change); - - foreach (var change in barLineSpeedAdjustments) - maniaPlayfield.Add(change); - } - - private void generateDefaultSpeedAdjustments() - { - DefaultControlPoints.ForEach(c => - { - foreach (List t in hitObjectSpeedAdjustments) - t.Add(new ManiaSpeedAdjustmentContainer(c, ScrollingAlgorithm.Basic)); - barLineSpeedAdjustments.Add(new ManiaSpeedAdjustmentContainer(c, ScrollingAlgorithm.Basic)); - }); - } - protected sealed override Playfield CreatePlayfield() => new ManiaPlayfield(PreferredColumns) { Anchor = Anchor.Centre, @@ -152,9 +96,7 @@ namespace osu.Game.Rulesets.Mania.UI protected override DrawableHitObject GetVisualRepresentation(ManiaHitObject h) { - var maniaPlayfield = (ManiaPlayfield)Playfield; - - Bindable key = maniaPlayfield.Columns.ElementAt(h.Column).Key; + Bindable key = Playfield.Columns.ElementAt(h.Column).Key; var holdNote = h as HoldNote; if (holdNote != null) @@ -168,5 +110,7 @@ namespace osu.Game.Rulesets.Mania.UI } protected override Vector2 GetPlayfieldAspectAdjust() => new Vector2(1, 0.8f); + + protected override SpeedAdjustmentContainer CreateSpeedAdjustmentContainer(MultiplierControlPoint controlPoint) => new ManiaSpeedAdjustmentContainer(controlPoint, ScrollingAlgorithm.Basic); } } diff --git a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj index 88d1ad7ad8..fb0b2d907f 100644 --- a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj +++ b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj @@ -79,11 +79,10 @@ - - + - + diff --git a/osu.Game.Rulesets.Osu/OsuKeyConversionInputManager.cs b/osu.Game.Rulesets.Osu/OsuKeyConversionInputManager.cs index d60aab90fb..10adca4e43 100644 --- a/osu.Game.Rulesets.Osu/OsuKeyConversionInputManager.cs +++ b/osu.Game.Rulesets.Osu/OsuKeyConversionInputManager.cs @@ -3,14 +3,13 @@ using System.Linq; using osu.Framework.Input; -using osu.Game.Screens.Play; using OpenTK.Input; using KeyboardState = osu.Framework.Input.KeyboardState; using MouseState = osu.Framework.Input.MouseState; namespace osu.Game.Rulesets.Osu { - public class OsuKeyConversionInputManager : KeyConversionInputManager + public class OsuKeyConversionInputManager : PassThroughInputManager { private bool leftViaKeyboard; private bool rightViaKeyboard; diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index 9a1971d791..212c634aaf 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -22,7 +22,7 @@ namespace osu.Game.Rulesets.Osu { public class OsuRuleset : Ruleset { - public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new OsuHitRenderer(beatmap, isForCurrentRuleset); + public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new OsuRulesetContainer(this, beatmap, isForCurrentRuleset); public override IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new[] { @@ -126,5 +126,10 @@ namespace osu.Game.Rulesets.Osu public override SettingsSubsection CreateSettings() => new OsuSettings(); public override int LegacyID => 0; + + public OsuRuleset(RulesetInfo rulesetInfo) + : base(rulesetInfo) + { + } } } diff --git a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs index 079ee928af..856ca0c98d 100644 --- a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs +++ b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs @@ -18,8 +18,8 @@ namespace osu.Game.Rulesets.Osu.Scoring { } - public OsuScoreProcessor(HitRenderer hitRenderer) - : base(hitRenderer) + public OsuScoreProcessor(RulesetContainer rulesetContainer) + : base(rulesetContainer) { } diff --git a/osu.Game.Rulesets.Osu/UI/OsuPlayfield.cs b/osu.Game.Rulesets.Osu/UI/OsuPlayfield.cs index e80ac933c8..2604b1ee8a 100644 --- a/osu.Game.Rulesets.Osu/UI/OsuPlayfield.cs +++ b/osu.Game.Rulesets.Osu/UI/OsuPlayfield.cs @@ -80,9 +80,9 @@ namespace osu.Game.Rulesets.Osu.UI public override void PostProcess() { - connectionLayer.HitObjects = HitObjects.Children + connectionLayer.HitObjects = HitObjects.Objects .Select(d => d.HitObject) - .OrderBy(h => h.StartTime); + .OrderBy(h => h.StartTime).OfType(); } public override void OnJudgement(DrawableHitObject judgedObject) diff --git a/osu.Game.Rulesets.Osu/UI/OsuHitRenderer.cs b/osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs similarity index 78% rename from osu.Game.Rulesets.Osu/UI/OsuHitRenderer.cs rename to osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs index e582d2fcd3..d029524a32 100644 --- a/osu.Game.Rulesets.Osu/UI/OsuHitRenderer.cs +++ b/osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Framework.Input; using OpenTK; using osu.Game.Beatmaps; using osu.Game.Rulesets.Beatmaps; @@ -12,14 +13,13 @@ using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Osu.Scoring; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; -using osu.Game.Screens.Play; namespace osu.Game.Rulesets.Osu.UI { - public class OsuHitRenderer : HitRenderer + public class OsuRulesetContainer : RulesetContainer { - public OsuHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) - : base(beatmap, isForCurrentRuleset) + public OsuRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset) + : base(ruleset, beatmap, isForCurrentRuleset) { } @@ -31,7 +31,7 @@ namespace osu.Game.Rulesets.Osu.UI protected override Playfield CreatePlayfield() => new OsuPlayfield(); - protected override KeyConversionInputManager CreateKeyConversionInputManager() => new OsuKeyConversionInputManager(); + protected override PassThroughInputManager CreateActionMappingInputManager() => new OsuKeyConversionInputManager(); protected override DrawableHitObject GetVisualRepresentation(OsuHitObject h) { diff --git a/osu.Game.Rulesets.Osu/osu.Game.Rulesets.Osu.csproj b/osu.Game.Rulesets.Osu/osu.Game.Rulesets.Osu.csproj index 684060c981..b24d5b3a4a 100644 --- a/osu.Game.Rulesets.Osu/osu.Game.Rulesets.Osu.csproj +++ b/osu.Game.Rulesets.Osu/osu.Game.Rulesets.Osu.csproj @@ -80,7 +80,7 @@ - + diff --git a/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs b/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs index 70df3d8317..647a1381c6 100644 --- a/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs +++ b/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs @@ -113,8 +113,8 @@ namespace osu.Game.Rulesets.Taiko.Scoring { } - public TaikoScoreProcessor(HitRenderer hitRenderer) - : base(hitRenderer) + public TaikoScoreProcessor(RulesetContainer rulesetContainer) + : base(rulesetContainer) { } diff --git a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs index 83db9b35af..4d4bbb7bc5 100644 --- a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs +++ b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs @@ -18,7 +18,7 @@ namespace osu.Game.Rulesets.Taiko { public class TaikoRuleset : Ruleset { - public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new TaikoHitRenderer(beatmap, isForCurrentRuleset); + public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new TaikoRulesetContainer(this, beatmap, isForCurrentRuleset); public override IEnumerable GetModsFor(ModType type) { @@ -103,5 +103,10 @@ namespace osu.Game.Rulesets.Taiko public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor(); public override int LegacyID => 1; + + public TaikoRuleset(RulesetInfo rulesetInfo) + : base(rulesetInfo) + { + } } } diff --git a/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs b/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs index dca339f734..119cd64fef 100644 --- a/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs +++ b/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs @@ -21,7 +21,7 @@ namespace osu.Game.Rulesets.Taiko.UI public class TaikoPlayfield : Playfield { /// - /// Default height of a when inside a . + /// Default height of a when inside a . /// public const float DEFAULT_HEIGHT = 178; diff --git a/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs b/osu.Game.Rulesets.Taiko/UI/TaikoRulesetContainer.cs similarity index 92% rename from osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs rename to osu.Game.Rulesets.Taiko/UI/TaikoRulesetContainer.cs index 570b4be488..29f563b735 100644 --- a/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs +++ b/osu.Game.Rulesets.Taiko/UI/TaikoRulesetContainer.cs @@ -21,10 +21,10 @@ using System.Linq; namespace osu.Game.Rulesets.Taiko.UI { - public class TaikoHitRenderer : HitRenderer + public class TaikoRulesetContainer : RulesetContainer { - public TaikoHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) - : base(beatmap, isForCurrentRuleset) + public TaikoRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset) + : base(ruleset, beatmap, isForCurrentRuleset) { } @@ -93,7 +93,6 @@ namespace osu.Game.Rulesets.Taiko.UI return new Vector2(1, default_relative_height * aspectAdjust); } - public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor(this); protected override BeatmapConverter CreateBeatmapConverter() => new TaikoBeatmapConverter(); diff --git a/osu.Game.Rulesets.Taiko/osu.Game.Rulesets.Taiko.csproj b/osu.Game.Rulesets.Taiko/osu.Game.Rulesets.Taiko.csproj index f719f2002b..59c6f4db0a 100644 --- a/osu.Game.Rulesets.Taiko/osu.Game.Rulesets.Taiko.csproj +++ b/osu.Game.Rulesets.Taiko/osu.Game.Rulesets.Taiko.csproj @@ -91,7 +91,7 @@ - + diff --git a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs index bd53a80555..2fb9a568f8 100644 --- a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs +++ b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs @@ -54,7 +54,7 @@ namespace osu.Game.Beatmaps private class DummyRulesetInfo : RulesetInfo { - public override Ruleset CreateInstance() => new DummyRuleset(); + public override Ruleset CreateInstance() => new DummyRuleset(this); private class DummyRuleset : Ruleset { @@ -62,7 +62,7 @@ namespace osu.Game.Beatmaps public override Mod GetAutoplayMod() => new ModAutoplay(); - public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) + public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) { throw new NotImplementedException(); } @@ -77,6 +77,11 @@ namespace osu.Game.Beatmaps public override string Description => "dummy"; public override IEnumerable CreateGameplayKeys() => new List(); + + public DummyRuleset(RulesetInfo rulesetInfo) + : base(rulesetInfo) + { + } } } } diff --git a/osu.Game/Input/ActionMappingInputManager.cs b/osu.Game/Input/ActionMappingInputManager.cs new file mode 100644 index 0000000000..c918982fab --- /dev/null +++ b/osu.Game/Input/ActionMappingInputManager.cs @@ -0,0 +1,74 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using osu.Framework.Allocation; +using osu.Framework.Input; +using osu.Game.Rulesets; +using OpenTK.Input; + +namespace osu.Game.Input +{ + /// + /// Maps custom action data of type and stores to . + /// + /// The type of the custom action. + public class ActionMappingInputManager : PassThroughInputManager + where T : struct + { + private readonly RulesetInfo ruleset; + + private readonly int? variant; + + /// + /// Create a new instance. + /// + /// A reference to identify the current . Used to lookup mappings. Null for global mappings. + /// An optional variant for the specified . Used when a ruleset has more than one possible keyboard layouts. + protected ActionMappingInputManager(RulesetInfo ruleset = null, int? variant = null) + { + this.ruleset = ruleset; + this.variant = variant; + } + + protected IDictionary Mappings { get; set; } + + [BackgroundDependencyLoader] + private void load(BindingStore bindings) + { + var rulesetId = ruleset?.ID; + foreach (var b in bindings.Query(b => b.RulesetID == rulesetId && b.Variant == variant)) + Mappings[b.Key] = (T)(object)b.Action; + } + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + { + mapKey(state, args.Key); + return base.OnKeyDown(state, args); + } + + protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) + { + mapKey(state, args.Key); + return base.OnKeyUp(state, args); + } + + private void mapKey(InputState state, Key key) + { + T mappedData; + if (Mappings.TryGetValue(key, out mappedData)) + state.Data = mappedData; + } + + private T parseStringRepresentation(string str) + { + T res; + + if (Enum.TryParse(str, out res)) + return res; + + return default(T); + } + } +} diff --git a/osu.Game/Input/Binding.cs b/osu.Game/Input/Binding.cs new file mode 100644 index 0000000000..e887d15a65 --- /dev/null +++ b/osu.Game/Input/Binding.cs @@ -0,0 +1,23 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Rulesets; +using OpenTK.Input; +using SQLite.Net.Attributes; +using SQLiteNetExtensions.Attributes; + +namespace osu.Game.Input +{ + public class Binding + { + [ForeignKey(typeof(RulesetInfo))] + public int? RulesetID { get; set; } + + [Indexed] + public int? Variant { get; set; } + + public Key Key { get; set; } + + public int Action { get; set; } + } +} \ No newline at end of file diff --git a/osu.Game/Input/BindingStore.cs b/osu.Game/Input/BindingStore.cs new file mode 100644 index 0000000000..aa47bee068 --- /dev/null +++ b/osu.Game/Input/BindingStore.cs @@ -0,0 +1,29 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using osu.Framework.Platform; +using osu.Game.Database; +using SQLite.Net; + +namespace osu.Game.Input +{ + public class BindingStore : DatabaseBackedStore + { + public BindingStore(SQLiteConnection connection, Storage storage = null) + : base(connection, storage) + { + } + + protected override void Prepare(bool reset = false) + { + Connection.CreateTable(); + } + + protected override Type[] ValidTypes => new[] + { + typeof(Binding) + }; + + } +} \ No newline at end of file diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 0dec4228de..b76235f3f4 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -19,6 +19,7 @@ using osu.Game.Online.API; using SQLite.Net; using osu.Framework.Graphics.Performance; using osu.Game.Database; +using osu.Game.Input; using osu.Game.IO; using osu.Game.Rulesets; using osu.Game.Rulesets.Scoring; @@ -37,6 +38,8 @@ namespace osu.Game protected ScoreStore ScoreStore; + protected BindingStore BindingStore; + protected override string MainResourceFile => @"osu.Game.Resources.dll"; public APIAccess API; @@ -104,6 +107,7 @@ namespace osu.Game dependencies.Cache(FileStore = new FileStore(connection, Host.Storage)); dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, FileStore, connection, RulesetStore, Host)); dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, connection, Host, BeatmapManager)); + dependencies.Cache(BindingStore = new BindingStore(connection)); dependencies.Cache(new OsuColour()); //this completely overrides the framework default. will need to change once we make a proper FontStore. diff --git a/osu.Game/Rulesets/Mods/IApplicableMod.cs b/osu.Game/Rulesets/Mods/IApplicableMod.cs index 18e1ae4b3d..1957952720 100644 --- a/osu.Game/Rulesets/Mods/IApplicableMod.cs +++ b/osu.Game/Rulesets/Mods/IApplicableMod.cs @@ -7,16 +7,16 @@ using osu.Game.Rulesets.UI; namespace osu.Game.Rulesets.Mods { /// - /// An interface for mods that are applied to a HitRenderer. + /// An interface for mods that are applied to a RulesetContainer. /// - /// The type of HitObject the HitRenderer contains. + /// The type of HitObject the RulesetContainer contains. public interface IApplicableMod where TObject : HitObject { /// - /// Applies the mod to a HitRenderer. + /// Applies the mod to a RulesetContainer. /// - /// The HitRenderer to apply the mod to. - void ApplyToHitRenderer(HitRenderer hitRenderer); + /// The RulesetContainer to apply the mod to. + void ApplyToRulesetContainer(RulesetContainer rulesetContainer); } } diff --git a/osu.Game/Rulesets/Mods/ModAutoplay.cs b/osu.Game/Rulesets/Mods/ModAutoplay.cs index 1217bf835f..ca120e446e 100644 --- a/osu.Game/Rulesets/Mods/ModAutoplay.cs +++ b/osu.Game/Rulesets/Mods/ModAutoplay.cs @@ -15,9 +15,9 @@ namespace osu.Game.Rulesets.Mods { protected abstract Score CreateReplayScore(Beatmap beatmap); - public void ApplyToHitRenderer(HitRenderer hitRenderer) + public void ApplyToRulesetContainer(RulesetContainer rulesetContainer) { - hitRenderer.SetReplay(CreateReplayScore(hitRenderer.Beatmap)?.Replay); + rulesetContainer.SetReplay(CreateReplayScore(rulesetContainer.Beatmap)?.Replay); } } diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs index 8dc17b9542..f67dd4dfea 100644 --- a/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs @@ -1,8 +1,8 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; using osu.Framework.Configuration; +using osu.Framework.Graphics; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Objects.Types; @@ -10,6 +10,8 @@ namespace osu.Game.Rulesets.Objects.Drawables { /// /// A basic class that overrides and implements . + /// This object does not need to have its set to be able to scroll, as this will + /// will be set by the scrolling container that contains it. /// public abstract class DrawableScrollingHitObject : DrawableHitObject, IScrollingHitObject where TObject : HitObject @@ -17,25 +19,40 @@ namespace osu.Game.Rulesets.Objects.Drawables { public BindableDouble LifetimeOffset { get; } = new BindableDouble(); + Axes IScrollingHitObject.ScrollingAxes + { + set + { + RelativePositionAxes |= value; + + if ((value & Axes.X) > 0) + X = (float)HitObject.StartTime; + if ((value & Axes.Y) > 0) + Y = (float)HitObject.StartTime; + } + } + protected DrawableScrollingHitObject(TObject hitObject) : base(hitObject) { } + private double? lifetimeStart; public override double LifetimeStart { - get { return Math.Min(HitObject.StartTime - LifetimeOffset, base.LifetimeStart); } - set { base.LifetimeStart = value; } + get { return lifetimeStart ?? HitObject.StartTime - LifetimeOffset; } + set { lifetimeStart = value; } } + private double? lifetimeEnd; public override double LifetimeEnd { get { var endTime = (HitObject as IHasEndTime)?.EndTime ?? HitObject.StartTime; - return Math.Max(endTime + LifetimeOffset, base.LifetimeEnd); + return lifetimeEnd ?? endTime + LifetimeOffset; } - set { base.LifetimeEnd = value; } + set { lifetimeEnd = value; } } protected override void AddNested(DrawableHitObject h) diff --git a/osu.Game/Rulesets/Objects/Drawables/IScrollingHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/IScrollingHitObject.cs index 560f15f133..30b65237a4 100644 --- a/osu.Game/Rulesets/Objects/Drawables/IScrollingHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/IScrollingHitObject.cs @@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Objects.Drawables /// /// An interface that exposes properties required for scrolling hit objects to be properly displayed. /// - public interface IScrollingHitObject : IDrawable + internal interface IScrollingHitObject : IDrawable { /// /// Time offset before the hit object start time at which this becomes visible and the time offset @@ -21,5 +21,11 @@ namespace osu.Game.Rulesets.Objects.Drawables /// /// BindableDouble LifetimeOffset { get; } + + /// + /// Axes which this will scroll through. + /// This is set by the container which this scrolls through. + /// + Axes ScrollingAxes { set; } } } \ No newline at end of file diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index b3be36a983..ba040403ba 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -15,12 +15,19 @@ namespace osu.Game.Rulesets { public abstract class Ruleset { + public readonly RulesetInfo RulesetInfo; + public virtual IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { }; public abstract IEnumerable GetModsFor(ModType type); public abstract Mod GetAutoplayMod(); + protected Ruleset(RulesetInfo rulesetInfo) + { + RulesetInfo = rulesetInfo; + } + /// /// Attempt to create a hit renderer for a beatmap /// @@ -28,7 +35,7 @@ namespace osu.Game.Rulesets /// Whether the hit renderer should assume the beatmap is for the current ruleset. /// Unable to successfully load the beatmap to be usable with this ruleset. /// - public abstract HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset); + public abstract RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset); public abstract DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap); diff --git a/osu.Game/Rulesets/RulesetInfo.cs b/osu.Game/Rulesets/RulesetInfo.cs index 84ecb7718e..bc23649ede 100644 --- a/osu.Game/Rulesets/RulesetInfo.cs +++ b/osu.Game/Rulesets/RulesetInfo.cs @@ -20,6 +20,6 @@ namespace osu.Game.Rulesets [Indexed] public bool Available { get; set; } - public virtual Ruleset CreateInstance() => (Ruleset)Activator.CreateInstance(Type.GetType(InstantiationInfo)); + public virtual Ruleset CreateInstance() => (Ruleset)Activator.CreateInstance(Type.GetType(InstantiationInfo), this); } } \ No newline at end of file diff --git a/osu.Game/Rulesets/RulesetStore.cs b/osu.Game/Rulesets/RulesetStore.cs index 1564df1366..2956c11d7f 100644 --- a/osu.Game/Rulesets/RulesetStore.cs +++ b/osu.Game/Rulesets/RulesetStore.cs @@ -44,7 +44,7 @@ namespace osu.Game.Rulesets continue; foreach (Type rulesetType in rulesets) - instances.Add((Ruleset)Activator.CreateInstance(rulesetType)); + instances.Add((Ruleset)Activator.CreateInstance(rulesetType, new RulesetInfo())); } catch (Exception) { } } diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index cd9089c859..5ccac2db32 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -150,13 +150,13 @@ namespace osu.Game.Rulesets.Scoring { } - protected ScoreProcessor(HitRenderer hitRenderer) + protected ScoreProcessor(RulesetContainer rulesetContainer) { - Judgements.Capacity = hitRenderer.Beatmap.HitObjects.Count; + Judgements.Capacity = rulesetContainer.Beatmap.HitObjects.Count; - hitRenderer.OnJudgement += AddJudgement; + rulesetContainer.OnJudgement += AddJudgement; - ComputeTargets(hitRenderer.Beatmap); + ComputeTargets(rulesetContainer.Beatmap); Reset(); } diff --git a/osu.Game/Rulesets/Timing/DrawableTimingSection.cs b/osu.Game/Rulesets/Timing/DrawableTimingSection.cs deleted file mode 100644 index 6345a566c2..0000000000 --- a/osu.Game/Rulesets/Timing/DrawableTimingSection.cs +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System.Linq; -using osu.Framework.Caching; -using osu.Framework.Configuration; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Game.Rulesets.Objects.Drawables; -using OpenTK; -using osu.Game.Rulesets.Objects.Types; - -namespace osu.Game.Rulesets.Timing -{ - /// - /// A collection of hit objects which scrolls within a . - /// - /// - /// This container handles the conversion between time and position through and - /// such that hit objects added to this container should have time values set as their - /// positions/sizes to make proper use of this container. - /// - /// - /// - /// This container will auto-size to the total duration of the contained hit objects along the desired auto-sizing axes such that the resulting size - /// of this container will be a value representing the total duration of all contained hit objects. - /// - /// - /// - /// This container is and must always be relatively-sized and positioned to its such that the parent can utilise - /// and to apply further time offsets to this collection of hit objects. - /// - /// - public abstract class DrawableTimingSection : Container - { - private readonly BindableDouble visibleTimeRange = new BindableDouble(); - /// - /// Gets or sets the range of time that is visible by the length of this container. - /// - public BindableDouble VisibleTimeRange - { - get { return visibleTimeRange; } - set { visibleTimeRange.BindTo(value); } - } - - /// - /// Axes through which this timing section scrolls. This is set by the . - /// - internal Axes ScrollingAxes; - - /// - /// The control point that provides the speed adjustments for this container. This is set by the . - /// - internal MultiplierControlPoint ControlPoint; - - protected override int Compare(Drawable x, Drawable y) - { - var xHitObject = x as DrawableHitObject; - var yHitObject = y as DrawableHitObject; - - // If either of the two drawables are not hit objects, fall back to the base comparer - if (xHitObject?.HitObject == null || yHitObject?.HitObject == null) - return base.Compare(x, y); - - // Compare by start time - int i = yHitObject.HitObject.StartTime.CompareTo(xHitObject.HitObject.StartTime); - if (i != 0) - return i; - - return base.Compare(x, y); - } - - /// - /// Creates a new . - /// - protected DrawableTimingSection() - { - RelativeSizeAxes = Axes.Both; - RelativePositionAxes = Axes.Both; - } - - public override void InvalidateFromChild(Invalidation invalidation) - { - // We only want to re-compute our size when a child's size or position has changed - if ((invalidation & Invalidation.RequiredParentSizeToFit) == 0) - { - base.InvalidateFromChild(invalidation); - return; - } - - durationBacking.Invalidate(); - - base.InvalidateFromChild(invalidation); - } - - private Cached durationBacking; - - private double computeDuration() - { - if (!Children.Any()) - return 0; - - double baseDuration = Children.Max(c => (c.HitObject as IHasEndTime)?.EndTime ?? c.HitObject.StartTime) - ControlPoint.StartTime; - - // If we have a singular hit object at the timing section's start time, let's set a sane default duration - if (baseDuration == 0) - baseDuration = 1; - - // Scrolling ruleset hit objects typically have anchors+origins set to the hit object's start time, but if the hit object doesn't implement IHasEndTime and lies on the control point - // then the baseDuration above will be 0. This will cause problems with masking when it is further set as the value for Size in Update(). We _want_ the timing section bounds to - // completely enclose the hit object to avoid the masking optimisations. - // - // To do this we need to find a duration that corresponds to the absolute size of the element that extrudes beyond the timing section's bounds and add that to baseDuration. - // We can utilize the fact that the Size and RelativeChildSpace are 1:1, meaning that an change in duration for the timing section has no change to the hit object's positioning - // and simply find the largest absolutely-sized element in this timing section. This introduces a little bit of error, but will never under-estimate the duration. - - // Find the largest element that is absolutely-sized along ScrollingAxes - float maxAbsoluteSize = Children.Where(c => (c.RelativeSizeAxes & ScrollingAxes) == 0) - .Select(c => (ScrollingAxes & Axes.X) > 0 ? c.Width : c.Height) - .DefaultIfEmpty().Max(); - - float ourAbsoluteSize = (ScrollingAxes & Axes.X) > 0 ? DrawWidth : DrawHeight; - - // Add the extra duration to account for the absolute size - baseDuration *= 1 + maxAbsoluteSize / ourAbsoluteSize; - - return baseDuration; - } - - /// - /// The maximum duration of any one hit object inside this . This is calculated as the maximum - /// end time between all hit objects relative to this 's . - /// - public double Duration => durationBacking.IsValid ? durationBacking : (durationBacking.Value = computeDuration()); - - protected override void Update() - { - base.Update(); - - // We want our size and position-space along ScrollingAxes to span our duration to completely enclose all the hit objects - Size = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)Duration : Size.X, (ScrollingAxes & Axes.Y) > 0 ? (float)Duration : Size.Y); - // And we need to make sure the hit object's position-space doesn't change due to our resizing - RelativeChildSize = Size; - } - } -} diff --git a/osu.Game/Rulesets/Timing/LinearScrollingContainer.cs b/osu.Game/Rulesets/Timing/LinearScrollingContainer.cs new file mode 100644 index 0000000000..db497b7664 --- /dev/null +++ b/osu.Game/Rulesets/Timing/LinearScrollingContainer.cs @@ -0,0 +1,30 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics; + +namespace osu.Game.Rulesets.Timing +{ + /// + /// A which scrolls linearly relative to the start time. + /// + internal class LinearScrollingContainer : ScrollingContainer + { + private readonly Axes scrollingAxes; + private readonly MultiplierControlPoint controlPoint; + + public LinearScrollingContainer(Axes scrollingAxes, MultiplierControlPoint controlPoint) + { + this.scrollingAxes = scrollingAxes; + this.controlPoint = controlPoint; + } + + protected override void Update() + { + base.Update(); + + if ((scrollingAxes & Axes.X) > 0) X = (float)(controlPoint.StartTime - Time.Current); + if ((scrollingAxes & Axes.Y) > 0) Y = (float)(controlPoint.StartTime - Time.Current); + } + } +} diff --git a/osu.Game/Rulesets/Timing/ScrollingContainer.cs b/osu.Game/Rulesets/Timing/ScrollingContainer.cs new file mode 100644 index 0000000000..843f307d0d --- /dev/null +++ b/osu.Game/Rulesets/Timing/ScrollingContainer.cs @@ -0,0 +1,103 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Linq; +using osu.Framework.Caching; +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Rulesets.Objects.Drawables; +using OpenTK; +using osu.Game.Rulesets.Objects.Types; + +namespace osu.Game.Rulesets.Timing +{ + /// + /// A container that scrolls relative to the current time. Will autosize to the total duration of all contained hit objects along the scrolling axes. + /// + public abstract class ScrollingContainer : Container + { + /// + /// Gets or sets the range of time that is visible by the length of the scrolling axes. + /// + public readonly BindableDouble VisibleTimeRange = new BindableDouble { Default = 1000 }; + + /// + /// The axes through which this scrolls. This is set by the . + /// + internal Axes ScrollingAxes; + + /// + /// The control point that defines the speed adjustments for this container. This is set by the . + /// + internal MultiplierControlPoint ControlPoint; + + private Cached durationBacking; + + /// + /// Creates a new . + /// + protected ScrollingContainer() + { + RelativeSizeAxes = Axes.Both; + RelativePositionAxes = Axes.Both; + } + + public override void InvalidateFromChild(Invalidation invalidation) + { + // We only want to re-compute our size when a child's size or position has changed + if ((invalidation & Invalidation.RequiredParentSizeToFit) == 0) + { + base.InvalidateFromChild(invalidation); + return; + } + + durationBacking.Invalidate(); + + base.InvalidateFromChild(invalidation); + } + + private double computeDuration() + { + if (!Children.Any()) + return 0; + + double baseDuration = Children.Max(c => (c.HitObject as IHasEndTime)?.EndTime ?? c.HitObject.StartTime) - ControlPoint.StartTime; + + // If we have a singular hit object at the timing section's start time, let's set a sane default duration + if (baseDuration == 0) + baseDuration = 1; + + // This container needs to resize such that it completely encloses the hit objects to avoid masking optimisations. This is done by converting the largest + // absolutely-sized element along the scrolling axes and adding a corresponding duration value. This introduces a bit of error, but will never under-estimate.ion. + + // Find the largest element that is absolutely-sized along ScrollingAxes + float maxAbsoluteSize = Children.Where(c => (c.RelativeSizeAxes & ScrollingAxes) == 0) + .Select(c => (ScrollingAxes & Axes.X) > 0 ? c.Width : c.Height) + .DefaultIfEmpty().Max(); + + float ourAbsoluteSize = (ScrollingAxes & Axes.X) > 0 ? DrawWidth : DrawHeight; + + // Add the extra duration to account for the absolute size + baseDuration *= 1 + maxAbsoluteSize / ourAbsoluteSize; + + return baseDuration; + } + + /// + /// The maximum duration of any one hit object inside this . This is calculated as the maximum + /// duration of all hit objects relative to this 's . + /// + public double Duration => durationBacking.IsValid ? durationBacking : (durationBacking.Value = computeDuration()); + + protected override void Update() + { + base.Update(); + + // We want our size and position-space along the scrolling axes to span our duration to completely enclose all the hit objects + Size = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)Duration : Size.X, (ScrollingAxes & Axes.Y) > 0 ? (float)Duration : Size.Y); + // And we need to make sure the hit object's position-space doesn't change due to our resizing + RelativeChildSize = Size; + } + } +} diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs deleted file mode 100644 index 22213be740..0000000000 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System; -using System.Collections.Generic; -using System.Linq; -using osu.Framework.Configuration; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Game.Rulesets.Objects.Drawables; - -namespace osu.Game.Rulesets.Timing -{ - /// - /// A collection of s. - /// - /// - /// This container redirects any 's added to it to the - /// which provides the speed adjustment active at the start time of the hit object. Furthermore, this container provides the - /// necessary for the contained s. - /// - /// - public class SpeedAdjustmentCollection : Container - { - private readonly BindableDouble visibleTimeRange = new BindableDouble(); - /// - /// Gets or sets the range of time that is visible by the length of this container. - /// For example, only hit objects with start time less than or equal to 1000 will be visible with = 1000. - /// - public Bindable VisibleTimeRange - { - get { return visibleTimeRange; } - set { visibleTimeRange.BindTo(value); } - } - - protected override int Compare(Drawable x, Drawable y) - { - var xSpeedAdjust = x as SpeedAdjustmentContainer; - var ySpeedAdjust = y as SpeedAdjustmentContainer; - - // If either of the two drawables are not hit objects, fall back to the base comparer - if (xSpeedAdjust?.ControlPoint == null || ySpeedAdjust?.ControlPoint == null) - return CompareReverseChildID(x, y); - - // Compare by start time - int i = ySpeedAdjust.ControlPoint.StartTime.CompareTo(xSpeedAdjust.ControlPoint.StartTime); - - return i != 0 ? i : CompareReverseChildID(x, y); - } - - /// - /// Hit objects that are to be re-processed on the next update. - /// - private readonly Queue queuedHitObjects = new Queue(); - - private readonly Axes scrollingAxes; - - /// - /// Creates a new . - /// - /// The axes upon which hit objects should appear to scroll inside this container. - public SpeedAdjustmentCollection(Axes scrollingAxes) - { - this.scrollingAxes = scrollingAxes; - } - - public override void Add(SpeedAdjustmentContainer speedAdjustment) - { - speedAdjustment.VisibleTimeRange.BindTo(VisibleTimeRange); - speedAdjustment.ScrollingAxes = scrollingAxes; - base.Add(speedAdjustment); - } - - /// - /// Adds a hit object to this . The hit objects will be kept in a queue - /// and will be processed when new s are added to this . - /// - /// The hit object to add. - public void Add(DrawableHitObject hitObject) - { - if (!(hitObject is IScrollingHitObject)) - throw new InvalidOperationException($"Hit objects added to a {nameof(SpeedAdjustmentCollection)} must implement {nameof(IScrollingHitObject)}."); - - queuedHitObjects.Enqueue(hitObject); - } - - protected override void Update() - { - base.Update(); - - // Todo: At the moment this is going to re-process every single Update, however this will only be a null-op - // when there are no SpeedAdjustmentContainers available. This should probably error or something, but it's okay for now. - - // An external count is kept because hit objects that can't be added are re-queued - int count = queuedHitObjects.Count; - while (count-- > 0) - { - var hitObject = queuedHitObjects.Dequeue(); - - var target = adjustmentContainerFor(hitObject); - if (target == null) - { - // We can't add this hit object to a speed adjustment container yet, so re-queue it - // for re-processing when the layout next invalidated - queuedHitObjects.Enqueue(hitObject); - continue; - } - - if (hitObject.RelativePositionAxes != target.ScrollingAxes) - throw new InvalidOperationException($"Make sure to set all {nameof(DrawableHitObject)}'s {nameof(RelativePositionAxes)} are equal to the correct axes of scrolling ({target.ScrollingAxes})."); - - target.Add(hitObject); - } - } - - /// - /// Finds the which provides the speed adjustment active at the start time - /// of a hit object. If there is no active at the start time of the hit object, - /// then the first (time-wise) speed adjustment is returned. - /// - /// The hit object to find the active for. - /// The active at 's start time. Null if there are no speed adjustments. - private SpeedAdjustmentContainer adjustmentContainerFor(DrawableHitObject hitObject) => Children.FirstOrDefault(c => c.CanContain(hitObject)) ?? Children.LastOrDefault(); - - /// - /// Finds the which provides the speed adjustment active at a time. - /// If there is no active at the time, then the first (time-wise) speed adjustment is returned. - /// - /// The time to find the active at. - /// The active at . Null if there are no speed adjustments. - private SpeedAdjustmentContainer adjustmentContainerAt(double time) => Children.FirstOrDefault(c => c.CanContain(time)) ?? Children.LastOrDefault(); - } -} diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs index f41ef21c1e..9d5f49e155 100644 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs +++ b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs @@ -11,61 +11,57 @@ using OpenTK; namespace osu.Game.Rulesets.Timing { /// - /// A container for hit objects which applies applies the speed adjustments defined by the properties of a - /// to affect the scroll speed of the contained . - /// - /// - /// This container must always be relatively-sized to its parent to provide the speed adjustments. This container will provide the speed adjustments - /// by modifying its size while maintaining a constant for its children - /// + /// A container that provides the speed adjustments defined by s to affect the scroll speed + /// of container s. /// - public abstract class SpeedAdjustmentContainer : Container + public class SpeedAdjustmentContainer : Container { - private readonly Bindable visibleTimeRange = new Bindable(); /// - /// Gets or sets the range of time that is visible by the length of this container. + /// Gets or sets the range of time that is visible by the length of the scrolling axes. /// - public Bindable VisibleTimeRange - { - get { return visibleTimeRange; } - set { visibleTimeRange.BindTo(value); } - } + public readonly Bindable VisibleTimeRange = new Bindable { Default = 1000 }; + + /// + /// Whether to reverse the scrolling direction is reversed. + /// + public readonly BindableBool Reversed = new BindableBool(); protected override Container Content => content; private Container content; /// - /// Axes which the content of this container will scroll through. + /// The axes which the content of this container will scroll through. /// - /// public Axes ScrollingAxes { get; internal set; } + /// + /// The that defines the speed adjustments. + /// public readonly MultiplierControlPoint ControlPoint; - private DrawableTimingSection timingSection; + private ScrollingContainer scrollingContainer; /// /// Creates a new . /// - /// The which provides the speed adjustments for this container. - protected SpeedAdjustmentContainer(MultiplierControlPoint controlPoint) + /// The that defines the speed adjustments. + public SpeedAdjustmentContainer(MultiplierControlPoint controlPoint) { ControlPoint = controlPoint; - RelativeSizeAxes = Axes.Both; } [BackgroundDependencyLoader] private void load() { - timingSection = CreateTimingSection(); + scrollingContainer = CreateScrollingContainer(); - timingSection.ScrollingAxes = ScrollingAxes; - timingSection.ControlPoint = ControlPoint; - timingSection.VisibleTimeRange.BindTo(VisibleTimeRange); - timingSection.RelativeChildOffset = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)ControlPoint.StartTime : 0, (ScrollingAxes & Axes.Y) > 0 ? (float)ControlPoint.StartTime : 0); + scrollingContainer.ScrollingAxes = ScrollingAxes; + scrollingContainer.ControlPoint = ControlPoint; + scrollingContainer.VisibleTimeRange.BindTo(VisibleTimeRange); + scrollingContainer.RelativeChildOffset = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)ControlPoint.StartTime : 0, (ScrollingAxes & Axes.Y) > 0 ? (float)ControlPoint.StartTime : 0); - AddInternal(content = timingSection); + AddInternal(content = scrollingContainer); } protected override void Update() @@ -74,34 +70,51 @@ namespace osu.Game.Rulesets.Timing // The speed adjustment happens by modifying our size by the multiplier while maintaining the visible time range as the relatve size for our children Size = new Vector2((ScrollingAxes & Axes.X) > 0 ? multiplier : 1, (ScrollingAxes & Axes.Y) > 0 ? multiplier : 1); - RelativeChildSize = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)VisibleTimeRange : 1, (ScrollingAxes & Axes.Y) > 0 ? (float)VisibleTimeRange : 1); + + if (Reversed) + { + RelativeChildSize = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)-VisibleTimeRange : 1, (ScrollingAxes & Axes.Y) > 0 ? (float)-VisibleTimeRange : 1); + RelativeChildOffset = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)VisibleTimeRange : 0, (ScrollingAxes & Axes.Y) > 0 ? (float)VisibleTimeRange : 0); + Origin = Anchor = Anchor.BottomRight; + } + else + { + RelativeChildSize = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)VisibleTimeRange : 1, (ScrollingAxes & Axes.Y) > 0 ? (float)VisibleTimeRange : 1); + RelativeChildOffset = Vector2.Zero; + Origin = Anchor = Anchor.TopLeft; + } } public override double LifetimeStart => ControlPoint.StartTime - VisibleTimeRange; - public override double LifetimeEnd => ControlPoint.StartTime + timingSection.Duration + VisibleTimeRange; + public override double LifetimeEnd => ControlPoint.StartTime + scrollingContainer.Duration + VisibleTimeRange; public override void Add(DrawableHitObject drawable) { var scrollingHitObject = drawable as IScrollingHitObject; - scrollingHitObject?.LifetimeOffset.BindTo(VisibleTimeRange); + + if (scrollingHitObject != null) + { + scrollingHitObject.LifetimeOffset.BindTo(VisibleTimeRange); + scrollingHitObject.ScrollingAxes = ScrollingAxes; + } base.Add(drawable); } /// - /// Whether this speed adjustment can contain a hit object. This is true if the hit object occurs after this speed adjustment with respect to time. + /// Whether a falls within this s affecting timespan. /// public bool CanContain(DrawableHitObject hitObject) => CanContain(hitObject.HitObject.StartTime); /// - /// Whether this speed adjustment can contain an object placed at a time value. This is true if the time occurs after this speed adjustment. + /// Whether a point in time falls within this s affecting timespan. /// public bool CanContain(double startTime) => ControlPoint.StartTime <= startTime; /// - /// Creates the container which handles the movement of a collection of hit objects. + /// Creates the which contains the scrolling s of this container. /// - /// The . - protected abstract DrawableTimingSection CreateTimingSection(); + /// The . + protected virtual ScrollingContainer CreateScrollingContainer() => new LinearScrollingContainer(ScrollingAxes, ControlPoint); } } \ No newline at end of file diff --git a/osu.Game/Rulesets/UI/Playfield.cs b/osu.Game/Rulesets/UI/Playfield.cs index ff321a18a5..cc16eff6d6 100644 --- a/osu.Game/Rulesets/UI/Playfield.cs +++ b/osu.Game/Rulesets/UI/Playfield.cs @@ -9,6 +9,8 @@ using osu.Game.Rulesets.Objects.Drawables; using OpenTK; using osu.Game.Rulesets.Judgements; using osu.Framework.Allocation; +using System.Collections.Generic; +using System.Linq; namespace osu.Game.Rulesets.UI { @@ -19,7 +21,7 @@ namespace osu.Game.Rulesets.UI /// /// The HitObjects contained in this Playfield. /// - protected HitObjectContainer> HitObjects; + public HitObjectContainer HitObjects { get; protected set; } internal Container ScaledContent; @@ -53,7 +55,7 @@ namespace osu.Game.Rulesets.UI } }); - HitObjects = new HitObjectContainer> + HitObjects = new HitObjectContainer { RelativeSizeAxes = Axes.Both, }; @@ -82,12 +84,25 @@ namespace osu.Game.Rulesets.UI /// The DrawableHitObject to add. public virtual void Add(DrawableHitObject h) => HitObjects.Add(h); + /// + /// Remove a DrawableHitObject from this Playfield. + /// + /// The DrawableHitObject to remove. + public virtual void Remove(DrawableHitObject h) => HitObjects.Remove(h); + /// /// Triggered when an object's Judgement is updated. /// /// The object that Judgement has been updated for. public virtual void OnJudgement(DrawableHitObject judgedObject) { } + public class HitObjectContainer : CompositeDrawable + { + public virtual IEnumerable Objects => InternalChildren.OfType(); + public virtual void Add(DrawableHitObject hitObject) => AddInternal(hitObject); + public virtual bool Remove(DrawableHitObject hitObject) => RemoveInternal(hitObject); + } + private class ScaledContainer : Container { /// @@ -98,9 +113,5 @@ namespace osu.Game.Rulesets.UI //dividing by the customwidth will effectively scale our content to the required container size. protected override Vector2 DrawScale => CustomWidth.HasValue ? new Vector2(DrawSize.X / CustomWidth.Value) : base.DrawScale; } - - public class HitObjectContainer : Container where U : Drawable - { - } } } diff --git a/osu.Game/Rulesets/UI/HitRenderer.cs b/osu.Game/Rulesets/UI/RulesetContainer.cs similarity index 72% rename from osu.Game/Rulesets/UI/HitRenderer.cs rename to osu.Game/Rulesets/UI/RulesetContainer.cs index 2ce868b22e..387fa15191 100644 --- a/osu.Game/Rulesets/UI/HitRenderer.cs +++ b/osu.Game/Rulesets/UI/RulesetContainer.cs @@ -14,6 +14,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using osu.Framework.Input; using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Scoring; using OpenTK; @@ -22,12 +23,12 @@ using osu.Game.Rulesets.Beatmaps; namespace osu.Game.Rulesets.UI { /// - /// Base HitRenderer. Doesn't hold objects. + /// Base RulesetContainer. Doesn't hold objects. /// - /// Should not be derived - derive instead. + /// Should not be derived - derive instead. /// /// - public abstract class HitRenderer : Container + public abstract class RulesetContainer : Container { /// /// Invoked when all the judgeable HitObjects have been judged. @@ -40,14 +41,14 @@ namespace osu.Game.Rulesets.UI public bool AspectAdjust = true; /// - /// The input manager for this HitRenderer. + /// The input manager for this RulesetContainer. /// internal readonly PlayerInputManager InputManager = new PlayerInputManager(); /// - /// The key conversion input manager for this HitRenderer. + /// The key conversion input manager for this RulesetContainer. /// - protected readonly KeyConversionInputManager KeyConversionInputManager; + protected readonly PassThroughInputManager KeyConversionInputManager; /// /// Whether we are currently providing the local user a gameplay cursor. @@ -66,9 +67,16 @@ namespace osu.Game.Rulesets.UI /// protected abstract bool AllObjectsJudged { get; } - internal HitRenderer() + protected readonly Ruleset Ruleset; + + /// + /// A visual representation of a . + /// + /// The ruleset being repesented. + internal RulesetContainer(Ruleset ruleset) { - KeyConversionInputManager = CreateKeyConversionInputManager(); + Ruleset = ruleset; + KeyConversionInputManager = CreateActionMappingInputManager(); KeyConversionInputManager.RelativeSizeAxes = Axes.Both; } @@ -87,7 +95,7 @@ namespace osu.Game.Rulesets.UI /// Creates a key conversion input manager. /// /// The input manager. - protected virtual KeyConversionInputManager CreateKeyConversionInputManager() => new KeyConversionInputManager(); + protected virtual PassThroughInputManager CreateActionMappingInputManager() => new PassThroughInputManager(); protected virtual FramedReplayInputHandler CreateReplayInputHandler(Replay replay) => new FramedReplayInputHandler(replay); @@ -105,14 +113,14 @@ namespace osu.Game.Rulesets.UI } /// - /// HitRenderer that applies conversion to Beatmaps. Does not contain a Playfield + /// RulesetContainer that applies conversion to Beatmaps. Does not contain a Playfield /// and does not load drawable hit objects. /// - /// Should not be derived - derive instead. + /// Should not be derived - derive instead. /// /// - /// The type of HitObject contained by this HitRenderer. - public abstract class HitRenderer : HitRenderer + /// The type of HitObject contained by this RulesetContainer. + public abstract class RulesetContainer : RulesetContainer where TObject : HitObject { /// @@ -133,11 +141,12 @@ namespace osu.Game.Rulesets.UI /// /// Creates a hit renderer for a beatmap. /// + /// The ruleset being repesented. /// The beatmap to create the hit renderer for. /// Whether to assume the beatmap is for the current ruleset. - internal HitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) + internal RulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset) : base(ruleset) { - Debug.Assert(beatmap != null, "HitRenderer initialized with a null beatmap."); + Debug.Assert(beatmap != null, "RulesetContainer initialized with a null beatmap."); Mods = beatmap.Mods.Value; @@ -171,7 +180,7 @@ namespace osu.Game.Rulesets.UI } /// - /// Applies the active mods to this HitRenderer. + /// Applies the active mods to this RulesetContainer. /// /// private void applyMods(IEnumerable mods) @@ -180,7 +189,7 @@ namespace osu.Game.Rulesets.UI return; foreach (var mod in mods.OfType>()) - mod.ApplyToHitRenderer(this); + mod.ApplyToRulesetContainer(this); } /// @@ -203,11 +212,11 @@ namespace osu.Game.Rulesets.UI } /// - /// A derivable HitRenderer that manages the Playfield and HitObjects. + /// A derivable RulesetContainer that manages the Playfield and HitObjects. /// - /// The type of HitObject contained by this HitRenderer. - /// The type of Judgement of DrawableHitObjects contained by this HitRenderer. - public abstract class HitRenderer : HitRenderer + /// The type of HitObject contained by this RulesetContainer. + /// The type of Judgement of DrawableHitObjects contained by this RulesetContainer. + public abstract class RulesetContainer : RulesetContainer where TObject : HitObject where TJudgement : Judgement { @@ -225,7 +234,7 @@ namespace osu.Game.Rulesets.UI /// /// The playfield. /// - protected Playfield Playfield; + public Playfield Playfield { get; private set; } protected override Container Content => content; private readonly Container content; @@ -235,10 +244,11 @@ namespace osu.Game.Rulesets.UI /// /// Creates a hit renderer for a beatmap. /// + /// The ruleset being repesented. /// The beatmap to create the hit renderer for. /// Whether to assume the beatmap is for the current ruleset. - protected HitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) - : base(beatmap, isForCurrentRuleset) + protected RulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset) + : base(ruleset, beatmap, isForCurrentRuleset) { InputManager.Add(content = new Container { @@ -323,6 +333,34 @@ namespace osu.Game.Rulesets.UI protected abstract Playfield CreatePlayfield(); } + /// + /// A derivable RulesetContainer that manages the Playfield and HitObjects. + /// + /// The type of Playfield contained by this RulesetContainer. + /// The type of HitObject contained by this RulesetContainer. + /// The type of Judgement of DrawableHitObjects contained by this RulesetContainer. + public abstract class RulesetContainer : RulesetContainer + where TObject : HitObject + where TJudgement : Judgement + where TPlayfield : Playfield + { + /// + /// The playfield. + /// + protected new TPlayfield Playfield => (TPlayfield)base.Playfield; + + /// + /// Creates a hit renderer for a beatmap. + /// + /// The ruleset being repesented. + /// The beatmap to create the hit renderer for. + /// Whether to assume the beatmap is for the current ruleset. + protected RulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset) + : base(ruleset, beatmap, isForCurrentRuleset) + { + } + } + public class BeatmapInvalidForRulesetException : ArgumentException { public BeatmapInvalidForRulesetException(string text) diff --git a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs new file mode 100644 index 0000000000..66ca2dd7c4 --- /dev/null +++ b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs @@ -0,0 +1,239 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using System.Linq; +using OpenTK.Input; +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Transforms; +using osu.Framework.Input; +using osu.Framework.MathUtils; +using osu.Game.Rulesets.Judgements; +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Rulesets.Timing; + +namespace osu.Game.Rulesets.UI +{ + /// + /// A type of specialized towards scrolling s. + /// + public class ScrollingPlayfield : Playfield + where TObject : HitObject + where TJudgement : Judgement + { + /// + /// The default span of time visible by the length of the scrolling axes. + /// This is clamped between and . + /// + private const double time_span_default = 1500; + /// + /// The minimum span of time that may be visible by the length of the scrolling axes. + /// + private const double time_span_min = 50; + /// + /// The maximum span of time that may be visible by the length of the scrolling axes. + /// + private const double time_span_max = 10000; + /// + /// The step increase/decrease of the span of time visible by the length of the scrolling axes. + /// + private const double time_span_step = 50; + + /// + /// The span of time that is visible by the length of the scrolling axes. + /// For example, only hit objects with start time less than or equal to 1000 will be visible with = 1000. + /// + public readonly BindableDouble VisibleTimeRange = new BindableDouble(time_span_default) + { + Default = time_span_default, + MinValue = time_span_min, + MaxValue = time_span_max + }; + + /// + /// Whether to reverse the scrolling direction is reversed. + /// + public readonly BindableBool Reversed = new BindableBool(); + + /// + /// The container that contains the s and s. + /// + internal new readonly ScrollingHitObjectContainer HitObjects; + + /// + /// Creates a new . + /// + /// The axes on which s in this container should scroll. + /// Whether we want our internal coordinate system to be scaled to a specified width + protected ScrollingPlayfield(Axes scrollingAxes, float? customWidth = null) + : base(customWidth) + { + base.HitObjects = HitObjects = new ScrollingHitObjectContainer(scrollingAxes) { RelativeSizeAxes = Axes.Both }; + HitObjects.VisibleTimeRange.BindTo(VisibleTimeRange); + HitObjects.Reversed.BindTo(Reversed); + } + + private List> nestedPlayfields; + /// + /// All the s nested inside this playfield. + /// + public IEnumerable> NestedPlayfields => nestedPlayfields; + + /// + /// Adds a to this playfield. The nested + /// will be given all of the same speed adjustments as this playfield. + /// + /// The to add. + protected void AddNested(ScrollingPlayfield otherPlayfield) + { + if (nestedPlayfields == null) + nestedPlayfields = new List>(); + + nestedPlayfields.Add(otherPlayfield); + } + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + { + if (state.Keyboard.ControlPressed) + { + switch (args.Key) + { + case Key.Minus: + transformVisibleTimeRangeTo(VisibleTimeRange + time_span_step, 200, Easing.OutQuint); + break; + case Key.Plus: + transformVisibleTimeRangeTo(VisibleTimeRange - time_span_step, 200, Easing.OutQuint); + break; + } + } + + return false; + } + + private void transformVisibleTimeRangeTo(double newTimeRange, double duration = 0, Easing easing = Easing.None) + { + this.TransformTo(this.PopulateTransform(new TransformVisibleTimeRange(), newTimeRange, duration, easing)); + } + + private class TransformVisibleTimeRange : Transform> + { + private double valueAt(double time) + { + if (time < StartTime) return StartValue; + if (time >= EndTime) return EndValue; + + return Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing); + } + + public override string TargetMember => "VisibleTimeRange.Value"; + + protected override void Apply(ScrollingPlayfield d, double time) => d.VisibleTimeRange.Value = valueAt(time); + protected override void ReadIntoStartValue(ScrollingPlayfield d) => StartValue = d.VisibleTimeRange.Value; + } + + /// + /// A container that provides the foundation for sorting s into s. + /// + internal class ScrollingHitObjectContainer : HitObjectContainer + { + /// + /// Gets or sets the range of time that is visible by the length of the scrolling axes. + /// For example, only hit objects with start time less than or equal to 1000 will be visible with = 1000. + /// + public readonly BindableDouble VisibleTimeRange = new BindableDouble { Default = 1000 }; + + /// + /// Whether to reverse the scrolling direction is reversed. + /// + public readonly BindableBool Reversed = new BindableBool(); + + /// + /// Hit objects that are to be re-processed on the next update. + /// + private readonly List queuedHitObjects = new List(); + private readonly List speedAdjustments = new List(); + + private readonly Axes scrollingAxes; + + /// + /// Creates a new . + /// + /// The axes upon which hit objects should appear to scroll inside this container. + public ScrollingHitObjectContainer(Axes scrollingAxes) + { + this.scrollingAxes = scrollingAxes; + } + + /// + /// Adds a to this container. + /// + /// The . + public void AddSpeedAdjustment(SpeedAdjustmentContainer speedAdjustment) + { + speedAdjustment.ScrollingAxes = scrollingAxes; + speedAdjustment.VisibleTimeRange.BindTo(VisibleTimeRange); + speedAdjustment.Reversed.BindTo(Reversed); + + speedAdjustments.Add(speedAdjustment); + AddInternal(speedAdjustment); + } + + public override IEnumerable Objects => speedAdjustments.SelectMany(s => s.Children); + + /// + /// Adds a hit object to this . The hit objects will be queued to be processed + /// new s are added to this . + /// + /// The hit object to add. + public override void Add(DrawableHitObject hitObject) + { + if (!(hitObject is IScrollingHitObject)) + throw new InvalidOperationException($"Hit objects added to a {nameof(ScrollingHitObjectContainer)} must implement {nameof(IScrollingHitObject)}."); + + queuedHitObjects.Add(hitObject); + } + + public override bool Remove(DrawableHitObject hitObject) => speedAdjustments.Any(s => s.Remove(hitObject)) || queuedHitObjects.Remove(hitObject); + + protected override void Update() + { + base.Update(); + + // Todo: At the moment this is going to re-process every single Update, however this will only be a null-op + // when there are no SpeedAdjustmentContainers available. This should probably error or something, but it's okay for now. + + for (int i = queuedHitObjects.Count - 1; i >= 0; i--) + { + var hitObject = queuedHitObjects[i]; + + var target = adjustmentContainerFor(hitObject); + if (target != null) + { + target.Add(hitObject); + queuedHitObjects.RemoveAt(i); + } + } + } + + /// + /// Finds the which provides the speed adjustment active at the start time + /// of a hit object. If there is no active at the start time of the hit object, + /// then the first (time-wise) speed adjustment is returned. + /// + /// The hit object to find the active for. + /// The active at 's start time. Null if there are no speed adjustments. + private SpeedAdjustmentContainer adjustmentContainerFor(DrawableHitObject hitObject) => speedAdjustments.FirstOrDefault(c => c.CanContain(hitObject)) ?? speedAdjustments.LastOrDefault(); + + /// + /// Finds the which provides the speed adjustment active at a time. + /// If there is no active at the time, then the first (time-wise) speed adjustment is returned. + /// + /// The time to find the active at. + /// The active at . Null if there are no speed adjustments. + private SpeedAdjustmentContainer adjustmentContainerAt(double time) => speedAdjustments.FirstOrDefault(c => c.CanContain(time)) ?? speedAdjustments.LastOrDefault(); + } + } +} \ No newline at end of file diff --git a/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs b/osu.Game/Rulesets/UI/ScrollingRulesetContainer.cs similarity index 59% rename from osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs rename to osu.Game/Rulesets/UI/ScrollingRulesetContainer.cs index 42dadb047d..64e865473d 100644 --- a/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs +++ b/osu.Game/Rulesets/UI/ScrollingRulesetContainer.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; +using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Lists; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; @@ -16,23 +17,36 @@ using osu.Game.Rulesets.Timing; namespace osu.Game.Rulesets.UI { /// - /// A type of that supports speed adjustments in some capacity. + /// A type of that supports a . + /// s inside this will scroll within the playfield. /// - public abstract class SpeedAdjustedHitRenderer : HitRenderer + public abstract class ScrollingRulesetContainer : RulesetContainer where TObject : HitObject where TJudgement : Judgement + where TPlayfield : ScrollingPlayfield { + /// + /// Provides the default s that adjust the scrolling rate of s + /// inside this . + /// + /// protected readonly SortedList DefaultControlPoints = new SortedList(Comparer.Default); - protected SpeedAdjustedHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) - : base(beatmap, isForCurrentRuleset) + protected ScrollingRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset) + : base(ruleset, beatmap, isForCurrentRuleset) { } [BackgroundDependencyLoader] private void load() { - ApplySpeedAdjustments(); + DefaultControlPoints.ForEach(c => applySpeedAdjustment(c, Playfield)); + } + + private void applySpeedAdjustment(MultiplierControlPoint controlPoint, ScrollingPlayfield playfield) + { + playfield.HitObjects.AddSpeedAdjustment(CreateSpeedAdjustmentContainer(controlPoint)); + playfield.NestedPlayfields.ForEach(p => applySpeedAdjustment(controlPoint, p)); } protected override void ApplyBeatmap() @@ -77,13 +91,17 @@ namespace osu.Game.Rulesets.UI .GroupBy(s => s.TimingPoint.BeatLength * s.DifficultyPoint.SpeedMultiplier).Select(g => g.First()); DefaultControlPoints.AddRange(timingChanges); + + // If we have no control points, add a default one + if (DefaultControlPoints.Count == 0) + DefaultControlPoints.Add(new MultiplierControlPoint()); } /// - /// Generates a control point with the default timing change/difficulty change from the beatmap at a time. + /// Generates a with the default timing change/difficulty change from the beatmap at a time. /// /// The time to create the control point at. - /// The at . + /// The default at . public MultiplierControlPoint CreateControlPointAt(double time) { if (DefaultControlPoints.Count == 0) @@ -97,8 +115,10 @@ namespace osu.Game.Rulesets.UI } /// - /// Applies speed changes to the playfield. + /// Creates a that facilitates the movement of hit objects. /// - protected abstract void ApplySpeedAdjustments(); + /// The that provides the speed adjustments for the hitobjects. + /// The . + protected virtual SpeedAdjustmentContainer CreateSpeedAdjustmentContainer(MultiplierControlPoint controlPoint) => new SpeedAdjustmentContainer(controlPoint); } } diff --git a/osu.Game/Screens/Play/HUDOverlay.cs b/osu.Game/Screens/Play/HUDOverlay.cs index ea75c140db..cf6bc03c60 100644 --- a/osu.Game/Screens/Play/HUDOverlay.cs +++ b/osu.Game/Screens/Play/HUDOverlay.cs @@ -90,11 +90,11 @@ namespace osu.Game.Screens.Play } } - public virtual void BindHitRenderer(HitRenderer hitRenderer) + public virtual void BindRulesetContainer(RulesetContainer rulesetContainer) { - hitRenderer.InputManager.Add(KeyCounter.GetReceptor()); + rulesetContainer.InputManager.Add(KeyCounter.GetReceptor()); - replayLoaded = hitRenderer.HasReplayLoaded; + replayLoaded = rulesetContainer.HasReplayLoaded; // in the case a replay isn't loaded, we want some elements to only appear briefly. if (!replayLoaded) diff --git a/osu.Game/Screens/Play/KeyConversionInputManager.cs b/osu.Game/Screens/Play/KeyConversionInputManager.cs deleted file mode 100644 index f3ca764bd7..0000000000 --- a/osu.Game/Screens/Play/KeyConversionInputManager.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Framework.Input; - -namespace osu.Game.Screens.Play -{ - /// - /// An InputManager primarily used to map keys to new functions. - /// By default this does nothing; override TransformState to make alterations. - /// - public class KeyConversionInputManager : PassThroughInputManager - { - - } -} \ No newline at end of file diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index a13e9ed369..00f1bd1b6b 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -32,7 +32,7 @@ namespace osu.Game.Screens.Play internal override bool ShowOverlays => false; - internal override bool HasLocalCursorDisplayed => !pauseContainer.IsPaused && !HasFailed && HitRenderer.ProvidingUserCursor; + internal override bool HasLocalCursorDisplayed => !pauseContainer.IsPaused && !HasFailed && RulesetContainer.ProvidingUserCursor; public Action RestartRequested; @@ -51,7 +51,7 @@ namespace osu.Game.Screens.Play private RulesetInfo ruleset; private ScoreProcessor scoreProcessor; - protected HitRenderer HitRenderer; + protected RulesetContainer RulesetContainer; #region User Settings @@ -66,7 +66,7 @@ namespace osu.Game.Screens.Play private HUDOverlay hudOverlay; private FailOverlay failOverlay; - private bool loadedSuccessfully => HitRenderer?.Objects.Any() == true; + private bool loadedSuccessfully => RulesetContainer?.Objects.Any() == true; [BackgroundDependencyLoader(permitNulls: true)] private void load(AudioManager audio, OsuConfigManager config, OsuGame osu) @@ -93,18 +93,18 @@ namespace osu.Game.Screens.Play try { - HitRenderer = rulesetInstance.CreateHitRendererWith(working, ruleset.ID == beatmap.BeatmapInfo.Ruleset.ID); + RulesetContainer = rulesetInstance.CreateRulesetContainerWith(working, ruleset.ID == beatmap.BeatmapInfo.Ruleset.ID); } catch (BeatmapInvalidForRulesetException) { - // we may fail to create a HitRenderer if the beatmap cannot be loaded with the user's preferred ruleset + // we may fail to create a RulesetContainer if the beatmap cannot be loaded with the user's preferred ruleset // let's try again forcing the beatmap's ruleset. ruleset = beatmap.BeatmapInfo.Ruleset; rulesetInstance = ruleset.CreateInstance(); - HitRenderer = rulesetInstance.CreateHitRendererWith(Beatmap, true); + RulesetContainer = rulesetInstance.CreateRulesetContainerWith(Beatmap, true); } - if (!HitRenderer.Objects.Any()) + if (!RulesetContainer.Objects.Any()) throw new InvalidOperationException("Beatmap contains no hit objects!"); } catch (Exception e) @@ -119,7 +119,7 @@ namespace osu.Game.Screens.Play adjustableSourceClock = (IAdjustableClock)working.Track ?? new StopwatchClock(); decoupledClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; - var firstObjectTime = HitRenderer.Objects.First().StartTime; + var firstObjectTime = RulesetContainer.Objects.First().StartTime; decoupledClock.Seek(Math.Min(0, firstObjectTime - Math.Max(beatmap.ControlPointInfo.TimingPointAt(firstObjectTime).BeatLength * 4, beatmap.BeatmapInfo.AudioLeadIn))); decoupledClock.ProcessFrame(); @@ -147,7 +147,7 @@ namespace osu.Game.Screens.Play FramedClock = offsetClock, OnRetry = Restart, OnQuit = Exit, - CheckCanPause = () => ValidForResume && !HasFailed && !HitRenderer.HasReplayLoaded, + CheckCanPause = () => ValidForResume && !HasFailed && !RulesetContainer.HasReplayLoaded, Retries = RestartCount, OnPause = () => { hudOverlay.KeyCounter.IsCounting = pauseContainer.IsPaused; @@ -164,7 +164,7 @@ namespace osu.Game.Screens.Play Clock = offsetClock, Children = new Drawable[] { - HitRenderer, + RulesetContainer, } }, hudOverlay = new HUDOverlay @@ -184,27 +184,27 @@ namespace osu.Game.Screens.Play Action = () => { //we want to hide the hitrenderer immediately (looks better). //we may be able to remove this once the mouse cursor trail is improved. - HitRenderer?.Hide(); + RulesetContainer?.Hide(); Restart(); }, } }; - scoreProcessor = HitRenderer.CreateScoreProcessor(); + scoreProcessor = RulesetContainer.CreateScoreProcessor(); hudOverlay.KeyCounter.AddRange(rulesetInstance.CreateGameplayKeys()); hudOverlay.BindProcessor(scoreProcessor); - hudOverlay.BindHitRenderer(HitRenderer); + hudOverlay.BindRulesetContainer(RulesetContainer); - hudOverlay.Progress.Objects = HitRenderer.Objects; + hudOverlay.Progress.Objects = RulesetContainer.Objects; hudOverlay.Progress.AudioClock = decoupledClock; - hudOverlay.Progress.AllowSeeking = HitRenderer.HasReplayLoaded; + hudOverlay.Progress.AllowSeeking = RulesetContainer.HasReplayLoaded; hudOverlay.Progress.OnSeek = pos => decoupledClock.Seek(pos); hudOverlay.ModDisplay.Current.BindTo(working.Mods); - //bind HitRenderer to ScoreProcessor and ourselves (for a pass situation) - HitRenderer.OnAllJudged += onCompletion; + //bind RulesetContainer to ScoreProcessor and ourselves (for a pass situation) + RulesetContainer.OnAllJudged += onCompletion; //bind ScoreProcessor to ourselves (for a fail situation) scoreProcessor.Failed += onFail; @@ -238,7 +238,7 @@ namespace osu.Game.Screens.Play Ruleset = ruleset }; scoreProcessor.PopulateScore(score); - score.User = HitRenderer.Replay?.User ?? (Game as OsuGame)?.API?.LocalUser?.Value; + score.User = RulesetContainer.Replay?.User ?? (Game as OsuGame)?.API?.LocalUser?.Value; Push(new Results(score)); }); } @@ -295,7 +295,7 @@ namespace osu.Game.Screens.Play protected override bool OnExiting(Screen next) { - if (HasFailed || !ValidForResume || pauseContainer?.AllowExit != false || HitRenderer?.HasReplayLoaded != false) + if (HasFailed || !ValidForResume || pauseContainer?.AllowExit != false || RulesetContainer?.HasReplayLoaded != false) { fadeOut(); return base.OnExiting(next); @@ -313,7 +313,7 @@ namespace osu.Game.Screens.Play { const float fade_out_duration = 250; - HitRenderer?.FadeOut(fade_out_duration); + RulesetContainer?.FadeOut(fade_out_duration); Content.FadeOut(fade_out_duration); hudOverlay?.ScaleTo(0.7f, fade_out_duration * 3, Easing.In); diff --git a/osu.Game/Screens/Play/ReplayPlayer.cs b/osu.Game/Screens/Play/ReplayPlayer.cs index 860675b62a..4748ddfd71 100644 --- a/osu.Game/Screens/Play/ReplayPlayer.cs +++ b/osu.Game/Screens/Play/ReplayPlayer.cs @@ -17,7 +17,7 @@ namespace osu.Game.Screens.Play protected override void LoadComplete() { base.LoadComplete(); - HitRenderer.SetReplay(Replay); + RulesetContainer.SetReplay(Replay); } } } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 69460e378d..c674768d4e 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -93,6 +93,8 @@ + + @@ -120,6 +122,7 @@ + @@ -230,9 +233,9 @@ - + + - @@ -311,7 +314,6 @@ - @@ -340,9 +342,10 @@ - + - + +