1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 16:22:59 +08:00
osu-lazer/osu.Game.Rulesets.Catch/Objects/Drawables/DrawablePalpableCatchHitObject.cs

96 lines
3.2 KiB
C#
Raw Normal View History

2020-11-24 18:16:03 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2022-06-17 15:37:17 +08:00
#nullable disable
using JetBrains.Annotations;
2020-11-24 18:16:03 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2020-11-24 18:16:03 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2020-11-24 18:16:03 +08:00
using osuTK;
using osuTK.Graphics;
2020-11-24 18:16:03 +08:00
namespace osu.Game.Rulesets.Catch.Objects.Drawables
{
[Cached(typeof(IHasCatchObjectState))]
2020-12-09 09:25:35 +08:00
public abstract class DrawablePalpableCatchHitObject : DrawableCatchHitObject, IHasCatchObjectState
2020-11-24 18:16:03 +08:00
{
2020-11-25 07:07:59 +08:00
public new PalpableCatchHitObject HitObject => (PalpableCatchHitObject)base.HitObject;
Bindable<Color4> IHasCatchObjectState.AccentColour => AccentColour;
public Bindable<bool> HyperDash { get; } = new Bindable<bool>();
public Bindable<float> ScaleBindable { get; } = new Bindable<float>(1);
public Bindable<int> IndexInBeatmap { get; } = new Bindable<int>();
/// <summary>
/// The multiplicative factor applied to <see cref="Drawable.Scale"/> relative to <see cref="HitObject"/> scale.
/// </summary>
protected virtual float ScaleFactor => 1;
/// <summary>
/// The container internal transforms (such as scaling based on the circle size) are applied to.
/// </summary>
protected readonly Container ScalingContainer;
public Vector2 DisplaySize => ScalingContainer.Size * ScalingContainer.Scale;
public float DisplayRotation => ScalingContainer.Rotation;
2020-12-09 09:25:35 +08:00
protected DrawablePalpableCatchHitObject([CanBeNull] CatchHitObject h)
: base(h)
2020-11-24 18:16:03 +08:00
{
Origin = Anchor.Centre;
Size = new Vector2(CatchHitObject.OBJECT_RADIUS * 2);
AddInternal(ScalingContainer = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(CatchHitObject.OBJECT_RADIUS * 2)
});
2020-11-24 18:16:03 +08:00
}
[BackgroundDependencyLoader]
private void load()
{
OriginalXBindable.BindValueChanged(updateXPosition);
XOffsetBindable.BindValueChanged(updateXPosition, true);
ScaleBindable.BindValueChanged(scale =>
{
ScalingContainer.Scale = new Vector2(scale.NewValue * ScaleFactor);
Size = DisplaySize;
}, true);
IndexInBeatmap.BindValueChanged(_ => UpdateComboColour());
}
private void updateXPosition(ValueChangedEvent<float> _)
{
X = OriginalXBindable.Value + XOffsetBindable.Value;
}
protected override void OnApply()
{
base.OnApply();
HyperDash.BindTo(HitObject.HyperDashBindable);
ScaleBindable.BindTo(HitObject.ScaleBindable);
IndexInBeatmap.BindTo(HitObject.IndexInBeatmapBindable);
}
protected override void OnFree()
{
HyperDash.UnbindFrom(HitObject.HyperDashBindable);
ScaleBindable.UnbindFrom(HitObject.ScaleBindable);
IndexInBeatmap.UnbindFrom(HitObject.IndexInBeatmapBindable);
base.OnFree();
2020-11-24 18:16:03 +08:00
}
}
}