1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 15:22:55 +08:00

Make DrawableHitObjects have generic JudgementInfos.

This commit is contained in:
smoogipooo 2017-03-15 18:55:38 +09:00
parent 1c87d998a6
commit 36e8618370
20 changed files with 132 additions and 62 deletions

View File

@ -123,7 +123,7 @@ namespace osu.Desktop.VisualTests.Tests
private int depth;
private void add(DrawableHitObject h)
private void add(DrawableHitObject<OsuJudgementInfo> h)
{
h.Anchor = Anchor.Centre;
h.Depth = depth++;

View File

@ -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
{
}
}

View File

@ -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<CatchBaseHit>
public class CatchHitRenderer : HitRenderer<CatchBaseHit, CatchJudgementInfo>
{
public CatchHitRenderer(WorkingBeatmap beatmap)
: base(beatmap)
@ -18,8 +19,8 @@ namespace osu.Game.Modes.Catch.UI
protected override IBeatmapConverter<CatchBaseHit> CreateBeatmapConverter() => new CatchBeatmapConverter();
protected override Playfield<CatchBaseHit> CreatePlayfield() => new CatchPlayfield();
protected override Playfield<CatchBaseHit, CatchJudgementInfo> CreatePlayfield() => new CatchPlayfield();
protected override DrawableHitObject<CatchBaseHit> GetVisualRepresentation(CatchBaseHit h) => null;// new DrawableFruit(h);
protected override DrawableHitObject<CatchBaseHit, CatchJudgementInfo> GetVisualRepresentation(CatchBaseHit h) => null;// new DrawableFruit(h);
}
}

View File

@ -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<CatchBaseHit>
public class CatchPlayfield : Playfield<CatchBaseHit, CatchJudgementInfo>
{
public CatchPlayfield()
{

View File

@ -49,6 +49,7 @@
<ItemGroup>
<Compile Include="Beatmaps\CatchBeatmapConverter.cs" />
<Compile Include="CatchDifficultyCalculator.cs" />
<Compile Include="Judgements\CatchJudgementInfo.cs" />
<Compile Include="Objects\CatchBaseHit.cs" />
<Compile Include="Objects\Drawable\DrawableFruit.cs" />
<Compile Include="Objects\Droplet.cs" />

View File

@ -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
{
}
}

View File

@ -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<ManiaBaseHit>
public class ManiaHitRenderer : HitRenderer<ManiaBaseHit, ManiaJudgementInfo>
{
private readonly int columns;
@ -21,9 +22,9 @@ namespace osu.Game.Modes.Mania.UI
protected override IBeatmapConverter<ManiaBaseHit> CreateBeatmapConverter() => new ManiaBeatmapConverter();
protected override Playfield<ManiaBaseHit> CreatePlayfield() => new ManiaPlayfield(columns);
protected override Playfield<ManiaBaseHit, ManiaJudgementInfo> CreatePlayfield() => new ManiaPlayfield(columns);
protected override DrawableHitObject<ManiaBaseHit> GetVisualRepresentation(ManiaBaseHit h)
protected override DrawableHitObject<ManiaBaseHit, ManiaJudgementInfo> GetVisualRepresentation(ManiaBaseHit h)
{
return null;
//return new DrawableNote(h)

View File

@ -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<ManiaBaseHit>
public class ManiaPlayfield : Playfield<ManiaBaseHit, ManiaJudgementInfo>
{
public ManiaPlayfield(int columns)
{

View File

@ -48,6 +48,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Beatmaps\ManiaBeatmapConverter.cs" />
<Compile Include="Judgements\ManiaJudgementInfo.cs" />
<Compile Include="ManiaDifficultyCalculator.cs" />
<Compile Include="Objects\Drawable\DrawableNote.cs" />
<Compile Include="Objects\HoldNote.cs" />

View File

@ -7,7 +7,7 @@ using osu.Game.Modes.Objects.Drawables;
namespace osu.Game.Modes.Osu.Objects.Drawables
{
public class DrawableOsuHitObject : DrawableHitObject<OsuHitObject>
public class DrawableOsuHitObject : DrawableHitObject<OsuHitObject, OsuJudgementInfo>
{
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)
{

View File

@ -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)
{

View File

@ -11,7 +11,7 @@ using osu.Game.Screens.Play;
namespace osu.Game.Modes.Osu.UI
{
public class OsuHitRenderer : HitRenderer<OsuHitObject>
public class OsuHitRenderer : HitRenderer<OsuHitObject, OsuJudgementInfo>
{
public OsuHitRenderer(WorkingBeatmap beatmap)
: base(beatmap)
@ -20,11 +20,11 @@ namespace osu.Game.Modes.Osu.UI
protected override IBeatmapConverter<OsuHitObject> CreateBeatmapConverter() => new OsuBeatmapConverter();
protected override Playfield<OsuHitObject> CreatePlayfield() => new OsuPlayfield();
protected override Playfield<OsuHitObject, OsuJudgementInfo> CreatePlayfield() => new OsuPlayfield();
protected override KeyConversionInputManager CreateKeyConversionInputManager() => new OsuKeyConversionInputManager();
protected override DrawableHitObject<OsuHitObject> GetVisualRepresentation(OsuHitObject h)
protected override DrawableHitObject<OsuHitObject, OsuJudgementInfo> GetVisualRepresentation(OsuHitObject h)
{
var circle = h as HitCircle;
if (circle != null)

View File

@ -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<OsuHitObject>
public class OsuPlayfield : Playfield<OsuHitObject, OsuJudgementInfo>
{
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<OsuHitObject> h)
public override void Add(DrawableHitObject<OsuHitObject, OsuJudgementInfo> 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<OsuHitObject> h, JudgementInfo j)
public override void OnJudgement(DrawableHitObject<OsuHitObject, OsuJudgementInfo> judgedObject)
{
HitExplosion explosion = new HitExplosion((OsuJudgementInfo)j, h.HitObject);
HitExplosion explosion = new HitExplosion(judgedObject.Judgement, judgedObject.HitObject);
judgementLayer.Add(explosion);
}

View File

@ -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
{
}
}

View File

@ -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<TaikoBaseHit>
public class TaikoHitRenderer : HitRenderer<TaikoBaseHit, TaikoJudgementInfo>
{
public TaikoHitRenderer(WorkingBeatmap beatmap)
: base(beatmap)
@ -18,8 +19,8 @@ namespace osu.Game.Modes.Taiko.UI
protected override IBeatmapConverter<TaikoBaseHit> CreateBeatmapConverter() => new TaikoBeatmapConverter();
protected override Playfield<TaikoBaseHit> CreatePlayfield() => new TaikoPlayfield();
protected override Playfield<TaikoBaseHit, TaikoJudgementInfo> CreatePlayfield() => new TaikoPlayfield();
protected override DrawableHitObject<TaikoBaseHit> GetVisualRepresentation(TaikoBaseHit h) => null;// new DrawableTaikoHit(h);
protected override DrawableHitObject<TaikoBaseHit, TaikoJudgementInfo> GetVisualRepresentation(TaikoBaseHit h) => null;// new DrawableTaikoHit(h);
}
}

View File

@ -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<TaikoBaseHit>
public class TaikoPlayfield : Playfield<TaikoBaseHit, TaikoJudgementInfo>
{
public TaikoPlayfield()
{

View File

@ -48,6 +48,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Beatmaps\TaikoBeatmapConverter.cs" />
<Compile Include="Judgements\TaikoJudgementInfo.cs" />
<Compile Include="TaikoDifficultyCalculator.cs" />
<Compile Include="Objects\Drawable\DrawableTaikoHit.cs" />
<Compile Include="Objects\TaikoBaseHit.cs" />

View File

@ -14,11 +14,16 @@ using Container = osu.Framework.Graphics.Containers.Container;
namespace osu.Game.Modes.Objects.Drawables
{
public abstract class DrawableHitObject : Container, IStateful<ArmedState>
public abstract class DrawableHitObject<TJudgement> : Container, IStateful<ArmedState>
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<TObject> : DrawableHitObject
public abstract class DrawableHitObject<TObject, TJudgement> : DrawableHitObject<TJudgement>
where TObject : HitObject
where TJudgement : JudgementInfo
{
public event Action<DrawableHitObject<TObject>, JudgementInfo> OnJudgement;
public event Action<DrawableHitObject<TObject, TJudgement>> 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<DrawableHitObject<TObject>> nestedHitObjects;
private List<DrawableHitObject<TObject, TJudgement>> nestedHitObjects;
protected IEnumerable<DrawableHitObject<TObject>> NestedHitObjects => nestedHitObjects;
protected IEnumerable<DrawableHitObject<TObject, TJudgement>> NestedHitObjects => nestedHitObjects;
protected void AddNested(DrawableHitObject<TObject> h)
protected void AddNested(DrawableHitObject<TObject, TJudgement> h)
{
if (nestedHitObjects == null)
nestedHitObjects = new List<DrawableHitObject<TObject>>();
nestedHitObjects = new List<DrawableHitObject<TObject, TJudgement>>();
h.OnJudgement += (d, j) => { OnJudgement?.Invoke(d, j); } ;
h.OnJudgement += d => OnJudgement?.Invoke(d);
nestedHitObjects.Add(h);
}
}

View File

@ -52,13 +52,6 @@ namespace osu.Game.Modes.UI
{
public Beatmap<TObject> Beatmap;
protected override Container<Drawable> Content => content;
protected override bool AllObjectsJudged => Playfield.HitObjects.Children.All(h => h.Judgement.Result.HasValue);
protected Playfield<TObject> 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<Mod> mods)
{
if (mods == null)
return;
foreach (var mod in mods.OfType<IApplicableMod<TObject>>())
mod.Apply(this);
}
protected abstract IBeatmapConverter<TObject> CreateBeatmapConverter();
}
public abstract class HitRenderer<TObject, TJudgement> : HitRenderer<TObject>
where TObject : HitObject
where TJudgement : JudgementInfo
{
protected override Container<Drawable> Content => content;
protected override bool AllObjectsJudged => Playfield.HitObjects.Children.All(h => h.Judgement.Result.HasValue);
protected Playfield<TObject, TJudgement> 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<TObject> 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<Mod> mods)
private void onJudgement(DrawableHitObject<TObject, TJudgement> j)
{
if (mods == null)
return;
foreach (var mod in mods.OfType<IApplicableMod<TObject>>())
mod.Apply(this);
TriggerOnJudgement(j.Judgement);
Playfield.OnJudgement(j);
}
private void onJudgement(DrawableHitObject<TObject> o, JudgementInfo j) => TriggerOnJudgement(j);
protected abstract DrawableHitObject<TObject> GetVisualRepresentation(TObject h);
protected abstract Playfield<TObject> CreatePlayfield();
protected abstract IBeatmapConverter<TObject> CreateBeatmapConverter();
protected abstract DrawableHitObject<TObject, TJudgement> GetVisualRepresentation(TObject h);
protected abstract Playfield<TObject, TJudgement> CreatePlayfield();
}
}

View File

@ -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<T> : Container
where T : HitObject
public abstract class Playfield<TObject, TJudgement> : Container
where TObject : HitObject
where TJudgement : JudgementInfo
{
public HitObjectContainer<DrawableHitObject<T>> HitObjects;
public HitObjectContainer<DrawableHitObject<TObject, TJudgement>> HitObjects;
public virtual void Add(DrawableHitObject<T> h) => HitObjects.Add(h);
public virtual void Add(DrawableHitObject<TObject, TJudgement> h) => HitObjects.Add(h);
internal Container<Drawable> ScaledContent;
@ -43,7 +45,7 @@ namespace osu.Game.Modes.UI
}
});
Add(HitObjects = new HitObjectContainer<DrawableHitObject<T>>
Add(HitObjects = new HitObjectContainer<DrawableHitObject<TObject, TJudgement>>
{
RelativeSizeAxes = Axes.Both,
});
@ -70,5 +72,7 @@ namespace osu.Game.Modes.UI
{
public override bool Contains(Vector2 screenSpacePos) => true;
}
public virtual void OnJudgement(DrawableHitObject<TObject, TJudgement> judgedObject) { }
}
}