From d026c8da851a5fbd399206b8efff28b76c09c643 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 15 Mar 2021 18:37:46 +0900 Subject: [PATCH] Initial pass of configuration interface --- .../Settings/TestSceneTabletSettings.cs | 40 +++++++ .../Sections/Input/TabletAreaSelection.cs | 79 ++++++------- .../Settings/Sections/Input/TabletSettings.cs | 111 ++++++++++++++++++ .../Settings/Sections/InputSection.cs | 6 + 4 files changed, 194 insertions(+), 42 deletions(-) create mode 100644 osu.Game.Tests/Visual/Settings/TestSceneTabletSettings.cs rename osu.Game.Tests/Visual/Settings/TestSceneTabletAreaSelection.cs => osu.Game/Overlays/Settings/Sections/Input/TabletAreaSelection.cs (55%) create mode 100644 osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs diff --git a/osu.Game.Tests/Visual/Settings/TestSceneTabletSettings.cs b/osu.Game.Tests/Visual/Settings/TestSceneTabletSettings.cs new file mode 100644 index 0000000000..be5b355e06 --- /dev/null +++ b/osu.Game.Tests/Visual/Settings/TestSceneTabletSettings.cs @@ -0,0 +1,40 @@ +// Copyright (c) ppy Pty Ltd . 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().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), + }); + } + } +} diff --git a/osu.Game.Tests/Visual/Settings/TestSceneTabletAreaSelection.cs b/osu.Game/Overlays/Settings/Sections/Input/TabletAreaSelection.cs similarity index 55% rename from osu.Game.Tests/Visual/Settings/TestSceneTabletAreaSelection.cs rename to osu.Game/Overlays/Settings/Sections/Input/TabletAreaSelection.cs index 30e265baaa..31a2768735 100644 --- a/osu.Game.Tests/Visual/Settings/TestSceneTabletAreaSelection.cs +++ b/osu.Game/Overlays/Settings/Sections/Input/TabletAreaSelection.cs @@ -1,65 +1,46 @@ // Copyright (c) ppy Pty Ltd . 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 areaOffset = new BindableSize(); + private readonly Bindable areaSize = new BindableSize(); + private readonly Bindable 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)tabletSize).BindTo(handler.TabletSize); + tabletSize.BindValueChanged(val => + { + tabletContainer.ResizeTo(new Vector2(tabletSize.Value.Width, tabletSize.Value.Height), 100, Easing.OutQuint); + }, true); } } } diff --git a/osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs b/osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs new file mode 100644 index 0000000000..5df9c879eb --- /dev/null +++ b/osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs @@ -0,0 +1,111 @@ +// Copyright (c) ppy Pty Ltd . 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 offsetX = new BindableNumber { MinValue = 0 }; + private readonly BindableNumber offsetY = new BindableNumber { MinValue = 0 }; + + private readonly BindableNumber sizeX = new BindableNumber { MinValue = 0 }; + private readonly BindableNumber sizeY = new BindableNumber { 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)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 + { + LabelText = "Offset X", + Current = offsetX + }, + new SettingsSlider + { + LabelText = "Offset Y", + Current = offsetY + }, + new SettingsSlider + { + LabelText = "Size X", + Current = sizeX + }, + new SettingsSlider + { + LabelText = "Size Y", + Current = sizeY + }, + new TabletAreaSelection(tabletHandler) + { + RelativeSizeAxes = Axes.X, + Height = 100, + } + }; + } + } +} diff --git a/osu.Game/Overlays/Settings/Sections/InputSection.cs b/osu.Game/Overlays/Settings/Sections/InputSection.cs index 8d5944f5bf..6e99891794 100644 --- a/osu.Game/Overlays/Settings/Sections/InputSection.cs +++ b/osu.Game/Overlays/Settings/Sections/InputSection.cs @@ -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;