1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-05 08:52:55 +08:00

Add bindable to drawable catch hit obejcts

This commit is contained in:
ekrctb 2020-11-27 10:55:33 +09:00
parent 5e36fb322a
commit 23109f5bbc
3 changed files with 68 additions and 11 deletions

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Rulesets.Catch.UI; using osu.Game.Rulesets.Catch.UI;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
@ -10,6 +11,8 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
{ {
public abstract class DrawableCatchHitObject : DrawableHitObject<CatchHitObject> public abstract class DrawableCatchHitObject : DrawableHitObject<CatchHitObject>
{ {
public readonly Bindable<float> XBindable = new Bindable<float>();
protected override double InitialLifetimeOffset => HitObject.TimePreempt; protected override double InitialLifetimeOffset => HitObject.TimePreempt;
public float DisplayRadius => DrawSize.X / 2 * Scale.X * HitObject.Scale; public float DisplayRadius => DrawSize.X / 2 * Scale.X * HitObject.Scale;
@ -19,10 +22,26 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
protected DrawableCatchHitObject(CatchHitObject hitObject) protected DrawableCatchHitObject(CatchHitObject hitObject)
: base(hitObject) : base(hitObject)
{ {
X = hitObject.X; if (hitObject != null)
XBindable.Value = hitObject.X;
Anchor = Anchor.BottomLeft; Anchor = Anchor.BottomLeft;
} }
protected override void OnApply()
{
base.OnApply();
XBindable.BindTo(HitObject.XBindable);
}
protected override void OnFree()
{
base.OnFree();
XBindable.UnbindFrom(HitObject.XBindable);
}
public Func<CatchHitObject, bool> CheckPosition; public Func<CatchHitObject, bool> CheckPosition;
public bool IsOnPlate; public bool IsOnPlate;

View File

@ -36,15 +36,19 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
VisualRepresentation.Value = GetVisualRepresentation(change.NewValue); VisualRepresentation.Value = GetVisualRepresentation(change.NewValue);
}, true); }, true);
VisualRepresentation.BindValueChanged(change => VisualRepresentation.BindValueChanged(_ => updatePiece());
{ HyperDash.BindValueChanged(_ => updatePiece(), true);
ScaleContainer.Child = new SkinnableDrawable( }
new CatchSkinComponent(getComponent(change.NewValue)),
_ => fruitPiece = new FruitPiece private void updatePiece()
{ {
VisualRepresentation = { BindTarget = VisualRepresentation }, ScaleContainer.Child = new SkinnableDrawable(
}); new CatchSkinComponent(getComponent(VisualRepresentation.Value)),
}, true); _ => fruitPiece = new FruitPiece
{
VisualRepresentation = { BindTarget = VisualRepresentation },
HyperDash = { BindTarget = HyperDash },
});
} }
protected override void OnApply() protected override void OnApply()

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osuTK; using osuTK;
@ -12,6 +13,15 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
{ {
public new PalpableCatchHitObject HitObject => (PalpableCatchHitObject)base.HitObject; public new PalpableCatchHitObject HitObject => (PalpableCatchHitObject)base.HitObject;
public Bindable<bool> HyperDash { get; } = new Bindable<bool>();
public Bindable<float> ScaleBindable { get; } = new Bindable<float>(1);
/// <summary>
/// The multiplicative factor applied to <see cref="ScaleContainer"/> scale relative to <see cref="HitObject"/> scale.
/// </summary>
protected virtual float ScaleFactor => 1;
/// <summary> /// <summary>
/// Whether this hit object should stay on the catcher plate when the object is caught by the catcher. /// Whether this hit object should stay on the catcher plate when the object is caught by the catcher.
/// </summary> /// </summary>
@ -36,7 +46,31 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
ScaleContainer.Scale = new Vector2(HitObject.Scale); XBindable.BindValueChanged(x =>
{
if (!IsOnPlate) X = x.NewValue;
}, true);
ScaleBindable.BindValueChanged(scale =>
{
ScaleContainer.Scale = new Vector2(scale.NewValue * ScaleFactor);
}, true);
}
protected override void OnApply()
{
base.OnApply();
HyperDash.BindTo(HitObject.HyperDashBindable);
ScaleBindable.BindTo(HitObject.ScaleBindable);
}
protected override void OnFree()
{
HyperDash.UnbindFrom(HitObject.HyperDashBindable);
ScaleBindable.UnbindFrom(HitObject.ScaleBindable);
base.OnFree();
} }
} }
} }