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-12-08 18:54:22 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2017-04-18 15:05:58 +08:00
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
2016-11-26 15:51:51 +08:00
|
|
|
|
using Container = osu.Framework.Graphics.Containers.Container;
|
2017-04-18 15:05:58 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2017-03-22 14:22:02 +08:00
|
|
|
|
using OpenTK.Graphics;
|
2017-04-06 10:41:16 +08:00
|
|
|
|
using osu.Game.Audio;
|
2017-05-11 13:48:08 +08:00
|
|
|
|
using System.Linq;
|
2017-09-11 03:51:44 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2016-10-19 18:44:03 +08:00
|
|
|
|
|
2017-04-18 15:05:58 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Objects.Drawables
|
2016-10-19 18:44:03 +08:00
|
|
|
|
{
|
2017-09-11 03:51:44 +08:00
|
|
|
|
public abstract class DrawableHitObject : Container, IHasAccentColour
|
2016-10-19 18:44:03 +08:00
|
|
|
|
{
|
2017-05-26 17:48:18 +08:00
|
|
|
|
public readonly HitObject HitObject;
|
2017-05-11 16:07:46 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The colour used for various elements of this DrawableHitObject.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual Color4 AccentColour { get; set; }
|
|
|
|
|
|
2017-05-26 17:48:18 +08:00
|
|
|
|
protected DrawableHitObject(HitObject hitObject)
|
|
|
|
|
{
|
|
|
|
|
HitObject = hitObject;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class DrawableHitObject<TObject> : DrawableHitObject
|
|
|
|
|
where TObject : HitObject
|
|
|
|
|
{
|
|
|
|
|
public new readonly TObject HitObject;
|
|
|
|
|
|
|
|
|
|
protected DrawableHitObject(TObject hitObject)
|
|
|
|
|
: base(hitObject)
|
|
|
|
|
{
|
|
|
|
|
HitObject = hitObject;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class DrawableHitObject<TObject, TJudgement> : DrawableHitObject<TObject>
|
|
|
|
|
where TObject : HitObject
|
|
|
|
|
where TJudgement : Judgement
|
|
|
|
|
{
|
|
|
|
|
public event Action<DrawableHitObject<TObject, TJudgement>> OnJudgement;
|
|
|
|
|
|
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;
|
|
|
|
|
|
2017-05-26 17:48:18 +08:00
|
|
|
|
protected List<SampleChannel> Samples = new List<SampleChannel>();
|
2017-04-05 20:34:28 +08:00
|
|
|
|
|
2017-05-26 17:48:18 +08:00
|
|
|
|
protected DrawableHitObject(TObject hitObject)
|
|
|
|
|
: base(hitObject)
|
|
|
|
|
{
|
|
|
|
|
}
|
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;
|
|
|
|
|
|
2017-03-22 08:43:44 +08:00
|
|
|
|
if (!IsLoaded)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-10-19 18:44:03 +08:00
|
|
|
|
UpdateState(state);
|
2016-12-15 20:47:57 +08:00
|
|
|
|
|
2016-12-08 18:54:22 +08:00
|
|
|
|
if (State == ArmedState.Hit)
|
2017-04-05 20:34:28 +08:00
|
|
|
|
PlaySamples();
|
2016-10-19 18:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-06 11:24:17 +08:00
|
|
|
|
protected void PlaySamples()
|
|
|
|
|
{
|
|
|
|
|
Samples.ForEach(s => s?.Play());
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-05 18:59:13 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2017-04-06 11:24:17 +08:00
|
|
|
|
|
|
|
|
|
//force application of the state that was set before we loaded.
|
2016-12-06 17:26:21 +08:00
|
|
|
|
UpdateState(State);
|
2016-11-26 15:51:51 +08:00
|
|
|
|
}
|
2017-04-06 11:24:17 +08:00
|
|
|
|
|
2017-05-11 13:48:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether this hit object and all of its nested hit objects have been judged.
|
|
|
|
|
/// </summary>
|
2017-05-11 16:16:01 +08:00
|
|
|
|
public bool Judged => (Judgement?.Result ?? HitResult.None) != HitResult.None && (NestedHitObjects?.All(h => h.Judged) ?? true);
|
2017-05-11 13:48:08 +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
|
|
|
|
{
|
2017-08-21 14:35:16 +08:00
|
|
|
|
if (Judgement == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-05-11 13:48:08 +08:00
|
|
|
|
var partial = Judgement as IPartialJudgement;
|
2017-03-29 16:57:36 +08:00
|
|
|
|
|
2017-03-31 10:54:12 +08:00
|
|
|
|
// Never re-process non-partial hits
|
|
|
|
|
if (Judgement.Result != HitResult.None && partial == null)
|
2016-11-02 11:57:43 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
2017-03-29 16:57:36 +08:00
|
|
|
|
// Update the judgement state
|
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
|
|
|
|
|
2017-03-29 16:57:36 +08:00
|
|
|
|
// Update the judgement state
|
|
|
|
|
bool hadResult = Judgement.Result != HitResult.None;
|
2016-11-26 15:51:51 +08:00
|
|
|
|
CheckJudgement(userTriggered);
|
2016-11-25 15:26:50 +08:00
|
|
|
|
|
2017-03-29 16:57:36 +08:00
|
|
|
|
// Don't process judgements with no result
|
|
|
|
|
if (Judgement.Result == HitResult.None)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Don't process judgements that previously had results but the results were unchanged
|
|
|
|
|
if (hadResult && partial?.Changed != true)
|
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
|
|
|
|
|
2017-03-29 16:57:36 +08:00
|
|
|
|
if (partial != null)
|
|
|
|
|
partial.Changed = false;
|
|
|
|
|
|
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-04-06 11:24:17 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio)
|
2017-04-06 10:41:16 +08:00
|
|
|
|
{
|
2017-04-06 11:24:17 +08:00
|
|
|
|
foreach (SampleInfo sample in HitObject.Samples)
|
|
|
|
|
{
|
|
|
|
|
SampleChannel channel = audio.Sample.Get($@"Gameplay/{sample.Bank}-{sample.Name}");
|
2017-04-06 10:41:16 +08:00
|
|
|
|
|
2017-04-06 11:24:17 +08:00
|
|
|
|
if (channel == null)
|
|
|
|
|
continue;
|
2017-04-06 10:41:16 +08:00
|
|
|
|
|
2017-04-06 11:24:17 +08:00
|
|
|
|
channel.Volume.Value = sample.Volume;
|
|
|
|
|
Samples.Add(channel);
|
|
|
|
|
}
|
2017-05-11 16:07:46 +08:00
|
|
|
|
|
|
|
|
|
//we may be setting a custom judgement in test cases or what not.
|
|
|
|
|
if (Judgement == null)
|
|
|
|
|
Judgement = CreateJudgement();
|
2017-03-06 12:59:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-15 17:55:38 +08:00
|
|
|
|
private List<DrawableHitObject<TObject, TJudgement>> nestedHitObjects;
|
|
|
|
|
protected IEnumerable<DrawableHitObject<TObject, TJudgement>> NestedHitObjects => nestedHitObjects;
|
2017-03-06 12:59:11 +08:00
|
|
|
|
|
2017-06-19 09:54:23 +08:00
|
|
|
|
protected virtual 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);
|
|
|
|
|
}
|
2017-05-26 17:48:18 +08:00
|
|
|
|
|
|
|
|
|
protected abstract TJudgement CreateJudgement();
|
|
|
|
|
protected abstract void UpdateState(ArmedState state);
|
2016-10-19 18:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|