1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 07:23:14 +08:00

Interface with SelectionRotationHandler via DI rather than explicit passing

This commit is contained in:
Bartłomiej Dach 2023-07-30 20:21:41 +02:00
parent 262f25dce8
commit ebe5dd2ac9
No known key found for this signature in database
4 changed files with 31 additions and 15 deletions

View File

@ -7,6 +7,7 @@ using System;
using System.Linq;
using JetBrains.Annotations;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
@ -22,6 +23,14 @@ namespace osu.Game.Tests.Visual.Editing
private Container selectionArea;
private SelectionBox selectionBox;
[Cached(typeof(SelectionRotationHandler))]
private TestSelectionRotationHandler rotationHandler;
public TestSceneComposeSelectBox()
{
rotationHandler = new TestSelectionRotationHandler(() => selectionArea);
}
[SetUp]
public void SetUp() => Schedule(() =>
{
@ -41,7 +50,6 @@ namespace osu.Game.Tests.Visual.Editing
CanFlipX = true,
CanFlipY = true,
RotationHandler = new TestSelectionRotationHandler(() => selectionArea),
OnScale = handleScale
}
}

View File

@ -23,7 +23,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
private const float button_padding = 5;
public SelectionRotationHandler? RotationHandler { get; init; }
[Resolved]
private SelectionRotationHandler? rotationHandler { get; set; }
public Func<Vector2, Anchor, bool>? OnScale;
public Func<Direction, bool, bool>? OnFlip;
public Func<bool>? OnReverse;
@ -149,8 +151,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
[BackgroundDependencyLoader]
private void load()
{
if (RotationHandler != null)
canRotate.BindTo(RotationHandler.CanRotate);
if (rotationHandler != null)
canRotate.BindTo(rotationHandler.CanRotate);
canRotate.BindValueChanged(_ => recreate(), true);
}
@ -252,8 +254,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
private void addRotationComponents()
{
rotateCounterClockwiseButton = addButton(FontAwesome.Solid.Undo, "Rotate 90 degrees counter-clockwise (Ctrl-<)", () => RotationHandler?.Rotate(-90));
rotateClockwiseButton = addButton(FontAwesome.Solid.Redo, "Rotate 90 degrees clockwise (Ctrl->)", () => RotationHandler?.Rotate(90));
rotateCounterClockwiseButton = addButton(FontAwesome.Solid.Undo, "Rotate 90 degrees counter-clockwise (Ctrl-<)", () => rotationHandler?.Rotate(-90));
rotateClockwiseButton = addButton(FontAwesome.Solid.Redo, "Rotate 90 degrees clockwise (Ctrl->)", () => rotationHandler?.Rotate(90));
addRotateHandle(Anchor.TopLeft);
addRotateHandle(Anchor.TopRight);
@ -323,7 +325,6 @@ namespace osu.Game.Screens.Edit.Compose.Components
var handle = new SelectionBoxRotationHandle
{
Anchor = anchor,
RotationHandler = RotationHandler
};
handle.OperationStarted += operationStarted;

View File

@ -19,8 +19,6 @@ namespace osu.Game.Screens.Edit.Compose.Components
{
public partial class SelectionBoxRotationHandle : SelectionBoxDragHandle, IHasTooltip
{
public SelectionRotationHandler? RotationHandler { get; init; }
public LocalisableString TooltipText { get; private set; }
private SpriteIcon icon = null!;
@ -32,6 +30,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
[Resolved]
private SelectionBox selectionBox { get; set; } = null!;
[Resolved]
private SelectionRotationHandler? rotationHandler { get; set; }
[BackgroundDependencyLoader]
private void load()
{
@ -61,9 +62,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
protected override bool OnDragStart(DragStartEvent e)
{
if (RotationHandler == null) return false;
if (rotationHandler == null) return false;
RotationHandler.Begin();
rotationHandler.Begin();
return true;
}
@ -97,7 +98,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
protected override void OnDragEnd(DragEndEvent e)
{
RotationHandler?.Commit();
rotationHandler?.Commit();
UpdateHoverState();
cumulativeRotation.Value = null;
@ -121,7 +122,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
cumulativeRotation.Value = newRotation;
RotationHandler?.Update(newRotation);
rotationHandler?.Update(newRotation);
TooltipText = shouldSnap ? EditorStrings.RotationSnapped(newRotation) : EditorStrings.RotationUnsnapped(newRotation);
}

View File

@ -65,12 +65,19 @@ namespace osu.Game.Screens.Edit.Compose.Components
AlwaysPresent = true;
}
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.CacheAs(RotationHandler = CreateRotationHandler());
return dependencies;
}
[BackgroundDependencyLoader]
private void load()
{
AddRangeInternal(new Drawable[]
{
RotationHandler = CreateRotationHandler(),
RotationHandler,
SelectionBox = CreateSelectionBox(),
});
@ -86,7 +93,6 @@ namespace osu.Game.Screens.Edit.Compose.Components
OperationStarted = OnOperationBegan,
OperationEnded = OnOperationEnded,
RotationHandler = RotationHandler,
OnScale = HandleScale,
OnFlip = HandleFlip,
OnReverse = HandleReverse,