mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 08:53:20 +08:00
Reduce complexity of creating edit ruleset containers
This commit is contained in:
parent
969477dadd
commit
d36ac59ca2
@ -4,36 +4,23 @@
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Rulesets.Edit;
|
|
||||||
using osu.Game.Rulesets.Mania.Objects;
|
|
||||||
using osu.Game.Rulesets.Mania.UI;
|
using osu.Game.Rulesets.Mania.UI;
|
||||||
using osu.Game.Rulesets.UI;
|
using osu.Game.Rulesets.UI;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Mania.Edit
|
namespace osu.Game.Rulesets.Mania.Edit
|
||||||
{
|
{
|
||||||
public class ManiaEditRulesetContainer : EditRulesetContainer<ManiaHitObject>
|
public class ManiaEditRulesetContainer : ManiaRulesetContainer
|
||||||
{
|
{
|
||||||
public ManiaEditRulesetContainer(Ruleset ruleset, WorkingBeatmap workingBeatmap)
|
public ManiaEditRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap)
|
||||||
: base(ruleset, workingBeatmap)
|
: base(ruleset, beatmap)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override RulesetContainer<ManiaHitObject> CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap workingBeatmap)
|
protected override Playfield CreatePlayfield() => new ManiaEditPlayfield(Beatmap.Stages)
|
||||||
=> new RulesetContainer(ruleset, workingBeatmap);
|
|
||||||
|
|
||||||
private new class RulesetContainer : ManiaRulesetContainer
|
|
||||||
{
|
{
|
||||||
public RulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap)
|
Anchor = Anchor.Centre,
|
||||||
: base(ruleset, beatmap)
|
Origin = Anchor.Centre,
|
||||||
{
|
Size = Vector2.One
|
||||||
}
|
};
|
||||||
|
|
||||||
protected override Playfield CreatePlayfield() => new ManiaEditPlayfield(Beatmap.Stages)
|
|
||||||
{
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
Size = Vector2.One
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,13 @@ using System.Collections.Generic;
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Game.Rulesets.Mania.Configuration;
|
using osu.Game.Rulesets.Mania.Configuration;
|
||||||
using osu.Game.Rulesets.Mania.Edit.Masks;
|
using osu.Game.Rulesets.Mania.Edit.Masks;
|
||||||
|
using osu.Game.Rulesets.Mania.Objects;
|
||||||
using osu.Game.Rulesets.Mania.UI;
|
using osu.Game.Rulesets.Mania.UI;
|
||||||
|
using osu.Game.Rulesets.UI;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Mania.Edit
|
namespace osu.Game.Rulesets.Mania.Edit
|
||||||
{
|
{
|
||||||
public class ManiaHitObjectComposer : HitObjectComposer
|
public class ManiaHitObjectComposer : HitObjectComposer<ManiaHitObject>
|
||||||
{
|
{
|
||||||
protected new ManiaConfigManager Config => (ManiaConfigManager)base.Config;
|
protected new ManiaConfigManager Config => (ManiaConfigManager)base.Config;
|
||||||
|
|
||||||
@ -31,7 +33,8 @@ namespace osu.Game.Rulesets.Mania.Edit
|
|||||||
return dependencies;
|
return dependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override EditRulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) => new ManiaEditRulesetContainer(ruleset, beatmap);
|
protected override RulesetContainer<ManiaHitObject> CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap)
|
||||||
|
=> new ManiaEditRulesetContainer(ruleset, beatmap);
|
||||||
|
|
||||||
protected override IReadOnlyList<HitObjectCompositionTool> CompositionTools => Array.Empty<HitObjectCompositionTool>();
|
protected override IReadOnlyList<HitObjectCompositionTool> CompositionTools => Array.Empty<HitObjectCompositionTool>();
|
||||||
|
|
||||||
|
@ -3,34 +3,21 @@
|
|||||||
|
|
||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Rulesets.Edit;
|
|
||||||
using osu.Game.Rulesets.Osu.Objects;
|
|
||||||
using osu.Game.Rulesets.Osu.UI;
|
using osu.Game.Rulesets.Osu.UI;
|
||||||
using osu.Game.Rulesets.UI;
|
using osu.Game.Rulesets.UI;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Osu.Edit
|
namespace osu.Game.Rulesets.Osu.Edit
|
||||||
{
|
{
|
||||||
public class OsuEditRulesetContainer : EditRulesetContainer<OsuHitObject>
|
public class OsuEditRulesetContainer : OsuRulesetContainer
|
||||||
{
|
{
|
||||||
public OsuEditRulesetContainer(Ruleset ruleset, WorkingBeatmap workingBeatmap)
|
public OsuEditRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap)
|
||||||
: base(ruleset, workingBeatmap)
|
: base(ruleset, beatmap)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override RulesetContainer<OsuHitObject> CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap workingBeatmap)
|
protected override CursorContainer CreateCursor() => null;
|
||||||
=> new RulesetContainer(ruleset, workingBeatmap);
|
|
||||||
|
|
||||||
private new class RulesetContainer : OsuRulesetContainer
|
protected override Playfield CreatePlayfield() => new OsuPlayfield { Size = Vector2.One };
|
||||||
{
|
|
||||||
public RulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap)
|
|
||||||
: base(ruleset, beatmap)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override CursorContainer CreateCursor() => null;
|
|
||||||
|
|
||||||
protected override Playfield CreatePlayfield() => new OsuPlayfield { Size = Vector2.One };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,19 +9,22 @@ using osu.Game.Rulesets.Edit;
|
|||||||
using osu.Game.Rulesets.Edit.Tools;
|
using osu.Game.Rulesets.Edit.Tools;
|
||||||
using osu.Game.Rulesets.Objects.Drawables;
|
using osu.Game.Rulesets.Objects.Drawables;
|
||||||
using osu.Game.Rulesets.Osu.Edit.Masks;
|
using osu.Game.Rulesets.Osu.Edit.Masks;
|
||||||
|
using osu.Game.Rulesets.Osu.Objects;
|
||||||
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
||||||
using osu.Game.Rulesets.Osu.UI;
|
using osu.Game.Rulesets.Osu.UI;
|
||||||
|
using osu.Game.Rulesets.UI;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Osu.Edit
|
namespace osu.Game.Rulesets.Osu.Edit
|
||||||
{
|
{
|
||||||
public class OsuHitObjectComposer : HitObjectComposer
|
public class OsuHitObjectComposer : HitObjectComposer<OsuHitObject>
|
||||||
{
|
{
|
||||||
public OsuHitObjectComposer(Ruleset ruleset)
|
public OsuHitObjectComposer(Ruleset ruleset)
|
||||||
: base(ruleset)
|
: base(ruleset)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override EditRulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) => new OsuEditRulesetContainer(ruleset, beatmap);
|
protected override RulesetContainer<OsuHitObject> CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap)
|
||||||
|
=> new OsuEditRulesetContainer(ruleset, beatmap);
|
||||||
|
|
||||||
protected override IReadOnlyList<HitObjectCompositionTool> CompositionTools => new[]
|
protected override IReadOnlyList<HitObjectCompositionTool> CompositionTools => new[]
|
||||||
{
|
{
|
||||||
|
@ -12,9 +12,10 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
{
|
{
|
||||||
public abstract class EditRulesetContainer : CompositeDrawable
|
public abstract class EditRulesetContainer : CompositeDrawable
|
||||||
{
|
{
|
||||||
public Playfield Playfield => RulesetContainer.Playfield;
|
/// <summary>
|
||||||
|
/// The <see cref="Playfield"/> contained by this <see cref="EditRulesetContainer"/>.
|
||||||
protected abstract RulesetContainer RulesetContainer { get; }
|
/// </summary>
|
||||||
|
public abstract Playfield Playfield { get; }
|
||||||
|
|
||||||
internal EditRulesetContainer()
|
internal EditRulesetContainer()
|
||||||
{
|
{
|
||||||
@ -29,21 +30,23 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
internal abstract DrawableHitObject Add(HitObject hitObject);
|
internal abstract DrawableHitObject Add(HitObject hitObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class EditRulesetContainer<TObject> : EditRulesetContainer
|
public class EditRulesetContainer<TObject> : EditRulesetContainer
|
||||||
where TObject : HitObject
|
where TObject : HitObject
|
||||||
{
|
{
|
||||||
private readonly Ruleset ruleset;
|
public override Playfield Playfield => rulesetContainer.Playfield;
|
||||||
|
|
||||||
private readonly RulesetContainer<TObject> rulesetContainer;
|
|
||||||
protected override RulesetContainer RulesetContainer => rulesetContainer;
|
|
||||||
|
|
||||||
|
private Ruleset ruleset => rulesetContainer.Ruleset;
|
||||||
private Beatmap<TObject> beatmap => rulesetContainer.Beatmap;
|
private Beatmap<TObject> beatmap => rulesetContainer.Beatmap;
|
||||||
|
|
||||||
protected EditRulesetContainer(Ruleset ruleset, WorkingBeatmap workingBeatmap)
|
private readonly RulesetContainer<TObject> rulesetContainer;
|
||||||
{
|
|
||||||
this.ruleset = ruleset;
|
|
||||||
|
|
||||||
InternalChild = rulesetContainer = CreateRulesetContainer(ruleset, workingBeatmap);
|
public EditRulesetContainer(RulesetContainer<TObject> rulesetContainer)
|
||||||
|
{
|
||||||
|
this.rulesetContainer = rulesetContainer;
|
||||||
|
|
||||||
|
InternalChild = rulesetContainer;
|
||||||
|
|
||||||
|
Playfield.DisplayJudgements.Value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override DrawableHitObject Add(HitObject hitObject)
|
internal override DrawableHitObject Add(HitObject hitObject)
|
||||||
@ -69,11 +72,5 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
|
|
||||||
return drawableObject;
|
return drawableObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates the underlying <see cref="RulesetContainer"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
protected abstract RulesetContainer<TObject> CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap workingBeatmap);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,23 +23,24 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
{
|
{
|
||||||
public abstract class HitObjectComposer : CompositeDrawable
|
public abstract class HitObjectComposer : CompositeDrawable
|
||||||
{
|
{
|
||||||
private readonly Ruleset ruleset;
|
|
||||||
|
|
||||||
public IEnumerable<DrawableHitObject> HitObjects => rulesetContainer.Playfield.AllHitObjects;
|
public IEnumerable<DrawableHitObject> HitObjects => rulesetContainer.Playfield.AllHitObjects;
|
||||||
|
|
||||||
|
protected readonly Ruleset Ruleset;
|
||||||
|
|
||||||
|
protected readonly IBindable<WorkingBeatmap> Beatmap = new Bindable<WorkingBeatmap>();
|
||||||
|
|
||||||
protected IRulesetConfigManager Config { get; private set; }
|
protected IRulesetConfigManager Config { get; private set; }
|
||||||
|
|
||||||
private readonly List<Container> layerContainers = new List<Container>();
|
private readonly List<Container> layerContainers = new List<Container>();
|
||||||
private readonly IBindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
|
||||||
|
|
||||||
private EditRulesetContainer rulesetContainer;
|
private EditRulesetContainer rulesetContainer;
|
||||||
|
|
||||||
private HitObjectMaskLayer maskLayer;
|
private HitObjectMaskLayer maskLayer;
|
||||||
private PlacementContainer placementContainer;
|
private PlacementContainer placementContainer;
|
||||||
|
|
||||||
protected HitObjectComposer(Ruleset ruleset)
|
internal HitObjectComposer(Ruleset ruleset)
|
||||||
{
|
{
|
||||||
this.ruleset = ruleset;
|
Ruleset = ruleset;
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
}
|
}
|
||||||
@ -47,11 +48,11 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(IBindableBeatmap beatmap, IFrameBasedClock framedClock)
|
private void load(IBindableBeatmap beatmap, IFrameBasedClock framedClock)
|
||||||
{
|
{
|
||||||
this.beatmap.BindTo(beatmap);
|
Beatmap.BindTo(beatmap);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
rulesetContainer = CreateRulesetContainer(ruleset, beatmap.Value);
|
rulesetContainer = CreateRulesetContainer();
|
||||||
rulesetContainer.Clock = framedClock;
|
rulesetContainer.Clock = framedClock;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -126,18 +127,11 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||||
|
|
||||||
dependencies.CacheAs(this);
|
dependencies.CacheAs(this);
|
||||||
Config = dependencies.Get<RulesetConfigCache>().GetConfigFor(ruleset);
|
Config = dependencies.Get<RulesetConfigCache>().GetConfigFor(Ruleset);
|
||||||
|
|
||||||
return dependencies;
|
return dependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
|
||||||
{
|
|
||||||
base.LoadComplete();
|
|
||||||
|
|
||||||
rulesetContainer.Playfield.DisplayJudgements.Value = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void UpdateAfterChildren()
|
protected override void UpdateAfterChildren()
|
||||||
{
|
{
|
||||||
base.UpdateAfterChildren();
|
base.UpdateAfterChildren();
|
||||||
@ -152,12 +146,12 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a <see cref="HitObject"/> to the <see cref="Beatmap"/> and visualises it.
|
/// Adds a <see cref="HitObject"/> to the <see cref="Beatmaps.Beatmap"/> and visualises it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="hitObject">The <see cref="HitObject"/> to add.</param>
|
/// <param name="hitObject">The <see cref="HitObject"/> to add.</param>
|
||||||
public void Add(HitObject hitObject) => maskLayer.AddMaskFor(rulesetContainer.Add(hitObject));
|
public void Add(HitObject hitObject) => maskLayer.AddMaskFor(rulesetContainer.Add(hitObject));
|
||||||
|
|
||||||
protected abstract EditRulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap);
|
internal abstract EditRulesetContainer CreateRulesetContainer();
|
||||||
|
|
||||||
protected abstract IReadOnlyList<HitObjectCompositionTool> CompositionTools { get; }
|
protected abstract IReadOnlyList<HitObjectCompositionTool> CompositionTools { get; }
|
||||||
|
|
||||||
@ -178,4 +172,18 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual Container CreateLayerContainer() => new Container { RelativeSizeAxes = Axes.Both };
|
protected virtual Container CreateLayerContainer() => new Container { RelativeSizeAxes = Axes.Both };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract class HitObjectComposer<TObject> : HitObjectComposer
|
||||||
|
where TObject : HitObject
|
||||||
|
{
|
||||||
|
protected HitObjectComposer(Ruleset ruleset)
|
||||||
|
: base(ruleset)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override EditRulesetContainer CreateRulesetContainer()
|
||||||
|
=> new EditRulesetContainer<TObject>(CreateRulesetContainer(Ruleset, Beatmap.Value));
|
||||||
|
|
||||||
|
protected abstract RulesetContainer<TObject> CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ namespace osu.Game.Rulesets.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly CursorContainer Cursor;
|
public readonly CursorContainer Cursor;
|
||||||
|
|
||||||
protected readonly Ruleset Ruleset;
|
public readonly Ruleset Ruleset;
|
||||||
|
|
||||||
protected IRulesetConfigManager Config { get; private set; }
|
protected IRulesetConfigManager Config { get; private set; }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user