mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 10:42:54 +08:00
Update bindings settings to handle the new structure and show all handlers
This commit is contained in:
parent
8635abbc4a
commit
03230edcb1
@ -1,11 +1,11 @@
|
|||||||
// 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 osu.Framework;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Input.Handlers.Mouse;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Input;
|
using osu.Game.Input;
|
||||||
@ -14,35 +14,39 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
{
|
{
|
||||||
public class MouseSettings : SettingsSubsection
|
public class MouseSettings : SettingsSubsection
|
||||||
{
|
{
|
||||||
|
private readonly MouseHandler mouseHandler;
|
||||||
|
|
||||||
protected override string Header => "Mouse";
|
protected override string Header => "Mouse";
|
||||||
|
|
||||||
private readonly BindableBool rawInputToggle = new BindableBool();
|
private Bindable<double> handlerSensitivity;
|
||||||
|
|
||||||
private Bindable<double> configSensitivity;
|
|
||||||
|
|
||||||
private Bindable<double> localSensitivity;
|
private Bindable<double> localSensitivity;
|
||||||
|
|
||||||
private Bindable<string> ignoredInputHandlers;
|
|
||||||
|
|
||||||
private Bindable<WindowMode> windowMode;
|
private Bindable<WindowMode> windowMode;
|
||||||
private SettingsEnumDropdown<OsuConfineMouseMode> confineMouseModeSetting;
|
private SettingsEnumDropdown<OsuConfineMouseMode> confineMouseModeSetting;
|
||||||
|
private Bindable<bool> relativeMode;
|
||||||
|
|
||||||
|
public MouseSettings(MouseHandler mouseHandler)
|
||||||
|
{
|
||||||
|
this.mouseHandler = mouseHandler;
|
||||||
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuConfigManager osuConfig, FrameworkConfigManager config)
|
private void load(OsuConfigManager osuConfig, FrameworkConfigManager config)
|
||||||
{
|
{
|
||||||
// use local bindable to avoid changing enabled state of game host's bindable.
|
// use local bindable to avoid changing enabled state of game host's bindable.
|
||||||
configSensitivity = config.GetBindable<double>(FrameworkSetting.CursorSensitivity);
|
handlerSensitivity = mouseHandler.Sensitivity.GetBoundCopy();
|
||||||
localSensitivity = configSensitivity.GetUnboundCopy();
|
localSensitivity = handlerSensitivity.GetUnboundCopy();
|
||||||
|
|
||||||
|
relativeMode = mouseHandler.UseRelativeMode.GetBoundCopy();
|
||||||
windowMode = config.GetBindable<WindowMode>(FrameworkSetting.WindowMode);
|
windowMode = config.GetBindable<WindowMode>(FrameworkSetting.WindowMode);
|
||||||
ignoredInputHandlers = config.GetBindable<string>(FrameworkSetting.IgnoredInputHandlers);
|
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new SettingsCheckbox
|
new SettingsCheckbox
|
||||||
{
|
{
|
||||||
LabelText = "Raw input",
|
LabelText = "High precision mouse",
|
||||||
Current = rawInputToggle
|
Current = relativeMode
|
||||||
},
|
},
|
||||||
new SensitivitySetting
|
new SensitivitySetting
|
||||||
{
|
{
|
||||||
@ -76,7 +80,9 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
configSensitivity.BindValueChanged(val =>
|
relativeMode.BindValueChanged(relative => localSensitivity.Disabled = !relative.NewValue, true);
|
||||||
|
|
||||||
|
handlerSensitivity.BindValueChanged(val =>
|
||||||
{
|
{
|
||||||
var disabled = localSensitivity.Disabled;
|
var disabled = localSensitivity.Disabled;
|
||||||
|
|
||||||
@ -85,7 +91,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
localSensitivity.Disabled = disabled;
|
localSensitivity.Disabled = disabled;
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
localSensitivity.BindValueChanged(val => configSensitivity.Value = val.NewValue);
|
localSensitivity.BindValueChanged(val => handlerSensitivity.Value = val.NewValue);
|
||||||
|
|
||||||
windowMode.BindValueChanged(mode =>
|
windowMode.BindValueChanged(mode =>
|
||||||
{
|
{
|
||||||
@ -102,32 +108,6 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
confineMouseModeSetting.TooltipText = string.Empty;
|
confineMouseModeSetting.TooltipText = string.Empty;
|
||||||
}
|
}
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
if (RuntimeInfo.OS != RuntimeInfo.Platform.Windows)
|
|
||||||
{
|
|
||||||
rawInputToggle.Disabled = true;
|
|
||||||
localSensitivity.Disabled = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rawInputToggle.ValueChanged += enabled =>
|
|
||||||
{
|
|
||||||
// this is temporary until we support per-handler settings.
|
|
||||||
const string raw_mouse_handler = @"OsuTKRawMouseHandler";
|
|
||||||
const string standard_mouse_handlers = @"OsuTKMouseHandler MouseHandler";
|
|
||||||
|
|
||||||
ignoredInputHandlers.Value = enabled.NewValue ? standard_mouse_handlers : raw_mouse_handler;
|
|
||||||
};
|
|
||||||
|
|
||||||
ignoredInputHandlers.ValueChanged += handler =>
|
|
||||||
{
|
|
||||||
bool raw = !handler.NewValue.Contains("Raw");
|
|
||||||
rawInputToggle.Value = raw;
|
|
||||||
localSensitivity.Disabled = !raw;
|
|
||||||
};
|
|
||||||
|
|
||||||
ignoredInputHandlers.TriggerChange();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SensitivitySetting : SettingsSlider<double, SensitivitySlider>
|
private class SensitivitySetting : SettingsSlider<double, SensitivitySlider>
|
||||||
@ -141,7 +121,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
|
|
||||||
private class SensitivitySlider : OsuSliderBar<double>
|
private class SensitivitySlider : OsuSliderBar<double>
|
||||||
{
|
{
|
||||||
public override string TooltipText => Current.Disabled ? "enable raw input to adjust sensitivity" : $"{base.TooltipText}x";
|
public override string TooltipText => Current.Disabled ? "enable high precision mouse to adjust sensitivity" : $"{base.TooltipText}x";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,88 @@
|
|||||||
// 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 osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Input.Handlers;
|
||||||
|
using osu.Framework.Input.Handlers.Mouse;
|
||||||
|
using osu.Framework.Platform;
|
||||||
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Overlays.Settings.Sections.Input;
|
using osu.Game.Overlays.Settings.Sections.Input;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Settings.Sections
|
namespace osu.Game.Overlays.Settings.Sections
|
||||||
{
|
{
|
||||||
public class InputSection : SettingsSection
|
public class InputSection : SettingsSection
|
||||||
{
|
{
|
||||||
|
private readonly KeyBindingPanel keyConfig;
|
||||||
|
|
||||||
public override string Header => "Input";
|
public override string Header => "Input";
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private GameHost host { get; set; }
|
||||||
|
|
||||||
public override Drawable CreateIcon() => new SpriteIcon
|
public override Drawable CreateIcon() => new SpriteIcon
|
||||||
{
|
{
|
||||||
Icon = FontAwesome.Solid.Keyboard
|
Icon = FontAwesome.Solid.Keyboard
|
||||||
};
|
};
|
||||||
|
|
||||||
public InputSection(KeyBindingPanel keyConfig)
|
public InputSection(KeyBindingPanel keyConfig)
|
||||||
|
{
|
||||||
|
this.keyConfig = keyConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
{
|
{
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new MouseSettings(),
|
new BindingSettings(keyConfig),
|
||||||
new KeyboardSettings(keyConfig),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
foreach (var handler in host.AvailableInputHandlers)
|
||||||
|
{
|
||||||
|
var handlerSection = createSectionFor(handler);
|
||||||
|
|
||||||
|
if (handlerSection != null)
|
||||||
|
Add(handlerSection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private SettingsSubsection createSectionFor(InputHandler handler)
|
||||||
|
{
|
||||||
|
var settingsControls = handler.CreateSettingsControlsFromAllBindables(false);
|
||||||
|
|
||||||
|
if (settingsControls.Count == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
SettingsSubsection section;
|
||||||
|
|
||||||
|
switch (handler)
|
||||||
|
{
|
||||||
|
case MouseHandler mh:
|
||||||
|
section = new MouseSettings(mh);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
section = new HandlerSection(handler);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
section.AddRange(settingsControls);
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class HandlerSection : SettingsSubsection
|
||||||
|
{
|
||||||
|
private readonly InputHandler handler;
|
||||||
|
|
||||||
|
public HandlerSection(InputHandler handler)
|
||||||
|
{
|
||||||
|
this.handler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string Header => handler.Description;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user