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

Merge pull request #465 from smoogipooo/refactor_hitrenderer

Make HitRenderer not have a publicly-settable Beatmap, replace AllObj…
This commit is contained in:
Dean Herbert 2017-03-12 12:56:41 +09:00 committed by GitHub
commit 6871588218
10 changed files with 68 additions and 64 deletions

View File

@ -1,11 +1,11 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic; using OpenTK;
using osu.Framework.Screens.Testing;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.MathUtils; using osu.Framework.MathUtils;
using osu.Framework.Screens.Testing;
using osu.Framework.Timing; using osu.Framework.Timing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Modes.Catch.UI; using osu.Game.Modes.Catch.UI;
@ -14,7 +14,7 @@ using osu.Game.Modes.Objects;
using osu.Game.Modes.Osu.Objects; using osu.Game.Modes.Osu.Objects;
using osu.Game.Modes.Osu.UI; using osu.Game.Modes.Osu.UI;
using osu.Game.Modes.Taiko.UI; using osu.Game.Modes.Taiko.UI;
using OpenTK; using System.Collections.Generic;
namespace osu.Desktop.VisualTests.Tests namespace osu.Desktop.VisualTests.Tests
{ {
@ -55,30 +55,26 @@ namespace osu.Desktop.VisualTests.Tests
Clock = new FramedClock(), Clock = new FramedClock(),
Children = new Drawable[] Children = new Drawable[]
{ {
new OsuHitRenderer new OsuHitRenderer(beatmap)
{ {
Beatmap = beatmap,
Scale = new Vector2(0.5f), Scale = new Vector2(0.5f),
Anchor = Anchor.TopLeft, Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft Origin = Anchor.TopLeft
}, },
new TaikoHitRenderer new TaikoHitRenderer(beatmap)
{ {
Beatmap = beatmap,
Scale = new Vector2(0.5f), Scale = new Vector2(0.5f),
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight Origin = Anchor.TopRight
}, },
new CatchHitRenderer new CatchHitRenderer(beatmap)
{ {
Beatmap = beatmap,
Scale = new Vector2(0.5f), Scale = new Vector2(0.5f),
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft Origin = Anchor.BottomLeft
}, },
new ManiaHitRenderer new ManiaHitRenderer(beatmap)
{ {
Beatmap = beatmap,
Scale = new Vector2(0.5f), Scale = new Vector2(0.5f),
Anchor = Anchor.BottomRight, Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight Origin = Anchor.BottomRight

View File

@ -14,10 +14,7 @@ namespace osu.Game.Modes.Catch
{ {
public class CatchRuleset : Ruleset public class CatchRuleset : Ruleset
{ {
public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new CatchHitRenderer public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new CatchHitRenderer(beatmap);
{
Beatmap = beatmap,
};
public override IEnumerable<Mod> GetModsFor(ModType type) public override IEnumerable<Mod> GetModsFor(ModType type)
{ {

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Beatmaps;
using osu.Game.Modes.Catch.Objects; using osu.Game.Modes.Catch.Objects;
using osu.Game.Modes.Objects; using osu.Game.Modes.Objects;
using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.Objects.Drawables;
@ -10,6 +11,11 @@ namespace osu.Game.Modes.Catch.UI
{ {
public class CatchHitRenderer : HitRenderer<CatchBaseHit> public class CatchHitRenderer : HitRenderer<CatchBaseHit>
{ {
public CatchHitRenderer(Beatmap beatmap)
: base(beatmap)
{
}
protected override HitObjectConverter<CatchBaseHit> Converter => new CatchConverter(); protected override HitObjectConverter<CatchBaseHit> Converter => new CatchConverter();
protected override Playfield<CatchBaseHit> CreatePlayfield() => new CatchPlayfield(); protected override Playfield<CatchBaseHit> CreatePlayfield() => new CatchPlayfield();

View File

@ -13,10 +13,7 @@ namespace osu.Game.Modes.Mania
{ {
public class ManiaRuleset : Ruleset public class ManiaRuleset : Ruleset
{ {
public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new ManiaHitRenderer public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new ManiaHitRenderer(beatmap);
{
Beatmap = beatmap,
};
public override IEnumerable<Mod> GetModsFor(ModType type) public override IEnumerable<Mod> GetModsFor(ModType type)
{ {

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Beatmaps;
using osu.Game.Modes.Mania.Objects; using osu.Game.Modes.Mania.Objects;
using osu.Game.Modes.Objects; using osu.Game.Modes.Objects;
using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.Objects.Drawables;
@ -12,7 +13,8 @@ namespace osu.Game.Modes.Mania.UI
{ {
private readonly int columns; private readonly int columns;
public ManiaHitRenderer(int columns = 5) public ManiaHitRenderer(Beatmap beatmap, int columns = 5)
: base(beatmap)
{ {
this.columns = columns; this.columns = columns;
} }

View File

@ -16,10 +16,7 @@ namespace osu.Game.Modes.Osu
{ {
public class OsuRuleset : Ruleset public class OsuRuleset : Ruleset
{ {
public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new OsuHitRenderer public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new OsuHitRenderer(beatmap);
{
Beatmap = beatmap,
};
public override IEnumerable<BeatmapStatistic> GetBeatmapStatistics(WorkingBeatmap beatmap) => new[] public override IEnumerable<BeatmapStatistic> GetBeatmapStatistics(WorkingBeatmap beatmap) => new[]
{ {

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Beatmaps;
using osu.Game.Modes.Objects; using osu.Game.Modes.Objects;
using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.Objects.Drawables;
using osu.Game.Modes.Osu.Objects; using osu.Game.Modes.Osu.Objects;
@ -11,6 +12,11 @@ namespace osu.Game.Modes.Osu.UI
{ {
public class OsuHitRenderer : HitRenderer<OsuHitObject> public class OsuHitRenderer : HitRenderer<OsuHitObject>
{ {
public OsuHitRenderer(Beatmap beatmap)
: base(beatmap)
{
}
protected override HitObjectConverter<OsuHitObject> Converter => new OsuHitObjectConverter(); protected override HitObjectConverter<OsuHitObject> Converter => new OsuHitObjectConverter();
protected override Playfield<OsuHitObject> CreatePlayfield() => new OsuPlayfield(); protected override Playfield<OsuHitObject> CreatePlayfield() => new OsuPlayfield();

View File

@ -14,10 +14,7 @@ namespace osu.Game.Modes.Taiko
{ {
public class TaikoRuleset : Ruleset public class TaikoRuleset : Ruleset
{ {
public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new TaikoHitRenderer public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new TaikoHitRenderer(beatmap);
{
Beatmap = beatmap,
};
public override IEnumerable<Mod> GetModsFor(ModType type) public override IEnumerable<Mod> GetModsFor(ModType type)
{ {

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Beatmaps;
using osu.Game.Modes.Objects; using osu.Game.Modes.Objects;
using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.Objects.Drawables;
using osu.Game.Modes.Taiko.Objects; using osu.Game.Modes.Taiko.Objects;
@ -10,6 +11,11 @@ namespace osu.Game.Modes.Taiko.UI
{ {
public class TaikoHitRenderer : HitRenderer<TaikoBaseHit> public class TaikoHitRenderer : HitRenderer<TaikoBaseHit>
{ {
public TaikoHitRenderer(Beatmap beatmap)
: base(beatmap)
{
}
protected override HitObjectConverter<TaikoBaseHit> Converter => new TaikoConverter(); protected override HitObjectConverter<TaikoBaseHit> Converter => new TaikoConverter();
protected override Playfield<TaikoBaseHit> CreatePlayfield() => new TaikoPlayfield(); protected override Playfield<TaikoBaseHit> CreatePlayfield() => new TaikoPlayfield();

View File

@ -1,24 +1,23 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System; using OpenTK;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Modes.Objects; using osu.Game.Modes.Objects;
using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.Objects.Drawables;
using osu.Game.Beatmaps;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using OpenTK; using System;
using System.Collections.Generic;
using System.Linq;
namespace osu.Game.Modes.UI namespace osu.Game.Modes.UI
{ {
public abstract class HitRenderer : Container public abstract class HitRenderer : Container
{ {
public event Action<JudgementInfo> OnJudgement; public event Action<JudgementInfo> OnJudgement;
public event Action OnAllJudged; public event Action OnAllJudged;
internal readonly PlayerInputManager InputManager = new PlayerInputManager(); internal readonly PlayerInputManager InputManager = new PlayerInputManager();
@ -28,11 +27,25 @@ namespace osu.Game.Modes.UI
/// </summary> /// </summary>
public abstract Func<Vector2, Vector2> MapPlayfieldToScreenSpace { get; } public abstract Func<Vector2, Vector2> MapPlayfieldToScreenSpace { get; }
public abstract bool AllObjectsJudged { get; } /// <summary>
/// Whether all the HitObjects have been judged.
/// </summary>
protected abstract bool AllObjectsJudged { get; }
/// <summary>
/// The beatmap this HitRenderer is initialized with.
/// </summary>
protected readonly Beatmap Beatmap;
protected HitRenderer(Beatmap beatmap)
{
Beatmap = beatmap;
}
protected void TriggerOnJudgement(JudgementInfo j) protected void TriggerOnJudgement(JudgementInfo j)
{ {
OnJudgement?.Invoke(j); OnJudgement?.Invoke(j);
if (AllObjectsJudged) if (AllObjectsJudged)
OnAllJudged?.Invoke(); OnAllJudged?.Invoke();
} }
@ -41,33 +54,21 @@ namespace osu.Game.Modes.UI
public abstract class HitRenderer<TObject> : HitRenderer public abstract class HitRenderer<TObject> : HitRenderer
where TObject : HitObject where TObject : HitObject
{ {
private List<TObject> objects; public override Func<Vector2, Vector2> MapPlayfieldToScreenSpace => Playfield.ScaledContent.ToScreenSpace;
public IEnumerable<DrawableHitObject> DrawableObjects => Playfield.HitObjects.Children;
protected abstract HitObjectConverter<TObject> Converter { get; }
protected virtual List<TObject> Convert(Beatmap beatmap) => Converter.Convert(beatmap);
protected override Container<Drawable> Content => content;
protected override bool AllObjectsJudged => Playfield.HitObjects.Children.All(h => h.Judgement.Result.HasValue);
protected Playfield<TObject> Playfield; protected Playfield<TObject> Playfield;
public override Func<Vector2, Vector2> MapPlayfieldToScreenSpace => Playfield.ScaledContent.ToScreenSpace; private Container content;
public override bool AllObjectsJudged => Playfield.HitObjects.Children.First()?.Judgement.Result != null; //reverse depth sort means First() instead of Last(). protected HitRenderer(Beatmap beatmap)
: base(beatmap)
public IEnumerable<DrawableHitObject> DrawableObjects => Playfield.HitObjects.Children;
public Beatmap Beatmap
{
set
{
objects = Convert(value);
if (IsLoaded)
loadObjects();
}
}
protected abstract Playfield<TObject> CreatePlayfield();
protected abstract HitObjectConverter<TObject> Converter { get; }
protected virtual List<TObject> Convert(Beatmap beatmap) => Converter.Convert(beatmap);
protected HitRenderer()
{ {
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
@ -83,9 +84,6 @@ namespace osu.Game.Modes.UI
AddInternal(InputManager); AddInternal(InputManager);
} }
protected override Container<Drawable> Content => content;
private Container content;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
@ -95,22 +93,24 @@ namespace osu.Game.Modes.UI
private void loadObjects() private void loadObjects()
{ {
if (objects == null) return; foreach (TObject h in Convert(Beatmap))
foreach (TObject h in objects)
{ {
DrawableHitObject<TObject> drawableObject = GetVisualRepresentation(h); DrawableHitObject<TObject> drawableObject = GetVisualRepresentation(h);
if (drawableObject == null) continue; if (drawableObject == null)
continue;
drawableObject.OnJudgement += onJudgement; drawableObject.OnJudgement += onJudgement;
Playfield.Add(drawableObject); Playfield.Add(drawableObject);
} }
Playfield.PostProcess(); Playfield.PostProcess();
} }
private void onJudgement(DrawableHitObject<TObject> o, JudgementInfo j) => TriggerOnJudgement(j); private void onJudgement(DrawableHitObject<TObject> o, JudgementInfo j) => TriggerOnJudgement(j);
protected abstract DrawableHitObject<TObject> GetVisualRepresentation(TObject h); protected abstract DrawableHitObject<TObject> GetVisualRepresentation(TObject h);
protected abstract Playfield<TObject> CreatePlayfield();
} }
} }