mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 01:43:15 +08:00
Implement an intermediary EditRulesetContainer
This commit is contained in:
parent
10d0e2fef1
commit
540a010fbb
@ -34,7 +34,7 @@ namespace osu.Game.Rulesets.Catch.UI
|
||||
|
||||
protected override Vector2 PlayfieldArea => new Vector2(0.86f); // matches stable's vertical offset for catcher plate
|
||||
|
||||
protected override DrawableHitObject<CatchHitObject> GetVisualRepresentation(CatchHitObject h)
|
||||
public override DrawableHitObject<CatchHitObject> GetVisualRepresentation(CatchHitObject h)
|
||||
{
|
||||
switch (h)
|
||||
{
|
||||
|
@ -4,24 +4,37 @@
|
||||
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 : ManiaRulesetContainer
|
||||
public class ManiaEditRulesetContainer : EditRulesetContainer<ManiaHitObject>
|
||||
{
|
||||
public ManiaEditRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap)
|
||||
: base(ruleset, beatmap)
|
||||
public ManiaEditRulesetContainer(Ruleset ruleset, WorkingBeatmap workingBeatmap)
|
||||
: base(ruleset, workingBeatmap)
|
||||
{
|
||||
}
|
||||
|
||||
protected override Playfield CreatePlayfield() => new ManiaEditPlayfield(Beatmap.Stages)
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
};
|
||||
protected override RulesetContainer<ManiaHitObject> CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap workingBeatmap)
|
||||
=> new RulesetContainer(ruleset, workingBeatmap);
|
||||
|
||||
protected override Vector2 PlayfieldArea => Vector2.One;
|
||||
private new class RulesetContainer : ManiaRulesetContainer
|
||||
{
|
||||
public RulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap)
|
||||
: base(ruleset, beatmap)
|
||||
{
|
||||
}
|
||||
|
||||
protected override Playfield CreatePlayfield() => new ManiaEditPlayfield(Beatmap.Stages)
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
};
|
||||
|
||||
protected override Vector2 PlayfieldArea => Vector2.One;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ using osu.Game.Rulesets.Edit.Tools;
|
||||
using osu.Game.Rulesets.Mania.Objects;
|
||||
using osu.Game.Rulesets.Mania.Objects.Drawables;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Rulesets.Mania.Configuration;
|
||||
@ -32,7 +31,7 @@ namespace osu.Game.Rulesets.Mania.Edit
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
protected override RulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) => new ManiaEditRulesetContainer(ruleset, beatmap);
|
||||
protected override EditRulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) => new ManiaEditRulesetContainer(ruleset, beatmap);
|
||||
|
||||
protected override IReadOnlyList<ICompositionTool> CompositionTools => new ICompositionTool[]
|
||||
{
|
||||
|
@ -97,7 +97,7 @@ namespace osu.Game.Rulesets.Mania.UI
|
||||
|
||||
public override PassThroughInputManager CreateInputManager() => new ManiaInputManager(Ruleset.RulesetInfo, Variant);
|
||||
|
||||
protected override DrawableHitObject<ManiaHitObject> GetVisualRepresentation(ManiaHitObject h)
|
||||
public override DrawableHitObject<ManiaHitObject> GetVisualRepresentation(ManiaHitObject h)
|
||||
{
|
||||
switch (h)
|
||||
{
|
||||
|
@ -3,20 +3,34 @@
|
||||
|
||||
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 : OsuRulesetContainer
|
||||
public class OsuEditRulesetContainer : EditRulesetContainer<OsuHitObject>
|
||||
{
|
||||
public OsuEditRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap)
|
||||
: base(ruleset, beatmap)
|
||||
public OsuEditRulesetContainer(Ruleset ruleset, WorkingBeatmap workingBeatmap)
|
||||
: base(ruleset, workingBeatmap)
|
||||
{
|
||||
}
|
||||
|
||||
protected override Vector2 PlayfieldArea => Vector2.One;
|
||||
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 Vector2 PlayfieldArea => Vector2.One;
|
||||
|
||||
protected override CursorContainer CreateCursor() => null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Edit.Tools;
|
||||
@ -22,7 +23,7 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
{
|
||||
}
|
||||
|
||||
protected override RulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) => new OsuEditRulesetContainer(ruleset, beatmap);
|
||||
protected override EditRulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) => new OsuEditRulesetContainer(ruleset, beatmap);
|
||||
|
||||
protected override IReadOnlyList<ICompositionTool> CompositionTools => new ICompositionTool[]
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ namespace osu.Game.Rulesets.Osu.UI
|
||||
|
||||
public override PassThroughInputManager CreateInputManager() => new OsuInputManager(Ruleset.RulesetInfo);
|
||||
|
||||
protected override DrawableHitObject<OsuHitObject> GetVisualRepresentation(OsuHitObject h)
|
||||
public override DrawableHitObject<OsuHitObject> GetVisualRepresentation(OsuHitObject h)
|
||||
{
|
||||
switch (h)
|
||||
{
|
||||
|
@ -96,7 +96,7 @@ namespace osu.Game.Rulesets.Taiko.UI
|
||||
Origin = Anchor.CentreLeft
|
||||
};
|
||||
|
||||
protected override DrawableHitObject<TaikoHitObject> GetVisualRepresentation(TaikoHitObject h)
|
||||
public override DrawableHitObject<TaikoHitObject> GetVisualRepresentation(TaikoHitObject h)
|
||||
{
|
||||
switch (h)
|
||||
{
|
||||
|
67
osu.Game/Rulesets/Edit/EditRulesetContainer.cs
Normal file
67
osu.Game/Rulesets/Edit/EditRulesetContainer.cs
Normal file
@ -0,0 +1,67 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.UI;
|
||||
|
||||
namespace osu.Game.Rulesets.Edit
|
||||
{
|
||||
public abstract class EditRulesetContainer : CompositeDrawable
|
||||
{
|
||||
public Playfield Playfield => RulesetContainer.Playfield;
|
||||
|
||||
protected abstract RulesetContainer RulesetContainer { get; }
|
||||
|
||||
internal EditRulesetContainer()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
}
|
||||
|
||||
public abstract void AddHitObject(HitObject hitObject);
|
||||
}
|
||||
|
||||
public abstract class EditRulesetContainer<TObject> : EditRulesetContainer
|
||||
where TObject : HitObject
|
||||
{
|
||||
private readonly Ruleset ruleset;
|
||||
|
||||
private readonly RulesetContainer<TObject> rulesetContainer;
|
||||
protected override RulesetContainer RulesetContainer => rulesetContainer;
|
||||
|
||||
private Beatmap<TObject> beatmap => rulesetContainer.Beatmap;
|
||||
|
||||
protected EditRulesetContainer(Ruleset ruleset, WorkingBeatmap workingBeatmap)
|
||||
{
|
||||
this.ruleset = ruleset;
|
||||
|
||||
InternalChild = rulesetContainer = CreateRulesetContainer(ruleset, workingBeatmap);
|
||||
}
|
||||
|
||||
public override void AddHitObject(HitObject hitObject)
|
||||
{
|
||||
var tObject = (TObject)hitObject;
|
||||
|
||||
// Insert into beatmap while maintaining sorting order
|
||||
var insertionIndex = beatmap.HitObjects.FindLastIndex(h => h.StartTime <= hitObject.StartTime);
|
||||
beatmap.HitObjects.Insert(insertionIndex + 1, tObject);
|
||||
|
||||
var processor = ruleset.CreateBeatmapProcessor(beatmap);
|
||||
|
||||
processor.PreProcess();
|
||||
tObject.ApplyDefaults(beatmap.ControlPointInfo, beatmap.BeatmapInfo.BaseDifficulty);
|
||||
processor.PostProcess();
|
||||
|
||||
rulesetContainer.Playfield.Add(rulesetContainer.GetVisualRepresentation(tObject));
|
||||
rulesetContainer.Playfield.PostProcess();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the underlying <see cref="RulesetContainer"/>.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract RulesetContainer<TObject> CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap workingBeatmap);
|
||||
}
|
||||
}
|
@ -32,7 +32,7 @@ namespace osu.Game.Rulesets.Edit
|
||||
private readonly List<Container> layerContainers = new List<Container>();
|
||||
private readonly IBindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
||||
|
||||
private RulesetContainer rulesetContainer;
|
||||
private EditRulesetContainer rulesetContainer;
|
||||
|
||||
protected HitObjectComposer(Ruleset ruleset)
|
||||
{
|
||||
@ -146,7 +146,7 @@ namespace osu.Game.Rulesets.Edit
|
||||
|
||||
private void setCompositionTool(ICompositionTool tool) => CurrentTool = tool;
|
||||
|
||||
protected virtual RulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) => ruleset.CreateRulesetContainerWith(beatmap);
|
||||
protected abstract EditRulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap);
|
||||
|
||||
protected abstract IReadOnlyList<ICompositionTool> CompositionTools { get; }
|
||||
|
||||
|
@ -291,17 +291,7 @@ namespace osu.Game.Rulesets.UI
|
||||
private void loadObjects()
|
||||
{
|
||||
foreach (TObject h in Beatmap.HitObjects)
|
||||
{
|
||||
var drawableObject = GetVisualRepresentation(h);
|
||||
|
||||
if (drawableObject == null)
|
||||
continue;
|
||||
|
||||
drawableObject.OnNewResult += (_, r) => OnNewResult?.Invoke(r);
|
||||
drawableObject.OnRevertResult += (_, r) => OnRevertResult?.Invoke(r);
|
||||
|
||||
Playfield.Add(drawableObject);
|
||||
}
|
||||
AddRepresentation(h);
|
||||
|
||||
Playfield.PostProcess();
|
||||
|
||||
@ -309,6 +299,23 @@ namespace osu.Game.Rulesets.UI
|
||||
mod.ApplyToDrawableHitObjects(Playfield.HitObjectContainer.Objects);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and adds the visual representation of a <see cref="TObject"/> to this <see cref="RulesetContainer{TObject}"/>.
|
||||
/// </summary>
|
||||
/// <param name="hitObject">The <see cref="TObject"/> to add the visual representation for.</param>
|
||||
internal void AddRepresentation(TObject hitObject)
|
||||
{
|
||||
var drawableObject = GetVisualRepresentation(hitObject);
|
||||
|
||||
if (drawableObject == null)
|
||||
return;
|
||||
|
||||
drawableObject.OnNewResult += (_, r) => OnNewResult?.Invoke(r);
|
||||
drawableObject.OnRevertResult += (_, r) => OnRevertResult?.Invoke(r);
|
||||
|
||||
Playfield.Add(drawableObject);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
@ -334,7 +341,7 @@ namespace osu.Game.Rulesets.UI
|
||||
/// </summary>
|
||||
/// <param name="h">The HitObject to make drawable.</param>
|
||||
/// <returns>The DrawableHitObject.</returns>
|
||||
protected abstract DrawableHitObject<TObject> GetVisualRepresentation(TObject h);
|
||||
public abstract DrawableHitObject<TObject> GetVisualRepresentation(TObject h);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user