1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 19:27:24 +08:00

Add test coverage and better UI handling of no tablet connected scenario

This commit is contained in:
Dean Herbert 2021-03-16 23:47:08 +09:00
parent a8e319a320
commit 9a6a0f3df5
2 changed files with 89 additions and 51 deletions

View File

@ -8,6 +8,7 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Input.Handlers.Tablet;
using osu.Framework.Platform;
using osu.Framework.Utils;
using osu.Game.Overlays;
using osu.Game.Overlays.Settings.Sections.Input;
@ -39,6 +40,7 @@ namespace osu.Game.Tests.Visual.Settings
AddStep("Test with square tablet", () => tabletHandler.SetTabletSize(new Size(300, 300)));
AddStep("Test with tall tablet", () => tabletHandler.SetTabletSize(new Size(100, 300)));
AddStep("Test with very tall tablet", () => tabletHandler.SetTabletSize(new Size(100, 700)));
AddStep("Test no tablet present", () => tabletHandler.SetTabletSize(System.Drawing.Size.Empty));
}
public class TestTabletHandler : ITabletHandler
@ -48,10 +50,14 @@ namespace osu.Game.Tests.Visual.Settings
public BindableSize AreaOffset { get; } = new BindableSize();
public BindableSize AreaSize { get; } = new BindableSize();
public IBindable<Size> TabletSize => tabletSize;
public string DeviceName => "test tablet T-421";
public string DeviceName { get; private set; }
public BindableBool Enabled { get; } = new BindableBool(true);
public void SetTabletSize(Size size) => tabletSize.Value = size;
public void SetTabletSize(Size size)
{
DeviceName = size != System.Drawing.Size.Empty ? $"test tablet T-{RNG.Next(999):000}" : string.Empty;
tabletSize.Value = size;
}
}
}
}

View File

@ -5,9 +5,11 @@ using System.Drawing;
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.Framework.Platform;
using osu.Framework.Threading;
using osu.Game.Graphics.Sprites;
namespace osu.Game.Overlays.Settings.Sections.Input
{
@ -44,6 +46,10 @@ namespace osu.Game.Overlays.Settings.Sections.Input
private ScheduledDelegate aspectRatioApplication;
private FillFlowContainer mainSettings;
private OsuSpriteText noTabletMessage;
protected override string Header => "Tablet";
public TabletSettings(ITabletHandler tabletHandler)
@ -56,60 +62,77 @@ namespace osu.Game.Overlays.Settings.Sections.Input
{
Children = new Drawable[]
{
new TabletAreaSelection(tabletHandler)
noTabletMessage = new OsuSpriteText
{
Text = "No tablet detected!",
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
mainSettings = new FillFlowContainer
{
Alpha = 0,
RelativeSizeAxes = Axes.X,
Height = 300,
},
new DangerousSettingsButton
{
Text = "Reset to full area",
Action = () =>
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
aspectLock.Value = false;
new TabletAreaSelection(tabletHandler)
{
RelativeSizeAxes = Axes.X,
Height = 300,
Margin = new MarginPadding(10)
},
new DangerousSettingsButton
{
Text = "Reset to full area",
Action = () =>
{
aspectLock.Value = false;
areaOffset.SetDefault();
areaSize.SetDefault();
},
},
new SettingsButton
{
Text = "Conform to current game aspect ratio",
Action = () =>
{
forceAspectRatio((float)host.Window.ClientSize.Width / host.Window.ClientSize.Height);
areaOffset.SetDefault();
areaSize.SetDefault();
},
},
new SettingsButton
{
Text = "Conform to current game aspect ratio",
Action = () =>
{
forceAspectRatio((float)host.Window.ClientSize.Width / host.Window.ClientSize.Height);
}
},
new SettingsSlider<float>
{
LabelText = "Aspect Ratio",
Current = aspectRatio
},
new SettingsSlider<int>
{
LabelText = "X Offset",
Current = offsetX
},
new SettingsSlider<int>
{
LabelText = "Y Offset",
Current = offsetY
},
new SettingsCheckbox
{
LabelText = "Lock aspect ratio",
Current = aspectLock
},
new SettingsSlider<int>
{
LabelText = "Width",
Current = sizeX
},
new SettingsSlider<int>
{
LabelText = "Height",
Current = sizeY
},
}
},
new SettingsSlider<float>
{
LabelText = "Aspect Ratio",
Current = aspectRatio
},
new SettingsSlider<int>
{
LabelText = "X Offset",
Current = offsetX
},
new SettingsSlider<int>
{
LabelText = "Y Offset",
Current = offsetY
},
new SettingsCheckbox
{
LabelText = "Lock aspect ratio",
Current = aspectLock
},
new SettingsSlider<int>
{
LabelText = "Width",
Current = sizeX
},
new SettingsSlider<int>
{
LabelText = "Height",
Current = sizeY
},
};
areaOffset.BindTo(tabletHandler.AreaOffset);
@ -154,8 +177,17 @@ namespace osu.Game.Overlays.Settings.Sections.Input
tabletSize.BindTo(tabletHandler.TabletSize);
tabletSize.BindValueChanged(val =>
{
if (tabletSize.Value == System.Drawing.Size.Empty)
bool tabletFound = tabletSize.Value != System.Drawing.Size.Empty;
if (!tabletFound)
{
mainSettings.Hide();
noTabletMessage.Show();
return;
}
mainSettings.Show();
noTabletMessage.Hide();
// todo: these should propagate from a TabletChanged event or similar.
offsetX.MaxValue = val.NewValue.Width;