1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 07:27:25 +08:00
osu-lazer/osu.Game/Rulesets/Edit/HitObjectComposer.cs

150 lines
5.7 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-11-29 15:22:11 +08:00
// 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;
2017-11-30 18:19:34 +08:00
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit.Tools;
2018-03-14 14:18:21 +08:00
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.UI;
2018-03-14 14:18:21 +08:00
using osu.Game.Screens.Edit.Screens.Compose.Layers;
using osu.Game.Screens.Edit.Screens.Compose.RadioButtons;
2017-11-29 15:22:11 +08:00
namespace osu.Game.Rulesets.Edit
{
public abstract class HitObjectComposer : CompositeDrawable
2017-11-29 15:22:11 +08:00
{
private readonly Ruleset ruleset;
2017-11-30 20:56:12 +08:00
protected ICompositionTool CurrentTool { get; private set; }
private RulesetContainer rulesetContainer;
2018-02-22 12:42:31 +08:00
private readonly List<Container> layerContainers = new List<Container>();
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
2018-03-19 15:27:52 +08:00
protected HitObjectComposer(Ruleset ruleset)
{
this.ruleset = ruleset;
2018-03-15 16:19:47 +08:00
RelativeSizeAxes = Axes.Both;
}
2017-11-29 15:22:11 +08:00
[BackgroundDependencyLoader]
private void load(OsuGameBase osuGame, IFrameBasedClock framedClock)
{
beatmap.BindTo(osuGame.Beatmap);
try
{
rulesetContainer = CreateRulesetContainer(ruleset, beatmap.Value);
2018-03-15 16:19:47 +08:00
rulesetContainer.Clock = framedClock;
}
catch (Exception e)
{
Logger.Error(e, "Could not load beatmap sucessfully!");
return;
}
2018-02-23 14:29:56 +08:00
var layerBelowRuleset = new BorderLayer
{
RelativeSizeAxes = Axes.Both,
Child = CreateLayerContainer()
};
var layerAboveRuleset = CreateLayerContainer();
2018-04-12 12:35:53 +08:00
layerAboveRuleset.Child = new HitObjectMaskLayer(rulesetContainer.Playfield, this);
2018-02-23 14:29:56 +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[]
{
2018-02-23 14:29:56 +08:00
layerBelowRuleset,
rulesetContainer,
2018-02-23 14:29:56 +08:00
layerAboveRuleset
}
}
},
},
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.Absolute, 200),
}
};
toolboxCollection.Items =
2018-04-02 12:06:34 +08:00
CompositionTools.Select(t => new RadioButton(t.Name, () => setCompositionTool(t)))
.Prepend(new RadioButton("Select", () => setCompositionTool(null)))
.ToList();
toolboxCollection.Items[0].Select();
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
layerContainers.ForEach(l =>
{
l.Anchor = rulesetContainer.Playfield.Anchor;
l.Origin = rulesetContainer.Playfield.Origin;
l.Position = rulesetContainer.Playfield.Position;
l.Size = rulesetContainer.Playfield.Size;
});
}
2017-11-30 20:56:12 +08:00
private void setCompositionTool(ICompositionTool tool) => CurrentTool = tool;
2017-11-30 18:19:34 +08:00
protected virtual RulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) => ruleset.CreateRulesetContainerWith(beatmap, true);
protected abstract IReadOnlyList<ICompositionTool> CompositionTools { get; }
/// <summary>
2018-03-14 14:18:21 +08:00
/// Creates a <see cref="HitObjectMask"/> for a specific <see cref="DrawableHitObject"/>.
/// </summary>
2018-03-14 14:18:21 +08:00
/// <param name="hitObject">The <see cref="DrawableHitObject"/> to create the overlay for.</param>
public virtual HitObjectMask CreateMaskFor(DrawableHitObject hitObject) => null;
/// <summary>
2018-04-12 12:35:53 +08:00
/// Creates a <see cref="MaskSelection"/> which outlines <see cref="DrawableHitObject"/>s
/// and handles hitobject pattern adjustments.
/// </summary>
2018-04-12 12:35:53 +08:00
public virtual MaskSelection CreateMaskSelection() => new MaskSelection();
/// <summary>
2018-03-14 14:18:21 +08:00
/// Creates a <see cref="ScalableContainer"/> which provides a layer above or below the <see cref="Playfield"/>.
/// </summary>
2018-03-14 14:18:21 +08:00
protected virtual ScalableContainer CreateLayerContainer() => new ScalableContainer { RelativeSizeAxes = Axes.Both };
2017-11-29 15:22:11 +08:00
}
}