mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 05:22:54 +08:00
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.Bindables;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Input.Handlers.Tablet;
|
using osu.Framework.Input.Handlers.Tablet;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.Settings.Sections.Input;
|
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 square tablet", () => tabletHandler.SetTabletSize(new Size(300, 300)));
|
||||||
AddStep("Test with tall tablet", () => tabletHandler.SetTabletSize(new Size(100, 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 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
|
public class TestTabletHandler : ITabletHandler
|
||||||
@ -48,10 +50,14 @@ namespace osu.Game.Tests.Visual.Settings
|
|||||||
public BindableSize AreaOffset { get; } = new BindableSize();
|
public BindableSize AreaOffset { get; } = new BindableSize();
|
||||||
public BindableSize AreaSize { get; } = new BindableSize();
|
public BindableSize AreaSize { get; } = new BindableSize();
|
||||||
public IBindable<Size> TabletSize => tabletSize;
|
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 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 System.Drawing;
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Input.Handlers.Tablet;
|
using osu.Framework.Input.Handlers.Tablet;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Settings.Sections.Input
|
namespace osu.Game.Overlays.Settings.Sections.Input
|
||||||
{
|
{
|
||||||
@ -44,6 +46,10 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
|
|
||||||
private ScheduledDelegate aspectRatioApplication;
|
private ScheduledDelegate aspectRatioApplication;
|
||||||
|
|
||||||
|
private FillFlowContainer mainSettings;
|
||||||
|
|
||||||
|
private OsuSpriteText noTabletMessage;
|
||||||
|
|
||||||
protected override string Header => "Tablet";
|
protected override string Header => "Tablet";
|
||||||
|
|
||||||
public TabletSettings(ITabletHandler tabletHandler)
|
public TabletSettings(ITabletHandler tabletHandler)
|
||||||
@ -54,12 +60,27 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
noTabletMessage = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Text = "No tablet detected!",
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
},
|
||||||
|
mainSettings = new FillFlowContainer
|
||||||
|
{
|
||||||
|
Alpha = 0,
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
Direction = FillDirection.Vertical,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new TabletAreaSelection(tabletHandler)
|
new TabletAreaSelection(tabletHandler)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Height = 300,
|
Height = 300,
|
||||||
|
Margin = new MarginPadding(10)
|
||||||
},
|
},
|
||||||
new DangerousSettingsButton
|
new DangerousSettingsButton
|
||||||
{
|
{
|
||||||
@ -110,6 +131,8 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
LabelText = "Height",
|
LabelText = "Height",
|
||||||
Current = sizeY
|
Current = sizeY
|
||||||
},
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
areaOffset.BindTo(tabletHandler.AreaOffset);
|
areaOffset.BindTo(tabletHandler.AreaOffset);
|
||||||
@ -154,8 +177,17 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
tabletSize.BindTo(tabletHandler.TabletSize);
|
tabletSize.BindTo(tabletHandler.TabletSize);
|
||||||
tabletSize.BindValueChanged(val =>
|
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;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mainSettings.Show();
|
||||||
|
noTabletMessage.Hide();
|
||||||
|
|
||||||
// todo: these should propagate from a TabletChanged event or similar.
|
// todo: these should propagate from a TabletChanged event or similar.
|
||||||
offsetX.MaxValue = val.NewValue.Width;
|
offsetX.MaxValue = val.NewValue.Width;
|
||||||
|
Loading…
Reference in New Issue
Block a user