Skip to content

Commit

Permalink
Remember origin for editor rotation popover
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Nov 3, 2024
1 parent b03963a commit 3a3471c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 6 deletions.
65 changes: 61 additions & 4 deletions osu.Game.Rulesets.Osu/Edit/PreciseRotationPopover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Game.Configuration;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Input.Bindings;
using osu.Game.Rulesets.Osu.UI;
Expand All @@ -30,8 +31,12 @@ public partial class PreciseRotationPopover : OsuPopover
private SliderWithTextBoxInput<float> angleInput = null!;
private EditorRadioButtonCollection rotationOrigin = null!;

private RadioButton gridCentreButton = null!;
private RadioButton playfieldCentreButton = null!;
private RadioButton selectionCentreButton = null!;

private Bindable<EditorOrigin> configRotationOrigin = null!;

public PreciseRotationPopover(SelectionRotationHandler rotationHandler, OsuGridToolboxGroup gridToolbox)
{
this.rotationHandler = rotationHandler;
Expand All @@ -41,8 +46,10 @@ public PreciseRotationPopover(SelectionRotationHandler rotationHandler, OsuGridT
}

[BackgroundDependencyLoader]
private void load()
private void load(OsuConfigManager config)
{
configRotationOrigin = config.GetBindable<EditorOrigin>(OsuSetting.EditorRotationOrigin);

Child = new FillFlowContainer
{
Width = 220,
Expand All @@ -66,10 +73,10 @@ private void load()
RelativeSizeAxes = Axes.X,
Items = new[]
{
new RadioButton("Grid centre",
gridCentreButton = new RadioButton("Grid centre",
() => rotationInfo.Value = rotationInfo.Value with { Origin = EditorOrigin.GridCentre },
() => new SpriteIcon { Icon = FontAwesome.Regular.PlusSquare }),
new RadioButton("Playfield centre",
playfieldCentreButton = new RadioButton("Playfield centre",
() => rotationInfo.Value = rotationInfo.Value with { Origin = EditorOrigin.PlayfieldCentre },
() => new SpriteIcon { Icon = FontAwesome.Regular.Square }),
selectionCentreButton = new RadioButton("Selection centre",
Expand All @@ -95,7 +102,57 @@ protected override void LoadComplete()
angleInput.SelectAll();
});
angleInput.Current.BindValueChanged(angle => rotationInfo.Value = rotationInfo.Value with { Degrees = angle.NewValue });
rotationOrigin.Items.First().Select();

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;
});

rotationHandler.CanRotateAroundSelectionOrigin.BindValueChanged(e =>
{
Expand Down
5 changes: 3 additions & 2 deletions osu.Game/Configuration/OsuConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ protected override void InitialiseDefaults()
SetDefault(OsuSetting.EditorLimitedDistanceSnap, false);
SetDefault(OsuSetting.EditorShowSpeedChanges, false);
SetDefault(OsuSetting.EditorScaleOrigin, EditorOrigin.GridCentre);
SetDefault(OsuSetting.EditorRotateOrigin, EditorOrigin.GridCentre);
SetDefault(OsuSetting.EditorRotationOrigin, EditorOrigin.GridCentre);

SetDefault(OsuSetting.HideCountryFlags, false);

Expand Down Expand Up @@ -438,6 +438,7 @@ public enum OsuSetting
EditorTimelineShowTicks,
AlwaysShowHoldForMenuButton,
EditorContractSidebars,
EditorScaleOrigin
EditorScaleOrigin,
EditorRotationOrigin
}
}

0 comments on commit 3a3471c

Please sign in to comment.