1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-18 03:52:54 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs

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

121 lines
5.1 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 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
2020-03-10 14:30:24 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
2020-11-05 12:51:46 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Judgements;
using osu.Game.Rulesets.Osu.Scoring;
using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.Scoring;
2020-11-05 12:51:46 +08:00
using osuTK;
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
2017-04-18 15:05:58 +08:00
namespace osu.Game.Rulesets.Osu.Objects.Drawables
{
public abstract partial class DrawableOsuHitObject : DrawableHitObject<OsuHitObject>
{
2020-11-05 12:51:46 +08:00
public readonly IBindable<Vector2> PositionBindable = new Bindable<Vector2>();
public readonly IBindable<int> StackHeightBindable = new Bindable<int>();
public readonly IBindable<float> ScaleBindable = new BindableFloat();
public readonly IBindable<int> IndexInCurrentComboBindable = new Bindable<int>();
2022-04-08 14:20:22 +08:00
// Must be set to update IsHovered as it's used in relax mod to detect osu hit objects.
2019-06-30 23:27:47 +08:00
public override bool HandlePositionalInput => true;
protected override float SamplePlaybackPosition => CalculateDrawableRelativePosition(this);
2020-03-10 14:30:24 +08:00
/// <summary>
/// What action this <see cref="DrawableOsuHitObject"/> should take in response to a
/// click at the given time value.
/// If non-null, judgements will be ignored for return values of <see cref="ClickAction.Ignore"/>
/// and <see cref="ClickAction.Shake"/>, and this hit object will be shaken for return values of
/// <see cref="ClickAction.Shake"/>.
2020-03-10 14:30:24 +08:00
/// </summary>
public Func<DrawableHitObject, double, HitResult, ClickAction> CheckHittable;
2020-03-10 14:30:24 +08:00
protected DrawableOsuHitObject(OsuHitObject hitObject)
: base(hitObject)
{
2020-11-05 12:51:46 +08:00
}
[BackgroundDependencyLoader]
private void load()
{
Alpha = 0;
}
protected override void OnApply()
{
base.OnApply();
2019-07-16 12:45:59 +08:00
2020-11-05 12:51:46 +08:00
IndexInCurrentComboBindable.BindTo(HitObject.IndexInCurrentComboBindable);
PositionBindable.BindTo(HitObject.PositionBindable);
StackHeightBindable.BindTo(HitObject.StackHeightBindable);
ScaleBindable.BindTo(HitObject.ScaleBindable);
}
2018-04-13 17:19:50 +08:00
protected override void OnFree()
{
base.OnFree();
IndexInCurrentComboBindable.UnbindFrom(HitObject.IndexInCurrentComboBindable);
PositionBindable.UnbindFrom(HitObject.PositionBindable);
StackHeightBindable.UnbindFrom(HitObject.StackHeightBindable);
ScaleBindable.UnbindFrom(HitObject.ScaleBindable);
}
protected virtual IEnumerable<Drawable> DimmablePieces => Enumerable.Empty<Drawable>();
protected override void UpdateInitialTransforms()
{
base.UpdateInitialTransforms();
foreach (var piece in DimmablePieces)
2022-10-05 16:48:56 +08:00
{
piece.FadeColour(new Color4(195, 195, 195, 255));
using (piece.BeginDelayedSequence(InitialLifetimeOffset - OsuHitWindows.MISS_WINDOW))
piece.FadeColour(Color4.White, 100);
2022-10-05 16:48:56 +08:00
}
}
protected sealed override double InitialLifetimeOffset => HitObject.TimePreempt;
private OsuInputManager osuActionInputManager;
2019-11-12 18:35:08 +08:00
internal OsuInputManager OsuActionInputManager => osuActionInputManager ??= GetContainingInputManager() as OsuInputManager;
/// <summary>
/// Shake the hit object in case it was clicked far too early or late (aka "note lock").
/// </summary>
public virtual void Shake() { }
2018-04-13 17:19:50 +08:00
/// <summary>
/// Causes this <see cref="DrawableOsuHitObject"/> to get hit, disregarding all conditions in implementations of <see cref="DrawableHitObject.CheckForResult"/>.
/// </summary>
public void HitForcefully() => ApplyResult(r => r.Type = r.Judgement.MaxResult);
/// <summary>
/// Causes this <see cref="DrawableOsuHitObject"/> to get missed, disregarding all conditions in implementations of <see cref="DrawableHitObject.CheckForResult"/>.
/// </summary>
public void MissForcefully() => ApplyResult(r => r.Type = r.Judgement.MinResult);
private RectangleF parentScreenSpaceRectangle => ((DrawableOsuHitObject)ParentHitObject)?.parentScreenSpaceRectangle ?? Parent!.ScreenSpaceDrawQuad.AABBFloat;
/// <summary>
/// Calculates the position of the given <paramref name="drawable"/> relative to the playfield area.
/// </summary>
/// <param name="drawable">The drawable to calculate its relative position.</param>
protected float CalculateDrawableRelativePosition(Drawable drawable) => (drawable.ScreenSpaceDrawQuad.Centre.X - parentScreenSpaceRectangle.X) / parentScreenSpaceRectangle.Width;
protected override JudgementResult CreateResult(Judgement judgement) => new OsuJudgementResult(HitObject, judgement);
}
}