// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. #nullable disable using System; using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.UI.Scrolling; using osu.Game.Rulesets.Mania.UI; namespace osu.Game.Rulesets.Mania.Objects.Drawables { public abstract class DrawableManiaHitObject : DrawableHitObject { /// /// The which causes this to be hit. /// protected readonly IBindable Action = new Bindable(); protected readonly IBindable Direction = new Bindable(); // Leaving the default (10s) makes hitobjects not appear, as this offset is used for the initial state transforms. // Calculated as DrawableManiaRuleset.MAX_TIME_RANGE + some additional allowance for velocity < 1. protected override double InitialLifetimeOffset => 30000; [Resolved(canBeNull: true)] private ManiaPlayfield playfield { get; set; } protected override float SamplePlaybackPosition { get { if (playfield == null) return base.SamplePlaybackPosition; return (float)HitObject.Column / playfield.TotalColumns; } } /// /// Whether this can be hit, given a time value. /// If non-null, judgements will be ignored whilst the function returns false. /// public Func CheckHittable; protected DrawableManiaHitObject(ManiaHitObject hitObject) : base(hitObject) { RelativeSizeAxes = Axes.X; } [BackgroundDependencyLoader(true)] private void load([CanBeNull] IBindable action, [NotNull] IScrollingInfo scrollingInfo) { if (action != null) Action.BindTo(action); Direction.BindTo(scrollingInfo.Direction); } protected override void LoadComplete() { base.LoadComplete(); Direction.BindValueChanged(OnDirectionChanged, true); } protected override void OnApply() { base.OnApply(); if (ParentHitObject != null) AccentColour.BindTo(ParentHitObject.AccentColour); } protected override void OnFree() { base.OnFree(); if (ParentHitObject != null) AccentColour.UnbindFrom(ParentHitObject.AccentColour); } protected virtual void OnDirectionChanged(ValueChangedEvent e) { Anchor = Origin = e.NewValue == ScrollingDirection.Up ? Anchor.TopCentre : Anchor.BottomCentre; } protected override void UpdateHitStateTransforms(ArmedState state) { switch (state) { case ArmedState.Miss: this.FadeOut(150, Easing.In); break; case ArmedState.Hit: this.FadeOut(); break; } } /// /// Causes this to get missed, disregarding all conditions in implementations of . /// public void MissForcefully() => ApplyResult(r => r.Type = r.Judgement.MinResult); } public abstract class DrawableManiaHitObject : DrawableManiaHitObject where TObject : ManiaHitObject { public new TObject HitObject => (TObject)base.HitObject; protected DrawableManiaHitObject(TObject hitObject) : base(hitObject) { } } }