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-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;
|
2017-03-15 15:07:40 +08:00
|
|
|
|
using osu.Game.Modes.Judgements;
|
2016-11-26 15:51:51 +08:00
|
|
|
|
using Container = osu.Framework.Graphics.Containers.Container;
|
2017-03-13 18:15:25 +08:00
|
|
|
|
using osu.Game.Modes.Objects.Types;
|
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
|
|
|
|
{
|
2017-03-15 17:55:38 +08:00
|
|
|
|
public abstract class DrawableHitObject<TJudgement> : Container, IStateful<ArmedState>
|
|
|
|
|
where TJudgement : JudgementInfo
|
2016-10-19 18:44:03 +08:00
|
|
|
|
{
|
2017-03-15 17:55:38 +08:00
|
|
|
|
public override bool HandleInput => Interactive;
|
2016-11-26 15:51:51 +08:00
|
|
|
|
|
2017-03-15 17:55:38 +08:00
|
|
|
|
public bool Interactive = true;
|
|
|
|
|
|
|
|
|
|
public TJudgement Judgement;
|
|
|
|
|
|
|
|
|
|
protected abstract TJudgement CreateJudgementInfo();
|
2016-11-19 18:07:57 +08:00
|
|
|
|
|
2017-03-06 12:59:11 +08:00
|
|
|
|
protected abstract void UpdateState(ArmedState state);
|
2016-10-19 18:44:03 +08:00
|
|
|
|
|
|
|
|
|
private ArmedState state;
|
|
|
|
|
public ArmedState State
|
|
|
|
|
{
|
|
|
|
|
get { return state; }
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-03-17 14:30:19 +08:00
|
|
|
|
if (state == value)
|
|
|
|
|
return;
|
2016-10-19 18:44:03 +08:00
|
|
|
|
state = value;
|
|
|
|
|
|
|
|
|
|
UpdateState(state);
|
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-03-06 12:59:11 +08:00
|
|
|
|
protected SampleChannel Sample;
|
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
|
|
|
|
{
|
2017-03-06 12:59:11 +08:00
|
|
|
|
Sample?.Play();
|
2016-12-08 18:54:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
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-11-26 15:51:51 +08:00
|
|
|
|
}
|
2017-03-06 12:59:11 +08:00
|
|
|
|
}
|
2016-11-26 15:51:51 +08:00
|
|
|
|
|
2017-03-15 17:55:38 +08:00
|
|
|
|
public abstract class DrawableHitObject<TObject, TJudgement> : DrawableHitObject<TJudgement>
|
2017-03-15 15:29:14 +08:00
|
|
|
|
where TObject : HitObject
|
2017-03-15 17:55:38 +08:00
|
|
|
|
where TJudgement : JudgementInfo
|
2017-03-06 12:59:11 +08:00
|
|
|
|
{
|
2017-03-15 17:55:38 +08:00
|
|
|
|
public event Action<DrawableHitObject<TObject, TJudgement>> OnJudgement;
|
2017-02-16 16:02:36 +08:00
|
|
|
|
|
2017-03-15 15:29:14 +08:00
|
|
|
|
public TObject HitObject;
|
2017-02-16 16:02:36 +08:00
|
|
|
|
|
2017-03-15 15:29:14 +08:00
|
|
|
|
protected DrawableHitObject(TObject hitObject)
|
2017-02-16 16:02:36 +08:00
|
|
|
|
{
|
2017-03-06 12:59:11 +08:00
|
|
|
|
HitObject = hitObject;
|
2017-02-16 16:02:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-25 15:26:50 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Process a hit of this hitobject. Carries out judgement.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <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;
|
|
|
|
|
|
2017-03-13 18:15:25 +08:00
|
|
|
|
double endTime = (HitObject as IHasEndTime)?.EndTime ?? HitObject.StartTime;
|
|
|
|
|
|
|
|
|
|
Judgement.TimeOffset = Time.Current - 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;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-15 17:55:38 +08:00
|
|
|
|
OnJudgement?.Invoke(this);
|
2016-11-29 20:28:43 +08:00
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2017-03-06 12:59:11 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
|
{
|
2017-03-09 14:52:40 +08:00
|
|
|
|
SampleType type = HitObject.Sample?.Type ?? SampleType.None;
|
|
|
|
|
if (type == SampleType.None)
|
|
|
|
|
type = SampleType.Normal;
|
2017-03-06 12:59:11 +08:00
|
|
|
|
|
2017-03-09 14:52:40 +08:00
|
|
|
|
SampleSet sampleSet = HitObject.Sample?.Set ?? SampleSet.Normal;
|
|
|
|
|
|
|
|
|
|
Sample = audio.Sample.Get($@"Gameplay/{sampleSet.ToString().ToLower()}-hit{type.ToString().ToLower()}");
|
2017-03-06 12:59:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-15 17:55:38 +08:00
|
|
|
|
private List<DrawableHitObject<TObject, TJudgement>> nestedHitObjects;
|
2017-03-06 12:59:11 +08:00
|
|
|
|
|
2017-03-15 17:55:38 +08:00
|
|
|
|
protected IEnumerable<DrawableHitObject<TObject, TJudgement>> NestedHitObjects => nestedHitObjects;
|
2017-03-06 12:59:11 +08:00
|
|
|
|
|
2017-03-15 17:55:38 +08:00
|
|
|
|
protected void AddNested(DrawableHitObject<TObject, TJudgement> h)
|
2017-03-06 12:59:11 +08:00
|
|
|
|
{
|
|
|
|
|
if (nestedHitObjects == null)
|
2017-03-15 17:55:38 +08:00
|
|
|
|
nestedHitObjects = new List<DrawableHitObject<TObject, TJudgement>>();
|
2017-03-06 12:59:11 +08:00
|
|
|
|
|
2017-03-15 17:55:38 +08:00
|
|
|
|
h.OnJudgement += d => OnJudgement?.Invoke(d);
|
2017-03-06 12:59:11 +08:00
|
|
|
|
nestedHitObjects.Add(h);
|
|
|
|
|
}
|
2016-10-19 18:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|