From 3a1fee59fbf6af189b4987fa6612e2916113430e Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 12 Nov 2018 18:24:18 +0900 Subject: [PATCH 01/16] Implement note placement --- .../TestCaseColumn.cs | 8 +- .../Edit/Blueprints/NotePlacementBlueprint.cs | 74 +++++++++++++++++++ .../Edit/ManiaHitObjectComposer.cs | 11 ++- .../Edit/NoteCompositionTool.cs | 20 +++++ osu.Game.Rulesets.Mania/UI/Column.cs | 9 ++- osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 27 +++++++ osu.Game.Rulesets.Mania/UI/ManiaStage.cs | 2 +- .../Rulesets/Edit/EditRulesetContainer.cs | 4 +- osu.Game/Rulesets/Edit/HitObjectComposer.cs | 24 +++--- .../Tests/Visual/ScrollingTestContainer.cs | 3 + 10 files changed, 160 insertions(+), 22 deletions(-) create mode 100644 osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs create mode 100644 osu.Game.Rulesets.Mania/Edit/NoteCompositionTool.cs diff --git a/osu.Game.Rulesets.Mania.Tests/TestCaseColumn.cs b/osu.Game.Rulesets.Mania.Tests/TestCaseColumn.cs index d044b48553..63724f8edf 100644 --- a/osu.Game.Rulesets.Mania.Tests/TestCaseColumn.cs +++ b/osu.Game.Rulesets.Mania.Tests/TestCaseColumn.cs @@ -49,8 +49,8 @@ namespace osu.Game.Rulesets.Mania.Tests Spacing = new Vector2(20, 0), Children = new[] { - createColumn(ScrollingDirection.Up, ManiaAction.Key1), - createColumn(ScrollingDirection.Down, ManiaAction.Key2) + createColumn(ScrollingDirection.Up, ManiaAction.Key1, 0), + createColumn(ScrollingDirection.Down, ManiaAction.Key2, 1) } }; } @@ -85,9 +85,9 @@ namespace osu.Game.Rulesets.Mania.Tests } } - private Drawable createColumn(ScrollingDirection direction, ManiaAction action) + private Drawable createColumn(ScrollingDirection direction, ManiaAction action, int index) { - var column = new Column + var column = new Column(index) { Anchor = Anchor.Centre, Origin = Anchor.Centre, diff --git a/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs b/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs new file mode 100644 index 0000000000..7102d328ec --- /dev/null +++ b/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs @@ -0,0 +1,74 @@ +// Copyright (c) 2007-2018 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.Framework.Input.Events; +using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Mania.Edit.Blueprints.Components; +using osu.Game.Rulesets.Mania.Objects; +using osu.Game.Rulesets.UI.Scrolling; + +namespace osu.Game.Rulesets.Mania.Edit.Blueprints +{ + public class NotePlacementBlueprint : PlacementBlueprint + { + protected new Note HitObject => (Note)base.HitObject; + + [Resolved] + private ManiaHitObjectComposer composer { get; set; } + + [Resolved] + private IScrollingInfo scrollingInfo { get; set; } + + public NotePlacementBlueprint() + : base(new Note()) + { + RelativeSizeAxes = Axes.None; + + Origin = Anchor.Centre; + + AutoSizeAxes = Axes.Y; + Width = 45; + + InternalChild = new EditNotePiece { RelativeSizeAxes = Axes.X }; + } + + protected override bool OnMouseMove(MouseMoveEvent e) + { + Position = e.MousePosition; + return true; + } + + protected override bool OnClick(ClickEvent e) + { + var offsetPosition = e.ScreenSpaceMousePosition; + switch (scrollingInfo.Direction.Value) + { + case ScrollingDirection.Up: + offsetPosition.Y -= DrawHeight / 2; + break; + case ScrollingDirection.Down: + offsetPosition.Y += DrawHeight / 2; + break; + } + + var column = composer.ColumnAt(offsetPosition); + if (column == null) + return base.OnClick(e); + + var hitObjectContainer = column.HitObjectContainer; + + HitObject.StartTime = scrollingInfo.Algorithm.TimeAt(hitObjectContainer.ToLocalSpace(offsetPosition).Y, + EditorClock.CurrentTime, + scrollingInfo.TimeRange.Value, + hitObjectContainer.DrawHeight); + + HitObject.Column = column.Index; + + EndPlacement(); + + return true; + } + } +} diff --git a/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs b/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs index 3531b81e68..33e52b1737 100644 --- a/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs +++ b/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs @@ -1,7 +1,6 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; using osu.Game.Beatmaps; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit.Tools; @@ -11,10 +10,13 @@ using osu.Game.Rulesets.Objects.Drawables; using System.Collections.Generic; using osu.Framework.Allocation; using osu.Game.Rulesets.Mania.Edit.Blueprints; +using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.UI; +using OpenTK; namespace osu.Game.Rulesets.Mania.Edit { + [Cached] public class ManiaHitObjectComposer : HitObjectComposer { public ManiaHitObjectComposer(Ruleset ruleset) @@ -27,6 +29,8 @@ namespace osu.Game.Rulesets.Mania.Edit protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) => dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); + public Column ColumnAt(Vector2 screenSpacePosition) => ((ManiaPlayfield)RulesetContainer.Playfield).GetColumnByPosition(screenSpacePosition); + protected override RulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) { var rulesetContainer = new ManiaEditRulesetContainer(ruleset, beatmap); @@ -37,7 +41,10 @@ namespace osu.Game.Rulesets.Mania.Edit return rulesetContainer; } - protected override IReadOnlyList CompositionTools => Array.Empty(); + protected override IReadOnlyList CompositionTools => new HitObjectCompositionTool[] + { + new NoteCompositionTool() + }; public override SelectionBlueprint CreateBlueprintFor(DrawableHitObject hitObject) { diff --git a/osu.Game.Rulesets.Mania/Edit/NoteCompositionTool.cs b/osu.Game.Rulesets.Mania/Edit/NoteCompositionTool.cs new file mode 100644 index 0000000000..93f49d1cc0 --- /dev/null +++ b/osu.Game.Rulesets.Mania/Edit/NoteCompositionTool.cs @@ -0,0 +1,20 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Edit.Tools; +using osu.Game.Rulesets.Mania.Edit.Blueprints; +using osu.Game.Rulesets.Mania.Objects; + +namespace osu.Game.Rulesets.Mania.Edit +{ + public class NoteCompositionTool : HitObjectCompositionTool + { + public NoteCompositionTool() + : base(nameof(Note)) + { + } + + public override PlacementBlueprint CreatePlacementBlueprint() => new NotePlacementBlueprint(); + } +} diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index 576af6d93a..da3ee8dddf 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -21,6 +21,11 @@ namespace osu.Game.Rulesets.Mania.UI private const float column_width = 45; private const float special_column_width = 70; + /// + /// The index of this column as part of the whole playfield. + /// + public readonly int Index; + public readonly Bindable Action = new Bindable(); private readonly ColumnBackground background; @@ -30,8 +35,10 @@ namespace osu.Game.Rulesets.Mania.UI internal readonly Container TopLevelContainer; private readonly Container explosionContainer; - public Column() + public Column(int index) { + Index = index; + RelativeSizeAxes = Axes.Y; Width = column_width; diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index c59917056d..410c6aa908 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -54,6 +54,33 @@ namespace osu.Game.Rulesets.Mania.UI public void Add(BarLine barline) => stages.ForEach(s => s.Add(barline)); + /// + /// Retrieves a column from a screen-space position. + /// + /// The screen-space position. + /// The column which the lies in. + public Column GetColumnByPosition(Vector2 screenSpacePosition) + { + Column found = null; + + foreach (var stage in stages) + { + foreach (var column in stage.Columns) + { + if (column.ReceivePositionalInputAt(screenSpacePosition)) + { + found = column; + break; + } + } + + if (found != null) + break; + } + + return found; + } + private ManiaStage getStageByColumn(int column) { int sum = 0; diff --git a/osu.Game.Rulesets.Mania/UI/ManiaStage.cs b/osu.Game.Rulesets.Mania/UI/ManiaStage.cs index 19e930f530..d1ce8b8679 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaStage.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaStage.cs @@ -123,7 +123,7 @@ namespace osu.Game.Rulesets.Mania.UI for (int i = 0; i < definition.Columns; i++) { var isSpecial = definition.IsSpecialColumn(i); - var column = new Column + var column = new Column(firstColumnIndex + i) { IsSpecial = isSpecial, Action = { Value = isSpecial ? specialColumnStartAction++ : normalColumnStartAction++ } diff --git a/osu.Game/Rulesets/Edit/EditRulesetContainer.cs b/osu.Game/Rulesets/Edit/EditRulesetContainer.cs index bc54c907ab..3c493eb16f 100644 --- a/osu.Game/Rulesets/Edit/EditRulesetContainer.cs +++ b/osu.Game/Rulesets/Edit/EditRulesetContainer.cs @@ -68,9 +68,9 @@ namespace osu.Game.Rulesets.Edit // Process object var processor = ruleset.CreateBeatmapProcessor(beatmap); - processor.PreProcess(); + processor?.PreProcess(); tObject.ApplyDefaults(beatmap.ControlPointInfo, beatmap.BeatmapInfo.BaseDifficulty); - processor.PostProcess(); + processor?.PostProcess(); // Add visual representation var drawableObject = rulesetContainer.GetVisualRepresentation(tObject); diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index 485c1921cf..0afe33ff2e 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -23,7 +23,7 @@ namespace osu.Game.Rulesets.Edit { public abstract class HitObjectComposer : CompositeDrawable { - public IEnumerable HitObjects => rulesetContainer.Playfield.AllHitObjects; + public IEnumerable HitObjects => RulesetContainer.Playfield.AllHitObjects; protected readonly Ruleset Ruleset; @@ -33,7 +33,7 @@ namespace osu.Game.Rulesets.Edit private readonly List layerContainers = new List(); - private EditRulesetContainer rulesetContainer; + protected EditRulesetContainer RulesetContainer { get; private set; } private BlueprintContainer blueprintContainer; @@ -51,8 +51,8 @@ namespace osu.Game.Rulesets.Edit try { - rulesetContainer = CreateRulesetContainer(); - rulesetContainer.Clock = framedClock; + RulesetContainer = CreateRulesetContainer(); + RulesetContainer.Clock = framedClock; } catch (Exception e) { @@ -64,7 +64,7 @@ namespace osu.Game.Rulesets.Edit layerBelowRuleset.Child = new EditorPlayfieldBorder { RelativeSizeAxes = Axes.Both }; var layerAboveRuleset = CreateLayerContainer(); - layerAboveRuleset.Child = new BlueprintContainer(); + layerAboveRuleset.Child = blueprintContainer = new BlueprintContainer(); layerContainers.Add(layerBelowRuleset); layerContainers.Add(layerAboveRuleset); @@ -94,7 +94,7 @@ namespace osu.Game.Rulesets.Edit Children = new Drawable[] { layerBelowRuleset, - rulesetContainer, + RulesetContainer, layerAboveRuleset } } @@ -130,10 +130,10 @@ namespace osu.Game.Rulesets.Edit layerContainers.ForEach(l => { - l.Anchor = rulesetContainer.Playfield.Anchor; - l.Origin = rulesetContainer.Playfield.Origin; - l.Position = rulesetContainer.Playfield.Position; - l.Size = rulesetContainer.Playfield.Size; + l.Anchor = RulesetContainer.Playfield.Anchor; + l.Origin = RulesetContainer.Playfield.Origin; + l.Position = RulesetContainer.Playfield.Position; + l.Size = RulesetContainer.Playfield.Size; }); } @@ -141,9 +141,9 @@ namespace osu.Game.Rulesets.Edit /// Adds a to the and visualises it. /// /// The to add. - public void Add(HitObject hitObject) => blueprintContainer.AddBlueprintFor(rulesetContainer.Add(hitObject)); + public void Add(HitObject hitObject) => blueprintContainer.AddBlueprintFor(RulesetContainer.Add(hitObject)); - public void Remove(HitObject hitObject) => blueprintContainer.RemoveBlueprintFor(rulesetContainer.Remove(hitObject)); + public void Remove(HitObject hitObject) => blueprintContainer.RemoveBlueprintFor(RulesetContainer.Remove(hitObject)); internal abstract EditRulesetContainer CreateRulesetContainer(); diff --git a/osu.Game/Tests/Visual/ScrollingTestContainer.cs b/osu.Game/Tests/Visual/ScrollingTestContainer.cs index 18b29345c1..1819fdb2a0 100644 --- a/osu.Game/Tests/Visual/ScrollingTestContainer.cs +++ b/osu.Game/Tests/Visual/ScrollingTestContainer.cs @@ -85,6 +85,9 @@ namespace osu.Game.Tests.Visual public float PositionAt(double time, double currentTime, double timeRange, float scrollLength) => implementation.PositionAt(time, currentTime, timeRange, scrollLength); + public double TimeAt(float position, double currentTime, double timeRange, float scrollLength) + => implementation.TimeAt(position, currentTime, timeRange, scrollLength); + public void Reset() => implementation.Reset(); } From 1d40a042f6ff8da4bc14b1c6997c092140febba3 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 12 Nov 2018 18:32:44 +0900 Subject: [PATCH 02/16] Extract common methods into ManiaPlacementBlueprint --- .../Blueprints/ManiaPlacementBlueprint.cs | 61 +++++++++++++++++++ .../Edit/Blueprints/NotePlacementBlueprint.cs | 39 ++---------- 2 files changed, 66 insertions(+), 34 deletions(-) create mode 100644 osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs diff --git a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs new file mode 100644 index 0000000000..402a124f01 --- /dev/null +++ b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs @@ -0,0 +1,61 @@ +// Copyright (c) 2007-2018 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.Edit; +using osu.Game.Rulesets.Mania.Objects; +using osu.Game.Rulesets.Mania.UI; +using osu.Game.Rulesets.UI.Scrolling; +using OpenTK; + +namespace osu.Game.Rulesets.Mania.Edit.Blueprints +{ + public class ManiaPlacementBlueprint : PlacementBlueprint + where T : ManiaHitObject + { + protected new T HitObject => (T)base.HitObject; + + [Resolved] + private ManiaHitObjectComposer composer { get; set; } + + [Resolved] + private IScrollingInfo scrollingInfo { get; set; } + + public ManiaPlacementBlueprint(T hitObject) + : base(hitObject) + { + RelativeSizeAxes = Axes.None; + } + + protected double TimeAt(Vector2 screenSpacePosition) + { + var column = ColumnAt(screenSpacePosition); + if (column == null) + return 0; + + return scrollingInfo.Algorithm.TimeAt(column.HitObjectContainer.ToLocalSpace(applyPositionOffset(screenSpacePosition)).Y, + EditorClock.CurrentTime, + scrollingInfo.TimeRange.Value, + column.HitObjectContainer.DrawHeight); + } + + protected Column ColumnAt(Vector2 screenSpacePosition) + => composer.ColumnAt(applyPositionOffset(screenSpacePosition)); + + private Vector2 applyPositionOffset(Vector2 position) + { + switch (scrollingInfo.Direction.Value) + { + case ScrollingDirection.Up: + position.Y -= DrawHeight / 2; + break; + case ScrollingDirection.Down: + position.Y += DrawHeight / 2; + break; + } + + return position; + } + } +} diff --git a/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs b/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs index 7102d328ec..1549b0ae45 100644 --- a/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs +++ b/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs @@ -1,31 +1,19 @@ // Copyright (c) 2007-2018 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.Framework.Input.Events; -using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Mania.Edit.Blueprints.Components; using osu.Game.Rulesets.Mania.Objects; -using osu.Game.Rulesets.UI.Scrolling; +using osu.Game.Rulesets.Mania.UI; namespace osu.Game.Rulesets.Mania.Edit.Blueprints { - public class NotePlacementBlueprint : PlacementBlueprint + public class NotePlacementBlueprint : ManiaPlacementBlueprint { - protected new Note HitObject => (Note)base.HitObject; - - [Resolved] - private ManiaHitObjectComposer composer { get; set; } - - [Resolved] - private IScrollingInfo scrollingInfo { get; set; } - public NotePlacementBlueprint() : base(new Note()) { - RelativeSizeAxes = Axes.None; - Origin = Anchor.Centre; AutoSizeAxes = Axes.Y; @@ -42,28 +30,11 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints protected override bool OnClick(ClickEvent e) { - var offsetPosition = e.ScreenSpaceMousePosition; - switch (scrollingInfo.Direction.Value) - { - case ScrollingDirection.Up: - offsetPosition.Y -= DrawHeight / 2; - break; - case ScrollingDirection.Down: - offsetPosition.Y += DrawHeight / 2; - break; - } - - var column = composer.ColumnAt(offsetPosition); - if (column == null) + Column column; + if ((column = ColumnAt(e.ScreenSpaceMousePosition)) == null) return base.OnClick(e); - var hitObjectContainer = column.HitObjectContainer; - - HitObject.StartTime = scrollingInfo.Algorithm.TimeAt(hitObjectContainer.ToLocalSpace(offsetPosition).Y, - EditorClock.CurrentTime, - scrollingInfo.TimeRange.Value, - hitObjectContainer.DrawHeight); - + HitObject.StartTime = TimeAt(e.ScreenSpaceMousePosition); HitObject.Column = column.Index; EndPlacement(); From 1403fa26cfdc9f3101d1f6fdd6ea1faf85586a95 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 12 Nov 2018 19:40:57 +0900 Subject: [PATCH 03/16] Fix placement not working correctly for downwards scroll --- .../Edit/Blueprints/ManiaPlacementBlueprint.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs index 402a124f01..a7e84a97da 100644 --- a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs +++ b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs @@ -34,10 +34,18 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints if (column == null) return 0; - return scrollingInfo.Algorithm.TimeAt(column.HitObjectContainer.ToLocalSpace(applyPositionOffset(screenSpacePosition)).Y, + var hitObjectContainer = column.HitObjectContainer; + + // If we're scrolling downwards, a position of 0 is actually further away from the hit target + // so we need to flip the vertical coordinate in the hitobject container's space + var hitObjectPos = column.HitObjectContainer.ToLocalSpace(applyPositionOffset(screenSpacePosition)).Y; + if (scrollingInfo.Direction.Value == ScrollingDirection.Down) + hitObjectPos = hitObjectContainer.DrawHeight - hitObjectPos; + + return scrollingInfo.Algorithm.TimeAt(hitObjectPos, EditorClock.CurrentTime, scrollingInfo.TimeRange.Value, - column.HitObjectContainer.DrawHeight); + hitObjectContainer.DrawHeight); } protected Column ColumnAt(Vector2 screenSpacePosition) From 3d8ef97e81053501bb7c7b9e3faba9dbeda90f68 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 12 Nov 2018 19:41:06 +0900 Subject: [PATCH 04/16] Add testcase --- .../ManiaPlacementBlueprintTestCase.cs | 50 +++++++++++++++++++ .../TestCaseNotePlacementBlueprint.cs | 18 +++++++ .../Blueprints/ManiaPlacementBlueprint.cs | 2 +- .../Edit/IManiaHitObjectComposer.cs | 13 +++++ .../Edit/ManiaHitObjectComposer.cs | 4 +- .../Visual/PlacementBlueprintTestCase.cs | 14 +++--- .../Tests/Visual/ScrollingTestContainer.cs | 2 + 7 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 osu.Game.Rulesets.Mania.Tests/ManiaPlacementBlueprintTestCase.cs create mode 100644 osu.Game.Rulesets.Mania.Tests/TestCaseNotePlacementBlueprint.cs create mode 100644 osu.Game.Rulesets.Mania/Edit/IManiaHitObjectComposer.cs diff --git a/osu.Game.Rulesets.Mania.Tests/ManiaPlacementBlueprintTestCase.cs b/osu.Game.Rulesets.Mania.Tests/ManiaPlacementBlueprintTestCase.cs new file mode 100644 index 0000000000..0c87978f15 --- /dev/null +++ b/osu.Game.Rulesets.Mania.Tests/ManiaPlacementBlueprintTestCase.cs @@ -0,0 +1,50 @@ +// Copyright (c) 2007-2018 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.Framework.Graphics.Containers; +using osu.Framework.Timing; +using osu.Game.Rulesets.Mania.Edit; +using osu.Game.Rulesets.Mania.Objects.Drawables; +using osu.Game.Rulesets.Mania.UI; +using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Rulesets.UI.Scrolling; +using osu.Game.Tests.Visual; +using OpenTK; +using OpenTK.Graphics; + +namespace osu.Game.Rulesets.Mania.Tests +{ + [Cached(Type = typeof(IManiaHitObjectComposer))] + public abstract class ManiaPlacementBlueprintTestCase : PlacementBlueprintTestCase, IManiaHitObjectComposer + { + private readonly Column column; + + protected ManiaPlacementBlueprintTestCase() + { + Add(column = new Column(0) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + AccentColour = Color4.OrangeRed, + Clock = new FramedClock(new StopwatchClock()), // No scroll + }); + } + + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) + { + var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); + + dependencies.CacheAs(((ScrollingTestContainer)HitObjectContainer).ScrollingInfo); + + return dependencies; + } + + protected override Container CreateHitObjectContainer() => new ScrollingTestContainer(ScrollingDirection.Down) { RelativeSizeAxes = Axes.Both }; + + protected override void AddHitObject(DrawableHitObject hitObject) => column.Add((DrawableManiaHitObject)hitObject); + + public Column ColumnAt(Vector2 screenSpacePosition) => column; + } +} diff --git a/osu.Game.Rulesets.Mania.Tests/TestCaseNotePlacementBlueprint.cs b/osu.Game.Rulesets.Mania.Tests/TestCaseNotePlacementBlueprint.cs new file mode 100644 index 0000000000..9ae49d200e --- /dev/null +++ b/osu.Game.Rulesets.Mania.Tests/TestCaseNotePlacementBlueprint.cs @@ -0,0 +1,18 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Mania.Edit.Blueprints; +using osu.Game.Rulesets.Mania.Objects; +using osu.Game.Rulesets.Mania.Objects.Drawables; +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Objects.Drawables; + +namespace osu.Game.Rulesets.Mania.Tests +{ + public class TestCaseNotePlacementBlueprint : ManiaPlacementBlueprintTestCase + { + protected override DrawableHitObject CreateHitObject(HitObject hitObject) => new DrawableNote((Note)hitObject); + protected override PlacementBlueprint CreateBlueprint() => new NotePlacementBlueprint(); + } +} diff --git a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs index a7e84a97da..305c92671f 100644 --- a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs +++ b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs @@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints protected new T HitObject => (T)base.HitObject; [Resolved] - private ManiaHitObjectComposer composer { get; set; } + private IManiaHitObjectComposer composer { get; set; } [Resolved] private IScrollingInfo scrollingInfo { get; set; } diff --git a/osu.Game.Rulesets.Mania/Edit/IManiaHitObjectComposer.cs b/osu.Game.Rulesets.Mania/Edit/IManiaHitObjectComposer.cs new file mode 100644 index 0000000000..6347370d72 --- /dev/null +++ b/osu.Game.Rulesets.Mania/Edit/IManiaHitObjectComposer.cs @@ -0,0 +1,13 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Rulesets.Mania.UI; +using OpenTK; + +namespace osu.Game.Rulesets.Mania.Edit +{ + public interface IManiaHitObjectComposer + { + Column ColumnAt(Vector2 screenSpacePosition); + } +} diff --git a/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs b/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs index 33e52b1737..07684f9eb8 100644 --- a/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs +++ b/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs @@ -16,8 +16,8 @@ using OpenTK; namespace osu.Game.Rulesets.Mania.Edit { - [Cached] - public class ManiaHitObjectComposer : HitObjectComposer + [Cached(Type = typeof(IManiaHitObjectComposer))] + public class ManiaHitObjectComposer : HitObjectComposer, IManiaHitObjectComposer { public ManiaHitObjectComposer(Ruleset ruleset) : base(ruleset) diff --git a/osu.Game/Tests/Visual/PlacementBlueprintTestCase.cs b/osu.Game/Tests/Visual/PlacementBlueprintTestCase.cs index f893d8456b..ca762c6be2 100644 --- a/osu.Game/Tests/Visual/PlacementBlueprintTestCase.cs +++ b/osu.Game/Tests/Visual/PlacementBlueprintTestCase.cs @@ -15,18 +15,14 @@ namespace osu.Game.Tests.Visual [Cached(Type = typeof(IPlacementHandler))] public abstract class PlacementBlueprintTestCase : OsuTestCase, IPlacementHandler { - private readonly Container hitObjectContainer; + protected readonly Container HitObjectContainer; private PlacementBlueprint currentBlueprint; protected PlacementBlueprintTestCase() { Beatmap.Value.BeatmapInfo.BaseDifficulty.CircleSize = 2; - Add(hitObjectContainer = new Container - { - RelativeSizeAxes = Axes.Both, - Clock = new FramedClock(new StopwatchClock()) - }); + Add(HitObjectContainer = CreateHitObjectContainer()); } [BackgroundDependencyLoader] @@ -49,7 +45,7 @@ namespace osu.Game.Tests.Visual public void EndPlacement(HitObject hitObject) { - hitObjectContainer.Add(CreateHitObject(hitObject)); + AddHitObject(CreateHitObject(hitObject)); Remove(currentBlueprint); Add(currentBlueprint = CreateBlueprint()); @@ -59,6 +55,10 @@ namespace osu.Game.Tests.Visual { } + protected virtual Container CreateHitObjectContainer() => new Container { RelativeSizeAxes = Axes.Both }; + + protected virtual void AddHitObject(DrawableHitObject hitObject) => HitObjectContainer.Add(hitObject); + protected abstract DrawableHitObject CreateHitObject(HitObject hitObject); protected abstract PlacementBlueprint CreateBlueprint(); } diff --git a/osu.Game/Tests/Visual/ScrollingTestContainer.cs b/osu.Game/Tests/Visual/ScrollingTestContainer.cs index 1819fdb2a0..bc251fddbe 100644 --- a/osu.Game/Tests/Visual/ScrollingTestContainer.cs +++ b/osu.Game/Tests/Visual/ScrollingTestContainer.cs @@ -24,6 +24,8 @@ namespace osu.Game.Tests.Visual public double TimeRange { set => scrollingInfo.TimeRange.Value = value; } + public IScrollingInfo ScrollingInfo => scrollingInfo; + [Cached(Type = typeof(IScrollingInfo))] private readonly TestScrollingInfo scrollingInfo = new TestScrollingInfo(); From 25101ecd2cfaf0634a6c4f65b1933d770f53c2a5 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 13 Nov 2018 14:13:29 +0900 Subject: [PATCH 05/16] Snap placement blueprint to columns --- .../Blueprints/ManiaPlacementBlueprint.cs | 32 +++++++++++++++++++ .../Edit/Blueprints/NotePlacementBlueprint.cs | 7 ++-- osu.Game.Rulesets.Mania/UI/Column.cs | 5 +++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs index 305c92671f..bfa07d0014 100644 --- a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs +++ b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs @@ -3,6 +3,8 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Framework.Input.Events; +using osu.Framework.Threading; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.UI; @@ -16,6 +18,11 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints { protected new T HitObject => (T)base.HitObject; + /// + /// The current mouse position, snapped to the closest column. + /// + protected Vector2 SnappedMousePosition { get; private set; } + [Resolved] private IManiaHitObjectComposer composer { get; set; } @@ -28,6 +35,31 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints RelativeSizeAxes = Axes.None; } + protected override bool OnMouseMove(MouseMoveEvent e) + { + updateSnappedPosition(e); + return true; + } + + private ScheduledDelegate scheduledSnappedPositionUpdate; + + private void updateSnappedPosition(MouseMoveEvent e) + { + scheduledSnappedPositionUpdate?.Cancel(); + scheduledSnappedPositionUpdate = Schedule(() => + { + Column column = ColumnAt(e.ScreenSpaceMousePosition); + if (column == null) + SnappedMousePosition = e.MousePosition; + else + { + // Snap to the column + var parentPos = Parent.ToLocalSpace(column.ToScreenSpace(new Vector2(column.DrawWidth / 2, 0))); + SnappedMousePosition = new Vector2(parentPos.X, e.MousePosition.Y); + } + }); + } + protected double TimeAt(Vector2 screenSpacePosition) { var column = ColumnAt(screenSpacePosition); diff --git a/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs b/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs index 1549b0ae45..0a904d962e 100644 --- a/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs +++ b/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs @@ -22,10 +22,11 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints InternalChild = new EditNotePiece { RelativeSizeAxes = Axes.X }; } - protected override bool OnMouseMove(MouseMoveEvent e) + protected override void Update() { - Position = e.MousePosition; - return true; + base.Update(); + + Position = SnappedMousePosition; } protected override bool OnClick(ClickEvent e) diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index da3ee8dddf..4c1929f182 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -13,6 +13,7 @@ using osu.Framework.Input.Bindings; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Mania.UI.Components; using osu.Game.Rulesets.UI.Scrolling; +using OpenTK; namespace osu.Game.Rulesets.Mania.UI { @@ -172,5 +173,9 @@ namespace osu.Game.Rulesets.Mania.UI } public bool OnReleased(ManiaAction action) => false; + + public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) + // This probably shouldn't exist as is, but the columns in the stage are separated by a 1px border + => DrawRectangle.Inflate(new Vector2(1, 0)).Contains(ToLocalSpace(screenSpacePos)); } } From 52309465ebf3c9592bd1bbbd3c9702e6989dc32f Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 19 Nov 2018 17:59:52 +0900 Subject: [PATCH 06/16] Apply some simple fixes --- .../Blueprints/ManiaPlacementBlueprint.cs | 35 +++++++------------ 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs index bfa07d0014..76c4f0c74c 100644 --- a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs +++ b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs @@ -4,7 +4,6 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Input.Events; -using osu.Framework.Threading; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.UI; @@ -13,7 +12,7 @@ using OpenTK; namespace osu.Game.Rulesets.Mania.Edit.Blueprints { - public class ManiaPlacementBlueprint : PlacementBlueprint + public abstract class ManiaPlacementBlueprint : PlacementBlueprint where T : ManiaHitObject { protected new T HitObject => (T)base.HitObject; @@ -29,7 +28,7 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints [Resolved] private IScrollingInfo scrollingInfo { get; set; } - public ManiaPlacementBlueprint(T hitObject) + protected ManiaPlacementBlueprint(T hitObject) : base(hitObject) { RelativeSizeAxes = Axes.None; @@ -37,27 +36,17 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints protected override bool OnMouseMove(MouseMoveEvent e) { - updateSnappedPosition(e); - return true; - } - - private ScheduledDelegate scheduledSnappedPositionUpdate; - - private void updateSnappedPosition(MouseMoveEvent e) - { - scheduledSnappedPositionUpdate?.Cancel(); - scheduledSnappedPositionUpdate = Schedule(() => + Column column = ColumnAt(e.ScreenSpaceMousePosition); + if (column == null) + SnappedMousePosition = e.MousePosition; + else { - Column column = ColumnAt(e.ScreenSpaceMousePosition); - if (column == null) - SnappedMousePosition = e.MousePosition; - else - { - // Snap to the column - var parentPos = Parent.ToLocalSpace(column.ToScreenSpace(new Vector2(column.DrawWidth / 2, 0))); - SnappedMousePosition = new Vector2(parentPos.X, e.MousePosition.Y); - } - }); + // Snap to the column + var parentPos = Parent.ToLocalSpace(column.ToScreenSpace(new Vector2(column.DrawWidth / 2, 0))); + SnappedMousePosition = new Vector2(parentPos.X, e.MousePosition.Y); + } + + return true; } protected double TimeAt(Vector2 screenSpacePosition) From d1cbaa9612cf1ccd2b14fa53e1de2a2d04b0a973 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 19 Nov 2018 18:02:01 +0900 Subject: [PATCH 07/16] Use the column width --- .../Edit/Blueprints/ManiaPlacementBlueprint.cs | 3 +++ .../Edit/Blueprints/NotePlacementBlueprint.cs | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs index 76c4f0c74c..0f020e0884 100644 --- a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs +++ b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs @@ -37,10 +37,13 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints protected override bool OnMouseMove(MouseMoveEvent e) { Column column = ColumnAt(e.ScreenSpaceMousePosition); + if (column == null) SnappedMousePosition = e.MousePosition; else { + Width = column.DrawWidth; + // Snap to the column var parentPos = Parent.ToLocalSpace(column.ToScreenSpace(new Vector2(column.DrawWidth / 2, 0))); SnappedMousePosition = new Vector2(parentPos.X, e.MousePosition.Y); diff --git a/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs b/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs index 0a904d962e..8114ee914f 100644 --- a/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs +++ b/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs @@ -17,7 +17,6 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints Origin = Anchor.Centre; AutoSizeAxes = Axes.Y; - Width = 45; InternalChild = new EditNotePiece { RelativeSizeAxes = Axes.X }; } From d9b8d2d15c7bf00a823139481d9581af35e4834e Mon Sep 17 00:00:00 2001 From: Dan Balasescu <1329837+smoogipoo@users.noreply.github.com> Date: Mon, 19 Nov 2018 18:05:21 +0900 Subject: [PATCH 08/16] Trim whitespace --- .../Edit/Blueprints/ManiaPlacementBlueprint.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs index 0f020e0884..a4675f71b3 100644 --- a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs +++ b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs @@ -43,7 +43,7 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints else { Width = column.DrawWidth; - + // Snap to the column var parentPos = Parent.ToLocalSpace(column.ToScreenSpace(new Vector2(column.DrawWidth / 2, 0))); SnappedMousePosition = new Vector2(parentPos.X, e.MousePosition.Y); From 8071244d97ba007999f6adfa5309e12215bb81d5 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 19 Nov 2018 18:40:16 +0900 Subject: [PATCH 09/16] Make sizing happen per-blueprint --- .../Edit/Blueprints/ManiaPlacementBlueprint.cs | 12 +++++++++--- .../Edit/Blueprints/NotePlacementBlueprint.cs | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs index a4675f71b3..7d9bbc064b 100644 --- a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs +++ b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs @@ -6,6 +6,7 @@ using osu.Framework.Graphics; using osu.Framework.Input.Events; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Mania.Objects; +using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces; using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.UI.Scrolling; using OpenTK; @@ -22,6 +23,11 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints /// protected Vector2 SnappedMousePosition { get; private set; } + /// + /// The width of the closest column to the current mouse position. + /// + protected float SnappedWidth { get; private set; } + [Resolved] private IManiaHitObjectComposer composer { get; set; } @@ -42,7 +48,7 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints SnappedMousePosition = e.MousePosition; else { - Width = column.DrawWidth; + SnappedWidth = column.DrawWidth; // Snap to the column var parentPos = Parent.ToLocalSpace(column.ToScreenSpace(new Vector2(column.DrawWidth / 2, 0))); @@ -80,10 +86,10 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints switch (scrollingInfo.Direction.Value) { case ScrollingDirection.Up: - position.Y -= DrawHeight / 2; + position.Y -= NotePiece.NOTE_HEIGHT / 2; break; case ScrollingDirection.Down: - position.Y += DrawHeight / 2; + position.Y += NotePiece.NOTE_HEIGHT / 2; break; } diff --git a/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs b/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs index 8114ee914f..26279de0d5 100644 --- a/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs +++ b/osu.Game.Rulesets.Mania/Edit/Blueprints/NotePlacementBlueprint.cs @@ -25,6 +25,7 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints { base.Update(); + Width = SnappedWidth; Position = SnappedMousePosition; } From d5b937f88fba7bb341f0ddba0f4df999880d27c7 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 19 Nov 2018 19:17:03 +0900 Subject: [PATCH 10/16] Fix post-merge issue --- osu.Game/Rulesets/Edit/HitObjectComposer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index b42758ebad..d41fd5c201 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -150,7 +150,7 @@ namespace osu.Game.Rulesets.Edit /// /// Whether the user's cursor is currently in an area of the that is valid for placement. /// - public virtual bool CursorInPlacementArea => rulesetContainer.Playfield.ReceivePositionalInputAt(inputManager.CurrentState.Mouse.Position); + public virtual bool CursorInPlacementArea => RulesetContainer.Playfield.ReceivePositionalInputAt(inputManager.CurrentState.Mouse.Position); /// /// Adds a to the and visualises it. From 4ba3fa4ab6af212df03ff6805632b7a7f9ceb0a8 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 26 Nov 2018 10:44:48 +0900 Subject: [PATCH 11/16] osuTK --- .../ManiaPlacementBlueprintTestCase.cs | 4 ++-- .../Edit/Blueprints/ManiaPlacementBlueprint.cs | 2 +- osu.Game.Rulesets.Mania/Edit/IManiaHitObjectComposer.cs | 2 +- osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs | 2 +- osu.Game.Rulesets.Mania/UI/Column.cs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Mania.Tests/ManiaPlacementBlueprintTestCase.cs b/osu.Game.Rulesets.Mania.Tests/ManiaPlacementBlueprintTestCase.cs index 0c87978f15..b5c08d6837 100644 --- a/osu.Game.Rulesets.Mania.Tests/ManiaPlacementBlueprintTestCase.cs +++ b/osu.Game.Rulesets.Mania.Tests/ManiaPlacementBlueprintTestCase.cs @@ -11,8 +11,8 @@ using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.UI.Scrolling; using osu.Game.Tests.Visual; -using OpenTK; -using OpenTK.Graphics; +using osuTK; +using osuTK.Graphics; namespace osu.Game.Rulesets.Mania.Tests { diff --git a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs index 7d9bbc064b..8394328e2c 100644 --- a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs +++ b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs @@ -9,7 +9,7 @@ using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces; using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.UI.Scrolling; -using OpenTK; +using osuTK; namespace osu.Game.Rulesets.Mania.Edit.Blueprints { diff --git a/osu.Game.Rulesets.Mania/Edit/IManiaHitObjectComposer.cs b/osu.Game.Rulesets.Mania/Edit/IManiaHitObjectComposer.cs index 6347370d72..977c7dd525 100644 --- a/osu.Game.Rulesets.Mania/Edit/IManiaHitObjectComposer.cs +++ b/osu.Game.Rulesets.Mania/Edit/IManiaHitObjectComposer.cs @@ -2,7 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Game.Rulesets.Mania.UI; -using OpenTK; +using osuTK; namespace osu.Game.Rulesets.Mania.Edit { diff --git a/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs b/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs index 07684f9eb8..6280f93606 100644 --- a/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs +++ b/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs @@ -12,7 +12,7 @@ using osu.Framework.Allocation; using osu.Game.Rulesets.Mania.Edit.Blueprints; using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.UI; -using OpenTK; +using osuTK; namespace osu.Game.Rulesets.Mania.Edit { diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index e113123454..b7c80c1adc 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -13,7 +13,7 @@ using osu.Framework.Input.Bindings; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Mania.UI.Components; using osu.Game.Rulesets.UI.Scrolling; -using OpenTK; +using osuTK; namespace osu.Game.Rulesets.Mania.UI { From 91aa00b0e99df3773f54021995d58ad171650563 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 26 Nov 2018 10:54:54 +0900 Subject: [PATCH 12/16] Add helper method to get column by position --- .../Edit/ManiaHitObjectComposer.cs | 17 ++++++++++++----- .../UI/ManiaRulesetContainer.cs | 8 ++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs b/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs index 6280f93606..8c8fe3b8b9 100644 --- a/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs +++ b/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs @@ -19,26 +19,33 @@ namespace osu.Game.Rulesets.Mania.Edit [Cached(Type = typeof(IManiaHitObjectComposer))] public class ManiaHitObjectComposer : HitObjectComposer, IManiaHitObjectComposer { + protected new ManiaEditRulesetContainer RulesetContainer { get; private set; } + public ManiaHitObjectComposer(Ruleset ruleset) : base(ruleset) { } + /// + /// Retrieves the column that intersects a screen-space position. + /// + /// The screen-space position. + /// The column which intersects with . + public Column ColumnAt(Vector2 screenSpacePosition) => RulesetContainer.GetColumnByPosition(screenSpacePosition); + private DependencyContainer dependencies; protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) => dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); - public Column ColumnAt(Vector2 screenSpacePosition) => ((ManiaPlayfield)RulesetContainer.Playfield).GetColumnByPosition(screenSpacePosition); - protected override RulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) { - var rulesetContainer = new ManiaEditRulesetContainer(ruleset, beatmap); + RulesetContainer = new ManiaEditRulesetContainer(ruleset, beatmap); // This is the earliest we can cache the scrolling info to ourselves, before masks are added to the hierarchy and inject it - dependencies.CacheAs(rulesetContainer.ScrollingInfo); + dependencies.CacheAs(RulesetContainer.ScrollingInfo); - return rulesetContainer; + return RulesetContainer; } protected override IReadOnlyList CompositionTools => new HitObjectCompositionTool[] diff --git a/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs b/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs index 321dd4e1cb..5263d4dcb9 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs @@ -25,6 +25,7 @@ using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI.Scrolling; +using osuTK; namespace osu.Game.Rulesets.Mania.UI { @@ -80,6 +81,13 @@ namespace osu.Game.Rulesets.Mania.UI Config.BindWith(ManiaSetting.ScrollTime, TimeRange); } + /// + /// Retrieves the column that intersects a screen-space position. + /// + /// The screen-space position. + /// The column which intersects with . + public Column GetColumnByPosition(Vector2 screenSpacePosition) => Playfield.GetColumnByPosition(screenSpacePosition); + protected override Playfield CreatePlayfield() => new ManiaPlayfield(Beatmap.Stages) { Anchor = Anchor.Centre, From 8fd04cb47bd9260e52e6280e31aeab43d385408b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 29 Nov 2018 13:20:37 +0900 Subject: [PATCH 13/16] Fix mania placement blueprints appearing outside valid stage placement area --- osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index 41c80dfb68..32d8ef343f 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -5,6 +5,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using System; using System.Collections.Generic; +using System.Linq; using osu.Game.Rulesets.Mania.Beatmaps; using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Objects.Drawables; @@ -17,6 +18,8 @@ namespace osu.Game.Rulesets.Mania.UI { private readonly List stages = new List(); + public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => stages.Any(s => s.ReceivePositionalInputAt(screenSpacePos)); + public ManiaPlayfield(List stageDefinitions) { if (stageDefinitions == null) From 3d46ac7d35393061778a89aae794bb9c3e43cee3 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 29 Nov 2018 13:21:11 +0900 Subject: [PATCH 14/16] Remove unnecessary high frequency input --- osu.Game/Rulesets/Edit/PlacementBlueprint.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Game/Rulesets/Edit/PlacementBlueprint.cs b/osu.Game/Rulesets/Edit/PlacementBlueprint.cs index 2414a682e9..7f39bdc4f9 100644 --- a/osu.Game/Rulesets/Edit/PlacementBlueprint.cs +++ b/osu.Game/Rulesets/Edit/PlacementBlueprint.cs @@ -7,7 +7,6 @@ using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Input; using osu.Framework.Input.Events; using osu.Framework.Timing; using osu.Game.Beatmaps; @@ -20,7 +19,7 @@ namespace osu.Game.Rulesets.Edit /// /// A blueprint which governs the creation of a new to actualisation. /// - public abstract class PlacementBlueprint : CompositeDrawable, IStateful, IRequireHighFrequencyMousePosition + public abstract class PlacementBlueprint : CompositeDrawable, IStateful { /// /// Invoked when has changed. From d1c976880c976ef19aa7d18dcb3c3a73e684e315 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 29 Nov 2018 14:15:23 +0900 Subject: [PATCH 15/16] Fix incorrect margin/spacing handling --- .../Edit/Blueprints/ManiaPlacementBlueprint.cs | 14 +++++--------- osu.Game.Rulesets.Mania/UI/Column.cs | 2 +- osu.Game.Rulesets.Mania/UI/ManiaStage.cs | 8 ++++++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs index 8394328e2c..c36c32bb84 100644 --- a/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs +++ b/osu.Game.Rulesets.Mania/Edit/Blueprints/ManiaPlacementBlueprint.cs @@ -44,17 +44,13 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints { Column column = ColumnAt(e.ScreenSpaceMousePosition); - if (column == null) - SnappedMousePosition = e.MousePosition; - else - { - SnappedWidth = column.DrawWidth; + if (column == null) return false; - // Snap to the column - var parentPos = Parent.ToLocalSpace(column.ToScreenSpace(new Vector2(column.DrawWidth / 2, 0))); - SnappedMousePosition = new Vector2(parentPos.X, e.MousePosition.Y); - } + SnappedWidth = column.DrawWidth; + // Snap to the column + var parentPos = Parent.ToLocalSpace(column.ToScreenSpace(new Vector2(column.DrawWidth / 2, 0))); + SnappedMousePosition = new Vector2(parentPos.X, e.MousePosition.Y); return true; } diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index 68030cdfb2..58e2066f72 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -183,6 +183,6 @@ namespace osu.Game.Rulesets.Mania.UI public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) // This probably shouldn't exist as is, but the columns in the stage are separated by a 1px border - => DrawRectangle.Inflate(new Vector2(1, 0)).Contains(ToLocalSpace(screenSpacePos)); + => DrawRectangle.Inflate(new Vector2(ManiaStage.COLUMN_SPACING / 2, 0)).Contains(ToLocalSpace(screenSpacePos)); } } diff --git a/osu.Game.Rulesets.Mania/UI/ManiaStage.cs b/osu.Game.Rulesets.Mania/UI/ManiaStage.cs index 58a49a7877..ab835cbbb3 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaStage.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaStage.cs @@ -25,6 +25,8 @@ namespace osu.Game.Rulesets.Mania.UI /// public class ManiaStage : ScrollingPlayfield { + public const float COLUMN_SPACING = 1; + public const float HIT_TARGET_POSITION = 50; public IReadOnlyList Columns => columnFlow.Children; @@ -40,6 +42,8 @@ namespace osu.Game.Rulesets.Mania.UI private List normalColumnColours = new List(); private Color4 specialColumnColour; + public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Columns.Any(c => c.ReceivePositionalInputAt(screenSpacePos)); + private readonly int firstColumnIndex; public ManiaStage(int firstColumnIndex, StageDefinition definition, ref ManiaAction normalColumnStartAction, ref ManiaAction specialColumnStartAction) @@ -84,8 +88,8 @@ namespace osu.Game.Rulesets.Mania.UI RelativeSizeAxes = Axes.Y, AutoSizeAxes = Axes.X, Direction = FillDirection.Horizontal, - Padding = new MarginPadding { Left = 1, Right = 1 }, - Spacing = new Vector2(1, 0) + Padding = new MarginPadding { Left = COLUMN_SPACING, Right = COLUMN_SPACING }, + Spacing = new Vector2(COLUMN_SPACING, 0) }, } }, From 7ffc597a8e8426e3e03266e333c42712f27c1eb9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 29 Nov 2018 14:55:20 +0900 Subject: [PATCH 16/16] Fix one-frame issues --- osu.Game/Rulesets/Edit/PlacementBlueprint.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/osu.Game/Rulesets/Edit/PlacementBlueprint.cs b/osu.Game/Rulesets/Edit/PlacementBlueprint.cs index 7f39bdc4f9..1d568313ca 100644 --- a/osu.Game/Rulesets/Edit/PlacementBlueprint.cs +++ b/osu.Game/Rulesets/Edit/PlacementBlueprint.cs @@ -49,6 +49,10 @@ namespace osu.Game.Rulesets.Edit RelativeSizeAxes = Axes.Both; + // This is required to allow the blueprint's position to be updated via OnMouseMove/Handle + // on the same frame it is made visible via a PlacementState change. + AlwaysPresent = true; + Alpha = 0; }