2019-01-24 16:43:03 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-11-14 17:34:13 +08:00
|
|
|
using osu.Framework.Input;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Framework.Logging;
|
|
|
|
using osu.Framework.Timing;
|
|
|
|
using osu.Game.Beatmaps;
|
2018-07-17 15:53:32 +08:00
|
|
|
using osu.Game.Rulesets.Configuration;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Game.Rulesets.Edit.Tools;
|
2019-04-08 17:32:05 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2018-10-17 16:41:17 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.UI;
|
2019-08-29 11:43:43 +08:00
|
|
|
using osu.Game.Screens.Edit;
|
2018-11-06 17:14:46 +08:00
|
|
|
using osu.Game.Screens.Edit.Components.RadioButtons;
|
2019-08-29 15:06:40 +08:00
|
|
|
using osu.Game.Screens.Edit.Compose;
|
2018-11-06 17:28:22 +08:00
|
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Edit
|
|
|
|
{
|
2019-08-29 17:02:50 +08:00
|
|
|
[Cached(Type = typeof(IPlacementHandler))]
|
|
|
|
public abstract class HitObjectComposer<TObject> : HitObjectComposer, IPlacementHandler
|
|
|
|
where TObject : HitObject
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2018-07-17 15:53:32 +08:00
|
|
|
protected IRulesetConfigManager Config { get; private set; }
|
2019-08-29 17:02:50 +08:00
|
|
|
protected DrawableEditRuleset DrawableRuleset { get; private set; }
|
2018-07-17 15:53:32 +08:00
|
|
|
|
2019-08-29 17:02:50 +08:00
|
|
|
protected readonly Ruleset Ruleset;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-08-29 17:02:50 +08:00
|
|
|
private IBindable<WorkingBeatmap> workingBeatmap;
|
|
|
|
private Beatmap<TObject> playableBeatmap;
|
|
|
|
private EditorBeatmap<TObject> editorBeatmap;
|
|
|
|
private IBeatmapProcessor beatmapProcessor;
|
2018-07-19 16:04:51 +08:00
|
|
|
|
2018-11-06 16:36:10 +08:00
|
|
|
private BlueprintContainer blueprintContainer;
|
2019-08-29 17:02:50 +08:00
|
|
|
private readonly List<Container> layerContainers = new List<Container>();
|
2018-10-17 14:46:30 +08:00
|
|
|
|
2018-11-14 17:34:13 +08:00
|
|
|
private InputManager inputManager;
|
|
|
|
|
2019-08-29 17:02:50 +08:00
|
|
|
protected HitObjectComposer(Ruleset ruleset)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2018-10-17 17:01:38 +08:00
|
|
|
Ruleset = ruleset;
|
2018-04-13 17:19:50 +08:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2019-08-29 17:02:50 +08:00
|
|
|
private void load(IFrameBasedClock framedClock)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2019-08-29 17:02:50 +08:00
|
|
|
DrawableRuleset = new DrawableEditRuleset<TObject>(CreateDrawableRuleset(Ruleset, workingBeatmap.Value, Array.Empty<Mod>()))
|
|
|
|
{
|
|
|
|
Clock = framedClock
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Logger.Error(e, "Could not load beatmap sucessfully!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-01 09:39:55 +08:00
|
|
|
var layerBelowRuleset = DrawableRuleset.CreatePlayfieldAdjustmentContainer();
|
2018-11-06 17:10:46 +08:00
|
|
|
layerBelowRuleset.Child = new EditorPlayfieldBorder { RelativeSizeAxes = Axes.Both };
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-04-01 09:39:55 +08:00
|
|
|
var layerAboveRuleset = DrawableRuleset.CreatePlayfieldAdjustmentContainer();
|
2018-11-09 10:36:06 +08:00
|
|
|
layerAboveRuleset.Child = blueprintContainer = new BlueprintContainer();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
layerContainers.Add(layerBelowRuleset);
|
|
|
|
layerContainers.Add(layerAboveRuleset);
|
|
|
|
|
|
|
|
RadioButtonCollection toolboxCollection;
|
|
|
|
InternalChild = new GridContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
Name = "Sidebar",
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding { Right = 10 },
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new ToolboxGroup { Child = toolboxCollection = new RadioButtonCollection { RelativeSizeAxes = Axes.X } }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Name = "Content",
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
layerBelowRuleset,
|
2019-03-19 22:44:15 +08:00
|
|
|
DrawableRuleset,
|
2018-04-13 17:19:50 +08:00
|
|
|
layerAboveRuleset
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ColumnDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(GridSizeMode.Absolute, 200),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
toolboxCollection.Items =
|
2018-11-06 17:02:55 +08:00
|
|
|
CompositionTools.Select(t => new RadioButton(t.Name, () => blueprintContainer.CurrentTool = t))
|
2019-02-28 12:31:40 +08:00
|
|
|
.Prepend(new RadioButton("Select", () => blueprintContainer.CurrentTool = null))
|
|
|
|
.ToList();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
toolboxCollection.Items[0].Select();
|
|
|
|
}
|
|
|
|
|
2019-08-29 17:02:50 +08:00
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
2018-11-14 17:34:13 +08:00
|
|
|
{
|
2019-08-29 17:02:50 +08:00
|
|
|
workingBeatmap = parent.Get<IBindable<WorkingBeatmap>>().GetBoundCopy();
|
|
|
|
playableBeatmap = (Beatmap<TObject>)workingBeatmap.Value.GetPlayableBeatmap(Ruleset.RulesetInfo, Array.Empty<Mod>());
|
2018-11-14 17:34:13 +08:00
|
|
|
|
2019-08-29 17:02:50 +08:00
|
|
|
beatmapProcessor = Ruleset.CreateBeatmapProcessor(playableBeatmap);
|
2018-11-14 17:34:13 +08:00
|
|
|
|
2019-08-29 17:02:50 +08:00
|
|
|
editorBeatmap = new EditorBeatmap<TObject>(playableBeatmap);
|
|
|
|
editorBeatmap.HitObjectAdded += addHitObject;
|
|
|
|
editorBeatmap.HitObjectRemoved += removeHitObject;
|
|
|
|
|
|
|
|
var dependencies = new DependencyContainer(parent);
|
|
|
|
dependencies.CacheAs<IEditorBeatmap>(editorBeatmap);
|
|
|
|
dependencies.CacheAs<IEditorBeatmap<TObject>>(editorBeatmap);
|
2018-07-17 15:53:32 +08:00
|
|
|
|
2018-10-17 17:01:38 +08:00
|
|
|
Config = dependencies.Get<RulesetConfigCache>().GetConfigFor(Ruleset);
|
2018-07-17 15:53:32 +08:00
|
|
|
|
2019-08-29 17:02:50 +08:00
|
|
|
return base.CreateChildDependencies(dependencies);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
inputManager = GetContainingInputManager();
|
2018-07-17 14:35:32 +08:00
|
|
|
}
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
{
|
|
|
|
base.UpdateAfterChildren();
|
|
|
|
|
|
|
|
layerContainers.ForEach(l =>
|
|
|
|
{
|
2019-03-19 22:44:15 +08:00
|
|
|
l.Anchor = DrawableRuleset.Playfield.Anchor;
|
|
|
|
l.Origin = DrawableRuleset.Playfield.Origin;
|
|
|
|
l.Position = DrawableRuleset.Playfield.Position;
|
|
|
|
l.Size = DrawableRuleset.Playfield.Size;
|
2018-04-13 17:19:50 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-08-29 15:06:40 +08:00
|
|
|
private void addHitObject(HitObject hitObject)
|
|
|
|
{
|
2019-08-29 16:21:52 +08:00
|
|
|
beatmapProcessor?.PreProcess();
|
2019-08-29 15:06:40 +08:00
|
|
|
hitObject.ApplyDefaults(playableBeatmap.ControlPointInfo, playableBeatmap.BeatmapInfo.BaseDifficulty);
|
2019-08-29 16:21:52 +08:00
|
|
|
beatmapProcessor?.PostProcess();
|
2019-08-29 15:06:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void removeHitObject(HitObject hitObject)
|
|
|
|
{
|
2019-08-29 16:21:52 +08:00
|
|
|
beatmapProcessor?.PreProcess();
|
|
|
|
beatmapProcessor?.PostProcess();
|
2019-08-29 11:43:43 +08:00
|
|
|
}
|
|
|
|
|
2019-08-29 17:02:50 +08:00
|
|
|
public override IEnumerable<DrawableHitObject> HitObjects => DrawableRuleset.Playfield.AllHitObjects;
|
|
|
|
public override bool CursorInPlacementArea => DrawableRuleset.Playfield.ReceivePositionalInputAt(inputManager.CurrentState.Mouse.Position);
|
|
|
|
|
|
|
|
protected abstract IReadOnlyList<HitObjectCompositionTool> CompositionTools { get; }
|
2018-10-17 17:01:38 +08:00
|
|
|
|
2019-04-10 16:13:12 +08:00
|
|
|
protected abstract DrawableRuleset<TObject> CreateDrawableRuleset(Ruleset ruleset, WorkingBeatmap beatmap, IReadOnlyList<Mod> mods);
|
2019-08-29 15:06:40 +08:00
|
|
|
|
|
|
|
public void BeginPlacement(HitObject hitObject)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void EndPlacement(HitObject hitObject) => editorBeatmap.Add(hitObject);
|
|
|
|
|
|
|
|
public void Delete(HitObject hitObject) => editorBeatmap.Remove(hitObject);
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
if (editorBeatmap != null)
|
|
|
|
{
|
|
|
|
editorBeatmap.HitObjectAdded -= addHitObject;
|
|
|
|
editorBeatmap.HitObjectRemoved -= removeHitObject;
|
|
|
|
}
|
|
|
|
}
|
2018-10-17 17:01:38 +08:00
|
|
|
}
|
2019-08-29 17:02:50 +08:00
|
|
|
|
|
|
|
[Cached(typeof(HitObjectComposer))]
|
|
|
|
public abstract class HitObjectComposer : CompositeDrawable
|
|
|
|
{
|
|
|
|
internal HitObjectComposer()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// All the <see cref="DrawableHitObject"/>s.
|
|
|
|
/// </summary>
|
|
|
|
public abstract IEnumerable<DrawableHitObject> HitObjects { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Whether the user's cursor is currently in an area of the <see cref="HitObjectComposer"/> that is valid for placement.
|
|
|
|
/// </summary>
|
|
|
|
public abstract bool CursorInPlacementArea { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a <see cref="SelectionBlueprint"/> for a specific <see cref="DrawableHitObject"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="hitObject">The <see cref="DrawableHitObject"/> to create the overlay for.</param>
|
|
|
|
public virtual SelectionBlueprint CreateBlueprintFor(DrawableHitObject hitObject) => null;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a <see cref="SelectionHandler"/> which outlines <see cref="DrawableHitObject"/>s and handles movement of selections.
|
|
|
|
/// </summary>
|
|
|
|
public virtual SelectionHandler CreateSelectionHandler() => new SelectionHandler();
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|