mirror of https://github.com/ppy/osu
Add test coverage and better UI handling of no tablet connected scenario
This commit is contained in:
parent
a8e319a320
commit
9a6a0f3df5
|
@ -8,6 +8,7 @@
|
|||
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 @@ private void load(GameHost host)
|
|||
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 @@ public class TestTabletHandler : ITabletHandler
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,11 @@
|
|||
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 @@ public class TabletSettings : SettingsSubsection
|
|||
|
||||
private ScheduledDelegate aspectRatioApplication;
|
||||
|
||||
private FillFlowContainer mainSettings;
|
||||
|
||||
private OsuSpriteText noTabletMessage;
|
||||
|
||||
protected override string Header => "Tablet";
|
||||
|
||||
public TabletSettings(ITabletHandler tabletHandler)
|
||||
|
@ -56,60 +62,77 @@ private void load()
|
|||
{
|
||||
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 @@ private void load()
|
|||
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;
|
||||
|
|
Loading…
Reference in New Issue