2017-02-07 12:59:30 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-10-19 18:44:03 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
2017-02-16 16:02:36 +08:00
|
|
|
|
using System.Collections.Generic;
|
2016-11-26 15:51:51 +08:00
|
|
|
|
using System.ComponentModel;
|
2016-10-19 18:44:03 +08:00
|
|
|
|
using osu.Framework;
|
2016-12-08 18:54:22 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
|
|
|
|
using osu.Game.Beatmaps.Samples;
|
2016-11-26 15:51:51 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using Container = osu.Framework.Graphics.Containers.Container;
|
2016-10-19 18:44:03 +08:00
|
|
|
|
|
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-29 20:28:43 +08:00
|
|
|
|
public event Action<DrawableHitObject, JudgementInfo> OnJudgement;
|
2016-11-02 11:57:43 +08:00
|
|
|
|
|
2017-02-14 16:52:53 +08:00
|
|
|
|
public override bool HandleInput => Interactive;
|
|
|
|
|
|
|
|
|
|
public bool Interactive = true;
|
|
|
|
|
|
2016-11-29 20:40:24 +08:00
|
|
|
|
public JudgementInfo Judgement;
|
2016-11-26 15:51:51 +08:00
|
|
|
|
|
|
|
|
|
public abstract JudgementInfo CreateJudgementInfo();
|
2016-11-19 18:07:57 +08:00
|
|
|
|
|
2016-10-19 18:44:03 +08:00
|
|
|
|
public HitObject HitObject;
|
|
|
|
|
|
|
|
|
|
public DrawableHitObject(HitObject hitObject)
|
|
|
|
|
{
|
|
|
|
|
HitObject = hitObject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2017-01-24 17:09:45 +08:00
|
|
|
|
if (IsLoaded)
|
|
|
|
|
Expire();
|
2016-12-15 20:47:57 +08:00
|
|
|
|
|
2016-12-08 18:54:22 +08:00
|
|
|
|
if (State == ArmedState.Hit)
|
|
|
|
|
PlaySample();
|
2016-10-19 18:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-18 16:35:04 +08:00
|
|
|
|
SampleChannel sample;
|
2016-12-08 18:54:22 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
|
{
|
2017-01-24 15:01:49 +08:00
|
|
|
|
string hitType = ((HitObject.Sample?.Type ?? SampleType.None) == SampleType.None ? SampleType.Normal : HitObject.Sample.Type).ToString().ToLower();
|
|
|
|
|
string sampleSet = (HitObject.Sample?.Set ?? SampleSet.Normal).ToString().ToLower();
|
2016-12-08 19:00:24 +08:00
|
|
|
|
|
|
|
|
|
sample = audio.Sample.Get($@"Gameplay/{sampleSet}-hit{hitType}");
|
2016-12-08 18:54:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-16 12:39:01 +08:00
|
|
|
|
protected virtual void PlaySample()
|
2016-12-08 18:54:22 +08:00
|
|
|
|
{
|
|
|
|
|
sample?.Play();
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-26 15:51:51 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2016-12-07 17:18:36 +08:00
|
|
|
|
//we may be setting a custom judgement in test cases or what not.
|
|
|
|
|
if (Judgement == null)
|
|
|
|
|
Judgement = CreateJudgementInfo();
|
2016-12-06 17:26:21 +08:00
|
|
|
|
|
|
|
|
|
//force application of the state that was set before we loaded.
|
|
|
|
|
UpdateState(State);
|
2016-12-15 20:47:57 +08:00
|
|
|
|
|
|
|
|
|
Expire(true);
|
2016-11-26 15:51:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-16 16:02:36 +08:00
|
|
|
|
private List<DrawableHitObject> nestedHitObjects;
|
|
|
|
|
|
|
|
|
|
protected IEnumerable<DrawableHitObject> NestedHitObjects => nestedHitObjects;
|
|
|
|
|
|
|
|
|
|
protected void AddNested(DrawableHitObject h)
|
|
|
|
|
{
|
|
|
|
|
if (nestedHitObjects == null)
|
|
|
|
|
nestedHitObjects = new List<DrawableHitObject>();
|
|
|
|
|
|
|
|
|
|
h.OnJudgement += (d, j) => { OnJudgement?.Invoke(d, j); } ;
|
|
|
|
|
nestedHitObjects.Add(h);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-25 15:26:50 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Process a hit of this hitobject. Carries out judgement.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="judgement">Preliminary judgement information provided by the hit source.</param>
|
|
|
|
|
/// <returns>Whether a hit was processed.</returns>
|
2016-11-26 15:51:51 +08:00
|
|
|
|
protected bool UpdateJudgement(bool userTriggered)
|
2016-11-02 11:57:43 +08:00
|
|
|
|
{
|
2016-11-26 15:51:51 +08:00
|
|
|
|
if (Judgement.Result != null)
|
2016-11-02 11:57:43 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
2016-11-26 15:51:51 +08:00
|
|
|
|
Judgement.TimeOffset = Time.Current - HitObject.EndTime;
|
2016-11-25 15:26:50 +08:00
|
|
|
|
|
2016-11-26 15:51:51 +08:00
|
|
|
|
CheckJudgement(userTriggered);
|
2016-11-25 15:26:50 +08:00
|
|
|
|
|
2016-11-26 15:51:51 +08:00
|
|
|
|
if (Judgement.Result == null)
|
2016-11-02 11:57:43 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
2016-11-26 15:51:51 +08:00
|
|
|
|
switch (Judgement.Result)
|
2016-11-25 15:26:50 +08:00
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
State = ArmedState.Hit;
|
|
|
|
|
break;
|
|
|
|
|
case HitResult.Miss:
|
|
|
|
|
State = ArmedState.Miss;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-29 20:28:43 +08:00
|
|
|
|
OnJudgement?.Invoke(this, Judgement);
|
|
|
|
|
|
2016-11-02 11:57:43 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-26 15:51:51 +08:00
|
|
|
|
protected virtual void CheckJudgement(bool userTriggered)
|
|
|
|
|
{
|
2017-02-16 16:02:36 +08:00
|
|
|
|
if (NestedHitObjects != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var d in NestedHitObjects)
|
|
|
|
|
d.CheckJudgement(userTriggered);
|
|
|
|
|
}
|
2016-11-26 15:51:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-03 21:40:15 +08:00
|
|
|
|
protected override void UpdateAfterChildren()
|
2016-10-19 18:44:03 +08:00
|
|
|
|
{
|
2016-12-03 21:40:15 +08:00
|
|
|
|
base.UpdateAfterChildren();
|
2016-10-19 18:44:03 +08:00
|
|
|
|
|
2016-11-26 15:51:51 +08:00
|
|
|
|
UpdateJudgement(false);
|
2016-10-19 18:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract void UpdateState(ArmedState state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum ArmedState
|
|
|
|
|
{
|
2016-11-25 15:26:50 +08:00
|
|
|
|
Idle,
|
|
|
|
|
Hit,
|
|
|
|
|
Miss
|
2016-10-19 18:44:03 +08:00
|
|
|
|
}
|
2016-11-26 15:51:51 +08:00
|
|
|
|
|
|
|
|
|
public class PositionalJudgementInfo : JudgementInfo
|
|
|
|
|
{
|
|
|
|
|
public Vector2 PositionOffset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class JudgementInfo
|
|
|
|
|
{
|
2016-11-29 20:46:30 +08:00
|
|
|
|
public ulong? ComboAtHit;
|
2016-11-26 15:51:51 +08:00
|
|
|
|
public HitResult? Result;
|
|
|
|
|
public double TimeOffset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum HitResult
|
|
|
|
|
{
|
|
|
|
|
[Description(@"Miss")]
|
|
|
|
|
Miss,
|
|
|
|
|
[Description(@"Hit")]
|
|
|
|
|
Hit,
|
|
|
|
|
}
|
2016-10-19 18:44:03 +08:00
|
|
|
|
}
|