mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 17:43:21 +08:00
Initial pass of configuration interface
This commit is contained in:
parent
1c865682ae
commit
d026c8da85
40
osu.Game.Tests/Visual/Settings/TestSceneTabletSettings.cs
Normal file
40
osu.Game.Tests/Visual/Settings/TestSceneTabletSettings.cs
Normal 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),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,65 +1,46 @@
|
||||
// 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 NUnit.Framework;
|
||||
using OpenTabletDriver.Plugin.Tablet;
|
||||
using System.Drawing;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.Handlers.Tablet;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osuTK;
|
||||
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Settings
|
||||
namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestSceneTabletAreaSelection : OsuTestScene
|
||||
public class TabletAreaSelection : CompositeDrawable
|
||||
{
|
||||
private TabletAreaSelection areaSelection;
|
||||
|
||||
[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 ITabletHandler handler;
|
||||
|
||||
private readonly Container tabletContainer;
|
||||
private readonly Container usableAreaContainer;
|
||||
|
||||
public TabletAreaSelection(DigitizerIdentifier tablet)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
private readonly Bindable<Size> areaOffset = new BindableSize();
|
||||
private readonly Bindable<Size> areaSize = new BindableSize();
|
||||
private readonly Bindable<Size> tabletSize = new BindableSize();
|
||||
|
||||
this.tablet = tablet;
|
||||
public TabletAreaSelection(ITabletHandler handler)
|
||||
{
|
||||
this.handler = handler;
|
||||
|
||||
Padding = new MarginPadding(5);
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
tabletContainer = new Container
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Scale = new Vector2(3),
|
||||
Masking = true,
|
||||
CornerRadius = 5,
|
||||
BorderThickness = 2,
|
||||
BorderColour = Color4.Black,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
@ -69,6 +50,8 @@ namespace osu.Game.Tests.Visual.Settings
|
||||
},
|
||||
usableAreaContainer = new Container
|
||||
{
|
||||
Masking = true,
|
||||
CornerRadius = 5,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
@ -94,11 +77,23 @@ namespace osu.Game.Tests.Visual.Settings
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
// TODO: handle tablet device changes etc.
|
||||
tabletContainer.Size = new Vector2(tablet.Width, tablet.Height);
|
||||
areaOffset.BindTo(handler.AreaOffset);
|
||||
areaOffset.BindValueChanged(val =>
|
||||
{
|
||||
usableAreaContainer.MoveTo(new Vector2(val.NewValue.Width, val.NewValue.Height), 100, Easing.OutQuint);
|
||||
}, true);
|
||||
|
||||
usableAreaContainer.Position = new Vector2(10, 30);
|
||||
usableAreaContainer.Size = new Vector2(80, 60);
|
||||
areaSize.BindTo(handler.AreaSize);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
111
osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs
Normal file
111
osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs
Normal 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,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ using osu.Framework.Input.Handlers;
|
||||
using osu.Framework.Input.Handlers.Joystick;
|
||||
using osu.Framework.Input.Handlers.Midi;
|
||||
using osu.Framework.Input.Handlers.Mouse;
|
||||
using osu.Framework.Input.Handlers.Tablet;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Overlays.Settings.Sections.Input;
|
||||
|
||||
@ -55,6 +56,11 @@ namespace osu.Game.Overlays.Settings.Sections
|
||||
|
||||
switch (handler)
|
||||
{
|
||||
// ReSharper disable once SuspiciousTypeConversion.Global (net standard fuckery)
|
||||
case ITabletHandler th:
|
||||
section = new TabletSettings(th);
|
||||
break;
|
||||
|
||||
case MouseHandler mh:
|
||||
section = new MouseSettings(mh);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user