// 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 osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Game.Skinning; using osuTK; using osuTK.Graphics; namespace osu.Game.Rulesets.Catch.Objects.Drawables { /// /// Represents a caught by the catcher. /// [Cached(typeof(IHasCatchObjectState))] public abstract partial class CaughtObject : SkinnableDrawable, IHasCatchObjectState { public PalpableCatchHitObject HitObject { get; private set; } = null!; public Bindable AccentColour { get; } = new Bindable(); public Bindable HyperDash { get; } = new Bindable(); public Bindable IndexInBeatmap { get; } = new Bindable(); public Vector2 DisplayPosition => DrawPosition; public Vector2 DisplaySize => Size * Scale; public float DisplayRotation => Rotation; public double DisplayStartTime => HitObject.StartTime; /// /// Whether this hit object should stay on the catcher plate when the object is caught by the catcher. /// public virtual bool StaysOnPlate => true; public override bool RemoveWhenNotAlive => true; protected CaughtObject(CatchSkinComponents skinComponent, Func defaultImplementation) : base(new CatchSkinComponentLookup(skinComponent), defaultImplementation) { Origin = Anchor.Centre; RelativeSizeAxes = Axes.None; Size = new Vector2(CatchHitObject.OBJECT_RADIUS * 2); } protected override void FreeAfterUse() { ClearTransforms(); Alpha = 1; base.FreeAfterUse(); } public void RestoreState(CatchObjectState state) { HitObject = state.HitObject; AccentColour.Value = state.AccentColour; HyperDash.Value = state.HyperDash; IndexInBeatmap.Value = state.IndexInBeatmap; Position = state.DisplayPosition; Scale = Vector2.Divide(state.DisplaySize, Size); Rotation = state.DisplayRotation; } } }