Implement hold note placement

This commit is contained in:
smoogipoo 2018-11-19 18:38:06 +09:00
parent 8071244d97
commit ad950cfc90
3 changed files with 108 additions and 1 deletions

View File

@ -0,0 +1,87 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// 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<HoldNote>
{
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
}
}
}

View File

@ -0,0 +1,19 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// 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();
}
}

View File

@ -43,7 +43,8 @@ protected override RulesetContainer<ManiaHitObject> CreateRulesetContainer(Rules
protected override IReadOnlyList<HitObjectCompositionTool> CompositionTools => new HitObjectCompositionTool[]
{
new NoteCompositionTool()
new NoteCompositionTool(),
new HoldNoteCompositionTool()
};
public override SelectionBlueprint CreateBlueprintFor(DrawableHitObject hitObject)