1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 20:33:11 +08:00

Initial pass of configuration interface

This commit is contained in:
Dean Herbert 2021-03-15 18:37:46 +09:00
parent 1c865682ae
commit d026c8da85
4 changed files with 194 additions and 42 deletions

View File

@ -0,0 +1,40 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Drawing;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Input.Handlers.Tablet;
using osu.Framework.Platform;
using osu.Game.Overlays.Settings.Sections.Input;
namespace osu.Game.Tests.Visual.Settings
{
[TestFixture]
public class TestSceneTabletSettings : OsuTestScene
{
[BackgroundDependencyLoader]
private void load(GameHost host)
{
var tabletHandler = host.AvailableInputHandlers.OfType<ITabletHandler>().FirstOrDefault();
if (tabletHandler == null)
return;
tabletHandler.AreaOffset.MinValue = new Size(0, 0);
tabletHandler.AreaOffset.MaxValue = new Size(160, 100);
tabletHandler.AreaOffset.Value = new Size(10, 10);
tabletHandler.AreaSize.MinValue = new Size(0, 0);
tabletHandler.AreaSize.MaxValue = new Size(160, 100);
tabletHandler.AreaSize.Value = new Size(100, 80);
AddRange(new Drawable[]
{
new TabletSettings(tabletHandler),
});
}
}
}

View File

@ -1,65 +1,46 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using NUnit.Framework; using System.Drawing;
using OpenTabletDriver.Plugin.Tablet;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Handlers.Tablet;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Tests.Visual.Settings namespace osu.Game.Overlays.Settings.Sections.Input
{ {
[TestFixture] public class TabletAreaSelection : CompositeDrawable
public class TestSceneTabletAreaSelection : OsuTestScene
{ {
private TabletAreaSelection areaSelection; private readonly ITabletHandler handler;
[BackgroundDependencyLoader]
private void load()
{
DigitizerIdentifier testTablet = new DigitizerIdentifier
{
// size specifications in millimetres.
Width = 160,
Height = 100,
};
AddRange(new[]
{
areaSelection = new TabletAreaSelection(testTablet)
{
State = { Value = Visibility.Visible }
}
});
}
}
public class TabletAreaSelection : OsuFocusedOverlayContainer
{
private readonly DigitizerIdentifier tablet;
private readonly Container tabletContainer; private readonly Container tabletContainer;
private readonly Container usableAreaContainer; private readonly Container usableAreaContainer;
public TabletAreaSelection(DigitizerIdentifier tablet) private readonly Bindable<Size> areaOffset = new BindableSize();
{ private readonly Bindable<Size> areaSize = new BindableSize();
RelativeSizeAxes = Axes.Both; private readonly Bindable<Size> tabletSize = new BindableSize();
this.tablet = tablet; public TabletAreaSelection(ITabletHandler handler)
{
this.handler = handler;
Padding = new MarginPadding(5);
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
tabletContainer = new Container tabletContainer = new Container
{ {
Anchor = Anchor.Centre, Masking = true,
Origin = Anchor.Centre, CornerRadius = 5,
Scale = new Vector2(3), BorderThickness = 2,
BorderColour = Color4.Black,
Children = new Drawable[] Children = new Drawable[]
{ {
new Box new Box
@ -69,6 +50,8 @@ namespace osu.Game.Tests.Visual.Settings
}, },
usableAreaContainer = new Container usableAreaContainer = new Container
{ {
Masking = true,
CornerRadius = 5,
Children = new Drawable[] Children = new Drawable[]
{ {
new Box new Box
@ -94,11 +77,23 @@ namespace osu.Game.Tests.Visual.Settings
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
// TODO: handle tablet device changes etc. areaOffset.BindTo(handler.AreaOffset);
tabletContainer.Size = new Vector2(tablet.Width, tablet.Height); areaOffset.BindValueChanged(val =>
{
usableAreaContainer.MoveTo(new Vector2(val.NewValue.Width, val.NewValue.Height), 100, Easing.OutQuint);
}, true);
usableAreaContainer.Position = new Vector2(10, 30); areaSize.BindTo(handler.AreaSize);
usableAreaContainer.Size = new Vector2(80, 60); areaSize.BindValueChanged(val =>
{
usableAreaContainer.ResizeTo(new Vector2(val.NewValue.Width, val.NewValue.Height), 100, Easing.OutQuint);
}, true);
((IBindable<Size>)tabletSize).BindTo(handler.TabletSize);
tabletSize.BindValueChanged(val =>
{
tabletContainer.ResizeTo(new Vector2(tabletSize.Value.Width, tabletSize.Value.Height), 100, Easing.OutQuint);
}, true);
} }
} }
} }

View File

@ -0,0 +1,111 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Drawing;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Input.Handlers.Tablet;
using osu.Game.Configuration;
namespace osu.Game.Overlays.Settings.Sections.Input
{
public class TabletSettings : SettingsSubsection
{
private readonly ITabletHandler tabletHandler;
private readonly BindableSize areaOffset = new BindableSize();
private readonly BindableSize areaSize = new BindableSize();
private readonly BindableSize tabletSize = new BindableSize();
private readonly BindableNumber<int> offsetX = new BindableNumber<int> { MinValue = 0 };
private readonly BindableNumber<int> offsetY = new BindableNumber<int> { MinValue = 0 };
private readonly BindableNumber<int> sizeX = new BindableNumber<int> { MinValue = 0 };
private readonly BindableNumber<int> sizeY = new BindableNumber<int> { MinValue = 0 };
protected override string Header => "Tablet";
public TabletSettings(ITabletHandler tabletHandler)
{
this.tabletHandler = tabletHandler;
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager osuConfig, FrameworkConfigManager config)
{
// TODO: this should all eventually be replaced with a control that handles BindableSize.
areaOffset.BindTo(tabletHandler.AreaOffset);
areaOffset.BindValueChanged(val =>
{
offsetX.Value = val.NewValue.Width;
offsetY.Value = val.NewValue.Height;
}, true);
offsetX.BindValueChanged(val => areaOffset.Value = new Size(val.NewValue, areaOffset.Value.Height));
offsetY.BindValueChanged(val => areaOffset.Value = new Size(areaOffset.Value.Width, val.NewValue));
areaSize.BindTo(tabletHandler.AreaSize);
areaSize.BindValueChanged(val =>
{
sizeX.Value = val.NewValue.Width;
sizeY.Value = val.NewValue.Height;
}, true);
sizeX.BindValueChanged(val => areaSize.Value = new Size(val.NewValue, areaSize.Value.Height));
sizeY.BindValueChanged(val => areaSize.Value = new Size(areaSize.Value.Width, val.NewValue));
((IBindable<Size>)tabletSize).BindTo(tabletHandler.TabletSize);
tabletSize.BindValueChanged(val =>
{
// todo: these should propagate from a TabletChanged event or similar.
offsetX.MaxValue = val.NewValue.Width;
sizeX.Default = sizeX.MaxValue = val.NewValue.Width;
offsetY.MaxValue = val.NewValue.Height;
sizeY.Default = sizeY.MaxValue = val.NewValue.Height;
updateDisplay();
}, true);
}
private void updateDisplay()
{
if (tabletSize.Value == System.Drawing.Size.Empty)
{
Clear();
return;
}
Children = new Drawable[]
{
new SettingsSlider<int>
{
LabelText = "Offset X",
Current = offsetX
},
new SettingsSlider<int>
{
LabelText = "Offset Y",
Current = offsetY
},
new SettingsSlider<int>
{
LabelText = "Size X",
Current = sizeX
},
new SettingsSlider<int>
{
LabelText = "Size Y",
Current = sizeY
},
new TabletAreaSelection(tabletHandler)
{
RelativeSizeAxes = Axes.X,
Height = 100,
}
};
}
}
}

View File

@ -8,6 +8,7 @@ using osu.Framework.Input.Handlers;
using osu.Framework.Input.Handlers.Joystick; using osu.Framework.Input.Handlers.Joystick;
using osu.Framework.Input.Handlers.Midi; using osu.Framework.Input.Handlers.Midi;
using osu.Framework.Input.Handlers.Mouse; using osu.Framework.Input.Handlers.Mouse;
using osu.Framework.Input.Handlers.Tablet;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Game.Overlays.Settings.Sections.Input; using osu.Game.Overlays.Settings.Sections.Input;
@ -55,6 +56,11 @@ namespace osu.Game.Overlays.Settings.Sections
switch (handler) switch (handler)
{ {
// ReSharper disable once SuspiciousTypeConversion.Global (net standard fuckery)
case ITabletHandler th:
section = new TabletSettings(th);
break;
case MouseHandler mh: case MouseHandler mh:
section = new MouseSettings(mh); section = new MouseSettings(mh);
break; break;