mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 15:03:13 +08:00
Make SelectionRotationHandler
a Component
This commit is contained in:
parent
821cd08f34
commit
262f25dce8
@ -163,10 +163,7 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
if ((reference & Anchor.y0) > 0) scale.Y = -scale.Y;
|
||||
}
|
||||
|
||||
public override SelectionRotationHandler CreateRotationHandler() => new OsuSelectionRotationHandler(ChangeHandler)
|
||||
{
|
||||
SelectedItems = { BindTarget = SelectedItems }
|
||||
};
|
||||
public override SelectionRotationHandler CreateRotationHandler() => new OsuSelectionRotationHandler();
|
||||
|
||||
private void scaleSlider(Slider slider, Vector2 scale)
|
||||
{
|
||||
|
@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
@ -16,17 +17,25 @@ using osuTK;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Edit
|
||||
{
|
||||
public class OsuSelectionRotationHandler : SelectionRotationHandler
|
||||
public partial class OsuSelectionRotationHandler : SelectionRotationHandler
|
||||
{
|
||||
private readonly IEditorChangeHandler? changeHandler;
|
||||
[Resolved]
|
||||
private IEditorChangeHandler? changeHandler { get; set; }
|
||||
|
||||
public BindableList<HitObject> SelectedItems { get; } = new BindableList<HitObject>();
|
||||
private BindableList<HitObject> selectedItems { get; } = new BindableList<HitObject>();
|
||||
|
||||
public OsuSelectionRotationHandler(IEditorChangeHandler? changeHandler)
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(EditorBeatmap editorBeatmap)
|
||||
{
|
||||
this.changeHandler = changeHandler;
|
||||
selectedItems.BindTo(editorBeatmap.SelectedHitObjects);
|
||||
}
|
||||
|
||||
SelectedItems.CollectionChanged += (_, __) => updateState();
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
selectedItems.CollectionChanged += (_, __) => updateState();
|
||||
updateState();
|
||||
}
|
||||
|
||||
private void updateState()
|
||||
@ -92,7 +101,7 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
defaultOrigin = null;
|
||||
}
|
||||
|
||||
private IEnumerable<OsuHitObject> selectedMovableObjects => SelectedItems.Cast<OsuHitObject>()
|
||||
private IEnumerable<OsuHitObject> selectedMovableObjects => selectedItems.Cast<OsuHitObject>()
|
||||
.Where(h => h is not Spinner);
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
return true;
|
||||
}
|
||||
|
||||
private class TestSelectionRotationHandler : SelectionRotationHandler
|
||||
private partial class TestSelectionRotationHandler : SelectionRotationHandler
|
||||
{
|
||||
private readonly Func<Container> getTargetContainer;
|
||||
|
||||
|
@ -26,9 +26,8 @@ namespace osu.Game.Overlays.SkinEditor
|
||||
[Resolved]
|
||||
private SkinEditor skinEditor { get; set; } = null!;
|
||||
|
||||
public override SelectionRotationHandler CreateRotationHandler() => new SkinSelectionRotationHandler(ChangeHandler)
|
||||
public override SelectionRotationHandler CreateRotationHandler() => new SkinSelectionRotationHandler
|
||||
{
|
||||
SelectedItems = { BindTarget = SelectedItems },
|
||||
UpdatePosition = updateDrawablePosition
|
||||
};
|
||||
|
||||
|
@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Screens.Edit;
|
||||
@ -15,23 +16,32 @@ using osuTK;
|
||||
|
||||
namespace osu.Game.Overlays.SkinEditor
|
||||
{
|
||||
public class SkinSelectionRotationHandler : SelectionRotationHandler
|
||||
public partial class SkinSelectionRotationHandler : SelectionRotationHandler
|
||||
{
|
||||
private readonly IEditorChangeHandler? changeHandler;
|
||||
|
||||
public BindableList<ISerialisableDrawable> SelectedItems { get; } = new BindableList<ISerialisableDrawable>();
|
||||
public Action<Drawable, Vector2> UpdatePosition { get; init; } = null!;
|
||||
|
||||
public SkinSelectionRotationHandler(IEditorChangeHandler? changeHandler)
|
||||
{
|
||||
this.changeHandler = changeHandler;
|
||||
[Resolved]
|
||||
private IEditorChangeHandler? changeHandler { get; set; }
|
||||
|
||||
SelectedItems.CollectionChanged += (_, __) => updateState();
|
||||
private BindableList<ISerialisableDrawable> selectedItems { get; } = new BindableList<ISerialisableDrawable>();
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(SkinEditor skinEditor)
|
||||
{
|
||||
selectedItems.BindTo(skinEditor.SelectedComponents);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
selectedItems.CollectionChanged += (_, __) => updateState();
|
||||
updateState();
|
||||
}
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
CanRotate.Value = SelectedItems.Count > 0;
|
||||
CanRotate.Value = selectedItems.Count > 0;
|
||||
}
|
||||
|
||||
private Drawable[]? objectsInRotation;
|
||||
@ -47,7 +57,7 @@ namespace osu.Game.Overlays.SkinEditor
|
||||
|
||||
changeHandler?.BeginChange();
|
||||
|
||||
objectsInRotation = SelectedItems.Cast<Drawable>().ToArray();
|
||||
objectsInRotation = selectedItems.Cast<Drawable>().ToArray();
|
||||
originalRotations = objectsInRotation.ToDictionary(d => d, d => d.Rotation);
|
||||
originalPositions = objectsInRotation.ToDictionary(d => d, d => d.ToScreenSpace(d.OriginPosition));
|
||||
defaultOrigin = GeometryUtils.GetSurroundingQuad(objectsInRotation.SelectMany(d => d.ScreenSpaceDrawQuad.GetVertices().ToArray())).Centre;
|
||||
|
@ -68,9 +68,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
RotationHandler = CreateRotationHandler();
|
||||
|
||||
InternalChild = SelectionBox = CreateSelectionBox();
|
||||
AddRangeInternal(new Drawable[]
|
||||
{
|
||||
RotationHandler = CreateRotationHandler(),
|
||||
SelectionBox = CreateSelectionBox(),
|
||||
});
|
||||
|
||||
SelectedItems.CollectionChanged += (_, _) =>
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Compose.Components
|
||||
@ -9,7 +10,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
/// <summary>
|
||||
/// Base handler for editor rotation operations.
|
||||
/// </summary>
|
||||
public class SelectionRotationHandler
|
||||
public partial class SelectionRotationHandler : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether the rotation can currently be performed.
|
||||
|
Loading…
Reference in New Issue
Block a user