mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 10:52:53 +08:00
Merge PlacementContainer into BlueprintContainer
This commit is contained in:
parent
f2a5f28ea2
commit
90c813618a
@ -36,7 +36,6 @@ namespace osu.Game.Rulesets.Edit
|
||||
private EditRulesetContainer rulesetContainer;
|
||||
|
||||
private BlueprintContainer blueprintContainer;
|
||||
private PlacementContainer placementContainer;
|
||||
|
||||
internal HitObjectComposer(Ruleset ruleset)
|
||||
{
|
||||
@ -65,11 +64,7 @@ namespace osu.Game.Rulesets.Edit
|
||||
layerBelowRuleset.Child = new BorderLayer { RelativeSizeAxes = Axes.Both };
|
||||
|
||||
var layerAboveRuleset = CreateLayerContainer();
|
||||
layerAboveRuleset.Children = new Drawable[]
|
||||
{
|
||||
blueprintContainer = new BlueprintContainer(),
|
||||
placementContainer = new PlacementContainer(),
|
||||
};
|
||||
layerAboveRuleset.Child = new BlueprintContainer();
|
||||
|
||||
layerContainers.Add(layerBelowRuleset);
|
||||
layerContainers.Add(layerAboveRuleset);
|
||||
@ -112,8 +107,8 @@ namespace osu.Game.Rulesets.Edit
|
||||
};
|
||||
|
||||
toolboxCollection.Items =
|
||||
CompositionTools.Select(t => new RadioButton(t.Name, () => placementContainer.CurrentTool = t))
|
||||
.Prepend(new RadioButton("Select", () => placementContainer.CurrentTool = null))
|
||||
CompositionTools.Select(t => new RadioButton(t.Name, () => blueprintContainer.CurrentTool = t))
|
||||
.Prepend(new RadioButton("Select", () => blueprintContainer.CurrentTool = null))
|
||||
.ToList();
|
||||
|
||||
toolboxCollection.Items[0].Select();
|
||||
@ -146,11 +141,7 @@ namespace osu.Game.Rulesets.Edit
|
||||
/// Adds a <see cref="HitObject"/> to the <see cref="Beatmaps.Beatmap"/> and visualises it.
|
||||
/// </summary>
|
||||
/// <param name="hitObject">The <see cref="HitObject"/> to add.</param>
|
||||
public void Add(HitObject hitObject)
|
||||
{
|
||||
blueprintContainer.AddBlueprintFor(rulesetContainer.Add(hitObject));
|
||||
placementContainer.Refresh();
|
||||
}
|
||||
public void Add(HitObject hitObject) => blueprintContainer.AddBlueprintFor(rulesetContainer.Add(hitObject));
|
||||
|
||||
public void Remove(HitObject hitObject) => blueprintContainer.RemoveBlueprintFor(rulesetContainer.Remove(hitObject));
|
||||
|
||||
|
@ -10,6 +10,7 @@ using osu.Framework.Graphics.Primitives;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Input.States;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Edit.Tools;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using OpenTK;
|
||||
|
||||
@ -18,6 +19,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
||||
public class BlueprintContainer : CompositeDrawable
|
||||
{
|
||||
private SelectionBlueprintContainer selectionBlueprints;
|
||||
private Container<PlacementMask> placementBlueprintContainer;
|
||||
private SelectionBox selectionBox;
|
||||
|
||||
private IEnumerable<SelectionBlueprint> selections => selectionBlueprints.Children.Where(c => c.IsAlive);
|
||||
@ -44,6 +46,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
||||
dragBox,
|
||||
selectionBox,
|
||||
selectionBlueprints = new SelectionBlueprintContainer { RelativeSizeAxes = Axes.Both },
|
||||
placementBlueprintContainer = new Container<PlacementMask> { RelativeSizeAxes = Axes.Both },
|
||||
dragBox.CreateProxy()
|
||||
};
|
||||
|
||||
@ -51,6 +54,64 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
||||
AddBlueprintFor(obj);
|
||||
}
|
||||
|
||||
private HitObjectCompositionTool currentTool;
|
||||
|
||||
/// <summary>
|
||||
/// The current placement tool.
|
||||
/// </summary>
|
||||
public HitObjectCompositionTool CurrentTool
|
||||
{
|
||||
get => currentTool;
|
||||
set
|
||||
{
|
||||
if (currentTool == value)
|
||||
return;
|
||||
currentTool = value;
|
||||
|
||||
refreshTool();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a blueprint for a <see cref="DrawableHitObject"/> which adds movement support.
|
||||
/// </summary>
|
||||
/// <param name="hitObject">The <see cref="DrawableHitObject"/> to create a blueprint for.</param>
|
||||
public void AddBlueprintFor(DrawableHitObject hitObject)
|
||||
{
|
||||
refreshTool();
|
||||
|
||||
var blueprint = composer.CreateMaskFor(hitObject);
|
||||
if (blueprint == null)
|
||||
return;
|
||||
|
||||
blueprint.Selected += onBlueprintSelected;
|
||||
blueprint.Deselected += onBlueprintDeselected;
|
||||
blueprint.SelectionRequested += onSelectionRequested;
|
||||
blueprint.DragRequested += onDragRequested;
|
||||
|
||||
selectionBlueprints.Add(blueprint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a blueprint for a <see cref="DrawableHitObject"/>.
|
||||
/// </summary>
|
||||
/// <param name="hitObject">The <see cref="DrawableHitObject"/> for which to remove the blueprint.</param>
|
||||
public void RemoveBlueprintFor(DrawableHitObject hitObject)
|
||||
{
|
||||
var blueprint = selectionBlueprints.Single(m => m.HitObject == hitObject);
|
||||
if (blueprint == null)
|
||||
return;
|
||||
|
||||
blueprint.Deselect();
|
||||
|
||||
blueprint.Selected -= onBlueprintSelected;
|
||||
blueprint.Deselected -= onBlueprintDeselected;
|
||||
blueprint.SelectionRequested -= onSelectionRequested;
|
||||
blueprint.DragRequested -= onDragRequested;
|
||||
|
||||
selectionBlueprints.Remove(blueprint);
|
||||
}
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
{
|
||||
deselectAll();
|
||||
@ -58,42 +119,17 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a mask for a <see cref="DrawableHitObject"/> which adds movement support.
|
||||
/// Refreshes the current placement tool.
|
||||
/// </summary>
|
||||
/// <param name="hitObject">The <see cref="DrawableHitObject"/> to create a mask for.</param>
|
||||
public void AddBlueprintFor(DrawableHitObject hitObject)
|
||||
private void refreshTool()
|
||||
{
|
||||
var mask = composer.CreateMaskFor(hitObject);
|
||||
if (mask == null)
|
||||
return;
|
||||
placementBlueprintContainer.Clear();
|
||||
|
||||
mask.Selected += onBlueprintSelected;
|
||||
mask.Deselected += onBlueprintDeselected;
|
||||
mask.SelectionRequested += onSelectionRequested;
|
||||
mask.DragRequested += onDragRequested;
|
||||
|
||||
selectionBlueprints.Add(mask);
|
||||
var blueprint = CurrentTool?.CreatePlacementMask();
|
||||
if (blueprint != null)
|
||||
placementBlueprintContainer.Child = blueprint;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a mask for a <see cref="DrawableHitObject"/>.
|
||||
/// </summary>
|
||||
/// <param name="hitObject">The <see cref="DrawableHitObject"/> for which to remove the mask.</param>
|
||||
public void RemoveBlueprintFor(DrawableHitObject hitObject)
|
||||
{
|
||||
var maskToRemove = selectionBlueprints.Single(m => m.HitObject == hitObject);
|
||||
if (maskToRemove == null)
|
||||
return;
|
||||
|
||||
maskToRemove.Deselect();
|
||||
|
||||
maskToRemove.Selected -= onBlueprintSelected;
|
||||
maskToRemove.Deselected -= onBlueprintDeselected;
|
||||
maskToRemove.SelectionRequested -= onSelectionRequested;
|
||||
maskToRemove.DragRequested -= onDragRequested;
|
||||
|
||||
selectionBlueprints.Remove(maskToRemove);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Select all masks in a given rectangle selection area.
|
||||
@ -101,12 +137,12 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
||||
/// <param name="rect">The rectangle to perform a selection on in screen-space coordinates.</param>
|
||||
private void select(RectangleF rect)
|
||||
{
|
||||
foreach (var mask in selections.ToList())
|
||||
foreach (var blueprint in selections.ToList())
|
||||
{
|
||||
if (mask.IsPresent && rect.Contains(mask.SelectionPoint))
|
||||
mask.Select();
|
||||
if (blueprint.IsPresent && rect.Contains(blueprint.SelectionPoint))
|
||||
blueprint.Select();
|
||||
else
|
||||
mask.Deselect();
|
||||
blueprint.Deselect();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,50 +0,0 @@
|
||||
// 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.Rulesets.Edit.Tools;
|
||||
using Container = System.ComponentModel.Container;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Screens.Compose.Layers
|
||||
{
|
||||
public class PlacementContainer : CompositeDrawable
|
||||
{
|
||||
private readonly Container maskContainer;
|
||||
|
||||
public PlacementContainer()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
}
|
||||
|
||||
private HitObjectCompositionTool currentTool;
|
||||
|
||||
/// <summary>
|
||||
/// The current placement tool.
|
||||
/// </summary>
|
||||
public HitObjectCompositionTool CurrentTool
|
||||
{
|
||||
get => currentTool;
|
||||
set
|
||||
{
|
||||
if (currentTool == value)
|
||||
return;
|
||||
currentTool = value;
|
||||
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Refreshes the current placement tool.
|
||||
/// </summary>
|
||||
public void Refresh()
|
||||
{
|
||||
ClearInternal();
|
||||
|
||||
var mask = CurrentTool?.CreatePlacementMask();
|
||||
if (mask != null)
|
||||
InternalChild = mask;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user