-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add precise rotation control to osu! editor
- Loading branch information
Showing
9 changed files
with
308 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// 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.Linq; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Game.Graphics.UserInterfaceV2; | ||
using osu.Game.Rulesets.Osu.UI; | ||
using osu.Game.Screens.Edit.Components.RadioButtons; | ||
using osu.Game.Screens.Edit.Compose.Components; | ||
using osu.Game.Screens.Edit.Timing; | ||
using osuTK; | ||
|
||
namespace osu.Game.Rulesets.Osu.Edit | ||
{ | ||
public partial class PreciseRotationPopover : OsuPopover | ||
{ | ||
private readonly SelectionRotationHandler rotationHandler; | ||
|
||
public IBindable<PreciseRotationInfo> RotationInfo => rotationInfo; | ||
private readonly Bindable<PreciseRotationInfo> rotationInfo = new Bindable<PreciseRotationInfo>(new PreciseRotationInfo(0, RotationOrigin.PlayfieldCentre)); | ||
|
||
private SliderWithTextBoxInput<float> angleInput = null!; | ||
private EditorRadioButtonCollection rotationOrigin = null!; | ||
|
||
public PreciseRotationPopover(SelectionRotationHandler rotationHandler) | ||
{ | ||
this.rotationHandler = rotationHandler; | ||
} | ||
|
||
[BackgroundDependencyLoader] | ||
private void load() | ||
{ | ||
Child = new FillFlowContainer | ||
{ | ||
Width = 300, | ||
AutoSizeAxes = Axes.Y, | ||
Spacing = new Vector2(20), | ||
Children = new Drawable[] | ||
{ | ||
angleInput = new SliderWithTextBoxInput<float>("Rotation angle (degrees):") | ||
{ | ||
Current = new BindableNumber<float> | ||
{ | ||
MinValue = -180, | ||
MaxValue = 180, | ||
Precision = 1 | ||
}, | ||
TransferValueOnCommit = false | ||
}, | ||
rotationOrigin = new EditorRadioButtonCollection | ||
{ | ||
RelativeSizeAxes = Axes.X, | ||
Items = new[] | ||
{ | ||
new RadioButton("Playfield centre", | ||
() => rotationInfo.Value = rotationInfo.Value with { Origin = RotationOrigin.PlayfieldCentre }, | ||
() => new SpriteIcon { Icon = FontAwesome.Regular.Square }), | ||
new RadioButton("Selection centre", | ||
() => rotationInfo.Value = rotationInfo.Value with { Origin = RotationOrigin.SelectionCentre }, | ||
() => new SpriteIcon { Icon = FontAwesome.Solid.ObjectGroup }) | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
protected override void LoadComplete() | ||
{ | ||
base.LoadComplete(); | ||
|
||
ScheduleAfterChildren(() => angleInput.TakeFocus()); | ||
angleInput.Current.BindValueChanged(angle => rotationInfo.Value = rotationInfo.Value with { Degrees = angle.NewValue }); | ||
rotationOrigin.Items.First().Select(); | ||
|
||
rotationInfo.BindValueChanged(rotation => | ||
{ | ||
rotationHandler.Update(rotation.NewValue.Degrees, rotation.NewValue.Origin == RotationOrigin.PlayfieldCentre ? OsuPlayfield.BASE_SIZE / 2 : null); | ||
}); | ||
} | ||
|
||
protected override void PopIn() | ||
{ | ||
base.PopIn(); | ||
rotationHandler.Begin(); | ||
} | ||
|
||
protected override void PopOut() | ||
{ | ||
base.PopOut(); | ||
|
||
if (IsLoaded) | ||
rotationHandler.Commit(); | ||
} | ||
} | ||
|
||
public enum RotationOrigin | ||
{ | ||
PlayfieldCentre, | ||
SelectionCentre | ||
} | ||
|
||
public record PreciseRotationInfo(float Degrees, RotationOrigin Origin); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// 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 osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Extensions; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Graphics.Cursor; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Framework.Graphics.UserInterface; | ||
using osu.Framework.Input.Events; | ||
using osu.Game.Graphics.UserInterface; | ||
using osu.Game.Rulesets.Edit; | ||
using osu.Game.Screens.Edit.Components.TernaryButtons; | ||
using osu.Game.Screens.Edit.Compose.Components; | ||
using osuTK; | ||
using osuTK.Input; | ||
|
||
namespace osu.Game.Rulesets.Osu.Edit | ||
{ | ||
public partial class TransformToolboxGroup : EditorToolboxGroup | ||
{ | ||
private readonly Bindable<bool> canRotate = new BindableBool(); | ||
private readonly Bindable<TernaryState> rotationState = new Bindable<TernaryState>(); | ||
|
||
private readonly Bindable<TernaryState> scaleState = new Bindable<TernaryState>(); | ||
|
||
private DrawableTernaryButtonWithPopover rotateButton = null!; | ||
|
||
public SelectionRotationHandler RotationHandler { get; init; } = null!; | ||
|
||
public TransformToolboxGroup() | ||
: base("transform") | ||
{ | ||
} | ||
|
||
[BackgroundDependencyLoader] | ||
private void load() | ||
{ | ||
Child = new FillFlowContainer | ||
{ | ||
RelativeSizeAxes = Axes.X, | ||
AutoSizeAxes = Axes.Y, | ||
Spacing = new Vector2(5), | ||
Children = new Drawable[] | ||
{ | ||
rotateButton = new DrawableTernaryButtonWithPopover(new TernaryButton(rotationState, "Rotate", () => new SpriteIcon { Icon = FontAwesome.Solid.Undo })) | ||
{ | ||
RelativeSizeAxes = Axes.X, | ||
Popover = () => new PreciseRotationPopover(RotationHandler), | ||
}, | ||
new DrawableTernaryButton(new TernaryButton(scaleState, "Scale", () => new SpriteIcon { Icon = FontAwesome.Solid.ArrowsAlt })) | ||
{ | ||
RelativeSizeAxes = Axes.X, | ||
}, | ||
} | ||
}; | ||
} | ||
|
||
protected override void LoadComplete() | ||
{ | ||
base.LoadComplete(); | ||
|
||
canRotate.BindTo(RotationHandler.CanRotate); | ||
canRotate.BindValueChanged(_ => rotateButton.Alpha = canRotate.Value ? 1 : 0, true); | ||
} | ||
|
||
protected override bool OnKeyDown(KeyDownEvent e) | ||
{ | ||
if (e.Repeat) return false; | ||
|
||
if (e.ControlPressed && e.Key == Key.R) | ||
{ | ||
rotateButton.TriggerClick(); | ||
return true; | ||
} | ||
|
||
return base.OnKeyDown(e); | ||
} | ||
|
||
private partial class DrawableTernaryButtonWithPopover : DrawableTernaryButton, IHasPopover | ||
{ | ||
public Func<Popover>? Popover { get; init; } | ||
|
||
public DrawableTernaryButtonWithPopover(TernaryButton button) | ||
: base(button) | ||
{ | ||
} | ||
|
||
public Popover? GetPopover() | ||
{ | ||
var popover = Popover?.Invoke(); | ||
|
||
popover?.State.BindValueChanged(state => | ||
{ | ||
if (state.NewValue == Visibility.Hidden) | ||
Button.Bindable.Value = TernaryState.False; | ||
}); | ||
|
||
return popover; | ||
} | ||
|
||
protected override void UpdateSelectionState() | ||
{ | ||
base.UpdateSelectionState(); | ||
|
||
if (Button.Bindable.Value == TernaryState.True) | ||
this.ShowPopover(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.