2016-10-19 18:44:03 +08:00
|
|
|
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
|
2016-11-14 18:49:29 +08:00
|
|
|
|
namespace osu.Game.Modes.Objects.Drawables
|
2016-10-19 18:44:03 +08:00
|
|
|
|
{
|
|
|
|
|
public abstract class DrawableHitObject : Container, IStateful<ArmedState>
|
|
|
|
|
{
|
2016-11-02 11:57:43 +08:00
|
|
|
|
//todo: move to a more central implementation. this logic should not be at a drawable level.
|
2016-10-19 18:44:03 +08:00
|
|
|
|
public Action<DrawableHitObject> OnHit;
|
|
|
|
|
public Action<DrawableHitObject> OnMiss;
|
|
|
|
|
|
2016-11-02 11:57:43 +08:00
|
|
|
|
public Func<DrawableHitObject, bool> AllowHit;
|
|
|
|
|
|
2016-11-19 18:07:57 +08:00
|
|
|
|
public Container<DrawableHitObject> ChildObjects;
|
|
|
|
|
|
|
|
|
|
public JudgementResult Result;
|
|
|
|
|
|
2016-10-19 18:44:03 +08:00
|
|
|
|
public HitObject HitObject;
|
|
|
|
|
|
|
|
|
|
public DrawableHitObject(HitObject hitObject)
|
|
|
|
|
{
|
|
|
|
|
HitObject = hitObject;
|
2016-11-02 18:42:07 +08:00
|
|
|
|
Depth = -(float)hitObject.StartTime;
|
2016-10-19 18:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ArmedState state;
|
|
|
|
|
public ArmedState State
|
|
|
|
|
{
|
|
|
|
|
get { return state; }
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-11-02 11:31:51 +08:00
|
|
|
|
if (state == value) return;
|
2016-10-19 18:44:03 +08:00
|
|
|
|
state = value;
|
|
|
|
|
|
|
|
|
|
UpdateState(state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-02 11:57:43 +08:00
|
|
|
|
protected double? HitTime;
|
|
|
|
|
|
|
|
|
|
protected virtual bool Hit()
|
|
|
|
|
{
|
|
|
|
|
if (State != ArmedState.Disarmed)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (AllowHit?.Invoke(this) == false)
|
|
|
|
|
return false;
|
|
|
|
|
|
2016-11-06 18:13:52 +08:00
|
|
|
|
HitTime = Time.Current;
|
2016-11-02 11:57:43 +08:00
|
|
|
|
|
|
|
|
|
State = ArmedState.Armed;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-19 18:44:03 +08:00
|
|
|
|
private bool counted;
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2016-11-06 15:25:21 +08:00
|
|
|
|
if (Time.Current >= HitObject.EndTime && !counted)
|
2016-10-19 18:44:03 +08:00
|
|
|
|
{
|
|
|
|
|
counted = true;
|
|
|
|
|
if (state == ArmedState.Armed)
|
|
|
|
|
OnHit?.Invoke(this);
|
|
|
|
|
else
|
|
|
|
|
OnMiss?.Invoke(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract void UpdateState(ArmedState state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum ArmedState
|
|
|
|
|
{
|
|
|
|
|
Disarmed,
|
|
|
|
|
Armed
|
|
|
|
|
}
|
|
|
|
|
}
|