Apply remaining changes required to restore previous functionality

This commit is contained in:
Dean Herbert 2020-01-15 19:09:49 +09:00
parent d8d12cbbdd
commit d57f55f053
11 changed files with 221 additions and 116 deletions

View File

@ -1,6 +1,7 @@
// 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.
using System.Collections.Generic;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Mania.Edit.Blueprints;
using osu.Game.Rulesets.Mania.Objects.Drawables;
@ -11,6 +12,11 @@ namespace osu.Game.Rulesets.Mania.Edit
{
public class ManiaBlueprintContainer : ComposeBlueprintContainer
{
public ManiaBlueprintContainer(IEnumerable<DrawableHitObject> drawableHitObjects)
: base(drawableHitObjects)
{
}
public override SelectionBlueprint CreateBlueprintFor(DrawableHitObject hitObject)
{
switch (hitObject)

View File

@ -49,7 +49,7 @@ namespace osu.Game.Rulesets.Mania.Edit
return drawableRuleset;
}
protected override ComposeBlueprintContainer CreateBlueprintContainer() => new ManiaBlueprintContainer();
protected override ComposeBlueprintContainer CreateBlueprintContainer() => new ManiaBlueprintContainer(drawableRuleset.Playfield.AllHitObjects);
protected override IReadOnlyList<HitObjectCompositionTool> CompositionTools => new HitObjectCompositionTool[]
{

View File

@ -1,6 +1,7 @@
// 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.
using System.Collections.Generic;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles;
@ -13,7 +14,7 @@ namespace osu.Game.Rulesets.Osu.Edit
{
public class OsuBlueprintContainer : ComposeBlueprintContainer
{
public override SelectionHandler CreateSelectionHandler() => new OsuSelectionHandler();
protected override SelectionHandler CreateSelectionHandler() => new OsuSelectionHandler();
public override SelectionBlueprint CreateBlueprintFor(DrawableHitObject hitObject)
{
@ -31,5 +32,10 @@ namespace osu.Game.Rulesets.Osu.Edit
return base.CreateBlueprintFor(hitObject);
}
public OsuBlueprintContainer(IEnumerable<DrawableHitObject> drawableHitObjects)
: base(drawableHitObjects)
{
}
}
}

View File

@ -32,7 +32,7 @@ namespace osu.Game.Rulesets.Osu.Edit
new SpinnerCompositionTool()
};
protected override ComposeBlueprintContainer CreateBlueprintContainer() => new OsuBlueprintContainer();
protected override ComposeBlueprintContainer CreateBlueprintContainer() => new OsuBlueprintContainer(HitObjects);
protected override DistanceSnapGrid CreateDistanceSnapGrid(IEnumerable<HitObject> selectedHitObjects)
{

View File

@ -1,7 +1,9 @@
// 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.
using System.Collections.Generic;
using NUnit.Framework;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Screens.Edit.Compose.Components;
using osu.Game.Tests.Visual;
@ -12,7 +14,7 @@ namespace osu.Game.Tests.Editor
[SetUp]
public void Setup() => Schedule(() =>
{
Child = new ComposeBlueprintContainer();
Child = new ComposeBlueprintContainer(new List<DrawableHitObject>());
});
}
}

View File

@ -51,7 +51,7 @@ namespace osu.Game.Rulesets.Edit
private IBeatmapProcessor beatmapProcessor;
private DrawableEditRulesetWrapper<TObject> drawableRulesetWrapper;
private BlueprintContainer blueprintContainer;
private ComposeBlueprintContainer blueprintContainer;
private Container distanceSnapGridContainer;
private DistanceSnapGrid distanceSnapGrid;
private readonly List<Container> layerContainers = new List<Container>();

View File

@ -14,7 +14,6 @@ using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Timing;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Tools;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osuTK;
@ -30,12 +29,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
{
public event Action<IEnumerable<HitObject>> SelectionChanged;
private DragBox dragBox;
protected DragBox DragBox;
private SelectionBlueprintContainer selectionBlueprints;
private Container<PlacementBlueprint> placementBlueprintContainer;
private PlacementBlueprint currentPlacement;
private SelectionHandler selectionHandler;
private InputManager inputManager;
[Resolved]
private IAdjustableClock adjustableClock { get; set; }
@ -43,6 +41,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
[Resolved]
private EditorBeatmap beatmap { get; set; }
[Resolved(canBeNull: true)]
private IDistanceSnapProvider snapProvider { get; set; }
protected BlueprintContainer()
{
RelativeSizeAxes = Axes.Both;
@ -51,13 +52,15 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <summary>
/// Creates a <see cref="SelectionHandler"/> which outlines <see cref="DrawableHitObject"/>s and handles movement of selections.
/// </summary>
public virtual SelectionHandler CreateSelectionHandler() => new SelectionHandler();
protected virtual SelectionHandler CreateSelectionHandler() => new SelectionHandler();
/// <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;
protected virtual SelectionBlueprint CreateBlueprintFor(HitObject hitObject) => null;
protected virtual DragBox CreateDragBox(Action<RectangleF> performSelect) => new DragBox(performSelect);
[BackgroundDependencyLoader]
private void load()
@ -65,46 +68,24 @@ namespace osu.Game.Screens.Edit.Compose.Components
selectionHandler = CreateSelectionHandler();
selectionHandler.DeselectAll = deselectAll;
InternalChildren = new[]
AddRangeInternal(new[]
{
dragBox = new DragBox(select),
DragBox = CreateDragBox(select),
selectionHandler,
selectionBlueprints = new SelectionBlueprintContainer { RelativeSizeAxes = Axes.Both },
placementBlueprintContainer = new Container<PlacementBlueprint> { RelativeSizeAxes = Axes.Both },
dragBox.CreateProxy()
};
DragBox.CreateProxy().With(p => p.Depth = int.MinValue)
});
foreach (var obj in beatmap.HitObjects)
addBlueprintFor(obj);
AddBlueprintFor(obj);
}
protected override void LoadComplete()
{
base.LoadComplete();
beatmap.HitObjectAdded += addBlueprintFor;
beatmap.HitObjectAdded += AddBlueprintFor;
beatmap.HitObjectRemoved += removeBlueprintFor;
inputManager = GetContainingInputManager();
}
private HitObjectCompositionTool currentTool;
/// <summary>
/// The current placement tool.
/// </summary>
public HitObjectCompositionTool CurrentTool
{
get => currentTool;
set
{
if (currentTool == value)
return;
currentTool = value;
refreshTool();
}
}
protected override bool OnMouseDown(MouseDownEvent e)
@ -148,17 +129,6 @@ namespace osu.Game.Screens.Edit.Compose.Components
return e.Button == MouseButton.Left;
}
protected override bool OnMouseMove(MouseMoveEvent e)
{
if (currentPlacement != null)
{
updatePlacementPosition(e.ScreenSpaceMousePosition);
return true;
}
return base.OnMouseMove(e);
}
protected override bool OnDragStart(DragStartEvent e)
{
if (e.Button == MouseButton.Right)
@ -166,8 +136,10 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (!beginSelectionMovement())
{
dragBox.UpdateDrag(e);
dragBox.FadeIn(250, Easing.OutQuint);
if (!DragBox.UpdateDrag(e))
return false;
DragBox.FadeIn(250, Easing.OutQuint);
}
return true;
@ -179,7 +151,10 @@ namespace osu.Game.Screens.Edit.Compose.Components
return false;
if (!moveCurrentSelection(e))
dragBox.UpdateDrag(e);
{
if (!DragBox.UpdateDrag(e))
return false;
}
return true;
}
@ -191,7 +166,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (!finishSelectionMovement())
{
dragBox.FadeOut(250, Easing.OutQuint);
DragBox.FadeOut(250, Easing.OutQuint);
selectionHandler.UpdateVisibility();
}
@ -229,30 +204,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
public bool OnReleased(PlatformAction action) => false;
protected override void Update()
{
base.Update();
if (currentPlacement != null)
{
if (composer.CursorInPlacementArea)
currentPlacement.State = PlacementState.Shown;
else if (currentPlacement?.PlacementBegun == false)
currentPlacement.State = PlacementState.Hidden;
}
}
#region Blueprint Addition/Removal
private void addBlueprintFor(HitObject hitObject)
{
var drawable = composer.HitObjects.FirstOrDefault(d => d.HitObject == hitObject);
if (drawable == null)
return;
addBlueprintFor(drawable);
}
private void removeBlueprintFor(HitObject hitObject)
{
var blueprint = selectionBlueprints.Single(m => m.DrawableObject.HitObject == hitObject);
@ -267,10 +220,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
selectionBlueprints.Remove(blueprint);
}
private void addBlueprintFor(DrawableHitObject hitObject)
protected virtual void AddBlueprintFor(HitObject hitObject)
{
refreshTool();
var blueprint = CreateBlueprintFor(hitObject);
if (blueprint == null)
return;
@ -283,37 +234,6 @@ namespace osu.Game.Screens.Edit.Compose.Components
#endregion
#region Placement
/// <summary>
/// Refreshes the current placement tool.
/// </summary>
private void refreshTool()
{
placementBlueprintContainer.Clear();
currentPlacement = null;
var blueprint = CurrentTool?.CreatePlacementBlueprint();
if (blueprint != null)
{
placementBlueprintContainer.Child = currentPlacement = blueprint;
// Fixes a 1-frame position discrepancy due to the first mouse move event happening in the next frame
updatePlacementPosition(inputManager.CurrentState.Mouse.Position);
}
}
private void updatePlacementPosition(Vector2 screenSpacePosition)
{
Vector2 snappedGridPosition = composer.GetSnappedPosition(ToLocalSpace(screenSpacePosition), 0).position;
Vector2 snappedScreenSpacePosition = ToScreenSpace(snappedGridPosition);
currentPlacement.UpdatePosition(snappedScreenSpacePosition);
}
#endregion
#region Selection
/// <summary>
@ -449,7 +369,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
// The final movement position, relative to screenSpaceMovementStartPosition
Vector2 movePosition = startPosition + e.ScreenSpaceMousePosition - e.ScreenSpaceMouseDownPosition;
(Vector2 snappedPosition, double snappedTime) = composer.GetSnappedPosition(ToLocalSpace(movePosition), draggedObject.StartTime);
(Vector2 snappedPosition, double snappedTime) = snapProvider.GetSnappedPosition(ToLocalSpace(movePosition), draggedObject.StartTime);
// Move the hitobjects
if (!selectionHandler.HandleMovement(new MoveSelectionEvent(movementBlueprint, startPosition, ToScreenSpace(snappedPosition))))
@ -486,7 +406,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (beatmap != null)
{
beatmap.HitObjectAdded -= addBlueprintFor;
beatmap.HitObjectAdded -= AddBlueprintFor;
beatmap.HitObjectRemoved -= removeBlueprintFor;
}
}

View File

@ -1,6 +1,19 @@
// 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.
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Tools;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osuTK;
namespace osu.Game.Screens.Edit.Compose.Components
{
/// <summary>
@ -8,5 +21,129 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </summary>
public class ComposeBlueprintContainer : BlueprintContainer
{
[Resolved]
private HitObjectComposer composer { get; set; }
private PlacementBlueprint currentPlacement;
private readonly Container<PlacementBlueprint> placementBlueprintContainer;
private InputManager inputManager;
private readonly IEnumerable<DrawableHitObject> drawableHitObjects;
public ComposeBlueprintContainer(IEnumerable<DrawableHitObject> drawableHitObjects)
{
this.drawableHitObjects = drawableHitObjects;
placementBlueprintContainer = new Container<PlacementBlueprint>
{
RelativeSizeAxes = Axes.Both
};
}
[BackgroundDependencyLoader]
private void load()
{
AddInternal(placementBlueprintContainer);
}
protected override void LoadComplete()
{
base.LoadComplete();
inputManager = GetContainingInputManager();
}
#region Placement
/// <summary>
/// Refreshes the current placement tool.
/// </summary>
private void refreshTool()
{
placementBlueprintContainer.Clear();
currentPlacement = null;
var blueprint = CurrentTool?.CreatePlacementBlueprint();
if (blueprint != null)
{
placementBlueprintContainer.Child = currentPlacement = blueprint;
// Fixes a 1-frame position discrepancy due to the first mouse move event happening in the next frame
updatePlacementPosition(inputManager.CurrentState.Mouse.Position);
}
}
private void updatePlacementPosition(Vector2 screenSpacePosition)
{
Vector2 snappedGridPosition = composer.GetSnappedPosition(ToLocalSpace(screenSpacePosition), 0).position;
Vector2 snappedScreenSpacePosition = ToScreenSpace(snappedGridPosition);
currentPlacement.UpdatePosition(snappedScreenSpacePosition);
}
#endregion
protected override bool OnMouseMove(MouseMoveEvent e)
{
if (currentPlacement != null)
{
updatePlacementPosition(e.ScreenSpaceMousePosition);
return true;
}
return base.OnMouseMove(e);
}
protected override void Update()
{
base.Update();
if (currentPlacement != null)
{
if (composer.CursorInPlacementArea)
currentPlacement.State = PlacementState.Shown;
else if (currentPlacement?.PlacementBegun == false)
currentPlacement.State = PlacementState.Hidden;
}
}
protected sealed override SelectionBlueprint CreateBlueprintFor(HitObject hitObject)
{
var drawable = drawableHitObjects.FirstOrDefault(d => d.HitObject == hitObject);
if (drawable == null)
return null;
return CreateBlueprintFor(drawable);
}
public virtual SelectionBlueprint CreateBlueprintFor(DrawableHitObject hitObject) => null;
protected override void AddBlueprintFor(HitObject hitObject)
{
refreshTool();
base.AddBlueprintFor(hitObject);
}
private HitObjectCompositionTool currentTool;
/// <summary>
/// The current placement tool.
/// </summary>
public HitObjectCompositionTool CurrentTool
{
get => currentTool;
set
{
if (currentTool == value)
return;
currentTool = value;
refreshTool();
}
}
}
}

View File

@ -50,7 +50,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
};
}
public void UpdateDrag(MouseButtonEvent e)
/// <summary>
/// Handle a forwarded mouse event.
/// </summary>
/// <param name="e">The mouse event.</param>
/// <returns>Whether the event should be handled and blocking.</returns>
public virtual bool UpdateDrag(MouseButtonEvent e)
{
var dragPosition = e.ScreenSpaceMousePosition;
var dragStartPosition = e.ScreenSpaceMouseDownPosition;
@ -67,6 +72,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
box.Size = bottomRight - topLeft;
performSelection?.Invoke(dragRectangle);
return true;
}
}
}

View File

@ -37,7 +37,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
private Drawable outline;
[Resolved]
[Resolved(CanBeNull = true)]
private IPlacementHandler placementHandler { get; set; }
public SelectionHandler()

View File

@ -1,11 +1,14 @@
// 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.
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Screens.Edit.Components.Timelines.Summary.Parts;
@ -26,7 +29,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
this.beatmap = beatmap;
AddInternal(content = new TimelinePart());
AddInternal(content = new TimelinePart { RelativeSizeAxes = Axes.Both });
}
[BackgroundDependencyLoader]
@ -44,6 +47,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
};
}
protected override void LoadComplete()
{
base.LoadComplete();
DragBox.Alpha = 0;
}
private void remove(HitObject h)
{
foreach (var d in content.OfType<TimelineHitObjectRepresentation>().Where(c => c.HitObject == h))
@ -57,6 +66,25 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
content.Add(new TimelineHitObjectRepresentation(h) { Y = -yOffset * TimelineHitObjectRepresentation.THICKNESS });
}
protected override bool OnMouseDown(MouseDownEvent e)
{
base.OnMouseDown(e);
return false; // tempoerary until we correctly handle selections.
}
protected override DragBox CreateDragBox(Action<RectangleF> performSelect) => new NoDragDragBox(performSelect);
internal class NoDragDragBox : DragBox
{
public NoDragDragBox(Action<RectangleF> performSelect)
: base(performSelect)
{
}
public override bool UpdateDrag(MouseButtonEvent e) => false;
}
private class TimelineHitObjectRepresentation : CompositeDrawable
{
public const float THICKNESS = 3;