mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 09:03:22 +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:
commit
6871588218
@ -1,11 +1,11 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Screens.Testing;
|
||||
using OpenTK;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.MathUtils;
|
||||
using osu.Framework.Screens.Testing;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Beatmaps;
|
||||
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.UI;
|
||||
using osu.Game.Modes.Taiko.UI;
|
||||
using OpenTK;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace osu.Desktop.VisualTests.Tests
|
||||
{
|
||||
@ -55,30 +55,26 @@ namespace osu.Desktop.VisualTests.Tests
|
||||
Clock = new FramedClock(),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OsuHitRenderer
|
||||
new OsuHitRenderer(beatmap)
|
||||
{
|
||||
Beatmap = beatmap,
|
||||
Scale = new Vector2(0.5f),
|
||||
Anchor = Anchor.TopLeft,
|
||||
Origin = Anchor.TopLeft
|
||||
},
|
||||
new TaikoHitRenderer
|
||||
new TaikoHitRenderer(beatmap)
|
||||
{
|
||||
Beatmap = beatmap,
|
||||
Scale = new Vector2(0.5f),
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight
|
||||
},
|
||||
new CatchHitRenderer
|
||||
new CatchHitRenderer(beatmap)
|
||||
{
|
||||
Beatmap = beatmap,
|
||||
Scale = new Vector2(0.5f),
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft
|
||||
},
|
||||
new ManiaHitRenderer
|
||||
new ManiaHitRenderer(beatmap)
|
||||
{
|
||||
Beatmap = beatmap,
|
||||
Scale = new Vector2(0.5f),
|
||||
Anchor = Anchor.BottomRight,
|
||||
Origin = Anchor.BottomRight
|
||||
|
@ -14,10 +14,7 @@ namespace osu.Game.Modes.Catch
|
||||
{
|
||||
public class CatchRuleset : Ruleset
|
||||
{
|
||||
public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new CatchHitRenderer
|
||||
{
|
||||
Beatmap = beatmap,
|
||||
};
|
||||
public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new CatchHitRenderer(beatmap);
|
||||
|
||||
public override IEnumerable<Mod> GetModsFor(ModType type)
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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.Objects;
|
||||
using osu.Game.Modes.Objects.Drawables;
|
||||
@ -10,6 +11,11 @@ namespace osu.Game.Modes.Catch.UI
|
||||
{
|
||||
public class CatchHitRenderer : HitRenderer<CatchBaseHit>
|
||||
{
|
||||
public CatchHitRenderer(Beatmap beatmap)
|
||||
: base(beatmap)
|
||||
{
|
||||
}
|
||||
|
||||
protected override HitObjectConverter<CatchBaseHit> Converter => new CatchConverter();
|
||||
|
||||
protected override Playfield<CatchBaseHit> CreatePlayfield() => new CatchPlayfield();
|
||||
|
@ -13,10 +13,7 @@ namespace osu.Game.Modes.Mania
|
||||
{
|
||||
public class ManiaRuleset : Ruleset
|
||||
{
|
||||
public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new ManiaHitRenderer
|
||||
{
|
||||
Beatmap = beatmap,
|
||||
};
|
||||
public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new ManiaHitRenderer(beatmap);
|
||||
|
||||
public override IEnumerable<Mod> GetModsFor(ModType type)
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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.Objects;
|
||||
using osu.Game.Modes.Objects.Drawables;
|
||||
@ -12,7 +13,8 @@ namespace osu.Game.Modes.Mania.UI
|
||||
{
|
||||
private readonly int columns;
|
||||
|
||||
public ManiaHitRenderer(int columns = 5)
|
||||
public ManiaHitRenderer(Beatmap beatmap, int columns = 5)
|
||||
: base(beatmap)
|
||||
{
|
||||
this.columns = columns;
|
||||
}
|
||||
|
@ -16,10 +16,7 @@ namespace osu.Game.Modes.Osu
|
||||
{
|
||||
public class OsuRuleset : Ruleset
|
||||
{
|
||||
public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new OsuHitRenderer
|
||||
{
|
||||
Beatmap = beatmap,
|
||||
};
|
||||
public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new OsuHitRenderer(beatmap);
|
||||
|
||||
public override IEnumerable<BeatmapStatistic> GetBeatmapStatistics(WorkingBeatmap beatmap) => new[]
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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.Drawables;
|
||||
using osu.Game.Modes.Osu.Objects;
|
||||
@ -11,6 +12,11 @@ namespace osu.Game.Modes.Osu.UI
|
||||
{
|
||||
public class OsuHitRenderer : HitRenderer<OsuHitObject>
|
||||
{
|
||||
public OsuHitRenderer(Beatmap beatmap)
|
||||
: base(beatmap)
|
||||
{
|
||||
}
|
||||
|
||||
protected override HitObjectConverter<OsuHitObject> Converter => new OsuHitObjectConverter();
|
||||
|
||||
protected override Playfield<OsuHitObject> CreatePlayfield() => new OsuPlayfield();
|
||||
|
@ -14,10 +14,7 @@ namespace osu.Game.Modes.Taiko
|
||||
{
|
||||
public class TaikoRuleset : Ruleset
|
||||
{
|
||||
public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new TaikoHitRenderer
|
||||
{
|
||||
Beatmap = beatmap,
|
||||
};
|
||||
public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new TaikoHitRenderer(beatmap);
|
||||
|
||||
public override IEnumerable<Mod> GetModsFor(ModType type)
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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.Drawables;
|
||||
using osu.Game.Modes.Taiko.Objects;
|
||||
@ -10,6 +11,11 @@ namespace osu.Game.Modes.Taiko.UI
|
||||
{
|
||||
public class TaikoHitRenderer : HitRenderer<TaikoBaseHit>
|
||||
{
|
||||
public TaikoHitRenderer(Beatmap beatmap)
|
||||
: base(beatmap)
|
||||
{
|
||||
}
|
||||
|
||||
protected override HitObjectConverter<TaikoBaseHit> Converter => new TaikoConverter();
|
||||
|
||||
protected override Playfield<TaikoBaseHit> CreatePlayfield() => new TaikoPlayfield();
|
||||
|
@ -1,24 +1,23 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenTK;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Modes.Objects;
|
||||
using osu.Game.Modes.Objects.Drawables;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Screens.Play;
|
||||
using OpenTK;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Modes.UI
|
||||
{
|
||||
public abstract class HitRenderer : Container
|
||||
{
|
||||
public event Action<JudgementInfo> OnJudgement;
|
||||
|
||||
public event Action OnAllJudged;
|
||||
|
||||
internal readonly PlayerInputManager InputManager = new PlayerInputManager();
|
||||
@ -28,11 +27,25 @@ namespace osu.Game.Modes.UI
|
||||
/// </summary>
|
||||
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)
|
||||
{
|
||||
OnJudgement?.Invoke(j);
|
||||
|
||||
if (AllObjectsJudged)
|
||||
OnAllJudged?.Invoke();
|
||||
}
|
||||
@ -41,33 +54,21 @@ namespace osu.Game.Modes.UI
|
||||
public abstract class HitRenderer<TObject> : HitRenderer
|
||||
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;
|
||||
|
||||
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().
|
||||
|
||||
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()
|
||||
protected HitRenderer(Beatmap beatmap)
|
||||
: base(beatmap)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
@ -83,9 +84,6 @@ namespace osu.Game.Modes.UI
|
||||
AddInternal(InputManager);
|
||||
}
|
||||
|
||||
protected override Container<Drawable> Content => content;
|
||||
|
||||
private Container content;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
@ -95,22 +93,24 @@ namespace osu.Game.Modes.UI
|
||||
|
||||
private void loadObjects()
|
||||
{
|
||||
if (objects == null) return;
|
||||
foreach (TObject h in objects)
|
||||
foreach (TObject h in Convert(Beatmap))
|
||||
{
|
||||
DrawableHitObject<TObject> drawableObject = GetVisualRepresentation(h);
|
||||
|
||||
if (drawableObject == null) continue;
|
||||
if (drawableObject == null)
|
||||
continue;
|
||||
|
||||
drawableObject.OnJudgement += onJudgement;
|
||||
|
||||
Playfield.Add(drawableObject);
|
||||
}
|
||||
|
||||
Playfield.PostProcess();
|
||||
}
|
||||
|
||||
private void onJudgement(DrawableHitObject<TObject> o, JudgementInfo j) => TriggerOnJudgement(j);
|
||||
|
||||
protected abstract DrawableHitObject<TObject> GetVisualRepresentation(TObject h);
|
||||
protected abstract Playfield<TObject> CreatePlayfield();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user