2023-07-10 03:00:35 +08: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.
|
|
|
|
|
2024-07-14 23:27:04 +08:00
|
|
|
using System;
|
2023-07-10 03:00:35 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2024-10-17 03:53:56 +08:00
|
|
|
using osu.Framework.Extensions;
|
2023-07-10 03:00:35 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2024-10-17 03:53:56 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2024-11-03 14:23:55 +08:00
|
|
|
using osu.Game.Configuration;
|
2023-07-10 03:00:35 +08:00
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
2024-10-17 03:53:56 +08:00
|
|
|
using osu.Game.Input.Bindings;
|
2024-07-14 23:27:04 +08:00
|
|
|
using osu.Game.Rulesets.Osu.UI;
|
2023-07-10 03:00:35 +08:00
|
|
|
using osu.Game.Screens.Edit.Components.RadioButtons;
|
|
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Edit
|
|
|
|
{
|
|
|
|
public partial class PreciseRotationPopover : OsuPopover
|
|
|
|
{
|
|
|
|
private readonly SelectionRotationHandler rotationHandler;
|
|
|
|
|
2023-12-30 08:53:19 +08:00
|
|
|
private readonly OsuGridToolboxGroup gridToolbox;
|
|
|
|
|
2024-11-03 14:20:45 +08:00
|
|
|
private readonly Bindable<PreciseRotationInfo> rotationInfo = new Bindable<PreciseRotationInfo>(new PreciseRotationInfo(0, EditorOrigin.GridCentre));
|
2023-07-10 03:00:35 +08:00
|
|
|
|
|
|
|
private SliderWithTextBoxInput<float> angleInput = null!;
|
|
|
|
private EditorRadioButtonCollection rotationOrigin = null!;
|
|
|
|
|
2024-11-03 14:23:55 +08:00
|
|
|
private RadioButton gridCentreButton = null!;
|
|
|
|
private RadioButton playfieldCentreButton = null!;
|
2024-01-25 15:24:35 +08:00
|
|
|
private RadioButton selectionCentreButton = null!;
|
2024-01-25 15:24:45 +08:00
|
|
|
|
2024-11-03 14:23:55 +08:00
|
|
|
private Bindable<EditorOrigin> configRotationOrigin = null!;
|
|
|
|
|
2023-12-30 08:53:19 +08:00
|
|
|
public PreciseRotationPopover(SelectionRotationHandler rotationHandler, OsuGridToolboxGroup gridToolbox)
|
2023-07-10 03:00:35 +08:00
|
|
|
{
|
|
|
|
this.rotationHandler = rotationHandler;
|
2023-12-30 08:53:19 +08:00
|
|
|
this.gridToolbox = gridToolbox;
|
2023-07-10 03:00:35 +08:00
|
|
|
|
|
|
|
AllowableAnchors = new[] { Anchor.CentreLeft, Anchor.CentreRight };
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2024-11-03 14:23:55 +08:00
|
|
|
private void load(OsuConfigManager config)
|
2023-07-10 03:00:35 +08:00
|
|
|
{
|
2024-11-03 14:23:55 +08:00
|
|
|
configRotationOrigin = config.GetBindable<EditorOrigin>(OsuSetting.EditorRotationOrigin);
|
|
|
|
|
2023-07-10 03:00:35 +08:00
|
|
|
Child = new FillFlowContainer
|
|
|
|
{
|
|
|
|
Width = 220,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Spacing = new Vector2(20),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
angleInput = new SliderWithTextBoxInput<float>("Angle (degrees):")
|
|
|
|
{
|
|
|
|
Current = new BindableNumber<float>
|
|
|
|
{
|
2023-08-19 21:09:59 +08:00
|
|
|
MinValue = -360,
|
|
|
|
MaxValue = 360,
|
2023-07-10 03:00:35 +08:00
|
|
|
Precision = 1
|
|
|
|
},
|
2024-10-17 03:18:48 +08:00
|
|
|
KeyboardStep = 1f,
|
2023-07-10 03:00:35 +08:00
|
|
|
Instantaneous = true
|
|
|
|
},
|
|
|
|
rotationOrigin = new EditorRadioButtonCollection
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Items = new[]
|
|
|
|
{
|
2024-11-03 14:23:55 +08:00
|
|
|
gridCentreButton = new RadioButton("Grid centre",
|
2024-11-03 14:20:45 +08:00
|
|
|
() => rotationInfo.Value = rotationInfo.Value with { Origin = EditorOrigin.GridCentre },
|
2024-07-14 23:13:22 +08:00
|
|
|
() => new SpriteIcon { Icon = FontAwesome.Regular.PlusSquare }),
|
2024-11-03 14:23:55 +08:00
|
|
|
playfieldCentreButton = new RadioButton("Playfield centre",
|
2024-11-03 14:20:45 +08:00
|
|
|
() => rotationInfo.Value = rotationInfo.Value with { Origin = EditorOrigin.PlayfieldCentre },
|
2024-07-14 23:27:04 +08:00
|
|
|
() => new SpriteIcon { Icon = FontAwesome.Regular.Square }),
|
2024-01-25 15:24:35 +08:00
|
|
|
selectionCentreButton = new RadioButton("Selection centre",
|
2024-11-03 14:20:45 +08:00
|
|
|
() => rotationInfo.Value = rotationInfo.Value with { Origin = EditorOrigin.SelectionCentre },
|
2023-08-17 18:08:18 +08:00
|
|
|
() => new SpriteIcon { Icon = FontAwesome.Solid.VectorSquare })
|
2023-07-10 03:00:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2024-03-30 18:03:40 +08:00
|
|
|
selectionCentreButton.Selected.DisabledChanged += isDisabled =>
|
2024-03-30 17:04:22 +08:00
|
|
|
{
|
2024-04-02 13:36:44 +08:00
|
|
|
selectionCentreButton.TooltipText = isDisabled ? "Select more than one object to perform selection-based rotation." : string.Empty;
|
2024-03-30 17:04:22 +08:00
|
|
|
};
|
2023-07-10 03:00:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2024-05-26 00:41:31 +08:00
|
|
|
ScheduleAfterChildren(() =>
|
|
|
|
{
|
|
|
|
angleInput.TakeFocus();
|
|
|
|
angleInput.SelectAll();
|
|
|
|
});
|
2023-07-10 03:00:35 +08:00
|
|
|
angleInput.Current.BindValueChanged(angle => rotationInfo.Value = rotationInfo.Value with { Degrees = angle.NewValue });
|
2024-11-03 14:23:55 +08:00
|
|
|
|
|
|
|
bool didSelect = false;
|
|
|
|
|
|
|
|
configRotationOrigin.BindValueChanged(val =>
|
|
|
|
{
|
|
|
|
switch (configRotationOrigin.Value)
|
|
|
|
{
|
|
|
|
case EditorOrigin.GridCentre:
|
|
|
|
if (!gridCentreButton.Selected.Disabled)
|
|
|
|
{
|
|
|
|
gridCentreButton.Select();
|
|
|
|
didSelect = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EditorOrigin.PlayfieldCentre:
|
|
|
|
if (!playfieldCentreButton.Selected.Disabled)
|
|
|
|
{
|
|
|
|
playfieldCentreButton.Select();
|
|
|
|
didSelect = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EditorOrigin.SelectionCentre:
|
|
|
|
if (!selectionCentreButton.Selected.Disabled)
|
|
|
|
{
|
|
|
|
selectionCentreButton.Select();
|
|
|
|
didSelect = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
if (!didSelect)
|
|
|
|
rotationOrigin.Items.First(b => !b.Selected.Disabled).Select();
|
|
|
|
|
|
|
|
gridCentreButton.Selected.BindValueChanged(b =>
|
|
|
|
{
|
|
|
|
if (b.NewValue) configRotationOrigin.Value = EditorOrigin.GridCentre;
|
|
|
|
});
|
|
|
|
playfieldCentreButton.Selected.BindValueChanged(b =>
|
|
|
|
{
|
|
|
|
if (b.NewValue) configRotationOrigin.Value = EditorOrigin.PlayfieldCentre;
|
|
|
|
});
|
|
|
|
selectionCentreButton.Selected.BindValueChanged(b =>
|
|
|
|
{
|
|
|
|
if (b.NewValue) configRotationOrigin.Value = EditorOrigin.SelectionCentre;
|
|
|
|
});
|
2023-07-10 03:00:35 +08:00
|
|
|
|
2024-05-29 15:40:29 +08:00
|
|
|
rotationHandler.CanRotateAroundSelectionOrigin.BindValueChanged(e =>
|
2024-01-25 15:24:35 +08:00
|
|
|
{
|
|
|
|
selectionCentreButton.Selected.Disabled = !e.NewValue;
|
|
|
|
}, true);
|
|
|
|
|
2023-07-10 03:00:35 +08:00
|
|
|
rotationInfo.BindValueChanged(rotation =>
|
|
|
|
{
|
2024-07-14 23:27:04 +08:00
|
|
|
rotationHandler.Update(rotation.NewValue.Degrees, getOriginPosition(rotation.NewValue));
|
2023-07-10 03:00:35 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-07-14 23:27:04 +08:00
|
|
|
private Vector2? getOriginPosition(PreciseRotationInfo rotation) =>
|
|
|
|
rotation.Origin switch
|
|
|
|
{
|
2024-11-03 14:20:45 +08:00
|
|
|
EditorOrigin.GridCentre => gridToolbox.StartPosition.Value,
|
|
|
|
EditorOrigin.PlayfieldCentre => OsuPlayfield.BASE_SIZE / 2,
|
|
|
|
EditorOrigin.SelectionCentre => null,
|
2024-07-14 23:27:04 +08:00
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(rotation))
|
|
|
|
};
|
|
|
|
|
2023-07-10 03:00:35 +08:00
|
|
|
protected override void PopIn()
|
|
|
|
{
|
|
|
|
base.PopIn();
|
|
|
|
rotationHandler.Begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
{
|
|
|
|
base.PopOut();
|
|
|
|
|
|
|
|
if (IsLoaded)
|
|
|
|
rotationHandler.Commit();
|
|
|
|
}
|
2024-10-17 03:53:56 +08:00
|
|
|
|
|
|
|
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
|
|
|
{
|
|
|
|
if (e.Action == GlobalAction.Select && !e.Repeat)
|
|
|
|
{
|
|
|
|
this.HidePopover();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return base.OnPressed(e);
|
|
|
|
}
|
2023-07-10 03:00:35 +08:00
|
|
|
}
|
|
|
|
|
2024-11-03 14:20:45 +08:00
|
|
|
public record PreciseRotationInfo(float Degrees, EditorOrigin Origin);
|
2023-07-10 03:00:35 +08:00
|
|
|
}
|