From ad950cfc909ad9afbf7790970caf46804e91bae7 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 19 Nov 2018 18:38:06 +0900 Subject: [PATCH] Implement hold note placement --- .../Blueprints/HoldNotePlacementBlueprint.cs | 87 +++++++++++++++++++ .../Edit/HoldNoteCompositionTool.cs | 19 ++++ .../Edit/ManiaHitObjectComposer.cs | 3 +- 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 osu.Game.Rulesets.Mania/Edit/Blueprints/HoldNotePlacementBlueprint.cs create mode 100644 osu.Game.Rulesets.Mania/Edit/HoldNoteCompositionTool.cs diff --git a/osu.Game.Rulesets.Mania/Edit/Blueprints/HoldNotePlacementBlueprint.cs b/osu.Game.Rulesets.Mania/Edit/Blueprints/HoldNotePlacementBlueprint.cs new file mode 100644 index 0000000000..0e5a381524 --- /dev/null +++ b/osu.Game.Rulesets.Mania/Edit/Blueprints/HoldNotePlacementBlueprint.cs @@ -0,0 +1,87 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics; +using osu.Framework.Input.Events; +using osu.Game.Rulesets.Mania.Edit.Blueprints.Components; +using osu.Game.Rulesets.Mania.Objects; +using osu.Game.Rulesets.Mania.UI; + +namespace osu.Game.Rulesets.Mania.Edit.Blueprints +{ + public class HoldNotePlacementBlueprint : ManiaPlacementBlueprint + { + private readonly EditNotePiece headPiece; + private readonly EditNotePiece tailPiece; + + private PlacementState state; + + public HoldNotePlacementBlueprint() + : base(new HoldNote()) + { + RelativeSizeAxes = Axes.Both; + + InternalChildren = new[] + { + headPiece = new EditNotePiece { Origin = Anchor.Centre }, + tailPiece = new EditNotePiece { Origin = Anchor.Centre } + }; + } + + protected override void Update() + { + base.Update(); + + switch (state) + { + case PlacementState.Start: + headPiece.Position = SnappedMousePosition; + headPiece.Width = SnappedWidth; + break; + case PlacementState.End: + tailPiece.Position = SnappedMousePosition; + tailPiece.Width = headPiece.Width; + break; + } + } + + protected override bool OnMouseDown(MouseDownEvent e) + { + Column column; + if ((column = ColumnAt(e.ScreenSpaceMousePosition)) == null) + return base.OnMouseDown(e); + + HitObject.StartTime = TimeAt(e.ScreenSpaceMousePosition); + HitObject.Column = column.Index; + + BeginPlacement(); + + state = PlacementState.End; + + return true; + } + + protected override bool OnMouseUp(MouseUpEvent e) + { + var endTime = TimeAt(e.ScreenSpaceMousePosition); + if (endTime < HitObject.StartTime) + { + var tmp = endTime; + endTime = HitObject.StartTime; + HitObject.StartTime = tmp; + } + + HitObject.Duration = endTime - HitObject.StartTime; + + EndPlacement(); + + return true; + } + + private enum PlacementState + { + Start, + End + } + } +} diff --git a/osu.Game.Rulesets.Mania/Edit/HoldNoteCompositionTool.cs b/osu.Game.Rulesets.Mania/Edit/HoldNoteCompositionTool.cs new file mode 100644 index 0000000000..b1872c200f --- /dev/null +++ b/osu.Game.Rulesets.Mania/Edit/HoldNoteCompositionTool.cs @@ -0,0 +1,19 @@ +// 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; + +namespace osu.Game.Rulesets.Mania.Edit +{ + public class HoldNoteCompositionTool : HitObjectCompositionTool + { + public HoldNoteCompositionTool() + : base("Hold") + { + } + + public override PlacementBlueprint CreatePlacementBlueprint() => new HoldNotePlacementBlueprint(); + } +} diff --git a/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs b/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs index 07684f9eb8..ca952e914d 100644 --- a/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs +++ b/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs @@ -43,7 +43,8 @@ namespace osu.Game.Rulesets.Mania.Edit protected override IReadOnlyList CompositionTools => new HitObjectCompositionTool[] { - new NoteCompositionTool() + new NoteCompositionTool(), + new HoldNoteCompositionTool() }; public override SelectionBlueprint CreateBlueprintFor(DrawableHitObject hitObject)