1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 19:17:25 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs

95 lines
4.0 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
2020-03-10 14:30:24 +08:00
using System;
2020-11-05 12:51:46 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Objects.Drawables;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Osu.Judgements;
using osu.Game.Graphics.Containers;
using osu.Game.Rulesets.Osu.UI;
2020-11-05 12:51:46 +08:00
using osuTK;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Osu.Objects.Drawables
{
public 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>();
2019-06-30 23:28:20 +08:00
// Must be set to update IsHovered as it's used in relax mdo to detect osu hit objects.
2019-06-30 23:27:47 +08:00
public override bool HandlePositionalInput => true;
protected override float SamplePlaybackPosition => HitObject.X / OsuPlayfield.BASE_SIZE.X;
2020-03-10 14:30:24 +08:00
/// <summary>
2020-08-31 12:33:41 +08:00
/// Whether this <see cref="DrawableOsuHitObject"/> can be hit, given a time value.
/// If non-null, judgements will be ignored (resulting in a shake) whilst the function returns false.
2020-03-10 14:30:24 +08:00
/// </summary>
2020-04-10 01:02:09 +08:00
public Func<DrawableHitObject, double, bool> CheckHittable;
2020-03-10 14:30:24 +08:00
2020-11-05 12:51:46 +08:00
private ShakeContainer shakeContainer;
2018-04-13 17:19:50 +08:00
protected DrawableOsuHitObject(OsuHitObject hitObject)
: base(hitObject)
{
2020-11-05 12:51:46 +08:00
}
[BackgroundDependencyLoader]
private void load()
{
Alpha = 0;
base.AddInternal(shakeContainer = new ShakeContainer
{
ShakeDuration = 30,
RelativeSizeAxes = Axes.Both
});
}
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);
}
// Forward all internal management to shakeContainer.
// This is a bit ugly but we don't have the concept of InternalContent so it'll have to do for now. (https://github.com/ppy/osu-framework/issues/1690)
protected override void AddInternal(Drawable drawable) => shakeContainer.Add(drawable);
protected override void ClearInternal(bool disposeChildren = true) => shakeContainer.Clear(disposeChildren);
protected override bool RemoveInternal(Drawable drawable) => shakeContainer.Remove(drawable);
protected sealed override double InitialLifetimeOffset => HitObject.TimePreempt;
2018-04-13 17:19:50 +08:00
private OsuInputManager osuActionInputManager;
2019-11-12 18:35:08 +08:00
internal OsuInputManager OsuActionInputManager => osuActionInputManager ??= GetContainingInputManager() as OsuInputManager;
2020-11-12 14:59:48 +08:00
public virtual void Shake(double maximumLength) => shakeContainer.Shake(maximumLength);
2018-04-13 17:19:50 +08:00
/// <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);
protected override JudgementResult CreateResult(Judgement judgement) => new OsuJudgementResult(HitObject, judgement);
2018-04-13 17:19:50 +08:00
}
}