mirror of
https://github.com/ppy/osu
synced 2024-12-29 02:12:43 +00:00
Hook up ScoreProcessor to Scoreoverlay etc.
This commit is contained in:
parent
9b243ccc23
commit
2947121e48
@ -3,10 +3,60 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Game.Modes.Objects.Drawables;
|
||||
using osu.Game.Modes.Osu.Objects.Drawables;
|
||||
|
||||
namespace osu.Game.Modes.Osu
|
||||
{
|
||||
class OsuScoreProcessor : ScoreProcessor
|
||||
{
|
||||
public override void AddJudgement(JudgementInfo judgement)
|
||||
{
|
||||
base.AddJudgement(judgement);
|
||||
|
||||
switch (judgement.Result)
|
||||
{
|
||||
case HitResult.Hit:
|
||||
Combo.Value++;
|
||||
break;
|
||||
case HitResult.Miss:
|
||||
Combo.Value = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
protected override void UpdateCalculations()
|
||||
{
|
||||
base.UpdateCalculations();
|
||||
|
||||
int score = 0;
|
||||
int maxScore = 0;
|
||||
|
||||
foreach (OsuJudgementInfo j in Judgements)
|
||||
{
|
||||
switch (j.Score)
|
||||
{
|
||||
case OsuScoreResult.Miss:
|
||||
maxScore += 300;
|
||||
break;
|
||||
case OsuScoreResult.Hit50:
|
||||
score += 50;
|
||||
maxScore += 300;
|
||||
break;
|
||||
case OsuScoreResult.Hit100:
|
||||
score += 100;
|
||||
maxScore += 300;
|
||||
break;
|
||||
case OsuScoreResult.Hit300:
|
||||
score += 300;
|
||||
maxScore += 300;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
TotalScore.Value = score;
|
||||
Accuracy.Value = (double)score / maxScore;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,9 +13,7 @@ namespace osu.Game.Modes.Objects.Drawables
|
||||
{
|
||||
public abstract class DrawableHitObject : Container, IStateful<ArmedState>
|
||||
{
|
||||
//todo: move to a more central implementation. this logic should not be at a drawable level.
|
||||
public Action<DrawableHitObject, JudgementInfo> OnHit;
|
||||
public Action<DrawableHitObject, JudgementInfo> OnMiss;
|
||||
public event Action<DrawableHitObject, JudgementInfo> OnJudgement;
|
||||
|
||||
public Container<DrawableHitObject> ChildObjects;
|
||||
|
||||
@ -73,14 +71,14 @@ namespace osu.Game.Modes.Objects.Drawables
|
||||
{
|
||||
default:
|
||||
State = ArmedState.Hit;
|
||||
OnHit?.Invoke(this, Judgement);
|
||||
break;
|
||||
case HitResult.Miss:
|
||||
State = ArmedState.Miss;
|
||||
OnMiss?.Invoke(this, Judgement);
|
||||
break;
|
||||
}
|
||||
|
||||
OnJudgement?.Invoke(this, Judgement);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -6,11 +6,35 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Game.Modes.Objects.Drawables;
|
||||
|
||||
namespace osu.Game.Modes
|
||||
{
|
||||
public class ScoreProcessor
|
||||
{
|
||||
public virtual Score GetScore() => new Score();
|
||||
|
||||
public BindableDouble TotalScore = new BindableDouble { MinValue = 0 };
|
||||
|
||||
public BindableDouble Accuracy = new BindableDouble { MinValue = 0, MaxValue = 1 };
|
||||
|
||||
public BindableInt Combo = new BindableInt();
|
||||
|
||||
public List<JudgementInfo> Judgements = new List<JudgementInfo>();
|
||||
|
||||
public virtual void AddJudgement(JudgementInfo judgement)
|
||||
{
|
||||
Judgements.Add(judgement);
|
||||
UpdateCalculations();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update any values that potentially need post-processing on a judgement change.
|
||||
/// </summary>
|
||||
protected virtual void UpdateCalculations()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -262,5 +262,13 @@ namespace osu.Game.Modes.UI
|
||||
(d as ComboCounter).DisplayedCount = CurrentValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void Set(ulong value)
|
||||
{
|
||||
if (value == 0)
|
||||
Roll();
|
||||
else
|
||||
Count = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,9 @@ namespace osu.Game.Modes.UI
|
||||
{
|
||||
public abstract class HitRenderer : Container
|
||||
{
|
||||
public Action<HitObject> OnHit;
|
||||
public Action<HitObject> OnMiss;
|
||||
public event Action<JudgementInfo> OnJudgement;
|
||||
|
||||
protected void TriggerOnJudgement(JudgementInfo j) => OnJudgement?.Invoke(j);
|
||||
|
||||
protected Playfield Playfield;
|
||||
|
||||
@ -68,22 +69,13 @@ namespace osu.Game.Modes.UI
|
||||
|
||||
if (drawableObject == null) continue;
|
||||
|
||||
drawableObject.OnHit = onHit;
|
||||
drawableObject.OnMiss = onMiss;
|
||||
drawableObject.OnJudgement += onJudgement;
|
||||
|
||||
Playfield.Add(drawableObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void onMiss(DrawableHitObject obj, JudgementInfo judgement)
|
||||
{
|
||||
OnMiss?.Invoke(obj.HitObject);
|
||||
}
|
||||
|
||||
private void onHit(DrawableHitObject obj, JudgementInfo judgement)
|
||||
{
|
||||
OnHit?.Invoke(obj.HitObject);
|
||||
}
|
||||
private void onJudgement(DrawableHitObject o, JudgementInfo j) => TriggerOnJudgement(j);
|
||||
|
||||
protected abstract DrawableHitObject GetVisualRepresentation(T h);
|
||||
}
|
||||
|
@ -49,7 +49,10 @@ namespace osu.Game.Modes.UI
|
||||
|
||||
public void BindProcessor(ScoreProcessor processor)
|
||||
{
|
||||
|
||||
//bind processor bindables to combocounter, score display etc.
|
||||
processor.TotalScore.ValueChanged += delegate { ScoreCounter?.Set((ulong)processor.TotalScore.Value); };
|
||||
processor.Accuracy.ValueChanged += delegate { AccuracyCounter?.Set((float)processor.Accuracy.Value); };
|
||||
processor.Combo.ValueChanged += delegate { ComboCounter?.Set((ulong)processor.Combo.Value); };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,8 +91,7 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
var hitRenderer = ruleset.CreateHitRendererWith(beatmap.HitObjects);
|
||||
|
||||
hitRenderer.OnHit += delegate (HitObject h) { scoreOverlay.OnHit(h); };
|
||||
hitRenderer.OnMiss += delegate (HitObject h) { scoreOverlay.OnMiss(h); };
|
||||
hitRenderer.OnJudgement += scoreProcessor.AddJudgement;
|
||||
|
||||
if (Autoplay)
|
||||
hitRenderer.Schedule(() => hitRenderer.DrawableObjects.ForEach(h => h.State = ArmedState.Hit));
|
||||
|
Loading…
Reference in New Issue
Block a user