2018-04-13 17:19:50 +08:00
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
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;
|
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;
|
2018-11-06 17:14:46 +08:00
|
|
|
using osu.Game.Screens.Edit.Components.RadioButtons;
|
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
|
|
|
|
{
|
|
|
|
public abstract class HitObjectComposer : CompositeDrawable
|
|
|
|
{
|
2018-11-12 17:24:18 +08:00
|
|
|
public IEnumerable<DrawableHitObject> HitObjects => RulesetContainer.Playfield.AllHitObjects;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-10-17 17:01:38 +08:00
|
|
|
protected readonly Ruleset Ruleset;
|
|
|
|
|
|
|
|
protected readonly IBindable<WorkingBeatmap> Beatmap = new Bindable<WorkingBeatmap>();
|
|
|
|
|
2018-07-17 15:53:32 +08:00
|
|
|
protected IRulesetConfigManager Config { get; private set; }
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
private readonly List<Container> layerContainers = new List<Container>();
|
|
|
|
|
2018-11-12 17:24:18 +08:00
|
|
|
protected EditRulesetContainer RulesetContainer { get; private set; }
|
2018-07-19 16:04:51 +08:00
|
|
|
|
2018-11-06 16:36:10 +08:00
|
|
|
private BlueprintContainer blueprintContainer;
|
2018-10-17 14:46:30 +08:00
|
|
|
|
2018-11-14 17:34:13 +08:00
|
|
|
private InputManager inputManager;
|
|
|
|
|
2018-10-17 17:01:38 +08:00
|
|
|
internal 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]
|
2018-06-06 19:16:20 +08:00
|
|
|
private void load(IBindableBeatmap beatmap, IFrameBasedClock framedClock)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2018-10-17 17:01:38 +08:00
|
|
|
Beatmap.BindTo(beatmap);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2018-11-12 17:24:18 +08:00
|
|
|
RulesetContainer = CreateRulesetContainer();
|
|
|
|
RulesetContainer.Clock = framedClock;
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Logger.Error(e, "Could not load beatmap sucessfully!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-17 17:29:30 +08:00
|
|
|
var layerBelowRuleset = CreateLayerContainer();
|
2018-11-06 17:10:46 +08:00
|
|
|
layerBelowRuleset.Child = new EditorPlayfieldBorder { RelativeSizeAxes = Axes.Both };
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
var layerAboveRuleset = CreateLayerContainer();
|
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,
|
2018-11-12 17:24:18 +08:00
|
|
|
RulesetContainer,
|
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))
|
|
|
|
.Prepend(new RadioButton("Select", () => blueprintContainer.CurrentTool = null))
|
2018-04-13 17:19:50 +08:00
|
|
|
.ToList();
|
|
|
|
|
|
|
|
toolboxCollection.Items[0].Select();
|
|
|
|
}
|
|
|
|
|
2018-11-14 17:34:13 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
inputManager = GetContainingInputManager();
|
|
|
|
}
|
|
|
|
|
2018-07-17 14:35:32 +08:00
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
|
|
|
{
|
|
|
|
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
2018-07-17 15:53:32 +08:00
|
|
|
|
2018-07-17 14:35:32 +08:00
|
|
|
dependencies.CacheAs(this);
|
2018-10-17 17:01:38 +08:00
|
|
|
Config = dependencies.Get<RulesetConfigCache>().GetConfigFor(Ruleset);
|
2018-07-17 15:53:32 +08:00
|
|
|
|
2018-07-17 14:35:32 +08:00
|
|
|
return dependencies;
|
|
|
|
}
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
{
|
|
|
|
base.UpdateAfterChildren();
|
|
|
|
|
|
|
|
layerContainers.ForEach(l =>
|
|
|
|
{
|
2018-11-12 17:24:18 +08:00
|
|
|
l.Anchor = RulesetContainer.Playfield.Anchor;
|
|
|
|
l.Origin = RulesetContainer.Playfield.Origin;
|
|
|
|
l.Position = RulesetContainer.Playfield.Position;
|
|
|
|
l.Size = RulesetContainer.Playfield.Size;
|
2018-04-13 17:19:50 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-11-14 17:34:13 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether the user's cursor is currently in an area of the <see cref="HitObjectComposer"/> that is valid for placement.
|
|
|
|
/// </summary>
|
2018-11-15 19:56:34 +08:00
|
|
|
public virtual bool CursorInPlacementArea => RulesetContainer.Playfield.ReceivePositionalInputAt(inputManager.CurrentState.Mouse.Position);
|
2018-11-14 17:34:13 +08:00
|
|
|
|
2018-10-17 16:41:17 +08:00
|
|
|
/// <summary>
|
2018-10-17 17:01:38 +08:00
|
|
|
/// Adds a <see cref="HitObject"/> to the <see cref="Beatmaps.Beatmap"/> and visualises it.
|
2018-10-17 16:41:17 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="hitObject">The <see cref="HitObject"/> to add.</param>
|
2018-11-12 17:24:18 +08:00
|
|
|
public void Add(HitObject hitObject) => blueprintContainer.AddBlueprintFor(RulesetContainer.Add(hitObject));
|
2018-10-17 16:41:17 +08:00
|
|
|
|
2018-11-12 17:24:18 +08:00
|
|
|
public void Remove(HitObject hitObject) => blueprintContainer.RemoveBlueprintFor(RulesetContainer.Remove(hitObject));
|
2018-10-18 15:36:06 +08:00
|
|
|
|
2018-10-17 17:01:38 +08:00
|
|
|
internal abstract EditRulesetContainer CreateRulesetContainer();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-10-03 15:27:26 +08:00
|
|
|
protected abstract IReadOnlyList<HitObjectCompositionTool> CompositionTools { get; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2018-11-06 16:56:04 +08:00
|
|
|
/// Creates a <see cref="SelectionBlueprint"/> for a specific <see cref="DrawableHitObject"/>.
|
2018-04-13 17:19:50 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="hitObject">The <see cref="DrawableHitObject"/> to create the overlay for.</param>
|
2018-11-06 17:03:21 +08:00
|
|
|
public virtual SelectionBlueprint CreateBlueprintFor(DrawableHitObject hitObject) => null;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2018-11-19 15:58:11 +08:00
|
|
|
/// Creates a <see cref="SelectionHandler"/> which outlines <see cref="DrawableHitObject"/>s and handles movement of selections.
|
2018-04-13 17:19:50 +08:00
|
|
|
/// </summary>
|
2018-11-19 15:58:11 +08:00
|
|
|
public virtual SelectionHandler CreateSelectionHandler() => new SelectionHandler();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a <see cref="ScalableContainer"/> which provides a layer above or below the <see cref="Playfield"/>.
|
|
|
|
/// </summary>
|
2018-09-21 13:02:32 +08:00
|
|
|
protected virtual Container CreateLayerContainer() => new Container { RelativeSizeAxes = Axes.Both };
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
2018-10-17 17:01:38 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|