2019-01-24 08:43:03 +00: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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2017-10-09 10:42:55 +00:00
|
|
|
|
using System;
|
2020-11-30 03:52:58 +00:00
|
|
|
|
using JetBrains.Annotations;
|
2020-11-27 01:55:33 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2017-10-09 10:42:55 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2020-12-08 06:02:55 +00:00
|
|
|
|
using osu.Game.Rulesets.Catch.Judgements;
|
2020-07-01 15:21:45 +00:00
|
|
|
|
using osu.Game.Rulesets.Catch.UI;
|
2020-12-08 06:02:55 +00:00
|
|
|
|
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
|
|
|
|
|
2020-02-19 09:01:59 +00:00
|
|
|
|
namespace osu.Game.Rulesets.Catch.Objects.Drawables
|
2017-10-09 10:42:55 +00:00
|
|
|
|
{
|
2018-01-04 09:50:17 +00:00
|
|
|
|
public abstract partial class DrawableCatchHitObject : DrawableHitObject<CatchHitObject>
|
2017-10-09 10:42:55 +00:00
|
|
|
|
{
|
2020-12-14 04:39:07 +00:00
|
|
|
|
public readonly Bindable<float> OriginalXBindable = new Bindable<float>();
|
|
|
|
|
public readonly Bindable<float> XOffsetBindable = new Bindable<float>();
|
2020-11-27 01:55:33 +00:00
|
|
|
|
|
2020-11-03 09:45:18 +00:00
|
|
|
|
protected override double InitialLifetimeOffset => HitObject.TimePreempt;
|
|
|
|
|
|
2020-12-09 08:58:53 +00:00
|
|
|
|
protected override float SamplePlaybackPosition => HitObject.EffectiveX / CatchPlayfield.WIDTH;
|
2020-04-11 23:33:25 +00:00
|
|
|
|
|
2020-12-02 11:53:47 +00:00
|
|
|
|
public int RandomSeed => HitObject?.RandomSeed ?? 0;
|
2020-12-02 07:53:01 +00:00
|
|
|
|
|
2020-11-30 03:52:58 +00:00
|
|
|
|
protected DrawableCatchHitObject([CanBeNull] CatchHitObject hitObject)
|
2017-10-09 10:42:55 +00:00
|
|
|
|
: base(hitObject)
|
|
|
|
|
{
|
2020-11-24 08:03:26 +00:00
|
|
|
|
Anchor = Anchor.BottomLeft;
|
2017-10-09 10:42:55 +00:00
|
|
|
|
}
|
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>
|
2020-12-02 11:53:47 +00:00
|
|
|
|
public float RandomSingle(int series) => StatelessRNG.NextSingle(RandomSeed, series);
|
2020-12-02 07:53:01 +00:00
|
|
|
|
|
2020-11-27 01:55:33 +00:00
|
|
|
|
protected override void OnApply()
|
|
|
|
|
{
|
|
|
|
|
base.OnApply();
|
|
|
|
|
|
2020-12-14 04:39:07 +00:00
|
|
|
|
OriginalXBindable.BindTo(HitObject.OriginalXBindable);
|
|
|
|
|
XOffsetBindable.BindTo(HitObject.XOffsetBindable);
|
2020-11-27 01:55:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnFree()
|
|
|
|
|
{
|
|
|
|
|
base.OnFree();
|
|
|
|
|
|
2020-12-14 04:39:07 +00:00
|
|
|
|
OriginalXBindable.UnbindFrom(HitObject.OriginalXBindable);
|
|
|
|
|
XOffsetBindable.UnbindFrom(HitObject.XOffsetBindable);
|
2020-11-27 01:55:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-15 07:27:49 +00:00
|
|
|
|
[CanBeNull]
|
2017-11-28 09:37:41 +00:00
|
|
|
|
public Func<CatchHitObject, bool> CheckPosition;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-12-08 06:02:55 +00:00
|
|
|
|
protected override JudgementResult CreateResult(Judgement judgement) => new CatchJudgementResult(HitObject, judgement);
|
|
|
|
|
|
2018-08-06 02:31:46 +00:00
|
|
|
|
protected override void CheckForResult(bool userTriggered, double timeOffset)
|
2017-10-09 10:42:55 +00:00
|
|
|
|
{
|
2018-01-12 12:46:50 +00:00
|
|
|
|
if (CheckPosition == null) return;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-08-03 06:38:48 +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);
|
2017-10-09 10:42:55 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-11-04 07:19:07 +00:00
|
|
|
|
protected override void UpdateHitStateTransforms(ArmedState state)
|
2019-08-26 12:15:23 +00:00
|
|
|
|
{
|
2020-11-04 07:19:07 +00:00
|
|
|
|
switch (state)
|
2017-10-09 10:42:55 +00:00
|
|
|
|
{
|
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;
|
2017-10-09 10:42:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|