From dcf879687d30fba36c5e7a1f19213ed63e84de27 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 24 May 2017 20:45:01 +0900 Subject: [PATCH 01/16] Implement basic hold note + tick input. --- .../Tests/TestCaseManiaPlayfield.cs | 47 +++++ .../Legacy/DistanceObjectPatternGenerator.cs | 9 +- .../Legacy/EndTimeObjectPatternGenerator.cs | 9 +- .../Judgements/HoldNoteTailJudgement.cs | 13 ++ .../Judgements/HoldNoteTickJudgement.cs | 9 + .../Objects/Drawables/DrawableHoldNote.cs | 198 ++++++++++++++++-- .../Objects/Drawables/DrawableHoldNoteTick.cs | 75 +++++++ osu.Game.Rulesets.Mania/Objects/HoldNote.cs | 42 ++-- .../Objects/HoldNoteTail.cs | 24 +++ .../Objects/HoldNoteTick.cs | 9 + .../osu.Game.Rulesets.Mania.csproj | 5 + 11 files changed, 406 insertions(+), 34 deletions(-) create mode 100644 osu.Game.Rulesets.Mania/Judgements/HoldNoteTailJudgement.cs create mode 100644 osu.Game.Rulesets.Mania/Judgements/HoldNoteTickJudgement.cs create mode 100644 osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs create mode 100644 osu.Game.Rulesets.Mania/Objects/HoldNoteTail.cs create mode 100644 osu.Game.Rulesets.Mania/Objects/HoldNoteTick.cs diff --git a/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs b/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs index 9dcba02849..27ad39fb1e 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs @@ -11,6 +11,9 @@ using OpenTK; using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Timing; +using osu.Framework.Configuration; +using OpenTK.Input; +using osu.Framework.Timing; namespace osu.Desktop.VisualTests.Tests { @@ -59,6 +62,48 @@ namespace osu.Desktop.VisualTests.Tests } }; + Action createPlayfieldWithNotesAcceptingInput = () => + { + Clear(); + + var rateAdjustClock = new StopwatchClock(true) { Rate = 0.2 }; + + ManiaPlayfield playField; + Add(playField = new ManiaPlayfield(4, new List { new TimingChange { BeatLength = 200 } }) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Scale = new Vector2(1, -1), + Clock = new FramedClock(rateAdjustClock) + }); + + playField.Add(new DrawableNote(new Note + { + StartTime = 1000, + Column = 0 + }, new Bindable(Key.D))); + + playField.Add(new DrawableHoldNote(new HoldNote + { + StartTime = 1000, + Duration = 2000, + Column = 1 + }, new Bindable(Key.F))); + + playField.Add(new DrawableHoldNote(new HoldNote + { + StartTime = 1000, + Duration = 2000, + Column = 2 + }, new Bindable(Key.J))); + + playField.Add(new DrawableNote(new Note + { + StartTime = 1000, + Column = 3 + }, new Bindable(Key.K))); + }; + AddStep("1 column", () => createPlayfield(1, SpecialColumnPosition.Normal)); AddStep("4 columns", () => createPlayfield(4, SpecialColumnPosition.Normal)); AddStep("Left special style", () => createPlayfield(4, SpecialColumnPosition.Left)); @@ -76,6 +121,8 @@ namespace osu.Desktop.VisualTests.Tests AddWaitStep(10); AddStep("Right special style", () => createPlayfieldWithNotes(4, SpecialColumnPosition.Right)); AddWaitStep(10); + + AddStep("Test", () => createPlayfieldWithNotesAcceptingInput()); } private void triggerKeyDown(Column column) diff --git a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs index 718e0967da..279ac868f1 100644 --- a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs +++ b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs @@ -471,14 +471,17 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy } else { - newObject = new HoldNote + var holdNote = new HoldNote { StartTime = startTime, - Samples = sampleInfoListAt(startTime), - EndSamples = sampleInfoListAt(endTime), Column = column, Duration = endTime - startTime }; + + holdNote.HeadNote.Samples = sampleInfoListAt(startTime); + holdNote.TailNote.Samples = sampleInfoListAt(endTime); + + newObject = holdNote; } pattern.Add(newObject); diff --git a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs index 8f438f9ff4..ddc7d77c0c 100644 --- a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs +++ b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs @@ -69,18 +69,21 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy if (holdNote) { - newObject = new HoldNote + var hold = new HoldNote { StartTime = HitObject.StartTime, - EndSamples = HitObject.Samples, Column = column, Duration = endTime - HitObject.StartTime }; - newObject.Samples.Add(new SampleInfo + hold.HeadNote.Samples.Add(new SampleInfo { Name = SampleInfo.HIT_NORMAL }); + + hold.TailNote.Samples = HitObject.Samples; + + newObject = hold; } else { diff --git a/osu.Game.Rulesets.Mania/Judgements/HoldNoteTailJudgement.cs b/osu.Game.Rulesets.Mania/Judgements/HoldNoteTailJudgement.cs new file mode 100644 index 0000000000..df2f7e9e63 --- /dev/null +++ b/osu.Game.Rulesets.Mania/Judgements/HoldNoteTailJudgement.cs @@ -0,0 +1,13 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +namespace osu.Game.Rulesets.Mania.Judgements +{ + public class HoldNoteTailJudgement : ManiaJudgement + { + /// + /// Whether the hold note has been released too early and shouldn't give full score for the release. + /// + public bool HasBroken; + } +} \ No newline at end of file diff --git a/osu.Game.Rulesets.Mania/Judgements/HoldNoteTickJudgement.cs b/osu.Game.Rulesets.Mania/Judgements/HoldNoteTickJudgement.cs new file mode 100644 index 0000000000..bead455c13 --- /dev/null +++ b/osu.Game.Rulesets.Mania/Judgements/HoldNoteTickJudgement.cs @@ -0,0 +1,9 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +namespace osu.Game.Rulesets.Mania.Judgements +{ + public class HoldNoteTickJudgement : ManiaJudgement + { + } +} \ No newline at end of file diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs index f9d027e7ce..a8efe5d2f8 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs @@ -7,14 +7,47 @@ using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces; using OpenTK.Graphics; using osu.Framework.Configuration; using OpenTK.Input; +using osu.Framework.Input; +using OpenTK; +using osu.Framework.Graphics.Containers; +using osu.Game.Rulesets.Mania.Judgements; namespace osu.Game.Rulesets.Mania.Objects.Drawables { public class DrawableHoldNote : DrawableManiaHitObject { - private readonly NotePiece headPiece; + private readonly DrawableNote headNote; + private readonly DrawableNote tailNote; private readonly BodyPiece bodyPiece; - private readonly NotePiece tailPiece; + private readonly Container tickContainer; + + /// + /// Relative time at which the user started holding this note. + /// + private double holdStartTime; + + /// + /// Whether the hold note has been released too early and shouldn't give full score for the release. + /// + private bool hasBroken; + + private bool _holding; + /// + /// Whether the user is holding the hold note. + /// + private bool holding + { + get { return _holding; } + set + { + if (_holding == value) + return; + _holding = value; + + if (holding) + holdStartTime = Time.Current; + } + } public DrawableHoldNote(HoldNote hitObject, Bindable key = null) : base(hitObject, key) @@ -32,17 +65,39 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, }, - headPiece = new NotePiece + tickContainer = new Container + { + RelativeSizeAxes = Axes.Both, + RelativeCoordinateSpace = new Vector2(1, (float)HitObject.Duration) + }, + headNote = new DrawableHoldNoteHead(this, key) { Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre }, - tailPiece = new NotePiece + tailNote = new DrawableHoldNoteTail(this, key) { Anchor = Anchor.BottomCentre, Origin = Anchor.TopCentre } }); + + foreach (var tick in HitObject.Ticks) + { + var drawableTick = new DrawableHoldNoteTick(tick) + { + IsHolding = () => holding, + HoldStartTime = () => holdStartTime + }; + + drawableTick.Y -= (float)HitObject.StartTime; + + tickContainer.Add(drawableTick); + AddNested(drawableTick); + } + + AddNested(headNote); + AddNested(tailNote); } public override Color4 AccentColour @@ -54,9 +109,9 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables return; base.AccentColour = value; - headPiece.AccentColour = value; bodyPiece.AccentColour = value; - tailPiece.AccentColour = value; + headNote.AccentColour = value; + tailNote.AccentColour = value; } } @@ -64,14 +119,133 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables { } - protected override void Update() + /// + /// Handles key down events on the body of the hold note. + /// + /// The input state. + /// The key down args. + /// Whether the key press was handled. + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { - if (Time.Current > HitObject.StartTime) - headPiece.Colour = Color4.Green; - if (Time.Current > HitObject.EndTime) + // Make sure the keypress happened within reasonable bounds of the hold note + if (Time.Current < HitObject.StartTime || Time.Current > HitObject.EndTime) + return false; + + if (args.Key != Key) + return false; + + if (args.Repeat) + return false; + + holding = true; + + return true; + } + + /// + /// Handles key up events on the body of the hold note. + /// + /// The input state. + /// The key down args. + /// Whether the key press was handled. + protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) + { + // Make sure that the user started holding the key during the hold note + if (!holding) + return false; + + if (args.Key != Key) + return false; + + holding = false; + + // If the key has been released too early, they should not receive full score for the release + if (!tailNote.Judged) + hasBroken = true; + + return true; + } + + private class DrawableHoldNoteHead : DrawableNote + { + private readonly DrawableHoldNote holdNote; + + public DrawableHoldNoteHead(DrawableHoldNote holdNote, Bindable key = null) + : base(holdNote.HitObject.HeadNote, key) { - bodyPiece.Colour = Color4.Green; - tailPiece.Colour = Color4.Green; + this.holdNote = holdNote; + + RelativePositionAxes = Axes.None; + Y = 0; + } + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + { + if (!base.OnKeyDown(state, args)) + return false; + + // We only want to trigger a holding state from the head if the head has received a judgement + if (Judgement.Result == HitResult.None) + return false; + + // If the head has been missed, make sure the user also can't receive a full score for the release + if (Judgement.Result == HitResult.Miss) + holdNote.hasBroken = true; + + holdNote.holding = true; + + return true; + } + } + + private class DrawableHoldNoteTail : DrawableNote + { + private readonly DrawableHoldNote holdNote; + + public DrawableHoldNoteTail(DrawableHoldNote holdNote, Bindable key = null) + : base(holdNote.HitObject.TailNote, key) + { + this.holdNote = holdNote; + + RelativePositionAxes = Axes.None; + Y = 0; + } + + protected override ManiaJudgement CreateJudgement() => new HoldNoteTailJudgement(); + + protected override void CheckJudgement(bool userTriggered) + { + base.CheckJudgement(userTriggered); + + var tailJudgement = Judgement as HoldNoteTailJudgement; + if (tailJudgement == null) + return; + + tailJudgement.HasBroken = holdNote.hasBroken; + } + + protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) + { + // Make sure that the user started holding the key during the hold note + if (!holdNote.holding) + return false; + + if (Judgement.Result != HitResult.None) + return false; + + if (args.Key != Key) + return false; + + UpdateJudgement(true); + + // Handled by the hold note, which will set holding = false + return false; + } + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + { + // Tail doesn't handle key down + return false; } } } diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs new file mode 100644 index 0000000000..13fde29bc2 --- /dev/null +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs @@ -0,0 +1,75 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using OpenTK.Graphics; +using OpenTK.Input; +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Input; +using osu.Game.Rulesets.Mania.Judgements; +using osu.Game.Rulesets.Objects.Drawables; + +namespace osu.Game.Rulesets.Mania.Objects.Drawables +{ + public class DrawableHoldNoteTick : DrawableManiaHitObject + { + public Func HoldStartTime; + public Func IsHolding; + + public DrawableHoldNoteTick(HoldNoteTick hitObject) + : base(hitObject, null) + { + RelativeSizeAxes = Axes.X; + + Children = new[] + { + new Box + { + RelativeSizeAxes = Axes.X, + Height = 1 + } + }; + } + + protected override ManiaJudgement CreateJudgement() => new HoldNoteTickJudgement(); + + protected override void CheckJudgement(bool userTriggered) + { + if (!userTriggered) + return; + + if (Time.Current < HitObject.StartTime) + return; + + + if (HoldStartTime?.Invoke() > HitObject.StartTime) + return; + + Judgement.ManiaResult = ManiaHitResult.Perfect; + Judgement.Result = HitResult.Hit; + } + + protected override void UpdateState(ArmedState state) + { + switch (State) + { + case ArmedState.Hit: + Colour = Color4.Green; + break; + } + } + + protected override void Update() + { + if (Judgement.Result != HitResult.None) + return; + + if (IsHolding?.Invoke() != true) + return; + + UpdateJudgement(true); + } + } +} \ No newline at end of file diff --git a/osu.Game.Rulesets.Mania/Objects/HoldNote.cs b/osu.Game.Rulesets.Mania/Objects/HoldNote.cs index 30e71aeb5d..926f434015 100644 --- a/osu.Game.Rulesets.Mania/Objects/HoldNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/HoldNote.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 System.Collections.Generic; using osu.Game.Audio; using osu.Game.Beatmaps.ControlPoints; using osu.Game.Database; @@ -12,32 +13,41 @@ namespace osu.Game.Rulesets.Mania.Objects /// /// Represents a hit object which requires pressing, holding, and releasing a key. /// - public class HoldNote : Note, IHasEndTime + public class HoldNote : ManiaHitObject, IHasEndTime { - /// - /// Lenience of release hit windows. This is to make cases where the hold note release - /// is timed alongside presses of other hit objects less awkward. - /// - private const double release_window_lenience = 1.5; - public double Duration { get; set; } public double EndTime => StartTime + Duration; - /// - /// The samples to be played when this hold note is released. - /// - public SampleInfoList EndSamples = new SampleInfoList(); + private Note headNote; + public Note HeadNote => headNote ?? (headNote = new Note { StartTime = StartTime }); + + private Note tailNote; + public Note TailNote => tailNote ?? (tailNote = new HoldNoteTail { StartTime = EndTime }); /// - /// The key-release hit windows for this hold note. + /// The length (in milliseconds) between ticks of this hold. /// - public HitWindows ReleaseHitWindows { get; protected set; } = new HitWindows(); + private double tickSpacing = 50; - public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) + public IEnumerable Ticks => ticks ?? (ticks = createTicks()); + private List ticks; + + private List createTicks() { - base.ApplyDefaults(controlPointInfo, difficulty); + var ret = new List(); - ReleaseHitWindows = HitWindows * release_window_lenience; + if (tickSpacing == 0) + return ret; + + for (double t = StartTime + HeadNote.HitWindows.Great / 2; t <= EndTime - TailNote.HitWindows.Great / 2; t+= tickSpacing) + { + ret.Add(new HoldNoteTick + { + StartTime = t + }); + } + + return ret; } } } diff --git a/osu.Game.Rulesets.Mania/Objects/HoldNoteTail.cs b/osu.Game.Rulesets.Mania/Objects/HoldNoteTail.cs new file mode 100644 index 0000000000..6399277a2b --- /dev/null +++ b/osu.Game.Rulesets.Mania/Objects/HoldNoteTail.cs @@ -0,0 +1,24 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Beatmaps.ControlPoints; +using osu.Game.Database; + +namespace osu.Game.Rulesets.Mania.Objects +{ + public class HoldNoteTail : Note + { + /// + /// Lenience of release hit windows. This is to make cases where the hold note release + /// is timed alongside presses of other hit objects less awkward. + /// + private const double release_window_lenience = 1.5; + + public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) + { + base.ApplyDefaults(controlPointInfo, difficulty); + + HitWindows *= release_window_lenience; + } + } +} \ No newline at end of file diff --git a/osu.Game.Rulesets.Mania/Objects/HoldNoteTick.cs b/osu.Game.Rulesets.Mania/Objects/HoldNoteTick.cs new file mode 100644 index 0000000000..805b2a0938 --- /dev/null +++ b/osu.Game.Rulesets.Mania/Objects/HoldNoteTick.cs @@ -0,0 +1,9 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +namespace osu.Game.Rulesets.Mania.Objects +{ + public class HoldNoteTick : ManiaHitObject + { + } +} \ No newline at end of file diff --git a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj index 9442d7cf8f..91cb551414 100644 --- a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj +++ b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj @@ -57,10 +57,13 @@ + + + @@ -68,6 +71,8 @@ + + From 78067e085c858f8e6d8ab70ac9bf2699a3d0e3ca Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 24 May 2017 20:53:47 +0900 Subject: [PATCH 02/16] Fix note input ordering. --- osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index ff763f87c4..495959b061 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -189,7 +189,12 @@ namespace osu.Game.Rulesets.Mania.UI } } - public override void Add(DrawableHitObject h) => Columns.ElementAt(h.HitObject.Column).Add(h); + public override void Add(DrawableHitObject h) + { + h.Depth = (float)h.HitObject.StartTime; + + Columns.ElementAt(h.HitObject.Column).Add(h); + } protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { From 4ef18ff135fd91e3e40274f507a545f438bfa590 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 24 May 2017 20:54:01 +0900 Subject: [PATCH 03/16] Test case improvements. --- .../Tests/TestCaseManiaPlayfield.cs | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs b/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs index 27ad39fb1e..8d0a87ae9d 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs @@ -77,31 +77,34 @@ namespace osu.Desktop.VisualTests.Tests Clock = new FramedClock(rateAdjustClock) }); - playField.Add(new DrawableNote(new Note + for (int t = 1000; t <= 2000; t += 100) { - StartTime = 1000, - Column = 0 - }, new Bindable(Key.D))); + playField.Add(new DrawableNote(new Note + { + StartTime = t, + Column = 0 + }, new Bindable(Key.J))); + + playField.Add(new DrawableNote(new Note + { + StartTime = t, + Column = 3 + }, new Bindable(Key.K))); + } playField.Add(new DrawableHoldNote(new HoldNote { StartTime = 1000, - Duration = 2000, + Duration = 1000, Column = 1 }, new Bindable(Key.F))); playField.Add(new DrawableHoldNote(new HoldNote { StartTime = 1000, - Duration = 2000, + Duration = 1000, Column = 2 }, new Bindable(Key.J))); - - playField.Add(new DrawableNote(new Note - { - StartTime = 1000, - Column = 3 - }, new Bindable(Key.K))); }; AddStep("1 column", () => createPlayfield(1, SpecialColumnPosition.Normal)); From d6b104d794d2fdebcd46949115c581f1b8d7565e Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 24 May 2017 21:24:18 +0900 Subject: [PATCH 04/16] Minor visual change for DrawableHoldNoteTick. --- .../Objects/Drawables/DrawableHoldNote.cs | 3 ++ .../Objects/Drawables/DrawableHoldNoteTick.cs | 50 ++++++++++++++++--- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs index a8efe5d2f8..ee371b61ca 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs @@ -11,6 +11,7 @@ using osu.Framework.Input; using OpenTK; using osu.Framework.Graphics.Containers; using osu.Game.Rulesets.Mania.Judgements; +using osu.Framework.Extensions.IEnumerableExtensions; namespace osu.Game.Rulesets.Mania.Objects.Drawables { @@ -109,6 +110,8 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables return; base.AccentColour = value; + tickContainer.Children.ForEach(t => t.AccentColour = value); + bodyPiece.AccentColour = value; headNote.AccentColour = value; tailNote.AccentColour = value; diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs index 13fde29bc2..7a8f25e098 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs @@ -2,12 +2,12 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; +using OpenTK; using OpenTK.Graphics; -using OpenTK.Input; -using osu.Framework.Configuration; +using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; -using osu.Framework.Input; using osu.Game.Rulesets.Mania.Judgements; using osu.Game.Rulesets.Objects.Drawables; @@ -18,19 +18,55 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables public Func HoldStartTime; public Func IsHolding; + private readonly Container glowContainer; + public DrawableHoldNoteTick(HoldNoteTick hitObject) : base(hitObject, null) { + Anchor = Anchor.TopCentre; + Origin = Anchor.TopCentre; + RelativeSizeAxes = Axes.X; + Size = new Vector2(1); Children = new[] { - new Box + glowContainer = new CircularContainer { - RelativeSizeAxes = Axes.X, - Height = 1 + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + RelativeSizeAxes = Axes.Both, + Masking = true, + Children = new[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Alpha = 0, + AlwaysPresent = true + } + } } }; + + AccentColour = Color4.White; + } + + public override Color4 AccentColour + { + get { return base.AccentColour; } + set + { + base.AccentColour = value; + + glowContainer.EdgeEffect = new EdgeEffect + { + Type = EdgeEffectType.Glow, + Radius = 2f, + Roundness = 15f, + Colour = value.Opacity(0.3f) + }; + } } protected override ManiaJudgement CreateJudgement() => new HoldNoteTickJudgement(); @@ -56,7 +92,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables switch (State) { case ArmedState.Hit: - Colour = Color4.Green; + AccentColour = Color4.Green; break; } } From 21cdee02f3cfce00771a10bc3ee89ef7421fbbd2 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 24 May 2017 21:24:33 +0900 Subject: [PATCH 05/16] Get tickSpacing from beatmap. --- osu.Game.Rulesets.Mania/Objects/HoldNote.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Objects/HoldNote.cs b/osu.Game.Rulesets.Mania/Objects/HoldNote.cs index 926f434015..b3e2482908 100644 --- a/osu.Game.Rulesets.Mania/Objects/HoldNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/HoldNote.cs @@ -2,10 +2,8 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Collections.Generic; -using osu.Game.Audio; using osu.Game.Beatmaps.ControlPoints; using osu.Game.Database; -using osu.Game.Rulesets.Mania.Judgements; using osu.Game.Rulesets.Objects.Types; namespace osu.Game.Rulesets.Mania.Objects @@ -29,6 +27,14 @@ namespace osu.Game.Rulesets.Mania.Objects /// private double tickSpacing = 50; + public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) + { + base.ApplyDefaults(controlPointInfo, difficulty); + + TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime); + tickSpacing = timingPoint.BeatLength / difficulty.SliderTickRate; + } + public IEnumerable Ticks => ticks ?? (ticks = createTicks()); private List ticks; From ed65b3559a72b27dc904268f36643d68a589983c Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 24 May 2017 21:25:01 +0900 Subject: [PATCH 06/16] CI fix. --- .../Objects/Drawables/DrawableHoldNoteTick.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs index 7a8f25e098..7c84157c26 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs @@ -21,7 +21,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables private readonly Container glowContainer; public DrawableHoldNoteTick(HoldNoteTick hitObject) - : base(hitObject, null) + : base(hitObject) { Anchor = Anchor.TopCentre; Origin = Anchor.TopCentre; From a5b79b2192b5d34fb8f1d69363fe03495dcd77a9 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 24 May 2017 21:56:49 +0900 Subject: [PATCH 07/16] Fix notes not getting accent colours. --- osu.Game.Rulesets.Mania/UI/Column.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index c8cb5f6387..6dfd5000d4 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -1,7 +1,6 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - using OpenTK; using OpenTK.Graphics; using OpenTK.Input; @@ -188,7 +187,11 @@ namespace osu.Game.Rulesets.Mania.UI } } - public void Add(DrawableHitObject hitObject) => ControlPointContainer.Add(hitObject); + public void Add(DrawableHitObject hitObject) + { + hitObject.AccentColour = AccentColour; + ControlPointContainer.Add(hitObject); + } private bool onKeyDown(InputState state, KeyDownEventArgs args) { From 946cd4bfa380ca4a3684f1375f11ee94d708ef1c Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 24 May 2017 21:57:38 +0900 Subject: [PATCH 08/16] General cleanup + more xmldocs. --- .../Tests/TestCaseManiaPlayfield.cs | 6 +-- .../Legacy/DistanceObjectPatternGenerator.cs | 4 +- .../Legacy/EndTimeObjectPatternGenerator.cs | 4 +- .../Objects/Drawables/DrawableHoldNote.cs | 45 ++++++++++++------- .../Objects/Drawables/DrawableHoldNoteTick.cs | 11 +++++ .../Objects/Drawables/DrawableNote.cs | 3 ++ osu.Game.Rulesets.Mania/Objects/HoldNote.cs | 40 ++++++++++++++--- .../Objects/HoldNoteTail.cs | 24 ---------- .../Objects/HoldNoteTick.cs | 3 ++ .../osu.Game.Rulesets.Mania.csproj | 1 - 10 files changed, 86 insertions(+), 55 deletions(-) delete mode 100644 osu.Game.Rulesets.Mania/Objects/HoldNoteTail.cs diff --git a/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs b/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs index 8d0a87ae9d..857c2c0ca7 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs @@ -66,7 +66,7 @@ namespace osu.Desktop.VisualTests.Tests { Clear(); - var rateAdjustClock = new StopwatchClock(true) { Rate = 0.2 }; + var rateAdjustClock = new StopwatchClock(true) { Rate = 0.5 }; ManiaPlayfield playField; Add(playField = new ManiaPlayfield(4, new List { new TimingChange { BeatLength = 200 } }) @@ -83,7 +83,7 @@ namespace osu.Desktop.VisualTests.Tests { StartTime = t, Column = 0 - }, new Bindable(Key.J))); + }, new Bindable(Key.D))); playField.Add(new DrawableNote(new Note { @@ -125,7 +125,7 @@ namespace osu.Desktop.VisualTests.Tests AddStep("Right special style", () => createPlayfieldWithNotes(4, SpecialColumnPosition.Right)); AddWaitStep(10); - AddStep("Test", () => createPlayfieldWithNotesAcceptingInput()); + AddStep("Notes with input", () => createPlayfieldWithNotesAcceptingInput()); } private void triggerKeyDown(Column column) diff --git a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs index 279ac868f1..076bcdfaab 100644 --- a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs +++ b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs @@ -478,8 +478,8 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy Duration = endTime - startTime }; - holdNote.HeadNote.Samples = sampleInfoListAt(startTime); - holdNote.TailNote.Samples = sampleInfoListAt(endTime); + holdNote.Head.Samples = sampleInfoListAt(startTime); + holdNote.Tail.Samples = sampleInfoListAt(endTime); newObject = holdNote; } diff --git a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs index ddc7d77c0c..6ad7489e0f 100644 --- a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs +++ b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs @@ -76,12 +76,12 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy Duration = endTime - HitObject.StartTime }; - hold.HeadNote.Samples.Add(new SampleInfo + hold.Head.Samples.Add(new SampleInfo { Name = SampleInfo.HIT_NORMAL }); - hold.TailNote.Samples = HitObject.Samples; + hold.Tail.Samples = HitObject.Samples; newObject = hold; } diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs index ee371b61ca..cef4eecd38 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs @@ -15,15 +15,19 @@ using osu.Framework.Extensions.IEnumerableExtensions; namespace osu.Game.Rulesets.Mania.Objects.Drawables { + /// + /// Visualises a hit object. + /// public class DrawableHoldNote : DrawableManiaHitObject { - private readonly DrawableNote headNote; - private readonly DrawableNote tailNote; + private readonly DrawableNote head; + private readonly DrawableNote tail; + private readonly BodyPiece bodyPiece; private readonly Container tickContainer; /// - /// Relative time at which the user started holding this note. + /// Time at which the user started holding this hold note. /// private double holdStartTime; @@ -34,7 +38,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables private bool _holding; /// - /// Whether the user is holding the hold note. + /// Whether the user is currently holding the hold note. /// private bool holding { @@ -71,12 +75,12 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables RelativeSizeAxes = Axes.Both, RelativeCoordinateSpace = new Vector2(1, (float)HitObject.Duration) }, - headNote = new DrawableHoldNoteHead(this, key) + head = new HeadNote(this, key) { Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre }, - tailNote = new DrawableHoldNoteTail(this, key) + tail = new TailNote(this, key) { Anchor = Anchor.BottomCentre, Origin = Anchor.TopCentre @@ -91,14 +95,15 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables HoldStartTime = () => holdStartTime }; + // To make the ticks relative to ourselves we need to offset them backwards drawableTick.Y -= (float)HitObject.StartTime; tickContainer.Add(drawableTick); AddNested(drawableTick); } - AddNested(headNote); - AddNested(tailNote); + AddNested(head); + AddNested(tail); } public override Color4 AccentColour @@ -113,8 +118,8 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables tickContainer.Children.ForEach(t => t.AccentColour = value); bodyPiece.AccentColour = value; - headNote.AccentColour = value; - tailNote.AccentColour = value; + head.AccentColour = value; + tail.AccentColour = value; } } @@ -163,18 +168,21 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables holding = false; // If the key has been released too early, they should not receive full score for the release - if (!tailNote.Judged) + if (!tail.Judged) hasBroken = true; return true; } - private class DrawableHoldNoteHead : DrawableNote + /// + /// The head note of a hold. + /// + private class HeadNote : DrawableNote { private readonly DrawableHoldNote holdNote; - public DrawableHoldNoteHead(DrawableHoldNote holdNote, Bindable key = null) - : base(holdNote.HitObject.HeadNote, key) + public HeadNote(DrawableHoldNote holdNote, Bindable key = null) + : base(holdNote.HitObject.Head, key) { this.holdNote = holdNote; @@ -201,12 +209,15 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables } } - private class DrawableHoldNoteTail : DrawableNote + /// + /// The tail note of a hold. + /// + private class TailNote : DrawableNote { private readonly DrawableHoldNote holdNote; - public DrawableHoldNoteTail(DrawableHoldNote holdNote, Bindable key = null) - : base(holdNote.HitObject.TailNote, key) + public TailNote(DrawableHoldNote holdNote, Bindable key = null) + : base(holdNote.HitObject.Tail, key) { this.holdNote = holdNote; diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs index 7c84157c26..8cd60e9901 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs @@ -13,9 +13,19 @@ using osu.Game.Rulesets.Objects.Drawables; namespace osu.Game.Rulesets.Mania.Objects.Drawables { + /// + /// Visualises a hit object. + /// public class DrawableHoldNoteTick : DrawableManiaHitObject { + /// + /// References the time at which the user started holding the hold note. + /// public Func HoldStartTime; + + /// + /// References whether the user is currently holding the hold note. + /// public Func IsHolding; private readonly Container glowContainer; @@ -49,6 +59,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables } }; + // Set the default glow AccentColour = Color4.White; } diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs index 42bb371975..658d409bb8 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs @@ -13,6 +13,9 @@ using osu.Game.Rulesets.Objects.Drawables; namespace osu.Game.Rulesets.Mania.Objects.Drawables { + /// + /// Visualises a hit object. + /// public class DrawableNote : DrawableManiaHitObject { private readonly NotePiece headPiece; diff --git a/osu.Game.Rulesets.Mania/Objects/HoldNote.cs b/osu.Game.Rulesets.Mania/Objects/HoldNote.cs index b3e2482908..db317ddf7b 100644 --- a/osu.Game.Rulesets.Mania/Objects/HoldNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/HoldNote.cs @@ -16,14 +16,20 @@ namespace osu.Game.Rulesets.Mania.Objects public double Duration { get; set; } public double EndTime => StartTime + Duration; - private Note headNote; - public Note HeadNote => headNote ?? (headNote = new Note { StartTime = StartTime }); + private Note head; + /// + /// The head note of the hold. + /// + public Note Head => head ?? (head = new Note { StartTime = StartTime }); - private Note tailNote; - public Note TailNote => tailNote ?? (tailNote = new HoldNoteTail { StartTime = EndTime }); + private Note tail; + /// + /// The tail note of the hold. + /// + public Note Tail => tail ?? (tail = new TailNote { StartTime = EndTime }); /// - /// The length (in milliseconds) between ticks of this hold. + /// The time between ticks of this hold. /// private double tickSpacing = 50; @@ -35,6 +41,9 @@ namespace osu.Game.Rulesets.Mania.Objects tickSpacing = timingPoint.BeatLength / difficulty.SliderTickRate; } + /// + /// The scoring scoring ticks of the hold note. + /// public IEnumerable Ticks => ticks ?? (ticks = createTicks()); private List ticks; @@ -45,7 +54,7 @@ namespace osu.Game.Rulesets.Mania.Objects if (tickSpacing == 0) return ret; - for (double t = StartTime + HeadNote.HitWindows.Great / 2; t <= EndTime - TailNote.HitWindows.Great / 2; t+= tickSpacing) + for (double t = StartTime + Head.HitWindows.Great / 2; t <= EndTime - Tail.HitWindows.Great / 2; t+= tickSpacing) { ret.Add(new HoldNoteTick { @@ -55,5 +64,24 @@ namespace osu.Game.Rulesets.Mania.Objects return ret; } + + /// + /// The tail of the hold note. + /// + private class TailNote : Note + { + /// + /// Lenience of release hit windows. This is to make cases where the hold note release + /// is timed alongside presses of other hit objects less awkward. + /// + private const double release_window_lenience = 1.5; + + public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) + { + base.ApplyDefaults(controlPointInfo, difficulty); + + HitWindows *= release_window_lenience; + } + } } } diff --git a/osu.Game.Rulesets.Mania/Objects/HoldNoteTail.cs b/osu.Game.Rulesets.Mania/Objects/HoldNoteTail.cs deleted file mode 100644 index 6399277a2b..0000000000 --- a/osu.Game.Rulesets.Mania/Objects/HoldNoteTail.cs +++ /dev/null @@ -1,24 +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.Beatmaps.ControlPoints; -using osu.Game.Database; - -namespace osu.Game.Rulesets.Mania.Objects -{ - public class HoldNoteTail : Note - { - /// - /// Lenience of release hit windows. This is to make cases where the hold note release - /// is timed alongside presses of other hit objects less awkward. - /// - private const double release_window_lenience = 1.5; - - public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) - { - base.ApplyDefaults(controlPointInfo, difficulty); - - HitWindows *= release_window_lenience; - } - } -} \ No newline at end of file diff --git a/osu.Game.Rulesets.Mania/Objects/HoldNoteTick.cs b/osu.Game.Rulesets.Mania/Objects/HoldNoteTick.cs index 805b2a0938..6c4cf127f3 100644 --- a/osu.Game.Rulesets.Mania/Objects/HoldNoteTick.cs +++ b/osu.Game.Rulesets.Mania/Objects/HoldNoteTick.cs @@ -3,6 +3,9 @@ namespace osu.Game.Rulesets.Mania.Objects { + /// + /// A scoring tick of a hold note. + /// public class HoldNoteTick : ManiaHitObject { } diff --git a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj index 91cb551414..7a8ec25fe4 100644 --- a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj +++ b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj @@ -71,7 +71,6 @@ - From c2d3b6c05ad5c8dfacb6d47fdceed144409ef16e Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 26 May 2017 15:53:49 +0900 Subject: [PATCH 09/16] Remove late initialization of head + tail, keep them updated with start time and end time. --- osu.Game.Rulesets.Mania/Objects/HoldNote.cs | 29 +++++++++++++++++---- osu.Game/Rulesets/Objects/HitObject.cs | 2 +- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Objects/HoldNote.cs b/osu.Game.Rulesets.Mania/Objects/HoldNote.cs index db317ddf7b..5069b4f623 100644 --- a/osu.Game.Rulesets.Mania/Objects/HoldNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/HoldNote.cs @@ -13,20 +13,39 @@ namespace osu.Game.Rulesets.Mania.Objects /// public class HoldNote : ManiaHitObject, IHasEndTime { - public double Duration { get; set; } public double EndTime => StartTime + Duration; - private Note head; + private double duration; + public double Duration + { + get { return duration; } + set + { + duration = value; + Tail.StartTime = EndTime; + } + } + + public override double StartTime + { + get { return base.StartTime; } + set + { + base.StartTime = value; + Head.StartTime = value; + Tail.StartTime = EndTime; + } + } + /// /// The head note of the hold. /// - public Note Head => head ?? (head = new Note { StartTime = StartTime }); + public Note Head = new Note(); - private Note tail; /// /// The tail note of the hold. /// - public Note Tail => tail ?? (tail = new TailNote { StartTime = EndTime }); + public Note Tail = new TailNote(); /// /// The time between ticks of this hold. diff --git a/osu.Game/Rulesets/Objects/HitObject.cs b/osu.Game/Rulesets/Objects/HitObject.cs index 5592681cab..b282965db8 100644 --- a/osu.Game/Rulesets/Objects/HitObject.cs +++ b/osu.Game/Rulesets/Objects/HitObject.cs @@ -19,7 +19,7 @@ namespace osu.Game.Rulesets.Objects /// /// The time at which the HitObject starts. /// - public double StartTime; + public virtual double StartTime { get; set; } /// /// The samples to be played when this hit object is hit. From d3206396e7b5474db47117541ce22487cfcbb38c Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 26 May 2017 16:10:04 +0900 Subject: [PATCH 10/16] Rewrite comments. --- .../Objects/Drawables/DrawableHoldNote.cs | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs index cef4eecd38..cee2e103b9 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs @@ -127,15 +127,9 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables { } - /// - /// Handles key down events on the body of the hold note. - /// - /// The input state. - /// The key down args. - /// Whether the key press was handled. protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { - // Make sure the keypress happened within reasonable bounds of the hold note + // Make sure the keypress happened within the body of the hold note if (Time.Current < HitObject.StartTime || Time.Current > HitObject.EndTime) return false; @@ -145,17 +139,14 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables if (args.Repeat) return false; + // The user has pressed during the body of the hold note, after the head note and its hit windows have passed + // and within the limited range of the above if-statement. This state will be managed by the head note if the + // user has pressed during the hit windows of the head note. holding = true; return true; } - /// - /// Handles key up events on the body of the hold note. - /// - /// The input state. - /// The key down args. - /// Whether the key press was handled. protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) { // Make sure that the user started holding the key during the hold note @@ -167,7 +158,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables holding = false; - // If the key has been released too early, they should not receive full score for the release + // If the key has been released too early, the user should not receive full score for the release if (!tail.Judged) hasBroken = true; @@ -196,13 +187,15 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables return false; // We only want to trigger a holding state from the head if the head has received a judgement - if (Judgement.Result == HitResult.None) + if (!Judged) return false; - // If the head has been missed, make sure the user also can't receive a full score for the release + // If the key has been released too early, the user should not receive full score for the release if (Judgement.Result == HitResult.Miss) holdNote.hasBroken = true; + // The head note also handles early hits before the body, but we want accurate early hits to count as the body being held + // The body doesn't handle these early early hits, so we have to explicitly set the holding state here holdNote.holding = true; return true; From 47e1b7b389e9347b22c6a1d1e28139ad4e000e80 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 26 May 2017 16:28:39 +0900 Subject: [PATCH 11/16] Fix tick construction loop. --- osu.Game.Rulesets.Mania/Objects/HoldNote.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Objects/HoldNote.cs b/osu.Game.Rulesets.Mania/Objects/HoldNote.cs index 5069b4f623..c241c4cf41 100644 --- a/osu.Game.Rulesets.Mania/Objects/HoldNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/HoldNote.cs @@ -40,12 +40,12 @@ namespace osu.Game.Rulesets.Mania.Objects /// /// The head note of the hold. /// - public Note Head = new Note(); + public readonly Note Head = new Note(); /// /// The tail note of the hold. /// - public Note Tail = new TailNote(); + public readonly Note Tail = new TailNote(); /// /// The time between ticks of this hold. @@ -73,7 +73,7 @@ namespace osu.Game.Rulesets.Mania.Objects if (tickSpacing == 0) return ret; - for (double t = StartTime + Head.HitWindows.Great / 2; t <= EndTime - Tail.HitWindows.Great / 2; t+= tickSpacing) + for (double t = StartTime + tickSpacing; t <= EndTime - tickSpacing; t += tickSpacing) { ret.Add(new HoldNoteTick { From 3f4cbd02cdaf2def643a4df6a4be4b79c63edd39 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 26 May 2017 16:29:20 +0900 Subject: [PATCH 12/16] Fix warnings. --- .../Patterns/Legacy/DistanceObjectPatternGenerator.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs index 076bcdfaab..2d1f75e196 100644 --- a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs +++ b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs @@ -475,11 +475,11 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy { StartTime = startTime, Column = column, - Duration = endTime - startTime + Duration = endTime - startTime, + Head = { Samples = sampleInfoListAt(startTime) }, + Tail = { Samples = sampleInfoListAt(endTime) } }; - holdNote.Head.Samples = sampleInfoListAt(startTime); - holdNote.Tail.Samples = sampleInfoListAt(endTime); newObject = holdNote; } From 871d44d6281cd6a795ce824645ee43f40aed1f6d Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 26 May 2017 16:39:43 +0900 Subject: [PATCH 13/16] Renamings. --- .../Objects/Drawables/DrawableHoldNote.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs index cee2e103b9..b9b94e7f45 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs @@ -75,12 +75,12 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables RelativeSizeAxes = Axes.Both, RelativeCoordinateSpace = new Vector2(1, (float)HitObject.Duration) }, - head = new HeadNote(this, key) + head = new DrawableHeadNote(this, key) { Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre }, - tail = new TailNote(this, key) + tail = new DrawableTailNote(this, key) { Anchor = Anchor.BottomCentre, Origin = Anchor.TopCentre @@ -168,11 +168,11 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables /// /// The head note of a hold. /// - private class HeadNote : DrawableNote + private class DrawableHeadNote : DrawableNote { private readonly DrawableHoldNote holdNote; - public HeadNote(DrawableHoldNote holdNote, Bindable key = null) + public DrawableHeadNote(DrawableHoldNote holdNote, Bindable key = null) : base(holdNote.HitObject.Head, key) { this.holdNote = holdNote; @@ -205,11 +205,11 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables /// /// The tail note of a hold. /// - private class TailNote : DrawableNote + private class DrawableTailNote : DrawableNote { private readonly DrawableHoldNote holdNote; - public TailNote(DrawableHoldNote holdNote, Bindable key = null) + public DrawableTailNote(DrawableHoldNote holdNote, Bindable key = null) : base(holdNote.HitObject.Tail, key) { this.holdNote = holdNote; From 3ec41a313b548d59a89fbdbd1e1b89a03b05c74c Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 26 May 2017 18:48:18 +0900 Subject: [PATCH 14/16] Add base DrawableHitObject + HitObjectStartTimeComparer. --- .../Objects/Drawables/DrawableHitObject.cs | 49 ++++++++++++----- .../Objects/HitObjectStartTimeComparer.cs | 55 +++++++++++++++++++ 2 files changed, 89 insertions(+), 15 deletions(-) create mode 100644 osu.Game/Rulesets/Objects/HitObjectStartTimeComparer.cs diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs index c5dbc27fd3..fcdcf672d5 100644 --- a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs @@ -15,28 +15,51 @@ using System.Linq; namespace osu.Game.Rulesets.Objects.Drawables { - public abstract class DrawableHitObject : Container - where TObject : HitObject - where TJudgement : Judgement + public abstract class DrawableHitObject : Container { - public event Action> OnJudgement; - - public TObject HitObject; + public readonly HitObject HitObject; /// /// The colour used for various elements of this DrawableHitObject. /// public virtual Color4 AccentColour { get; set; } + protected DrawableHitObject(HitObject hitObject) + { + HitObject = hitObject; + } + } + + public abstract class DrawableHitObject : DrawableHitObject + where TObject : HitObject + { + public new readonly TObject HitObject; + + protected DrawableHitObject(TObject hitObject) + : base(hitObject) + { + HitObject = hitObject; + } + } + + public abstract class DrawableHitObject : DrawableHitObject + where TObject : HitObject + where TJudgement : Judgement + { + public event Action> OnJudgement; + public override bool HandleInput => Interactive; public bool Interactive = true; public TJudgement Judgement; - protected abstract TJudgement CreateJudgement(); + protected List Samples = new List(); - protected abstract void UpdateState(ArmedState state); + protected DrawableHitObject(TObject hitObject) + : base(hitObject) + { + } private ArmedState state; public ArmedState State @@ -59,8 +82,6 @@ namespace osu.Game.Rulesets.Objects.Drawables } } - protected List Samples = new List(); - protected void PlaySamples() { Samples.ForEach(s => s?.Play()); @@ -79,11 +100,6 @@ namespace osu.Game.Rulesets.Objects.Drawables /// public bool Judged => (Judgement?.Result ?? HitResult.None) != HitResult.None && (NestedHitObjects?.All(h => h.Judged) ?? true); - protected DrawableHitObject(TObject hitObject) - { - HitObject = hitObject; - } - /// /// Process a hit of this hitobject. Carries out judgement. /// @@ -176,5 +192,8 @@ namespace osu.Game.Rulesets.Objects.Drawables h.OnJudgement += d => OnJudgement?.Invoke(d); nestedHitObjects.Add(h); } + + protected abstract TJudgement CreateJudgement(); + protected abstract void UpdateState(ArmedState state); } } diff --git a/osu.Game/Rulesets/Objects/HitObjectStartTimeComparer.cs b/osu.Game/Rulesets/Objects/HitObjectStartTimeComparer.cs new file mode 100644 index 0000000000..e65bc4a99f --- /dev/null +++ b/osu.Game/Rulesets/Objects/HitObjectStartTimeComparer.cs @@ -0,0 +1,55 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics; +using osu.Game.Rulesets.Objects.Drawables; + +namespace osu.Game.Rulesets.Objects +{ + /// + /// Compares two hit objects by their start time, falling back to creation order if their start time is equal. + /// + public class HitObjectStartTimeComparer : Drawable.CreationOrderDepthComparer + { + public override int Compare(Drawable x, Drawable y) + { + var hitObjectX = x as DrawableHitObject; + var hitObjectY = y as DrawableHitObject; + + // If either of the two drawables are not hit objects, fall back to the base comparer + if ((hitObjectX ?? hitObjectY) == null) + return base.Compare(x, y); + + // Compare by start time + int i = hitObjectX.HitObject.StartTime.CompareTo(hitObjectY.HitObject.StartTime); + if (i != 0) + return i; + + return base.Compare(x, y); + } + } + + /// + /// Compares two hit objects by their start time, falling back to creation order if their start time is equal. + /// This will compare the two hit objects in reverse order. + /// + public class HitObjectReverseStartTimeComparer : Drawable.ReverseCreationOrderDepthComparer + { + public override int Compare(Drawable x, Drawable y) + { + var hitObjectX = x as DrawableHitObject; + var hitObjectY = y as DrawableHitObject; + + // If either of the two drawables are not hit objects, fall back to the base comparer + if ((hitObjectX ?? hitObjectY) == null) + return base.Compare(x, y); + + // Compare by start time + int i = hitObjectY.HitObject.StartTime.CompareTo(hitObjectX.HitObject.StartTime); + if (i != 0) + return i; + + return base.Compare(x, y); + } + } +} \ No newline at end of file From e4b59314ea0735dc2607d3e56df6e2ec6a580d78 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 26 May 2017 18:52:43 +0900 Subject: [PATCH 15/16] Use new HitObjectStartTimeComparer. --- osu-framework | 2 +- osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs | 3 +++ osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 7 +------ 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/osu-framework b/osu-framework index 777996fb97..ea5a2a7e1a 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 777996fb9731ba1895a5ab1323cbbc97259ff741 +Subproject commit ea5a2a7e1abffb1515c020fd017b583b71780316 diff --git a/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs b/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs index cc8897840e..636c84d9dc 100644 --- a/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs +++ b/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs @@ -8,6 +8,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using OpenTK; using osu.Game.Beatmaps.ControlPoints; +using osu.Game.Rulesets.Objects; namespace osu.Game.Rulesets.Mania.Timing { @@ -28,6 +29,8 @@ namespace osu.Game.Rulesets.Mania.Timing private readonly List drawableControlPoints; + protected override IComparer DepthComparer => new HitObjectStartTimeComparer(); + public ControlPointContainer(IEnumerable timingChanges) { drawableControlPoints = timingChanges.Select(t => new DrawableControlPoint(t)).ToList(); diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index 495959b061..ff763f87c4 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -189,12 +189,7 @@ namespace osu.Game.Rulesets.Mania.UI } } - public override void Add(DrawableHitObject h) - { - h.Depth = (float)h.HitObject.StartTime; - - Columns.ElementAt(h.HitObject.Column).Add(h); - } + public override void Add(DrawableHitObject h) => Columns.ElementAt(h.HitObject.Column).Add(h); protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { From f294fef29bcaf1264639c7ffc952e12c2056b25d Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 26 May 2017 18:56:21 +0900 Subject: [PATCH 16/16] Remove holding property in favor of a nullable hold start time. --- .../Objects/Drawables/DrawableHoldNote.cs | 33 ++++--------------- .../Objects/Drawables/DrawableHoldNoteTick.cs | 3 +- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs index b9b94e7f45..5d7f3314cd 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs @@ -27,33 +27,15 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables private readonly Container tickContainer; /// - /// Time at which the user started holding this hold note. + /// Time at which the user started holding this hold note. Null if the user is not holding this hold note. /// - private double holdStartTime; + private double? holdStartTime; /// /// Whether the hold note has been released too early and shouldn't give full score for the release. /// private bool hasBroken; - private bool _holding; - /// - /// Whether the user is currently holding the hold note. - /// - private bool holding - { - get { return _holding; } - set - { - if (_holding == value) - return; - _holding = value; - - if (holding) - holdStartTime = Time.Current; - } - } - public DrawableHoldNote(HoldNote hitObject, Bindable key = null) : base(hitObject, key) { @@ -91,7 +73,6 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables { var drawableTick = new DrawableHoldNoteTick(tick) { - IsHolding = () => holding, HoldStartTime = () => holdStartTime }; @@ -142,7 +123,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables // The user has pressed during the body of the hold note, after the head note and its hit windows have passed // and within the limited range of the above if-statement. This state will be managed by the head note if the // user has pressed during the hit windows of the head note. - holding = true; + holdStartTime = Time.Current; return true; } @@ -150,13 +131,13 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) { // Make sure that the user started holding the key during the hold note - if (!holding) + if (!holdStartTime.HasValue) return false; if (args.Key != Key) return false; - holding = false; + holdStartTime = null; // If the key has been released too early, the user should not receive full score for the release if (!tail.Judged) @@ -196,7 +177,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables // The head note also handles early hits before the body, but we want accurate early hits to count as the body being held // The body doesn't handle these early early hits, so we have to explicitly set the holding state here - holdNote.holding = true; + holdNote.holdStartTime = Time.Current; return true; } @@ -234,7 +215,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) { // Make sure that the user started holding the key during the hold note - if (!holdNote.holding) + if (!holdNote.holdStartTime.HasValue) return false; if (Judgement.Result != HitResult.None) diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs index 8cd60e9901..9ecc77d3fc 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNoteTick.cs @@ -21,7 +21,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables /// /// References the time at which the user started holding the hold note. /// - public Func HoldStartTime; + public Func HoldStartTime; /// /// References whether the user is currently holding the hold note. @@ -90,7 +90,6 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables if (Time.Current < HitObject.StartTime) return; - if (HoldStartTime?.Invoke() > HitObject.StartTime) return;