mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 14:57:52 +08:00
Implement initial slider placement (linear)
This commit is contained in:
parent
38ce8f8af1
commit
bd915e8dca
99
osu.Game.Rulesets.Osu/Edit/Masks/SliderPlacementMask.cs
Normal file
99
osu.Game.Rulesets.Osu/Edit/Masks/SliderPlacementMask.cs
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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 };
|
||||
|
20
osu.Game.Rulesets.Osu/Edit/SliderCompositionTool.cs
Normal file
20
osu.Game.Rulesets.Osu/Edit/SliderCompositionTool.cs
Normal 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();
|
||||
}
|
||||
}
|
@ -38,6 +38,7 @@ namespace osu.Game.Tests.Visual
|
||||
typeof(HitCircleSelectionMask),
|
||||
typeof(HitCirclePlacementMask),
|
||||
typeof(SliderSelectionMask),
|
||||
typeof(SliderPlacementMask)
|
||||
};
|
||||
|
||||
private HitObjectComposer composer;
|
||||
|
Loading…
Reference in New Issue
Block a user