2021-03-30 12:01:48 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2021-10-12 05:10:56 +08:00
|
|
|
using System.Collections.Generic;
|
2021-03-30 12:01:48 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Input.Handlers.Tablet;
|
|
|
|
using osu.Game.Graphics;
|
2021-10-12 05:10:56 +08:00
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
2021-03-30 12:01:48 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Settings.Sections.Input
|
|
|
|
{
|
2021-10-12 05:10:56 +08:00
|
|
|
internal class RotationPresetButtons : CompositeDrawable
|
2021-03-30 12:01:48 +08:00
|
|
|
{
|
2021-10-12 05:10:56 +08:00
|
|
|
public new MarginPadding Padding
|
|
|
|
{
|
|
|
|
get => base.Padding;
|
|
|
|
set => base.Padding = value;
|
|
|
|
}
|
|
|
|
|
2021-03-30 12:01:48 +08:00
|
|
|
private readonly ITabletHandler tabletHandler;
|
|
|
|
|
|
|
|
private Bindable<float> rotation;
|
2021-10-12 05:10:56 +08:00
|
|
|
private readonly RotationButton[] rotationPresets = new RotationButton[preset_count];
|
2021-03-30 12:01:48 +08:00
|
|
|
|
2021-10-12 05:10:56 +08:00
|
|
|
private const int preset_count = 4;
|
2021-03-30 12:01:48 +08:00
|
|
|
private const int height = 50;
|
|
|
|
|
|
|
|
public RotationPresetButtons(ITabletHandler tabletHandler)
|
|
|
|
{
|
|
|
|
this.tabletHandler = tabletHandler;
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
Height = height;
|
|
|
|
|
2021-10-12 05:10:56 +08:00
|
|
|
IEnumerable<Dimension> createColumns(int count)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
yield return new Dimension(GridSizeMode.Absolute, 10);
|
|
|
|
|
|
|
|
yield return new Dimension();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GridContainer grid;
|
|
|
|
|
|
|
|
InternalChild = grid = new GridContainer
|
2021-03-30 12:01:48 +08:00
|
|
|
{
|
2021-10-12 05:10:56 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
ColumnDimensions = createColumns(preset_count).ToArray()
|
|
|
|
};
|
2021-03-30 12:01:48 +08:00
|
|
|
|
2021-10-12 05:10:56 +08:00
|
|
|
grid.Content = new[] { new Drawable[preset_count * 2 - 1] };
|
|
|
|
|
|
|
|
for (int i = 0; i < preset_count; i++)
|
|
|
|
{
|
2021-10-27 12:04:41 +08:00
|
|
|
int rotationValue = i * 90;
|
2021-10-12 05:10:56 +08:00
|
|
|
|
|
|
|
var rotationPreset = new RotationButton(rotationValue)
|
2021-03-30 12:01:48 +08:00
|
|
|
{
|
2021-10-12 05:10:56 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Height = 1,
|
|
|
|
Text = $@"{rotationValue}º",
|
|
|
|
Action = () => tabletHandler.Rotation.Value = rotationValue,
|
|
|
|
};
|
|
|
|
grid.Content[0][2 * i] = rotationPresets[i] = rotationPreset;
|
2021-03-30 12:01:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
rotation = tabletHandler.Rotation.GetBoundCopy();
|
|
|
|
rotation.BindValueChanged(val =>
|
|
|
|
{
|
2021-10-12 05:10:56 +08:00
|
|
|
foreach (var b in rotationPresets)
|
2021-03-30 12:01:48 +08:00
|
|
|
b.IsSelected = b.Preset == val.NewValue;
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
2021-10-12 05:10:56 +08:00
|
|
|
public class RotationButton : RoundedButton
|
2021-03-30 12:01:48 +08:00
|
|
|
{
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
2021-10-12 05:10:56 +08:00
|
|
|
[Resolved]
|
|
|
|
private OverlayColourProvider colourProvider { get; set; }
|
|
|
|
|
2021-03-30 12:01:48 +08:00
|
|
|
public readonly int Preset;
|
|
|
|
|
|
|
|
public RotationButton(int preset)
|
|
|
|
{
|
|
|
|
Preset = preset;
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool isSelected;
|
|
|
|
|
|
|
|
public bool IsSelected
|
|
|
|
{
|
|
|
|
get => isSelected;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value == isSelected)
|
|
|
|
return;
|
|
|
|
|
|
|
|
isSelected = value;
|
|
|
|
|
|
|
|
if (IsLoaded)
|
|
|
|
updateColour();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
updateColour();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateColour()
|
|
|
|
{
|
2021-10-12 05:10:56 +08:00
|
|
|
BackgroundColour = isSelected ? colours.Blue3 : colourProvider.Background3;
|
2021-03-30 12:01:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|