1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-30 15:43:00 +08:00
osu-lazer/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs

181 lines
5.4 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-08-27 19:24:08 +08:00
using System;
using JetBrains.Annotations;
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Game.Audio;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Objects.Drawables;
2018-06-08 14:16:45 +08:00
using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Rulesets.Mania.UI;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Mania.Objects.Drawables
{
public abstract class DrawableManiaHitObject : DrawableHitObject<ManiaHitObject>
2018-04-13 17:19:50 +08:00
{
/// <summary>
/// The <see cref="ManiaAction"/> which causes this <see cref="DrawableManiaHitObject{TObject}"/> to be hit.
2018-04-13 17:19:50 +08:00
/// </summary>
protected readonly IBindable<ManiaAction> Action = new Bindable<ManiaAction>();
2018-04-13 17:19:50 +08:00
protected readonly IBindable<ScrollingDirection> Direction = new Bindable<ScrollingDirection>();
[Resolved(canBeNull: true)]
2020-04-13 12:42:21 +08:00
private ManiaPlayfield playfield { get; set; }
/// <summary>
/// Gets the samples that are played by this object during gameplay.
/// </summary>
public ISampleInfo[] GetGameplaySamples() => Samples.Samples;
protected override float SamplePlaybackPosition
{
get
{
2020-04-13 12:42:21 +08:00
if (playfield == null)
return base.SamplePlaybackPosition;
2020-04-13 12:42:21 +08:00
return (float)HitObject.Column / playfield.TotalColumns;
}
}
2020-08-31 12:33:41 +08:00
/// <summary>
/// Whether this <see cref="DrawableManiaHitObject"/> can be hit, given a time value.
/// If non-null, judgements will be ignored whilst the function returns false.
2020-08-31 12:33:41 +08:00
/// </summary>
2020-08-27 19:24:08 +08:00
public Func<DrawableHitObject, double, bool> CheckHittable;
protected DrawableManiaHitObject(ManiaHitObject hitObject)
2018-04-13 17:19:50 +08:00
: base(hitObject)
{
2021-05-12 15:35:05 +08:00
RelativeSizeAxes = Axes.X;
2018-04-13 17:19:50 +08:00
}
[BackgroundDependencyLoader(true)]
private void load([CanBeNull] IBindable<ManiaAction> action, [NotNull] IScrollingInfo scrollingInfo)
{
if (action != null)
Action.BindTo(action);
Direction.BindTo(scrollingInfo.Direction);
2021-05-12 15:40:46 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
Direction.BindValueChanged(OnDirectionChanged, true);
}
2021-05-12 15:35:05 +08:00
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);
}
2020-04-28 14:34:10 +08:00
private double computedLifetimeStart;
public override double LifetimeStart
{
get => base.LifetimeStart;
set
{
computedLifetimeStart = value;
if (!AlwaysAlive)
base.LifetimeStart = value;
}
}
private double computedLifetimeEnd;
public override double LifetimeEnd
{
get => base.LifetimeEnd;
set
{
computedLifetimeEnd = value;
if (!AlwaysAlive)
base.LifetimeEnd = value;
}
}
private bool alwaysAlive;
/// <summary>
/// Whether this <see cref="DrawableManiaHitObject"/> should always remain alive.
/// </summary>
internal bool AlwaysAlive
{
get => alwaysAlive;
set
{
if (alwaysAlive == value)
return;
alwaysAlive = value;
if (value)
{
// Set the base lifetimes directly, to avoid mangling the computed lifetimes
base.LifetimeStart = double.MinValue;
base.LifetimeEnd = double.MaxValue;
}
else
{
LifetimeStart = computedLifetimeStart;
LifetimeEnd = computedLifetimeEnd;
}
}
}
2019-02-21 17:56:34 +08:00
protected virtual void OnDirectionChanged(ValueChangedEvent<ScrollingDirection> e)
{
2019-02-21 17:56:34 +08:00
Anchor = Origin = e.NewValue == ScrollingDirection.Up ? Anchor.TopCentre : Anchor.BottomCentre;
}
2020-11-04 15:19:07 +08:00
protected override void UpdateHitStateTransforms(ArmedState state)
{
switch (state)
{
case ArmedState.Miss:
2019-09-12 18:29:08 +08:00
this.FadeOut(150, Easing.In);
break;
2019-04-01 11:44:46 +08:00
case ArmedState.Hit:
2020-08-21 22:56:27 +08:00
this.FadeOut();
break;
}
}
2020-08-27 19:24:08 +08:00
/// <summary>
/// Causes this <see cref="DrawableManiaHitObject"/> to get missed, disregarding all conditions in implementations of <see cref="DrawableHitObject.CheckForResult"/>.
/// </summary>
public void MissForcefully() => ApplyResult(r => r.Type = r.Judgement.MinResult);
2018-04-13 17:19:50 +08:00
}
public abstract class DrawableManiaHitObject<TObject> : DrawableManiaHitObject
where TObject : ManiaHitObject
{
2021-05-12 15:35:05 +08:00
public new TObject HitObject => (TObject)base.HitObject;
protected DrawableManiaHitObject(TObject hitObject)
: base(hitObject)
{
}
}
2018-04-13 17:19:50 +08:00
}