2019-01-24 16:43:03 +08: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 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
2018-11-09 12:58:46 +08:00
|
|
|
|
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;
|
2019-02-14 17:47:05 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-07-24 17:50:57 +08:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2019-07-24 17:50:57 +08:00
|
|
|
|
using osu.Game.Skinning;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|
|
|
|
{
|
|
|
|
|
public class DrawableHitCircle : DrawableOsuHitObject, IDrawableHitObjectWithProxiedApproach
|
|
|
|
|
{
|
|
|
|
|
public ApproachCircle ApproachCircle;
|
|
|
|
|
|
2018-11-09 12:58:46 +08:00
|
|
|
|
private readonly IBindable<Vector2> positionBindable = new Bindable<Vector2>();
|
|
|
|
|
private readonly IBindable<int> stackHeightBindable = new Bindable<int>();
|
|
|
|
|
private readonly IBindable<float> scaleBindable = new Bindable<float>();
|
|
|
|
|
|
2019-07-24 17:50:57 +08:00
|
|
|
|
public OsuAction? HitAction => hitArea.HitAction;
|
2019-02-14 17:47:05 +08:00
|
|
|
|
|
|
|
|
|
private readonly Container scaleContainer;
|
|
|
|
|
|
2019-07-24 17:50:57 +08:00
|
|
|
|
private readonly HitArea hitArea;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public DrawableHitCircle(HitCircle h)
|
|
|
|
|
: base(h)
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
|
|
|
|
|
Position = HitObject.StackedPosition;
|
|
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
|
{
|
2019-02-14 17:47:05 +08:00
|
|
|
|
scaleContainer = new Container
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-02-14 17:47:05 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2019-07-24 17:50:57 +08:00
|
|
|
|
Children = new Drawable[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-07-24 17:50:57 +08:00
|
|
|
|
hitArea = new HitArea
|
2019-02-14 17:47:05 +08:00
|
|
|
|
{
|
2019-07-24 17:50:57 +08:00
|
|
|
|
Hit = () =>
|
2019-02-14 17:47:05 +08:00
|
|
|
|
{
|
2019-07-24 17:50:57 +08:00
|
|
|
|
if (AllJudged)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
UpdateResult(true);
|
|
|
|
|
return true;
|
2019-02-14 17:47:05 +08:00
|
|
|
|
},
|
2019-07-24 17:50:57 +08:00
|
|
|
|
},
|
2019-07-30 21:41:20 +08:00
|
|
|
|
new SkinnableDrawable("Play/osu/hitcircle", _ => new MainCirclePiece(HitObject.IndexInCurrentCombo)),
|
2019-07-24 17:50:57 +08:00
|
|
|
|
ApproachCircle = new ApproachCircle
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Scale = new Vector2(4),
|
2019-02-14 17:47:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2019-07-24 17:50:57 +08:00
|
|
|
|
Size = hitArea.DrawSize;
|
2018-11-09 12:58:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
positionBindable.BindValueChanged(_ => Position = HitObject.StackedPosition);
|
|
|
|
|
stackHeightBindable.BindValueChanged(_ => Position = HitObject.StackedPosition);
|
2019-02-22 19:13:38 +08:00
|
|
|
|
scaleBindable.BindValueChanged(scale => scaleContainer.Scale = new Vector2(scale.NewValue), true);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-09 12:58:46 +08:00
|
|
|
|
positionBindable.BindTo(HitObject.PositionBindable);
|
|
|
|
|
stackHeightBindable.BindTo(HitObject.StackHeightBindable);
|
|
|
|
|
scaleBindable.BindTo(HitObject.ScaleBindable);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-07-24 17:50:57 +08:00
|
|
|
|
AccentColour.BindValueChanged(accent => ApproachCircle.Colour = accent.NewValue, true);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-06 10:31:46 +08:00
|
|
|
|
protected override void CheckForResult(bool userTriggered, double timeOffset)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
if (!userTriggered)
|
|
|
|
|
{
|
|
|
|
|
if (!HitObject.HitWindows.CanBeHit(timeOffset))
|
2018-08-03 14:38:48 +08:00
|
|
|
|
ApplyResult(r => r.Type = HitResult.Miss);
|
2018-08-01 20:46:22 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = HitObject.HitWindows.ResultFor(timeOffset);
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
if (result == HitResult.None)
|
2018-06-28 19:41:23 +08:00
|
|
|
|
{
|
2018-07-06 16:24:30 +08:00
|
|
|
|
Shake(Math.Abs(timeOffset) - HitObject.HitWindows.HalfWindowFor(HitResult.Miss));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return;
|
2018-06-28 19:41:23 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-08-03 14:38:48 +08:00
|
|
|
|
ApplyResult(r => r.Type = result);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-22 14:33:12 +08:00
|
|
|
|
protected override void UpdateInitialTransforms()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-07-22 14:33:12 +08:00
|
|
|
|
base.UpdateInitialTransforms();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-07-05 10:32:09 +08:00
|
|
|
|
ApproachCircle.FadeIn(Math.Min(HitObject.TimeFadeIn * 2, HitObject.TimePreempt));
|
2019-07-24 18:32:24 +08:00
|
|
|
|
ApproachCircle.ScaleTo(1f, HitObject.TimePreempt);
|
2018-12-13 13:55:28 +08:00
|
|
|
|
ApproachCircle.Expire(true);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-22 14:33:12 +08:00
|
|
|
|
protected override void UpdateStateTransforms(ArmedState state)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case ArmedState.Idle:
|
|
|
|
|
this.Delay(HitObject.TimePreempt).FadeOut(500);
|
|
|
|
|
|
|
|
|
|
Expire(true);
|
|
|
|
|
|
2019-07-24 17:50:57 +08:00
|
|
|
|
hitArea.HitAction = null;
|
2019-01-21 09:57:14 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
// override lifetime end as FadeIn may have been changed externally, causing out expiration to be too early.
|
|
|
|
|
LifetimeEnd = HitObject.StartTime + HitObject.HitWindows.HalfWindowFor(HitResult.Miss);
|
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case ArmedState.Miss:
|
|
|
|
|
ApproachCircle.FadeOut(50);
|
|
|
|
|
this.FadeOut(100);
|
|
|
|
|
Expire();
|
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case ArmedState.Hit:
|
|
|
|
|
ApproachCircle.FadeOut(50);
|
|
|
|
|
|
2019-07-24 17:50:57 +08:00
|
|
|
|
// todo: temporary / arbitrary
|
|
|
|
|
this.Delay(800).Expire();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-07-24 17:50:57 +08:00
|
|
|
|
public Drawable ProxiedLayer => ApproachCircle;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-07-24 17:50:57 +08:00
|
|
|
|
private class HitArea : Drawable, IKeyBindingHandler<OsuAction>
|
|
|
|
|
{
|
|
|
|
|
// IsHovered is used
|
|
|
|
|
public override bool HandlePositionalInput => true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-07-24 17:50:57 +08:00
|
|
|
|
public Func<bool> Hit;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-07-24 17:50:57 +08:00
|
|
|
|
public OsuAction? HitAction;
|
|
|
|
|
|
|
|
|
|
public HitArea()
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
|
|
|
|
|
|
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
|
Origin = Anchor.Centre;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-24 17:50:57 +08:00
|
|
|
|
public bool OnPressed(OsuAction action)
|
|
|
|
|
{
|
|
|
|
|
switch (action)
|
|
|
|
|
{
|
|
|
|
|
case OsuAction.LeftButton:
|
|
|
|
|
case OsuAction.RightButton:
|
|
|
|
|
if (IsHovered && (Hit?.Invoke() ?? false))
|
|
|
|
|
{
|
|
|
|
|
HitAction = action;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool OnReleased(OsuAction action) => false;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|