From 36e861837031f2b4636cb252d7d5b1c401d99859 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Wed, 15 Mar 2017 18:55:38 +0900 Subject: [PATCH] Make DrawableHitObjects have generic JudgementInfos. --- .../Tests/TestCaseHitObjects.cs | 2 +- .../Judgements/CatchJudgementInfo.cs | 13 +++++ osu.Game.Modes.Catch/UI/CatchHitRenderer.cs | 7 +-- osu.Game.Modes.Catch/UI/CatchPlayfield.cs | 3 +- .../osu.Game.Modes.Catch.csproj | 1 + .../Judgements/ManiaJudgementInfo.cs | 13 +++++ osu.Game.Modes.Mania/UI/ManiaHitRenderer.cs | 7 +-- osu.Game.Modes.Mania/UI/ManiaPlayfield.cs | 3 +- .../osu.Game.Modes.Mania.csproj | 1 + .../Objects/Drawables/DrawableOsuHitObject.cs | 4 +- .../Objects/Drawables/DrawableSliderTick.cs | 2 +- osu.Game.Modes.Osu/UI/OsuHitRenderer.cs | 6 +-- osu.Game.Modes.Osu/UI/OsuPlayfield.cs | 14 +++-- .../Judgements/TaikoJudgementInfo.cs | 13 +++++ osu.Game.Modes.Taiko/UI/TaikoHitRenderer.cs | 7 +-- osu.Game.Modes.Taiko/UI/TaikoPlayfield.cs | 3 +- .../osu.Game.Modes.Taiko.csproj | 1 + .../Objects/Drawables/DrawableHitObject.cs | 28 ++++++---- osu.Game/Modes/UI/HitRenderer.cs | 52 ++++++++++++------- osu.Game/Modes/UI/Playfield.cs | 14 +++-- 20 files changed, 132 insertions(+), 62 deletions(-) create mode 100644 osu.Game.Modes.Catch/Judgements/CatchJudgementInfo.cs create mode 100644 osu.Game.Modes.Mania/Judgements/ManiaJudgementInfo.cs create mode 100644 osu.Game.Modes.Taiko/Judgements/TaikoJudgementInfo.cs diff --git a/osu.Desktop.VisualTests/Tests/TestCaseHitObjects.cs b/osu.Desktop.VisualTests/Tests/TestCaseHitObjects.cs index 436f048e10..01c10489d7 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseHitObjects.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseHitObjects.cs @@ -123,7 +123,7 @@ namespace osu.Desktop.VisualTests.Tests private int depth; - private void add(DrawableHitObject h) + private void add(DrawableHitObject h) { h.Anchor = Anchor.Centre; h.Depth = depth++; diff --git a/osu.Game.Modes.Catch/Judgements/CatchJudgementInfo.cs b/osu.Game.Modes.Catch/Judgements/CatchJudgementInfo.cs new file mode 100644 index 0000000000..e560091d2d --- /dev/null +++ b/osu.Game.Modes.Catch/Judgements/CatchJudgementInfo.cs @@ -0,0 +1,13 @@ +using osu.Game.Modes.Judgements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Game.Modes.Catch.Judgements +{ + public class CatchJudgementInfo : JudgementInfo + { + } +} diff --git a/osu.Game.Modes.Catch/UI/CatchHitRenderer.cs b/osu.Game.Modes.Catch/UI/CatchHitRenderer.cs index a8b2d48760..b537ec6e8a 100644 --- a/osu.Game.Modes.Catch/UI/CatchHitRenderer.cs +++ b/osu.Game.Modes.Catch/UI/CatchHitRenderer.cs @@ -3,13 +3,14 @@ using osu.Game.Beatmaps; using osu.Game.Modes.Catch.Beatmaps; +using osu.Game.Modes.Catch.Judgements; using osu.Game.Modes.Catch.Objects; using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.UI; namespace osu.Game.Modes.Catch.UI { - public class CatchHitRenderer : HitRenderer + public class CatchHitRenderer : HitRenderer { public CatchHitRenderer(WorkingBeatmap beatmap) : base(beatmap) @@ -18,8 +19,8 @@ namespace osu.Game.Modes.Catch.UI protected override IBeatmapConverter CreateBeatmapConverter() => new CatchBeatmapConverter(); - protected override Playfield CreatePlayfield() => new CatchPlayfield(); + protected override Playfield CreatePlayfield() => new CatchPlayfield(); - protected override DrawableHitObject GetVisualRepresentation(CatchBaseHit h) => null;// new DrawableFruit(h); + protected override DrawableHitObject GetVisualRepresentation(CatchBaseHit h) => null;// new DrawableFruit(h); } } diff --git a/osu.Game.Modes.Catch/UI/CatchPlayfield.cs b/osu.Game.Modes.Catch/UI/CatchPlayfield.cs index c9c3df8197..eba8734eaf 100644 --- a/osu.Game.Modes.Catch/UI/CatchPlayfield.cs +++ b/osu.Game.Modes.Catch/UI/CatchPlayfield.cs @@ -6,10 +6,11 @@ using osu.Framework.Graphics.Sprites; using osu.Game.Modes.Catch.Objects; using osu.Game.Modes.UI; using OpenTK; +using osu.Game.Modes.Catch.Judgements; namespace osu.Game.Modes.Catch.UI { - public class CatchPlayfield : Playfield + public class CatchPlayfield : Playfield { public CatchPlayfield() { diff --git a/osu.Game.Modes.Catch/osu.Game.Modes.Catch.csproj b/osu.Game.Modes.Catch/osu.Game.Modes.Catch.csproj index 4908bcd0d0..d7c3a9f828 100644 --- a/osu.Game.Modes.Catch/osu.Game.Modes.Catch.csproj +++ b/osu.Game.Modes.Catch/osu.Game.Modes.Catch.csproj @@ -49,6 +49,7 @@ + diff --git a/osu.Game.Modes.Mania/Judgements/ManiaJudgementInfo.cs b/osu.Game.Modes.Mania/Judgements/ManiaJudgementInfo.cs new file mode 100644 index 0000000000..1b587e4ae1 --- /dev/null +++ b/osu.Game.Modes.Mania/Judgements/ManiaJudgementInfo.cs @@ -0,0 +1,13 @@ +using osu.Game.Modes.Judgements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Game.Modes.Mania.Judgements +{ + public class ManiaJudgementInfo : JudgementInfo + { + } +} diff --git a/osu.Game.Modes.Mania/UI/ManiaHitRenderer.cs b/osu.Game.Modes.Mania/UI/ManiaHitRenderer.cs index d29a088225..52b35d5032 100644 --- a/osu.Game.Modes.Mania/UI/ManiaHitRenderer.cs +++ b/osu.Game.Modes.Mania/UI/ManiaHitRenderer.cs @@ -3,13 +3,14 @@ using osu.Game.Beatmaps; using osu.Game.Modes.Mania.Beatmaps; +using osu.Game.Modes.Mania.Judgements; using osu.Game.Modes.Mania.Objects; using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.UI; namespace osu.Game.Modes.Mania.UI { - public class ManiaHitRenderer : HitRenderer + public class ManiaHitRenderer : HitRenderer { private readonly int columns; @@ -21,9 +22,9 @@ namespace osu.Game.Modes.Mania.UI protected override IBeatmapConverter CreateBeatmapConverter() => new ManiaBeatmapConverter(); - protected override Playfield CreatePlayfield() => new ManiaPlayfield(columns); + protected override Playfield CreatePlayfield() => new ManiaPlayfield(columns); - protected override DrawableHitObject GetVisualRepresentation(ManiaBaseHit h) + protected override DrawableHitObject GetVisualRepresentation(ManiaBaseHit h) { return null; //return new DrawableNote(h) diff --git a/osu.Game.Modes.Mania/UI/ManiaPlayfield.cs b/osu.Game.Modes.Mania/UI/ManiaPlayfield.cs index ab3c231917..3984fce626 100644 --- a/osu.Game.Modes.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Modes.Mania/UI/ManiaPlayfield.cs @@ -7,10 +7,11 @@ using osu.Game.Modes.Mania.Objects; using osu.Game.Modes.UI; using OpenTK; using OpenTK.Graphics; +using osu.Game.Modes.Mania.Judgements; namespace osu.Game.Modes.Mania.UI { - public class ManiaPlayfield : Playfield + public class ManiaPlayfield : Playfield { public ManiaPlayfield(int columns) { diff --git a/osu.Game.Modes.Mania/osu.Game.Modes.Mania.csproj b/osu.Game.Modes.Mania/osu.Game.Modes.Mania.csproj index 48f8d23a07..d1b9e2971f 100644 --- a/osu.Game.Modes.Mania/osu.Game.Modes.Mania.csproj +++ b/osu.Game.Modes.Mania/osu.Game.Modes.Mania.csproj @@ -48,6 +48,7 @@ + diff --git a/osu.Game.Modes.Osu/Objects/Drawables/DrawableOsuHitObject.cs b/osu.Game.Modes.Osu/Objects/Drawables/DrawableOsuHitObject.cs index be237a22f4..60f2c130c9 100644 --- a/osu.Game.Modes.Osu/Objects/Drawables/DrawableOsuHitObject.cs +++ b/osu.Game.Modes.Osu/Objects/Drawables/DrawableOsuHitObject.cs @@ -7,7 +7,7 @@ using osu.Game.Modes.Objects.Drawables; namespace osu.Game.Modes.Osu.Objects.Drawables { - public class DrawableOsuHitObject : DrawableHitObject + public class DrawableOsuHitObject : DrawableHitObject { public const float TIME_PREEMPT = 600; public const float TIME_FADEIN = 400; @@ -18,7 +18,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables { } - protected override JudgementInfo CreateJudgementInfo() => new OsuJudgementInfo { MaxScore = OsuScoreResult.Hit300 }; + protected override OsuJudgementInfo CreateJudgementInfo() => new OsuJudgementInfo { MaxScore = OsuScoreResult.Hit300 }; protected override void UpdateState(ArmedState state) { diff --git a/osu.Game.Modes.Osu/Objects/Drawables/DrawableSliderTick.cs b/osu.Game.Modes.Osu/Objects/Drawables/DrawableSliderTick.cs index acda9da62f..7d74463107 100644 --- a/osu.Game.Modes.Osu/Objects/Drawables/DrawableSliderTick.cs +++ b/osu.Game.Modes.Osu/Objects/Drawables/DrawableSliderTick.cs @@ -27,7 +27,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables public override bool RemoveWhenNotAlive => false; - protected override JudgementInfo CreateJudgementInfo() => new OsuJudgementInfo { MaxScore = OsuScoreResult.SliderTick }; + protected override OsuJudgementInfo CreateJudgementInfo() => new OsuJudgementInfo { MaxScore = OsuScoreResult.SliderTick }; public DrawableSliderTick(SliderTick sliderTick) : base(sliderTick) { diff --git a/osu.Game.Modes.Osu/UI/OsuHitRenderer.cs b/osu.Game.Modes.Osu/UI/OsuHitRenderer.cs index 51433df4af..c5d729e76f 100644 --- a/osu.Game.Modes.Osu/UI/OsuHitRenderer.cs +++ b/osu.Game.Modes.Osu/UI/OsuHitRenderer.cs @@ -11,7 +11,7 @@ using osu.Game.Screens.Play; namespace osu.Game.Modes.Osu.UI { - public class OsuHitRenderer : HitRenderer + public class OsuHitRenderer : HitRenderer { public OsuHitRenderer(WorkingBeatmap beatmap) : base(beatmap) @@ -20,11 +20,11 @@ namespace osu.Game.Modes.Osu.UI protected override IBeatmapConverter CreateBeatmapConverter() => new OsuBeatmapConverter(); - protected override Playfield CreatePlayfield() => new OsuPlayfield(); + protected override Playfield CreatePlayfield() => new OsuPlayfield(); protected override KeyConversionInputManager CreateKeyConversionInputManager() => new OsuKeyConversionInputManager(); - protected override DrawableHitObject GetVisualRepresentation(OsuHitObject h) + protected override DrawableHitObject GetVisualRepresentation(OsuHitObject h) { var circle = h as HitCircle; if (circle != null) diff --git a/osu.Game.Modes.Osu/UI/OsuPlayfield.cs b/osu.Game.Modes.Osu/UI/OsuPlayfield.cs index ab19a92212..4b890b61b3 100644 --- a/osu.Game.Modes.Osu/UI/OsuPlayfield.cs +++ b/osu.Game.Modes.Osu/UI/OsuPlayfield.cs @@ -13,10 +13,11 @@ using System.Linq; using osu.Game.Graphics.Cursor; using osu.Game.Modes.Judgements; using OpenTK.Graphics; +using System; namespace osu.Game.Modes.Osu.UI { - public class OsuPlayfield : Playfield + public class OsuPlayfield : Playfield { private Container approachCircles; private Container judgementLayer; @@ -66,16 +67,13 @@ namespace osu.Game.Modes.Osu.UI AddInternal(new OsuCursorContainer { Colour = Color4.LightYellow }); } - public override void Add(DrawableHitObject h) + public override void Add(DrawableHitObject h) { h.Depth = (float)h.HitObject.StartTime; + IDrawableHitObjectWithProxiedApproach c = h as IDrawableHitObjectWithProxiedApproach; if (c != null) - { approachCircles.Add(c.ProxiedLayer.CreateProxy()); - } - - h.OnJudgement += judgement; base.Add(h); } @@ -87,9 +85,9 @@ namespace osu.Game.Modes.Osu.UI .OrderBy(h => h.StartTime); } - private void judgement(DrawableHitObject h, JudgementInfo j) + public override void OnJudgement(DrawableHitObject judgedObject) { - HitExplosion explosion = new HitExplosion((OsuJudgementInfo)j, h.HitObject); + HitExplosion explosion = new HitExplosion(judgedObject.Judgement, judgedObject.HitObject); judgementLayer.Add(explosion); } diff --git a/osu.Game.Modes.Taiko/Judgements/TaikoJudgementInfo.cs b/osu.Game.Modes.Taiko/Judgements/TaikoJudgementInfo.cs new file mode 100644 index 0000000000..509b85ad91 --- /dev/null +++ b/osu.Game.Modes.Taiko/Judgements/TaikoJudgementInfo.cs @@ -0,0 +1,13 @@ +using osu.Game.Modes.Judgements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Game.Modes.Taiko.Judgements +{ + public class TaikoJudgementInfo : JudgementInfo + { + } +} diff --git a/osu.Game.Modes.Taiko/UI/TaikoHitRenderer.cs b/osu.Game.Modes.Taiko/UI/TaikoHitRenderer.cs index fb5e38d4dc..fe1e5b5804 100644 --- a/osu.Game.Modes.Taiko/UI/TaikoHitRenderer.cs +++ b/osu.Game.Modes.Taiko/UI/TaikoHitRenderer.cs @@ -4,12 +4,13 @@ using osu.Game.Beatmaps; using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.Taiko.Beatmaps; +using osu.Game.Modes.Taiko.Judgements; using osu.Game.Modes.Taiko.Objects; using osu.Game.Modes.UI; namespace osu.Game.Modes.Taiko.UI { - public class TaikoHitRenderer : HitRenderer + public class TaikoHitRenderer : HitRenderer { public TaikoHitRenderer(WorkingBeatmap beatmap) : base(beatmap) @@ -18,8 +19,8 @@ namespace osu.Game.Modes.Taiko.UI protected override IBeatmapConverter CreateBeatmapConverter() => new TaikoBeatmapConverter(); - protected override Playfield CreatePlayfield() => new TaikoPlayfield(); + protected override Playfield CreatePlayfield() => new TaikoPlayfield(); - protected override DrawableHitObject GetVisualRepresentation(TaikoBaseHit h) => null;// new DrawableTaikoHit(h); + protected override DrawableHitObject GetVisualRepresentation(TaikoBaseHit h) => null;// new DrawableTaikoHit(h); } } diff --git a/osu.Game.Modes.Taiko/UI/TaikoPlayfield.cs b/osu.Game.Modes.Taiko/UI/TaikoPlayfield.cs index 2fcfce4fa3..d80aa94fa1 100644 --- a/osu.Game.Modes.Taiko/UI/TaikoPlayfield.cs +++ b/osu.Game.Modes.Taiko/UI/TaikoPlayfield.cs @@ -9,10 +9,11 @@ using osu.Game.Modes.Taiko.Objects; using osu.Game.Modes.UI; using OpenTK; using OpenTK.Graphics; +using osu.Game.Modes.Taiko.Judgements; namespace osu.Game.Modes.Taiko.UI { - public class TaikoPlayfield : Playfield + public class TaikoPlayfield : Playfield { public TaikoPlayfield() { diff --git a/osu.Game.Modes.Taiko/osu.Game.Modes.Taiko.csproj b/osu.Game.Modes.Taiko/osu.Game.Modes.Taiko.csproj index 7d6bcf4853..0a72c663e3 100644 --- a/osu.Game.Modes.Taiko/osu.Game.Modes.Taiko.csproj +++ b/osu.Game.Modes.Taiko/osu.Game.Modes.Taiko.csproj @@ -48,6 +48,7 @@ + diff --git a/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs index a7f3a1534b..2963c84493 100644 --- a/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs @@ -14,11 +14,16 @@ using Container = osu.Framework.Graphics.Containers.Container; namespace osu.Game.Modes.Objects.Drawables { - public abstract class DrawableHitObject : Container, IStateful + public abstract class DrawableHitObject : Container, IStateful + where TJudgement : JudgementInfo { - public JudgementInfo Judgement; + public override bool HandleInput => Interactive; - protected abstract JudgementInfo CreateJudgementInfo(); + public bool Interactive = true; + + public TJudgement Judgement; + + protected abstract TJudgement CreateJudgementInfo(); protected abstract void UpdateState(ArmedState state); @@ -63,10 +68,11 @@ namespace osu.Game.Modes.Objects.Drawables } } - public abstract class DrawableHitObject : DrawableHitObject + public abstract class DrawableHitObject : DrawableHitObject where TObject : HitObject + where TJudgement : JudgementInfo { - public event Action, JudgementInfo> OnJudgement; + public event Action> OnJudgement; public TObject HitObject; @@ -101,7 +107,7 @@ namespace osu.Game.Modes.Objects.Drawables break; } - OnJudgement?.Invoke(this, Judgement); + OnJudgement?.Invoke(this); return true; } @@ -134,16 +140,16 @@ namespace osu.Game.Modes.Objects.Drawables Sample = audio.Sample.Get($@"Gameplay/{sampleSet.ToString().ToLower()}-hit{type.ToString().ToLower()}"); } - private List> nestedHitObjects; + private List> nestedHitObjects; - protected IEnumerable> NestedHitObjects => nestedHitObjects; + protected IEnumerable> NestedHitObjects => nestedHitObjects; - protected void AddNested(DrawableHitObject h) + protected void AddNested(DrawableHitObject h) { if (nestedHitObjects == null) - nestedHitObjects = new List>(); + nestedHitObjects = new List>(); - h.OnJudgement += (d, j) => { OnJudgement?.Invoke(d, j); } ; + h.OnJudgement += d => OnJudgement?.Invoke(d); nestedHitObjects.Add(h); } } diff --git a/osu.Game/Modes/UI/HitRenderer.cs b/osu.Game/Modes/UI/HitRenderer.cs index 6b2bd55a7d..6d576b63f3 100644 --- a/osu.Game/Modes/UI/HitRenderer.cs +++ b/osu.Game/Modes/UI/HitRenderer.cs @@ -52,13 +52,6 @@ namespace osu.Game.Modes.UI { public Beatmap Beatmap; - protected override Container Content => content; - protected override bool AllObjectsJudged => Playfield.HitObjects.Children.All(h => h.Judgement.Result.HasValue); - - protected Playfield Playfield; - - private Container content; - protected HitRenderer(WorkingBeatmap beatmap) { Beatmap = CreateBeatmapConverter().Convert(beatmap.Beatmap); @@ -66,7 +59,34 @@ namespace osu.Game.Modes.UI applyMods(beatmap.Mods.Value); RelativeSizeAxes = Axes.Both; + } + private void applyMods(IEnumerable mods) + { + if (mods == null) + return; + + foreach (var mod in mods.OfType>()) + mod.Apply(this); + } + + protected abstract IBeatmapConverter CreateBeatmapConverter(); + } + + public abstract class HitRenderer : HitRenderer + where TObject : HitObject + where TJudgement : JudgementInfo + { + protected override Container Content => content; + protected override bool AllObjectsJudged => Playfield.HitObjects.Children.All(h => h.Judgement.Result.HasValue); + + protected Playfield Playfield; + + private Container content; + + protected HitRenderer(WorkingBeatmap beatmap) + : base(beatmap) + { KeyConversionInputManager.Add(Playfield = CreatePlayfield()); InputManager.Add(content = new Container @@ -91,7 +111,7 @@ namespace osu.Game.Modes.UI { foreach (TObject h in Beatmap.HitObjects) { - DrawableHitObject drawableObject = GetVisualRepresentation(h); + var drawableObject = GetVisualRepresentation(h); if (drawableObject == null) continue; @@ -104,19 +124,13 @@ namespace osu.Game.Modes.UI Playfield.PostProcess(); } - private void applyMods(IEnumerable mods) + private void onJudgement(DrawableHitObject j) { - if (mods == null) - return; - - foreach (var mod in mods.OfType>()) - mod.Apply(this); + TriggerOnJudgement(j.Judgement); + Playfield.OnJudgement(j); } - private void onJudgement(DrawableHitObject o, JudgementInfo j) => TriggerOnJudgement(j); - - protected abstract DrawableHitObject GetVisualRepresentation(TObject h); - protected abstract Playfield CreatePlayfield(); - protected abstract IBeatmapConverter CreateBeatmapConverter(); + protected abstract DrawableHitObject GetVisualRepresentation(TObject h); + protected abstract Playfield CreatePlayfield(); } } diff --git a/osu.Game/Modes/UI/Playfield.cs b/osu.Game/Modes/UI/Playfield.cs index 0cc7b0468e..ba12fa4abf 100644 --- a/osu.Game/Modes/UI/Playfield.cs +++ b/osu.Game/Modes/UI/Playfield.cs @@ -6,15 +6,17 @@ using osu.Framework.Graphics.Containers; using osu.Game.Modes.Objects; using osu.Game.Modes.Objects.Drawables; using OpenTK; +using osu.Game.Modes.Judgements; namespace osu.Game.Modes.UI { - public abstract class Playfield : Container - where T : HitObject + public abstract class Playfield : Container + where TObject : HitObject + where TJudgement : JudgementInfo { - public HitObjectContainer> HitObjects; + public HitObjectContainer> HitObjects; - public virtual void Add(DrawableHitObject h) => HitObjects.Add(h); + public virtual void Add(DrawableHitObject h) => HitObjects.Add(h); internal Container ScaledContent; @@ -43,7 +45,7 @@ namespace osu.Game.Modes.UI } }); - Add(HitObjects = new HitObjectContainer> + Add(HitObjects = new HitObjectContainer> { RelativeSizeAxes = Axes.Both, }); @@ -70,5 +72,7 @@ namespace osu.Game.Modes.UI { public override bool Contains(Vector2 screenSpacePos) => true; } + + public virtual void OnJudgement(DrawableHitObject judgedObject) { } } }