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;
|
|
|
|
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;
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
using osu.Game.Screens.Edit.Screens.Compose.Layers;
|
|
|
|
using osu.Game.Screens.Edit.Screens.Compose.RadioButtons;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Edit
|
|
|
|
{
|
|
|
|
public abstract class HitObjectComposer : CompositeDrawable
|
|
|
|
{
|
|
|
|
private readonly Ruleset ruleset;
|
|
|
|
|
2018-07-19 16:04:51 +08:00
|
|
|
public IEnumerable<DrawableHitObject> HitObjects => rulesetContainer.Playfield.AllHitObjects;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-07-19 16:04:51 +08:00
|
|
|
protected ICompositionTool CurrentTool { get; private set; }
|
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-05-23 16:37:39 +08:00
|
|
|
private readonly IBindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-07-19 16:04:51 +08:00
|
|
|
private RulesetContainer rulesetContainer;
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
protected HitObjectComposer(Ruleset ruleset)
|
|
|
|
{
|
|
|
|
this.ruleset = ruleset;
|
|
|
|
|
|
|
|
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-05-23 16:37:39 +08:00
|
|
|
this.beatmap.BindTo(beatmap);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2018-07-19 16:04:51 +08:00
|
|
|
rulesetContainer = CreateRulesetContainer(ruleset, beatmap.Value);
|
|
|
|
rulesetContainer.Clock = framedClock;
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Logger.Error(e, "Could not load beatmap sucessfully!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var layerBelowRuleset = new BorderLayer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Child = CreateLayerContainer()
|
|
|
|
};
|
|
|
|
|
|
|
|
var layerAboveRuleset = CreateLayerContainer();
|
2018-07-19 16:04:51 +08:00
|
|
|
layerAboveRuleset.Child = new HitObjectMaskLayer();
|
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-07-19 16:04:51 +08:00
|
|
|
rulesetContainer,
|
2018-04-13 17:19:50 +08:00
|
|
|
layerAboveRuleset
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ColumnDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(GridSizeMode.Absolute, 200),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
toolboxCollection.Items =
|
|
|
|
CompositionTools.Select(t => new RadioButton(t.Name, () => setCompositionTool(t)))
|
|
|
|
.Prepend(new RadioButton("Select", () => setCompositionTool(null)))
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
toolboxCollection.Items[0].Select();
|
|
|
|
}
|
|
|
|
|
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-07-17 15:53:32 +08:00
|
|
|
Config = dependencies.Get<RulesetConfigCache>().GetConfigFor(ruleset);
|
|
|
|
|
2018-07-17 14:35:32 +08:00
|
|
|
return dependencies;
|
|
|
|
}
|
|
|
|
|
2018-07-20 16:04:33 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
rulesetContainer.Playfield.DisplayJudgements.Value = false;
|
|
|
|
}
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
{
|
|
|
|
base.UpdateAfterChildren();
|
|
|
|
|
|
|
|
layerContainers.ForEach(l =>
|
|
|
|
{
|
2018-07-19 16:04:51 +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
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setCompositionTool(ICompositionTool tool) => CurrentTool = tool;
|
|
|
|
|
2018-05-07 09:17:54 +08:00
|
|
|
protected virtual RulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) => ruleset.CreateRulesetContainerWith(beatmap);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
protected abstract IReadOnlyList<ICompositionTool> CompositionTools { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a <see cref="HitObjectMask"/> for a specific <see cref="DrawableHitObject"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="hitObject">The <see cref="DrawableHitObject"/> to create the overlay for.</param>
|
|
|
|
public virtual HitObjectMask CreateMaskFor(DrawableHitObject hitObject) => null;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a <see cref="MaskSelection"/> which outlines <see cref="DrawableHitObject"/>s
|
|
|
|
/// and handles hitobject pattern adjustments.
|
|
|
|
/// </summary>
|
|
|
|
public virtual MaskSelection CreateMaskSelection() => new MaskSelection();
|
|
|
|
|
|
|
|
/// <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
|
|
|
}
|
|
|
|
}
|