mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 04:52:57 +08:00
Refactor SliderSelectionMask
This commit is contained in:
parent
9b19050faf
commit
38ce8f8af1
67
osu.Game.Rulesets.Osu/Edit/Masks/SliderSelectionMask.cs
Normal file
67
osu.Game.Rulesets.Osu/Edit/Masks/SliderSelectionMask.cs
Normal file
@ -0,0 +1,67 @@
|
||||
// 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.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
||||
using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Edit.Masks
|
||||
{
|
||||
public partial class SliderSelectionMask : SelectionMask
|
||||
{
|
||||
private readonly SliderBody body;
|
||||
private readonly DrawableSlider slider;
|
||||
|
||||
public SliderSelectionMask(DrawableSlider slider)
|
||||
: base(slider)
|
||||
{
|
||||
this.slider = slider;
|
||||
|
||||
Position = slider.Position;
|
||||
|
||||
var sliderObject = (Slider)slider.HitObject;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
body = new SliderBody(sliderObject)
|
||||
{
|
||||
AccentColour = Color4.Transparent,
|
||||
PathWidth = sliderObject.Scale * 64
|
||||
},
|
||||
new CircleSelectionMask(slider.HeadCircle, slider),
|
||||
new CircleSelectionMask(slider.TailCircle, slider),
|
||||
};
|
||||
|
||||
sliderObject.PositionChanged += _ => Position = slider.Position;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
body.BorderColour = colours.Yellow;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
Size = slider.Size;
|
||||
OriginPosition = slider.OriginPosition;
|
||||
|
||||
// Need to cause one update
|
||||
body.UpdateProgress(0);
|
||||
}
|
||||
|
||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => body.ReceivePositionalInputAt(screenSpacePos);
|
||||
|
||||
public override Vector2 SelectionPoint => ToScreenSpace(OriginPosition);
|
||||
public override Quad SelectionQuad => body.PathDrawQuad;
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
// 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.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
||||
using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Edit.Masks
|
||||
{
|
||||
public partial class SliderSelectionMask
|
||||
{
|
||||
private class CircleSelectionMask : SelectionMask
|
||||
{
|
||||
public CircleSelectionMask(DrawableHitCircle sliderHead, DrawableSlider slider)
|
||||
: this(sliderHead, Vector2.Zero, slider)
|
||||
{
|
||||
}
|
||||
|
||||
public CircleSelectionMask(DrawableSliderTail sliderTail, DrawableSlider slider)
|
||||
: this(sliderTail, ((Slider)slider.HitObject).Curve.PositionAt(1), slider)
|
||||
{
|
||||
}
|
||||
|
||||
private readonly DrawableOsuHitObject hitObject;
|
||||
|
||||
private CircleSelectionMask(DrawableOsuHitObject hitObject, Vector2 position, DrawableSlider slider)
|
||||
: base(hitObject)
|
||||
{
|
||||
this.hitObject = hitObject;
|
||||
|
||||
Origin = Anchor.Centre;
|
||||
|
||||
Position = position;
|
||||
Size = slider.HeadCircle.Size;
|
||||
Scale = slider.HeadCircle.Scale;
|
||||
|
||||
AddInternal(new RingPiece());
|
||||
|
||||
Select();
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
Colour = colours.Yellow;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
RelativeAnchorPosition = hitObject.RelativeAnchorPosition;
|
||||
}
|
||||
|
||||
// Todo: This is temporary, since the slider circle masks don't do anything special yet. In the future they will handle input.
|
||||
public override bool HandlePositionalInput => false;
|
||||
}
|
||||
}
|
||||
}
|
@ -37,6 +37,7 @@ namespace osu.Game.Tests.Visual
|
||||
typeof(HitCirclePiece),
|
||||
typeof(HitCircleSelectionMask),
|
||||
typeof(HitCirclePlacementMask),
|
||||
typeof(SliderSelectionMask),
|
||||
};
|
||||
|
||||
private HitObjectComposer composer;
|
||||
|
Loading…
Reference in New Issue
Block a user