From 9a6a0f3df5e8a2d4a67f4bc567ba3e5db8a76a2c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 16 Mar 2021 23:47:08 +0900 Subject: [PATCH] Add test coverage and better UI handling of no tablet connected scenario --- .../Settings/TestSceneTabletSettings.cs | 10 +- .../Settings/Sections/Input/TabletSettings.cs | 130 +++++++++++------- 2 files changed, 89 insertions(+), 51 deletions(-) diff --git a/osu.Game.Tests/Visual/Settings/TestSceneTabletSettings.cs b/osu.Game.Tests/Visual/Settings/TestSceneTabletSettings.cs index aaf2f13953..2baeadddc0 100644 --- a/osu.Game.Tests/Visual/Settings/TestSceneTabletSettings.cs +++ b/osu.Game.Tests/Visual/Settings/TestSceneTabletSettings.cs @@ -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 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; + } } } } diff --git a/osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs b/osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs index 3f8723025f..7da61cf192 100644 --- a/osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs @@ -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 + { + LabelText = "Aspect Ratio", + Current = aspectRatio + }, + new SettingsSlider + { + LabelText = "X Offset", + Current = offsetX + }, + new SettingsSlider + { + LabelText = "Y Offset", + Current = offsetY + }, + new SettingsCheckbox + { + LabelText = "Lock aspect ratio", + Current = aspectLock + }, + new SettingsSlider + { + LabelText = "Width", + Current = sizeX + }, + new SettingsSlider + { + LabelText = "Height", + Current = sizeY + }, } }, - new SettingsSlider - { - LabelText = "Aspect Ratio", - Current = aspectRatio - }, - new SettingsSlider - { - LabelText = "X Offset", - Current = offsetX - }, - new SettingsSlider - { - LabelText = "Y Offset", - Current = offsetY - }, - new SettingsCheckbox - { - LabelText = "Lock aspect ratio", - Current = aspectLock - }, - new SettingsSlider - { - LabelText = "Width", - Current = sizeX - }, - new SettingsSlider - { - 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;