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

Give HitRenderer a reference to Ruleset

Used to get correct bindings for a mode (ActionMappingInputManager).
This commit is contained in:
Dean Herbert 2017-08-09 13:04:11 +09:00
parent eee6404986
commit 7c0e7ebcd0
19 changed files with 93 additions and 39 deletions

View File

@ -1,7 +1,9 @@
// 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.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Catch; using osu.Game.Rulesets.Catch;
using osu.Game.Rulesets.Catch.UI; using osu.Game.Rulesets.Catch.UI;
using OpenTK; using OpenTK;
@ -10,13 +12,12 @@ namespace osu.Desktop.Tests.Visual
{ {
internal class TestCaseCatcher : OsuTestCase internal class TestCaseCatcher : OsuTestCase
{ {
protected override void LoadComplete() [BackgroundDependencyLoader]
private void load(RulesetStore rulesets)
{ {
base.LoadComplete();
Children = new Drawable[] Children = new Drawable[]
{ {
new CatchInputManager new CatchInputManager(rulesets.GetRuleset(2))
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Child = new CatcherArea Child = new CatcherArea

View File

@ -11,11 +11,15 @@ using osu.Framework.Timing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Catch;
using osu.Game.Rulesets.Catch.UI; using osu.Game.Rulesets.Catch.UI;
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.Mania.UI;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.UI; using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.Taiko;
using osu.Game.Rulesets.Taiko.UI; using osu.Game.Rulesets.Taiko.UI;
using OpenTK; using OpenTK;
@ -84,25 +88,25 @@ namespace osu.Desktop.Tests.Visual
Clock = new FramedClock(), Clock = new FramedClock(),
Children = new Drawable[] Children = new Drawable[]
{ {
new OsuHitRenderer(beatmap, false) new OsuHitRenderer(new OsuRuleset(new RulesetInfo()), beatmap, false)
{ {
Scale = new Vector2(0.5f), Scale = new Vector2(0.5f),
Anchor = Anchor.TopLeft, Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft Origin = Anchor.TopLeft
}, },
new TaikoHitRenderer(beatmap, false) new TaikoHitRenderer(new TaikoRuleset(new RulesetInfo()),beatmap, false)
{ {
Scale = new Vector2(0.5f), Scale = new Vector2(0.5f),
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight Origin = Anchor.TopRight
}, },
new CatchHitRenderer(beatmap, false) new CatchHitRenderer(new CatchRuleset(new RulesetInfo()),beatmap, false)
{ {
Scale = new Vector2(0.5f), Scale = new Vector2(0.5f),
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft Origin = Anchor.BottomLeft
}, },
new ManiaHitRenderer(beatmap, false) new ManiaHitRenderer(new ManiaRuleset(new RulesetInfo()),beatmap, false)
{ {
Scale = new Vector2(0.5f), Scale = new Vector2(0.5f),
Anchor = Anchor.BottomRight, Anchor = Anchor.BottomRight,

View File

@ -59,7 +59,7 @@ namespace osu.Desktop.Tests.Visual
private class TestHitRenderer : ScrollingHitRenderer<TestPlayfield, TestHitObject, TestJudgement> private class TestHitRenderer : ScrollingHitRenderer<TestPlayfield, TestHitObject, TestJudgement>
{ {
public TestHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) public TestHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset)
: base(beatmap, isForCurrentRuleset) : base(null, beatmap, isForCurrentRuleset)
{ {
} }

View File

@ -18,7 +18,7 @@ namespace osu.Game.Rulesets.Catch
{ {
public class CatchRuleset : Ruleset public class CatchRuleset : Ruleset
{ {
public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new CatchHitRenderer(beatmap, isForCurrentRuleset); public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new CatchHitRenderer(this, beatmap, isForCurrentRuleset);
public override IEnumerable<Mod> GetModsFor(ModType type) public override IEnumerable<Mod> GetModsFor(ModType type)
{ {
@ -102,5 +102,10 @@ namespace osu.Game.Rulesets.Catch
public override ScoreProcessor CreateScoreProcessor() => new CatchScoreProcessor(); public override ScoreProcessor CreateScoreProcessor() => new CatchScoreProcessor();
public override int LegacyID => 2; public override int LegacyID => 2;
public CatchRuleset(RulesetInfo rulesetInfo)
: base(rulesetInfo)
{
}
} }
} }

View File

@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Catch
{ {
public class CatchInputManager : ActionMappingInputManager<CatchAction> public class CatchInputManager : ActionMappingInputManager<CatchAction>
{ {
public CatchInputManager() public CatchInputManager(RulesetInfo ruleset) : base(ruleset)
{ {
Mappings = new Dictionary<Key, CatchAction> Mappings = new Dictionary<Key, CatchAction>
{ {

View File

@ -17,8 +17,8 @@ namespace osu.Game.Rulesets.Catch.UI
{ {
public class CatchHitRenderer : ScrollingHitRenderer<CatchPlayfield, CatchBaseHit, CatchJudgement> public class CatchHitRenderer : ScrollingHitRenderer<CatchPlayfield, CatchBaseHit, CatchJudgement>
{ {
public CatchHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) public CatchHitRenderer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset)
: base(beatmap, isForCurrentRuleset) : base(ruleset, beatmap, isForCurrentRuleset)
{ {
} }
@ -28,7 +28,7 @@ namespace osu.Game.Rulesets.Catch.UI
protected override Playfield<CatchBaseHit, CatchJudgement> CreatePlayfield() => new CatchPlayfield(); protected override Playfield<CatchBaseHit, CatchJudgement> CreatePlayfield() => new CatchPlayfield();
protected override PassThroughInputManager CreateKeyConversionInputManager() => new CatchInputManager(); protected override PassThroughInputManager CreateActionMappingInputManager() => new CatchInputManager(Ruleset.RulesetInfo);
protected override DrawableHitObject<CatchBaseHit, CatchJudgement> GetVisualRepresentation(CatchBaseHit h) protected override DrawableHitObject<CatchBaseHit, CatchJudgement> GetVisualRepresentation(CatchBaseHit h)
{ {

View File

@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.Mania
{ {
public class ManiaRuleset : Ruleset public class ManiaRuleset : Ruleset
{ {
public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new ManiaHitRenderer(beatmap, isForCurrentRuleset); public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new ManiaHitRenderer(this, beatmap, isForCurrentRuleset);
public override IEnumerable<Mod> GetModsFor(ModType type) public override IEnumerable<Mod> GetModsFor(ModType type)
{ {
@ -118,5 +118,10 @@ namespace osu.Game.Rulesets.Mania
public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor(); public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor();
public override int LegacyID => 3; public override int LegacyID => 3;
public ManiaRuleset(RulesetInfo rulesetInfo)
: base(rulesetInfo)
{
}
} }
} }

View File

@ -38,8 +38,8 @@ namespace osu.Game.Rulesets.Mania.UI
public IEnumerable<DrawableBarLine> BarLines; public IEnumerable<DrawableBarLine> BarLines;
public ManiaHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) public ManiaHitRenderer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset)
: base(beatmap, isForCurrentRuleset) : base(ruleset, beatmap, isForCurrentRuleset)
{ {
// Generate the bar lines // Generate the bar lines
double lastObjectTime = (Objects.LastOrDefault() as IHasEndTime)?.EndTime ?? Objects.LastOrDefault()?.StartTime ?? double.MaxValue; double lastObjectTime = (Objects.LastOrDefault() as IHasEndTime)?.EndTime ?? Objects.LastOrDefault()?.StartTime ?? double.MaxValue;

View File

@ -22,7 +22,7 @@ namespace osu.Game.Rulesets.Osu
{ {
public class OsuRuleset : Ruleset public class OsuRuleset : Ruleset
{ {
public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new OsuHitRenderer(beatmap, isForCurrentRuleset); public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new OsuHitRenderer(this, beatmap, isForCurrentRuleset);
public override IEnumerable<BeatmapStatistic> GetBeatmapStatistics(WorkingBeatmap beatmap) => new[] public override IEnumerable<BeatmapStatistic> GetBeatmapStatistics(WorkingBeatmap beatmap) => new[]
{ {
@ -126,5 +126,10 @@ namespace osu.Game.Rulesets.Osu
public override SettingsSubsection CreateSettings() => new OsuSettings(); public override SettingsSubsection CreateSettings() => new OsuSettings();
public override int LegacyID => 0; public override int LegacyID => 0;
public OsuRuleset(RulesetInfo rulesetInfo)
: base(rulesetInfo)
{
}
} }
} }

View File

@ -18,8 +18,8 @@ namespace osu.Game.Rulesets.Osu.UI
{ {
public class OsuHitRenderer : HitRenderer<OsuHitObject, OsuJudgement> public class OsuHitRenderer : HitRenderer<OsuHitObject, OsuJudgement>
{ {
public OsuHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) public OsuHitRenderer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset)
: base(beatmap, isForCurrentRuleset) : base(ruleset, beatmap, isForCurrentRuleset)
{ {
} }
@ -31,7 +31,7 @@ namespace osu.Game.Rulesets.Osu.UI
protected override Playfield<OsuHitObject, OsuJudgement> CreatePlayfield() => new OsuPlayfield(); protected override Playfield<OsuHitObject, OsuJudgement> CreatePlayfield() => new OsuPlayfield();
protected override PassThroughInputManager CreateKeyConversionInputManager() => new OsuKeyConversionInputManager(); protected override PassThroughInputManager CreateActionMappingInputManager() => new OsuKeyConversionInputManager();
protected override DrawableHitObject<OsuHitObject, OsuJudgement> GetVisualRepresentation(OsuHitObject h) protected override DrawableHitObject<OsuHitObject, OsuJudgement> GetVisualRepresentation(OsuHitObject h)
{ {

View File

@ -18,7 +18,7 @@ namespace osu.Game.Rulesets.Taiko
{ {
public class TaikoRuleset : Ruleset public class TaikoRuleset : Ruleset
{ {
public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new TaikoHitRenderer(beatmap, isForCurrentRuleset); public override HitRenderer CreateHitRendererWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new TaikoHitRenderer(this, beatmap, isForCurrentRuleset);
public override IEnumerable<Mod> GetModsFor(ModType type) public override IEnumerable<Mod> GetModsFor(ModType type)
{ {
@ -103,5 +103,10 @@ namespace osu.Game.Rulesets.Taiko
public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor(); public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor();
public override int LegacyID => 1; public override int LegacyID => 1;
public TaikoRuleset(RulesetInfo rulesetInfo)
: base(rulesetInfo)
{
}
} }
} }

View File

@ -23,8 +23,8 @@ namespace osu.Game.Rulesets.Taiko.UI
{ {
public class TaikoHitRenderer : HitRenderer<TaikoHitObject, TaikoJudgement> public class TaikoHitRenderer : HitRenderer<TaikoHitObject, TaikoJudgement>
{ {
public TaikoHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) public TaikoHitRenderer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset)
: base(beatmap, isForCurrentRuleset) : base(ruleset, beatmap, isForCurrentRuleset)
{ {
} }
@ -93,7 +93,6 @@ namespace osu.Game.Rulesets.Taiko.UI
return new Vector2(1, default_relative_height * aspectAdjust); return new Vector2(1, default_relative_height * aspectAdjust);
} }
public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor(this); public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor(this);
protected override BeatmapConverter<TaikoHitObject> CreateBeatmapConverter() => new TaikoBeatmapConverter(); protected override BeatmapConverter<TaikoHitObject> CreateBeatmapConverter() => new TaikoBeatmapConverter();

View File

@ -54,7 +54,7 @@ namespace osu.Game.Beatmaps
private class DummyRulesetInfo : RulesetInfo private class DummyRulesetInfo : RulesetInfo
{ {
public override Ruleset CreateInstance() => new DummyRuleset(); public override Ruleset CreateInstance() => new DummyRuleset(this);
private class DummyRuleset : Ruleset private class DummyRuleset : Ruleset
{ {
@ -77,6 +77,11 @@ namespace osu.Game.Beatmaps
public override string Description => "dummy"; public override string Description => "dummy";
public override IEnumerable<KeyCounter> CreateGameplayKeys() => new List<KeyCounter>(); public override IEnumerable<KeyCounter> CreateGameplayKeys() => new List<KeyCounter>();
public DummyRuleset(RulesetInfo rulesetInfo)
: base(rulesetInfo)
{
}
} }
} }
} }

View File

@ -17,12 +17,20 @@ namespace osu.Game.Input
public class ActionMappingInputManager<T> : PassThroughInputManager public class ActionMappingInputManager<T> : PassThroughInputManager
where T : struct where T : struct
{ {
private readonly RulesetInfo ruleset;
protected ActionMappingInputManager(RulesetInfo ruleset = null)
{
this.ruleset = ruleset;
}
protected IDictionary<Key, T> Mappings { get; set; } protected IDictionary<Key, T> Mappings { get; set; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(BindingStore bindings) private void load(BindingStore bindings)
{ {
foreach (var b in bindings.Query<Binding>()) var rulesetId = ruleset?.ID;
foreach (var b in bindings.Query<Binding>(b => b.RulesetID == rulesetId))
Mappings[b.Key] = (T)(object)b.Action; Mappings[b.Key] = (T)(object)b.Action;
} }

View File

@ -15,12 +15,19 @@ namespace osu.Game.Rulesets
{ {
public abstract class Ruleset public abstract class Ruleset
{ {
public readonly RulesetInfo RulesetInfo;
public virtual IEnumerable<BeatmapStatistic> GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { }; public virtual IEnumerable<BeatmapStatistic> GetBeatmapStatistics(WorkingBeatmap beatmap) => new BeatmapStatistic[] { };
public abstract IEnumerable<Mod> GetModsFor(ModType type); public abstract IEnumerable<Mod> GetModsFor(ModType type);
public abstract Mod GetAutoplayMod(); public abstract Mod GetAutoplayMod();
protected Ruleset(RulesetInfo rulesetInfo)
{
RulesetInfo = rulesetInfo;
}
/// <summary> /// <summary>
/// Attempt to create a hit renderer for a beatmap /// Attempt to create a hit renderer for a beatmap
/// </summary> /// </summary>

View File

@ -20,6 +20,6 @@ namespace osu.Game.Rulesets
[Indexed] [Indexed]
public bool Available { get; set; } public bool Available { get; set; }
public virtual Ruleset CreateInstance() => (Ruleset)Activator.CreateInstance(Type.GetType(InstantiationInfo)); public virtual Ruleset CreateInstance() => (Ruleset)Activator.CreateInstance(Type.GetType(InstantiationInfo), this);
} }
} }

View File

@ -44,7 +44,7 @@ namespace osu.Game.Rulesets
continue; continue;
foreach (Type rulesetType in rulesets) foreach (Type rulesetType in rulesets)
instances.Add((Ruleset)Activator.CreateInstance(rulesetType)); instances.Add((Ruleset)Activator.CreateInstance(rulesetType, new RulesetInfo()));
} }
catch (Exception) { } catch (Exception) { }
} }

View File

@ -67,9 +67,16 @@ namespace osu.Game.Rulesets.UI
/// </summary> /// </summary>
protected abstract bool AllObjectsJudged { get; } protected abstract bool AllObjectsJudged { get; }
internal HitRenderer() protected readonly Ruleset Ruleset;
/// <summary>
/// A visual representation of a <see cref="Rulesets.Ruleset"/>.
/// </summary>
/// <param name="ruleset">The ruleset being repesented.</param>
internal HitRenderer(Ruleset ruleset)
{ {
KeyConversionInputManager = CreateKeyConversionInputManager(); Ruleset = ruleset;
KeyConversionInputManager = CreateActionMappingInputManager();
KeyConversionInputManager.RelativeSizeAxes = Axes.Both; KeyConversionInputManager.RelativeSizeAxes = Axes.Both;
} }
@ -88,7 +95,7 @@ namespace osu.Game.Rulesets.UI
/// Creates a key conversion input manager. /// Creates a key conversion input manager.
/// </summary> /// </summary>
/// <returns>The input manager.</returns> /// <returns>The input manager.</returns>
protected virtual PassThroughInputManager CreateKeyConversionInputManager() => new PassThroughInputManager(); protected virtual PassThroughInputManager CreateActionMappingInputManager() => new PassThroughInputManager();
protected virtual FramedReplayInputHandler CreateReplayInputHandler(Replay replay) => new FramedReplayInputHandler(replay); protected virtual FramedReplayInputHandler CreateReplayInputHandler(Replay replay) => new FramedReplayInputHandler(replay);
@ -134,9 +141,10 @@ namespace osu.Game.Rulesets.UI
/// <summary> /// <summary>
/// Creates a hit renderer for a beatmap. /// Creates a hit renderer for a beatmap.
/// </summary> /// </summary>
/// <param name="ruleset">The ruleset being repesented.</param>
/// <param name="beatmap">The beatmap to create the hit renderer for.</param> /// <param name="beatmap">The beatmap to create the hit renderer for.</param>
/// <param name="isForCurrentRuleset">Whether to assume the beatmap is for the current ruleset.</param> /// <param name="isForCurrentRuleset">Whether to assume the beatmap is for the current ruleset.</param>
internal HitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) internal HitRenderer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset) : base(ruleset)
{ {
Debug.Assert(beatmap != null, "HitRenderer initialized with a null beatmap."); Debug.Assert(beatmap != null, "HitRenderer initialized with a null beatmap.");
@ -236,10 +244,11 @@ namespace osu.Game.Rulesets.UI
/// <summary> /// <summary>
/// Creates a hit renderer for a beatmap. /// Creates a hit renderer for a beatmap.
/// </summary> /// </summary>
/// <param name="ruleset">The ruleset being repesented.</param>
/// <param name="beatmap">The beatmap to create the hit renderer for.</param> /// <param name="beatmap">The beatmap to create the hit renderer for.</param>
/// <param name="isForCurrentRuleset">Whether to assume the beatmap is for the current ruleset.</param> /// <param name="isForCurrentRuleset">Whether to assume the beatmap is for the current ruleset.</param>
protected HitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) protected HitRenderer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset)
: base(beatmap, isForCurrentRuleset) : base(ruleset, beatmap, isForCurrentRuleset)
{ {
InputManager.Add(content = new Container InputManager.Add(content = new Container
{ {
@ -343,10 +352,11 @@ namespace osu.Game.Rulesets.UI
/// <summary> /// <summary>
/// Creates a hit renderer for a beatmap. /// Creates a hit renderer for a beatmap.
/// </summary> /// </summary>
/// <param name="ruleset">The ruleset being repesented.</param>
/// <param name="beatmap">The beatmap to create the hit renderer for.</param> /// <param name="beatmap">The beatmap to create the hit renderer for.</param>
/// <param name="isForCurrentRuleset">Whether to assume the beatmap is for the current ruleset.</param> /// <param name="isForCurrentRuleset">Whether to assume the beatmap is for the current ruleset.</param>
protected HitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) protected HitRenderer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset)
: base(beatmap, isForCurrentRuleset) : base(ruleset, beatmap, isForCurrentRuleset)
{ {
} }
} }

View File

@ -32,8 +32,8 @@ namespace osu.Game.Rulesets.UI
/// <returns></returns> /// <returns></returns>
protected readonly SortedList<MultiplierControlPoint> DefaultControlPoints = new SortedList<MultiplierControlPoint>(Comparer<MultiplierControlPoint>.Default); protected readonly SortedList<MultiplierControlPoint> DefaultControlPoints = new SortedList<MultiplierControlPoint>(Comparer<MultiplierControlPoint>.Default);
protected ScrollingHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) protected ScrollingHitRenderer(Ruleset ruleset, WorkingBeatmap beatmap, bool isForCurrentRuleset)
: base(beatmap, isForCurrentRuleset) : base(ruleset, beatmap, isForCurrentRuleset)
{ {
} }