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