osu/osu.Game.Rulesets.Catch/Objects/Drawables/DrawableCatchHitObject.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

84 lines
2.7 KiB
C#
Raw Normal View History

// 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.
2018-04-13 09:19:50 +00:00
2022-06-17 07:37:17 +00:00
#nullable disable
using System;
using JetBrains.Annotations;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Catch.Judgements;
using osu.Game.Rulesets.Catch.UI;
using osu.Game.Rulesets.Judgements;
2020-11-04 07:19:07 +00:00
using osu.Game.Rulesets.Objects.Drawables;
2020-12-02 07:53:01 +00:00
using osu.Game.Utils;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Rulesets.Catch.Objects.Drawables
{
public abstract partial class DrawableCatchHitObject : DrawableHitObject<CatchHitObject>
{
public readonly Bindable<float> OriginalXBindable = new Bindable<float>();
public readonly Bindable<float> XOffsetBindable = new Bindable<float>();
protected override double InitialLifetimeOffset => HitObject.TimePreempt;
protected override float SamplePlaybackPosition => HitObject.EffectiveX / CatchPlayfield.WIDTH;
public int RandomSeed => HitObject?.RandomSeed ?? 0;
2020-12-02 07:53:01 +00:00
protected DrawableCatchHitObject([CanBeNull] CatchHitObject hitObject)
: base(hitObject)
{
Anchor = Anchor.BottomLeft;
}
2018-04-13 09:19:50 +00:00
2020-12-02 07:53:01 +00:00
/// <summary>
/// Get a random number in range [0,1) based on seed <see cref="RandomSeed"/>.
/// </summary>
public float RandomSingle(int series) => StatelessRNG.NextSingle(RandomSeed, series);
2020-12-02 07:53:01 +00:00
protected override void OnApply()
{
base.OnApply();
OriginalXBindable.BindTo(HitObject.OriginalXBindable);
XOffsetBindable.BindTo(HitObject.XOffsetBindable);
}
protected override void OnFree()
{
base.OnFree();
OriginalXBindable.UnbindFrom(HitObject.OriginalXBindable);
XOffsetBindable.UnbindFrom(HitObject.XOffsetBindable);
}
[CanBeNull]
public Func<CatchHitObject, bool> CheckPosition;
2018-04-13 09:19:50 +00:00
protected override JudgementResult CreateResult(Judgement judgement) => new CatchJudgementResult(HitObject, judgement);
protected override void CheckForResult(bool userTriggered, double timeOffset)
{
2018-01-12 12:46:50 +00:00
if (CheckPosition == null) return;
2018-04-13 09:19:50 +00:00
if (timeOffset >= 0 && Result != null)
2020-09-29 05:26:36 +00:00
ApplyResult(r => r.Type = CheckPosition.Invoke(HitObject) ? r.Judgement.MaxResult : r.Judgement.MinResult);
}
2018-04-13 09:19:50 +00:00
2020-11-04 07:19:07 +00:00
protected override void UpdateHitStateTransforms(ArmedState state)
{
2020-11-04 07:19:07 +00:00
switch (state)
{
2020-11-04 07:19:07 +00:00
case ArmedState.Miss:
this.FadeOut(250).RotateTo(Rotation * 2, 250, Easing.Out);
break;
2019-04-01 03:44:46 +00:00
2020-11-04 07:19:07 +00:00
case ArmedState.Hit:
this.FadeOut();
break;
}
}
}
}