Merge branch 'master' into better_hitobject_defaults

This commit is contained in:
Dean Herbert
2017-03-17 02:51:15 +09:00
committed by GitHub
8 changed files with 125 additions and 63 deletions

View File

@ -33,10 +33,10 @@ namespace osu.Desktop.VisualTests.Tests
Position = new Vector2(275, 5) Position = new Vector2(275, 5)
}); });
filter.PinTab(GroupMode.All); filter.PinItem(GroupMode.All);
filter.PinTab(GroupMode.RecentlyPlayed); filter.PinItem(GroupMode.RecentlyPlayed);
filter.ValueChanged += (sender, mode) => filter.ItemChanged += (sender, mode) =>
{ {
text.Text = "Currently Selected: " + mode.ToString(); text.Text = "Currently Selected: " + mode.ToString();
}; };

View File

@ -39,7 +39,7 @@ namespace osu.Game.Database
using (SerializationReader sr = new SerializationReader(s)) using (SerializationReader sr = new SerializationReader(s))
{ {
var ruleset = Ruleset.GetRuleset((PlayMode)sr.ReadByte()); var ruleset = Ruleset.GetRuleset((PlayMode)sr.ReadByte());
score = ruleset.CreateScoreProcessor().GetScore(); score = ruleset.CreateScoreProcessor().CreateScore();
/* score.Pass = true;*/ /* score.Pass = true;*/
var version = sr.ReadInt32(); var version = sr.ReadInt32();

View File

@ -28,7 +28,7 @@ namespace osu.Game.Graphics.UserInterface
throw new InvalidOperationException("OsuTabControl only supports enums as the generic type argument"); throw new InvalidOperationException("OsuTabControl only supports enums as the generic type argument");
foreach (var val in (T[])Enum.GetValues(typeof(T))) foreach (var val in (T[])Enum.GetValues(typeof(T)))
AddTab(val); AddItem(val);
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]

View File

@ -7,12 +7,64 @@ using System.Collections.Generic;
using osu.Game.Modes.Judgements; using osu.Game.Modes.Judgements;
using osu.Game.Modes.UI; using osu.Game.Modes.UI;
using osu.Game.Modes.Objects; using osu.Game.Modes.Objects;
using osu.Game.Beatmaps;
namespace osu.Game.Modes namespace osu.Game.Modes
{ {
public abstract class ScoreProcessor public abstract class ScoreProcessor
{ {
public virtual Score GetScore() => new Score /// <summary>
/// Invoked when the ScoreProcessor is in a failed state.
/// </summary>
public event Action Failed;
/// <summary>
/// The current total score.
/// </summary>
public readonly BindableDouble TotalScore = new BindableDouble { MinValue = 0 };
/// <summary>
/// The current accuracy.
/// </summary>
public readonly BindableDouble Accuracy = new BindableDouble { MinValue = 0, MaxValue = 1 };
/// <summary>
/// The current health.
/// </summary>
public readonly BindableDouble Health = new BindableDouble { MinValue = 0, MaxValue = 1 };
/// <summary>
/// The current combo.
/// </summary>
public readonly BindableInt Combo = new BindableInt();
/// <summary>
/// THe highest combo achieved by this score.
/// </summary>
public readonly BindableInt HighestCombo = new BindableInt();
/// <summary>
/// Whether the score is in a failed state.
/// </summary>
public virtual bool HasFailed => false;
/// <summary>
/// Whether this ScoreProcessor has already triggered the failed state.
/// </summary>
private bool alreadyFailed;
protected ScoreProcessor()
{
Combo.ValueChanged += delegate { HighestCombo.Value = Math.Max(HighestCombo.Value, Combo.Value); };
Reset();
}
/// <summary>
/// Creates a Score applicable to the game mode in which this ScoreProcessor resides.
/// </summary>
/// <returns>The Score.</returns>
public virtual Score CreateScore() => new Score
{ {
TotalScore = TotalScore, TotalScore = TotalScore,
Combo = Combo, Combo = Combo,
@ -21,30 +73,32 @@ namespace osu.Game.Modes
Health = Health, Health = Health,
}; };
public readonly BindableDouble TotalScore = new BindableDouble { MinValue = 0 };
public readonly BindableDouble Accuracy = new BindableDouble { MinValue = 0, MaxValue = 1 };
public readonly BindableDouble Health = new BindableDouble { MinValue = 0, MaxValue = 1 };
public readonly BindableInt Combo = new BindableInt();
/// <summary> /// <summary>
/// Keeps track of the highest combo ever achieved in this play. /// Resets this ScoreProcessor to a default state.
/// This is handled automatically by ScoreProcessor.
/// </summary> /// </summary>
public readonly BindableInt HighestCombo = new BindableInt(); protected virtual void Reset()
/// <summary>
/// Called when we reach a failing health of zero.
/// </summary>
public event Action Failed;
/// <summary>
/// Notifies subscribers that the score is in a failed state.
/// </summary>
protected void TriggerFailed()
{ {
TotalScore.Value = 0;
Accuracy.Value = 0;
Health.Value = 0;
Combo.Value = 0;
HighestCombo.Value = 0;
alreadyFailed = false;
}
/// <summary>
/// Checks if the score is in a failed state and notifies subscribers.
/// <para>
/// This can only ever notify subscribers once.
/// </para>
/// </summary>
protected void UpdateFailed()
{
if (alreadyFailed || !HasFailed)
return;
alreadyFailed = true;
Failed?.Invoke(); Failed?.Invoke();
} }
} }
@ -56,32 +110,35 @@ namespace osu.Game.Modes
/// <summary> /// <summary>
/// All judgements held by this ScoreProcessor. /// All judgements held by this ScoreProcessor.
/// </summary> /// </summary>
protected List<TJudgement> Judgements; protected readonly List<TJudgement> Judgements = new List<TJudgement>();
/// <summary> public override bool HasFailed => Health.Value == Health.MinValue;
/// Are we allowed to fail?
/// </summary>
protected bool CanFail => true;
/// <summary>
/// Whether this ScoreProcessor has already triggered the failed event.
/// </summary>
protected bool HasFailed { get; private set; }
protected ScoreProcessor() protected ScoreProcessor()
{ {
Combo.ValueChanged += delegate { HighestCombo.Value = Math.Max(HighestCombo.Value, Combo.Value); }; }
protected ScoreProcessor(HitRenderer<TObject, TJudgement> hitRenderer)
{
Judgements.Capacity = hitRenderer.Beatmap.HitObjects.Count;
hitRenderer.OnJudgement += addJudgement;
ComputeTargets(hitRenderer.Beatmap);
Reset(); Reset();
} }
protected ScoreProcessor(HitRenderer<TObject, TJudgement> hitRenderer) /// <summary>
: this() /// Computes target scoring values for this ScoreProcessor. This is equivalent to performing an auto-play of the score to find the values.
{ /// </summary>
Judgements = new List<TJudgement>(hitRenderer.Beatmap.HitObjects.Count); /// <param name="beatmap">The Beatmap containing the objects that will be judged by this ScoreProcessor.</param>
hitRenderer.OnJudgement += addJudgement; protected virtual void ComputeTargets(Beatmap<TObject> beatmap) { }
}
/// <summary>
/// Adds a judgement to this ScoreProcessor.
/// </summary>
/// <param name="judgement">The judgement to add.</param>
private void addJudgement(TJudgement judgement) private void addJudgement(TJudgement judgement)
{ {
Judgements.Add(judgement); Judgements.Add(judgement);
@ -89,17 +146,14 @@ namespace osu.Game.Modes
UpdateCalculations(judgement); UpdateCalculations(judgement);
judgement.ComboAtHit = (ulong)Combo.Value; judgement.ComboAtHit = (ulong)Combo.Value;
if (Health.Value == Health.MinValue && !HasFailed)
{ UpdateFailed();
HasFailed = true;
TriggerFailed();
}
} }
/// <summary> protected override void Reset()
/// Resets this ScoreProcessor to a stale state. {
/// </summary> Judgements.Clear();
protected virtual void Reset() { } }
/// <summary> /// <summary>
/// Update any values that potentially need post-processing on a judgement change. /// Update any values that potentially need post-processing on a judgement change.
@ -107,4 +161,4 @@ namespace osu.Game.Modes
/// <param name="newJudgement">A new JudgementInfo that triggered this calculation. May be null.</param> /// <param name="newJudgement">A new JudgementInfo that triggered this calculation. May be null.</param>
protected abstract void UpdateCalculations(TJudgement newJudgement); protected abstract void UpdateCalculations(TJudgement newJudgement);
} }
} }

View File

@ -25,6 +25,9 @@ namespace osu.Game.Modes.UI
/// </summary> /// </summary>
public abstract class HitRenderer : Container public abstract class HitRenderer : Container
{ {
/// <summary>
/// Invoked when all the judgeable HitObjects have been judged.
/// </summary>
public event Action OnAllJudged; public event Action OnAllJudged;
/// <summary> /// <summary>
@ -200,9 +203,10 @@ namespace osu.Game.Modes.UI
/// <param name="judgedObject">The object that Judgement has been updated for.</param> /// <param name="judgedObject">The object that Judgement has been updated for.</param>
private void onJudgement(DrawableHitObject<TObject, TJudgement> judgedObject) private void onJudgement(DrawableHitObject<TObject, TJudgement> judgedObject)
{ {
OnJudgement?.Invoke(judgedObject.Judgement);
Playfield.OnJudgement(judgedObject); Playfield.OnJudgement(judgedObject);
OnJudgement?.Invoke(judgedObject.Judgement);
CheckAllJudged(); CheckAllJudged();
} }

View File

@ -135,7 +135,7 @@ namespace osu.Game.Screens.Play
hudOverlay.BindHitRenderer(hitRenderer); hudOverlay.BindHitRenderer(hitRenderer);
//bind HitRenderer to ScoreProcessor and ourselves (for a pass situation) //bind HitRenderer to ScoreProcessor and ourselves (for a pass situation)
hitRenderer.OnAllJudged += onPass; hitRenderer.OnAllJudged += onCompletion;
//bind ScoreProcessor to ourselves (for a fail situation) //bind ScoreProcessor to ourselves (for a fail situation)
scoreProcessor.Failed += onFail; scoreProcessor.Failed += onFail;
@ -237,15 +237,19 @@ namespace osu.Game.Screens.Play
}); });
} }
private void onPass() private void onCompletion()
{ {
// Only show the completion screen if the player hasn't failed
if (scoreProcessor.HasFailed)
return;
Delay(1000); Delay(1000);
Schedule(delegate Schedule(delegate
{ {
ValidForResume = false; ValidForResume = false;
Push(new Results Push(new Results
{ {
Score = scoreProcessor.GetScore() Score = scoreProcessor.CreateScore()
}); });
}); });
} }

View File

@ -141,10 +141,10 @@ namespace osu.Game.Screens.Select
} }
}; };
groupTabs.PinTab(GroupMode.All); groupTabs.PinItem(GroupMode.All);
groupTabs.PinTab(GroupMode.RecentlyPlayed); groupTabs.PinItem(GroupMode.RecentlyPlayed);
groupTabs.ValueChanged += (sender, value) => Group = value; groupTabs.ItemChanged += (sender, value) => Group = value;
sortTabs.ValueChanged += (sender, value) => Sort = value; sortTabs.ItemChanged += (sender, value) => Sort = value;
} }
public void Deactivate() public void Deactivate()