2023-07-09 19:00:35 +00:00
|
|
|
// 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 osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Input.Bindings;
|
|
|
|
using osu.Game.Rulesets.Edit;
|
|
|
|
using osu.Game.Screens.Edit.Components;
|
2024-01-25 09:56:59 +00:00
|
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
2023-07-09 19:00:35 +00:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Edit
|
|
|
|
{
|
|
|
|
public partial class TransformToolboxGroup : EditorToolboxGroup, IKeyBindingHandler<GlobalAction>
|
|
|
|
{
|
2024-05-29 07:49:16 +00:00
|
|
|
private readonly AggregateBindable<bool> canRotate = new AggregateBindable<bool>((x, y) => x || y);
|
|
|
|
private readonly AggregateBindable<bool> canScale = new AggregateBindable<bool>((x, y) => x || y);
|
2023-07-09 19:00:35 +00:00
|
|
|
|
|
|
|
private EditorToolButton rotateButton = null!;
|
2024-05-25 16:31:19 +00:00
|
|
|
private EditorToolButton scaleButton = null!;
|
2023-07-09 19:00:35 +00:00
|
|
|
|
2024-01-25 09:56:59 +00:00
|
|
|
public SelectionRotationHandler RotationHandler { get; init; } = null!;
|
2024-05-28 15:12:16 +00:00
|
|
|
public OsuSelectionScaleHandler ScaleHandler { get; init; } = null!;
|
2023-07-09 19:00:35 +00:00
|
|
|
|
|
|
|
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 EditorToolButton("Rotate",
|
|
|
|
() => new SpriteIcon { Icon = FontAwesome.Solid.Undo },
|
|
|
|
() => new PreciseRotationPopover(RotationHandler)),
|
2024-05-25 16:31:19 +00:00
|
|
|
scaleButton = new EditorToolButton("Scale",
|
|
|
|
() => new SpriteIcon { Icon = FontAwesome.Solid.ArrowsAlt },
|
|
|
|
() => new PreciseScalePopover(ScaleHandler))
|
2023-07-09 19:00:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2024-05-29 07:49:16 +00:00
|
|
|
canRotate.AddSource(RotationHandler.CanRotateAroundPlayfieldOrigin);
|
|
|
|
canRotate.AddSource(RotationHandler.CanRotateAroundSelectionOrigin);
|
2024-04-02 05:04:34 +00:00
|
|
|
|
2024-05-29 07:49:16 +00:00
|
|
|
canScale.AddSource(ScaleHandler.CanScaleX);
|
|
|
|
canScale.AddSource(ScaleHandler.CanScaleY);
|
|
|
|
canScale.AddSource(ScaleHandler.CanScaleFromPlayfieldOrigin);
|
2024-05-25 16:31:19 +00:00
|
|
|
|
2023-07-09 19:00:35 +00:00
|
|
|
// bindings to `Enabled` on the buttons are decoupled on purpose
|
|
|
|
// due to the weird `OsuButton` behaviour of resetting `Enabled` to `false` when `Action` is set.
|
2024-05-29 07:49:16 +00:00
|
|
|
canRotate.Result.BindValueChanged(rotate => rotateButton.Enabled.Value = rotate.NewValue, true);
|
|
|
|
canScale.Result.BindValueChanged(scale => scaleButton.Enabled.Value = scale.NewValue, true);
|
2023-07-09 19:00:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
|
|
|
{
|
|
|
|
if (e.Repeat) return false;
|
|
|
|
|
|
|
|
switch (e.Action)
|
|
|
|
{
|
|
|
|
case GlobalAction.EditorToggleRotateControl:
|
|
|
|
{
|
2024-06-25 13:01:43 +00:00
|
|
|
if (!RotationHandler.OperationInProgress.Value || rotateButton.Selected.Value)
|
|
|
|
rotateButton.TriggerClick();
|
2023-07-09 19:00:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2024-05-25 16:31:19 +00:00
|
|
|
|
|
|
|
case GlobalAction.EditorToggleScaleControl:
|
|
|
|
{
|
2024-06-25 13:01:43 +00:00
|
|
|
if (!ScaleHandler.OperationInProgress.Value || scaleButton.Selected.Value)
|
|
|
|
scaleButton.TriggerClick();
|
2024-05-25 16:31:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
2023-07-09 19:00:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|