Use bindables for hitobject events

This commit is contained in:
smoogipoo
2018-11-09 13:58:46 +09:00
parent 0833ba2692
commit cc8531790a
12 changed files with 150 additions and 96 deletions

View File

@ -1,14 +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.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Osu.Objects;
using OpenTK;
namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
{
public class PathControlPointVisualiser : CompositeDrawable
{
private readonly IBindable<Vector2[]> controlPointsBindable = new Bindable<Vector2[]>();
private readonly Slider slider;
private readonly Container<PathControlPointPiece> pieces;
@ -18,9 +23,13 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
this.slider = slider;
InternalChild = pieces = new Container<PathControlPointPiece> { RelativeSizeAxes = Axes.Both };
}
slider.ControlPointsChanged += _ => updatePathControlPoints();
updatePathControlPoints();
[BackgroundDependencyLoader]
private void load()
{
controlPointsBindable.BindValueChanged(_ => updatePathControlPoints());
controlPointsBindable.BindTo(slider.ControlPointsBindable);
}
private void updatePathControlPoints()

View File

@ -3,6 +3,7 @@
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Rulesets.Osu.Objects;
@ -14,6 +15,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
{
public class SliderBodyPiece : CompositeDrawable
{
private readonly IBindable<Vector2> positionBindable = new Bindable<Vector2>();
private readonly IBindable<float> scaleBindable = new Bindable<float>();
private readonly Slider slider;
private readonly ManualSliderBody body;
@ -26,9 +30,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
AccentColour = Color4.Transparent,
PathWidth = slider.Scale * 64
};
slider.PositionChanged += _ => updatePosition();
slider.ScaleChanged += _ => body.PathWidth = slider.Scale * 64;
}
[BackgroundDependencyLoader]
@ -36,7 +37,11 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
{
body.BorderColour = colours.Yellow;
updatePosition();
positionBindable.BindValueChanged(_ => updatePosition());
scaleBindable.BindValueChanged(v => body.PathWidth = v * 64);
positionBindable.BindTo(slider.PositionBindable);
scaleBindable.BindTo(slider.ScaleBindable);
}
private void updatePosition() => Position = slider.StackedPosition;

View File

@ -1,13 +1,18 @@
// 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.Configuration;
using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles.Components;
using osu.Game.Rulesets.Osu.Objects;
using OpenTK;
namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
{
public class SliderCirclePiece : HitCirclePiece
{
private readonly IBindable<Vector2[]> controlPointsBindable = new Bindable<Vector2[]>();
private readonly Slider slider;
private readonly SliderPosition position;
@ -16,8 +21,13 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
{
this.slider = slider;
this.position = position;
}
slider.ControlPointsChanged += _ => UpdatePosition();
[BackgroundDependencyLoader]
private void load()
{
controlPointsBindable.BindValueChanged(_ => UpdatePosition());
controlPointsBindable.BindTo(slider.ControlPointsBindable);
}
protected override void UpdatePosition()