1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 04:52:57 +08:00

Implement initial slider placement (linear)

This commit is contained in:
smoogipoo 2018-10-04 13:44:49 +09:00
parent 38ce8f8af1
commit bd915e8dca
5 changed files with 151 additions and 1 deletions

View File

@ -0,0 +1,99 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Objects;
using OpenTK;
namespace osu.Game.Rulesets.Osu.Edit.Masks
{
public partial class SliderPlacementMask : PlacementMask
{
public new Slider HitObject => (Slider)base.HitObject;
private readonly CirclePlacementMask headMask;
private readonly CirclePlacementMask tailMask;
private readonly List<Vector2> controlPoints = new List<Vector2>();
private PlacementState state = PlacementState.Head;
public SliderPlacementMask()
: base(new Slider())
{
RelativeSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
headMask = new CirclePlacementMask(),
tailMask = new CirclePlacementMask(),
};
setState(PlacementState.Head);
}
protected override bool OnMouseMove(MouseMoveEvent e)
{
switch (state)
{
case PlacementState.Head:
headMask.Position = e.MousePosition;
return true;
case PlacementState.Tail:
tailMask.Position = ToLocalSpace(e.ScreenSpaceMousePosition);
return true;
}
return false;
}
protected override bool OnClick(ClickEvent e)
{
switch (state)
{
case PlacementState.Head:
setState(PlacementState.Tail);
controlPoints.Add(Vector2.Zero);
break;
case PlacementState.Tail:
controlPoints.Add(tailMask.Position - headMask.Position);
HitObject.Position = headMask.Position;
HitObject.ControlPoints = controlPoints.ToList();
HitObject.CurveType = CurveType.Linear;
HitObject.Distance = Vector2.Distance(controlPoints.First(), controlPoints.Last());
Finish();
break;
}
return base.OnClick(e);
}
private void setState(PlacementState newState)
{
switch (newState)
{
case PlacementState.Head:
tailMask.Alpha = 0;
break;
case PlacementState.Tail:
tailMask.Alpha = 1;
break;
}
state = newState;
}
private enum PlacementState
{
Head,
Body,
Tail
}
}
}

View File

@ -0,0 +1,29 @@
// 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.Edit;
using osu.Game.Rulesets.Osu.Objects;
namespace osu.Game.Rulesets.Osu.Edit.Masks
{
public partial class SliderPlacementMask
{
private class CirclePlacementMask : PlacementMask
{
public new HitCircle HitObject => (HitCircle)base.HitObject;
public CirclePlacementMask()
: base(new HitCircle())
{
Origin = Anchor.Centre;
AutoSizeAxes = Axes.Both;
InternalChild = new HitCircleMask(HitObject);
}
protected override bool Handle(UIEvent e) => false;
}
}
}

View File

@ -27,9 +27,10 @@ namespace osu.Game.Rulesets.Osu.Edit
protected override RulesetContainer<OsuHitObject> CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap)
=> new OsuEditRulesetContainer(ruleset, beatmap);
protected override IReadOnlyList<HitObjectCompositionTool> CompositionTools => new[]
protected override IReadOnlyList<HitObjectCompositionTool> CompositionTools => new HitObjectCompositionTool[]
{
new HitCircleCompositionTool(),
new SliderCompositionTool(),
};
protected override Container CreateLayerContainer() => new PlayfieldAdjustmentContainer { RelativeSizeAxes = Axes.Both };

View File

@ -0,0 +1,20 @@
// 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.Osu.Edit.Masks;
using osu.Game.Rulesets.Osu.Objects;
namespace osu.Game.Rulesets.Osu.Edit
{
public class SliderCompositionTool : HitObjectCompositionTool
{
public SliderCompositionTool()
: base(nameof(Slider))
{
}
public override PlacementMask CreatePlacementMask() => new SliderPlacementMask();
}
}

View File

@ -38,6 +38,7 @@ namespace osu.Game.Tests.Visual
typeof(HitCircleSelectionMask),
typeof(HitCirclePlacementMask),
typeof(SliderSelectionMask),
typeof(SliderPlacementMask)
};
private HitObjectComposer composer;