// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics.Containers; using osu.Game.Rulesets.Catch.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables; using osuTK.Graphics; namespace osu.Game.Rulesets.Catch.Skinning.Default { public abstract class CatchHitObjectPiece : CompositeDrawable { public readonly Bindable AccentColour = new Bindable(); public readonly Bindable HyperDash = new Bindable(); [Resolved(canBeNull: true)] [CanBeNull] protected DrawableHitObject DrawableHitObject { get; private set; } [Resolved(canBeNull: true)] [CanBeNull] protected CaughtObject CaughtObject { get; private set; } /// /// A part of this piece that will be faded out while falling in the playfield. /// [CanBeNull] protected virtual BorderPiece BorderPiece => null; /// /// A part of this piece that will be only visible when is true. /// [CanBeNull] protected virtual HyperBorderPiece HyperBorderPiece => null; protected override void LoadComplete() { base.LoadComplete(); var hitObject = (DrawablePalpableCatchHitObject)DrawableHitObject; if (hitObject != null) { AccentColour.BindTo(hitObject.AccentColour); HyperDash.BindTo(hitObject.HyperDash); } if (CaughtObject != null) AccentColour.BindTo(CaughtObject.AccentColour); HyperDash.BindValueChanged(hyper => { if (HyperBorderPiece != null) HyperBorderPiece.Alpha = hyper.NewValue ? 1 : 0; }, true); } protected override void Update() { if (BorderPiece != null) { if (DrawableHitObject?.HitObject != null) BorderPiece.Alpha = (float)Math.Clamp((DrawableHitObject.HitObject.StartTime - Time.Current) / 500, 0, 1); else BorderPiece.Alpha = 0; } } } }