mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 22:02:56 +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 OpenTK;
|
||||
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.UI;
|
||||
|
||||
namespace osu.Game.Rulesets.Mania.Edit
|
||||
{
|
||||
public class ManiaEditRulesetContainer : EditRulesetContainer<ManiaHitObject>
|
||||
public class ManiaEditRulesetContainer : ManiaRulesetContainer
|
||||
{
|
||||
public ManiaEditRulesetContainer(Ruleset ruleset, WorkingBeatmap workingBeatmap)
|
||||
: base(ruleset, workingBeatmap)
|
||||
public ManiaEditRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap)
|
||||
: base(ruleset, beatmap)
|
||||
{
|
||||
}
|
||||
|
||||
protected override RulesetContainer<ManiaHitObject> CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap workingBeatmap)
|
||||
=> new RulesetContainer(ruleset, workingBeatmap);
|
||||
|
||||
private new class RulesetContainer : ManiaRulesetContainer
|
||||
protected override Playfield CreatePlayfield() => new ManiaEditPlayfield(Beatmap.Stages)
|
||||
{
|
||||
public RulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap)
|
||||
: base(ruleset, beatmap)
|
||||
{
|
||||
}
|
||||
|
||||
protected override Playfield CreatePlayfield() => new ManiaEditPlayfield(Beatmap.Stages)
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = Vector2.One
|
||||
};
|
||||
}
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = Vector2.One
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,13 @@ using System.Collections.Generic;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Rulesets.Mania.Configuration;
|
||||
using osu.Game.Rulesets.Mania.Edit.Masks;
|
||||
using osu.Game.Rulesets.Mania.Objects;
|
||||
using osu.Game.Rulesets.Mania.UI;
|
||||
using osu.Game.Rulesets.UI;
|
||||
|
||||
namespace osu.Game.Rulesets.Mania.Edit
|
||||
{
|
||||
public class ManiaHitObjectComposer : HitObjectComposer
|
||||
public class ManiaHitObjectComposer : HitObjectComposer<ManiaHitObject>
|
||||
{
|
||||
protected new ManiaConfigManager Config => (ManiaConfigManager)base.Config;
|
||||
|
||||
@ -31,7 +33,8 @@ namespace osu.Game.Rulesets.Mania.Edit
|
||||
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>();
|
||||
|
||||
|
@ -3,34 +3,21 @@
|
||||
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
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.UI;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Edit
|
||||
{
|
||||
public class OsuEditRulesetContainer : EditRulesetContainer<OsuHitObject>
|
||||
public class OsuEditRulesetContainer : OsuRulesetContainer
|
||||
{
|
||||
public OsuEditRulesetContainer(Ruleset ruleset, WorkingBeatmap workingBeatmap)
|
||||
: base(ruleset, workingBeatmap)
|
||||
public OsuEditRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap)
|
||||
: base(ruleset, beatmap)
|
||||
{
|
||||
}
|
||||
|
||||
protected override RulesetContainer<OsuHitObject> CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap workingBeatmap)
|
||||
=> new RulesetContainer(ruleset, workingBeatmap);
|
||||
protected override CursorContainer CreateCursor() => null;
|
||||
|
||||
private new class RulesetContainer : OsuRulesetContainer
|
||||
{
|
||||
public RulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap)
|
||||
: base(ruleset, beatmap)
|
||||
{
|
||||
}
|
||||
|
||||
protected override CursorContainer CreateCursor() => null;
|
||||
|
||||
protected override Playfield CreatePlayfield() => new OsuPlayfield { Size = Vector2.One };
|
||||
}
|
||||
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.Objects.Drawables;
|
||||
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.UI;
|
||||
using osu.Game.Rulesets.UI;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Edit
|
||||
{
|
||||
public class OsuHitObjectComposer : HitObjectComposer
|
||||
public class OsuHitObjectComposer : HitObjectComposer<OsuHitObject>
|
||||
{
|
||||
public OsuHitObjectComposer(Ruleset 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[]
|
||||
{
|
||||
|
@ -12,9 +12,10 @@ namespace osu.Game.Rulesets.Edit
|
||||
{
|
||||
public abstract class EditRulesetContainer : CompositeDrawable
|
||||
{
|
||||
public Playfield Playfield => RulesetContainer.Playfield;
|
||||
|
||||
protected abstract RulesetContainer RulesetContainer { get; }
|
||||
/// <summary>
|
||||
/// The <see cref="Playfield"/> contained by this <see cref="EditRulesetContainer"/>.
|
||||
/// </summary>
|
||||
public abstract Playfield Playfield { get; }
|
||||
|
||||
internal EditRulesetContainer()
|
||||
{
|
||||
@ -29,21 +30,23 @@ namespace osu.Game.Rulesets.Edit
|
||||
internal abstract DrawableHitObject Add(HitObject hitObject);
|
||||
}
|
||||
|
||||
public abstract class EditRulesetContainer<TObject> : EditRulesetContainer
|
||||
public class EditRulesetContainer<TObject> : EditRulesetContainer
|
||||
where TObject : HitObject
|
||||
{
|
||||
private readonly Ruleset ruleset;
|
||||
|
||||
private readonly RulesetContainer<TObject> rulesetContainer;
|
||||
protected override RulesetContainer RulesetContainer => rulesetContainer;
|
||||
public override Playfield Playfield => rulesetContainer.Playfield;
|
||||
|
||||
private Ruleset ruleset => rulesetContainer.Ruleset;
|
||||
private Beatmap<TObject> beatmap => rulesetContainer.Beatmap;
|
||||
|
||||
protected EditRulesetContainer(Ruleset ruleset, WorkingBeatmap workingBeatmap)
|
||||
{
|
||||
this.ruleset = ruleset;
|
||||
private readonly RulesetContainer<TObject> rulesetContainer;
|
||||
|
||||
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)
|
||||
@ -69,11 +72,5 @@ namespace osu.Game.Rulesets.Edit
|
||||
|
||||
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
|
||||
{
|
||||
private readonly Ruleset ruleset;
|
||||
|
||||
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; }
|
||||
|
||||
private readonly List<Container> layerContainers = new List<Container>();
|
||||
private readonly IBindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
||||
|
||||
private EditRulesetContainer rulesetContainer;
|
||||
|
||||
private HitObjectMaskLayer maskLayer;
|
||||
private PlacementContainer placementContainer;
|
||||
|
||||
protected HitObjectComposer(Ruleset ruleset)
|
||||
internal HitObjectComposer(Ruleset ruleset)
|
||||
{
|
||||
this.ruleset = ruleset;
|
||||
Ruleset = ruleset;
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
}
|
||||
@ -47,11 +48,11 @@ namespace osu.Game.Rulesets.Edit
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(IBindableBeatmap beatmap, IFrameBasedClock framedClock)
|
||||
{
|
||||
this.beatmap.BindTo(beatmap);
|
||||
Beatmap.BindTo(beatmap);
|
||||
|
||||
try
|
||||
{
|
||||
rulesetContainer = CreateRulesetContainer(ruleset, beatmap.Value);
|
||||
rulesetContainer = CreateRulesetContainer();
|
||||
rulesetContainer.Clock = framedClock;
|
||||
}
|
||||
catch (Exception e)
|
||||
@ -126,18 +127,11 @@ namespace osu.Game.Rulesets.Edit
|
||||
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||
|
||||
dependencies.CacheAs(this);
|
||||
Config = dependencies.Get<RulesetConfigCache>().GetConfigFor(ruleset);
|
||||
Config = dependencies.Get<RulesetConfigCache>().GetConfigFor(Ruleset);
|
||||
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
rulesetContainer.Playfield.DisplayJudgements.Value = false;
|
||||
}
|
||||
|
||||
protected override void UpdateAfterChildren()
|
||||
{
|
||||
base.UpdateAfterChildren();
|
||||
@ -152,12 +146,12 @@ namespace osu.Game.Rulesets.Edit
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// <param name="hitObject">The <see cref="HitObject"/> to add.</param>
|
||||
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; }
|
||||
|
||||
@ -178,4 +172,18 @@ namespace osu.Game.Rulesets.Edit
|
||||
/// </summary>
|
||||
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>
|
||||
public readonly CursorContainer Cursor;
|
||||
|
||||
protected readonly Ruleset Ruleset;
|
||||
public readonly Ruleset Ruleset;
|
||||
|
||||
protected IRulesetConfigManager Config { get; private set; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user