mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 15:43:22 +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)
|
||||||
@ -56,60 +62,77 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
{
|
{
|
||||||
Children = new Drawable[]
|
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,
|
RelativeSizeAxes = Axes.X,
|
||||||
Height = 300,
|
AutoSizeAxes = Axes.Y,
|
||||||
},
|
Direction = FillDirection.Vertical,
|
||||||
new DangerousSettingsButton
|
Children = new Drawable[]
|
||||||
{
|
|
||||||
Text = "Reset to full area",
|
|
||||||
Action = () =>
|
|
||||||
{
|
{
|
||||||
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();
|
areaOffset.SetDefault();
|
||||||
areaSize.SetDefault();
|
areaSize.SetDefault();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
new SettingsButton
|
new SettingsButton
|
||||||
{
|
{
|
||||||
Text = "Conform to current game aspect ratio",
|
Text = "Conform to current game aspect ratio",
|
||||||
Action = () =>
|
Action = () =>
|
||||||
{
|
{
|
||||||
forceAspectRatio((float)host.Window.ClientSize.Width / host.Window.ClientSize.Height);
|
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);
|
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