1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 13:17:26 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Edit/Blueprints/Spinners/Components/SpinnerPiece.cs

74 lines
2.5 KiB
C#
Raw Normal View History

2018-10-29 17:23:23 +08:00
// 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;
2018-11-09 12:58:46 +08:00
using osu.Framework.Configuration;
2018-10-29 17:23:23 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces;
using OpenTK;
2018-11-07 15:08:56 +08:00
namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Spinners.Components
2018-10-29 17:23:23 +08:00
{
public class SpinnerPiece : CompositeDrawable
{
2018-11-09 12:58:46 +08:00
private readonly IBindable<Vector2> positionBindable = new Bindable<Vector2>();
private readonly IBindable<int> stackHeightBindable = new Bindable<int>();
private readonly IBindable<float> scaleBindable = new Bindable<float>();
2018-10-29 17:23:23 +08:00
private readonly Spinner spinner;
private readonly CircularContainer circle;
2018-11-09 12:58:46 +08:00
private readonly RingPiece ring;
2018-10-29 17:23:23 +08:00
public SpinnerPiece(Spinner spinner)
{
this.spinner = spinner;
Origin = Anchor.Centre;
RelativeSizeAxes = Axes.Both;
FillMode = FillMode.Fit;
Size = new Vector2(1.3f);
InternalChildren = new Drawable[]
{
circle = new CircularContainer
{
RelativeSizeAxes = Axes.Both,
Masking = true,
Alpha = 0.5f,
Child = new Box { RelativeSizeAxes = Axes.Both }
},
ring = new RingPiece
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
}
};
ring.Scale = new Vector2(spinner.Scale);
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Colour = colours.Yellow;
2018-11-09 12:58:46 +08:00
positionBindable.BindValueChanged(_ => updatePosition());
stackHeightBindable.BindValueChanged(_ => updatePosition());
scaleBindable.BindValueChanged(v => ring.Scale = new Vector2(v));
positionBindable.BindTo(spinner.PositionBindable);
stackHeightBindable.BindTo(spinner.StackHeightBindable);
scaleBindable.BindTo(spinner.ScaleBindable);
2018-10-29 17:23:23 +08:00
}
private void updatePosition() => Position = spinner.Position;
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => circle.ReceivePositionalInputAt(screenSpacePos);
}
}