2019-01-24 16:43:03 +08:00
|
|
|
|
// 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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-03 02:02:45 +08:00
|
|
|
|
using System.Collections.Generic;
|
2018-06-10 21:17:57 +08:00
|
|
|
|
using System.Drawing;
|
2018-06-03 02:02:45 +08:00
|
|
|
|
using System.Linq;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
2019-01-08 12:48:38 +08:00
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-01-04 14:28:35 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-02-28 19:19:51 +08:00
|
|
|
|
using osu.Framework.Platform;
|
2019-01-04 12:29:37 +08:00
|
|
|
|
using osu.Game.Configuration;
|
2019-01-04 14:28:35 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-11-14 17:02:38 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2019-01-04 14:28:35 +08:00
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Settings.Sections.Graphics
|
|
|
|
|
{
|
|
|
|
|
public class LayoutSettings : SettingsSubsection
|
|
|
|
|
{
|
|
|
|
|
protected override string Header => "Layout";
|
|
|
|
|
|
2019-01-08 12:48:38 +08:00
|
|
|
|
private FillFlowContainer<SettingsSlider<float>> scalingSettings;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-01-04 12:29:37 +08:00
|
|
|
|
private Bindable<ScalingMode> scalingMode;
|
2018-06-10 21:17:57 +08:00
|
|
|
|
private Bindable<Size> sizeFullscreen;
|
2019-06-09 16:22:02 +08:00
|
|
|
|
private readonly IBindableList<WindowMode> windowModes = new BindableList<WindowMode>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-23 17:45:13 +08:00
|
|
|
|
private OsuGameBase game;
|
2018-09-05 10:32:38 +08:00
|
|
|
|
private SettingsDropdown<Size> resolutionDropdown;
|
2019-02-28 19:19:51 +08:00
|
|
|
|
private SettingsDropdown<WindowMode> windowModeDropdown;
|
2018-06-03 02:02:45 +08:00
|
|
|
|
|
2019-01-04 13:55:59 +08:00
|
|
|
|
private Bindable<float> scalingPositionX;
|
|
|
|
|
private Bindable<float> scalingPositionY;
|
|
|
|
|
private Bindable<float> scalingSizeX;
|
|
|
|
|
private Bindable<float> scalingSizeY;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private const int transition_duration = 400;
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2019-02-28 19:19:51 +08:00
|
|
|
|
private void load(FrameworkConfigManager config, OsuConfigManager osuConfig, OsuGameBase game, GameHost host)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-06-03 02:02:45 +08:00
|
|
|
|
this.game = game;
|
|
|
|
|
|
2019-01-04 12:29:37 +08:00
|
|
|
|
scalingMode = osuConfig.GetBindable<ScalingMode>(OsuSetting.Scaling);
|
2018-06-10 21:17:57 +08:00
|
|
|
|
sizeFullscreen = config.GetBindable<Size>(FrameworkSetting.SizeFullscreen);
|
2019-01-04 13:55:59 +08:00
|
|
|
|
scalingSizeX = osuConfig.GetBindable<float>(OsuSetting.ScalingSizeX);
|
|
|
|
|
scalingSizeY = osuConfig.GetBindable<float>(OsuSetting.ScalingSizeY);
|
|
|
|
|
scalingPositionX = osuConfig.GetBindable<float>(OsuSetting.ScalingPositionX);
|
|
|
|
|
scalingPositionY = osuConfig.GetBindable<float>(OsuSetting.ScalingPositionY);
|
2018-06-10 21:17:57 +08:00
|
|
|
|
|
2019-02-28 20:38:55 +08:00
|
|
|
|
if (host.Window != null)
|
|
|
|
|
windowModes.BindTo(host.Window.SupportedWindowModes);
|
|
|
|
|
|
2018-09-19 16:52:35 +08:00
|
|
|
|
Container resolutionSettingsContainer;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2019-02-28 19:19:51 +08:00
|
|
|
|
windowModeDropdown = new SettingsDropdown<WindowMode>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
LabelText = "Screen mode",
|
|
|
|
|
Bindable = config.GetBindable<WindowMode>(FrameworkSetting.WindowMode),
|
2019-02-28 20:38:55 +08:00
|
|
|
|
ItemSource = windowModes,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
2018-09-19 16:52:35 +08:00
|
|
|
|
resolutionSettingsContainer = new Container
|
2018-06-03 02:02:45 +08:00
|
|
|
|
{
|
2018-09-19 16:52:35 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y
|
2018-06-03 02:02:45 +08:00
|
|
|
|
},
|
2019-01-09 18:01:33 +08:00
|
|
|
|
new SettingsSlider<float, UIScaleSlider>
|
|
|
|
|
{
|
|
|
|
|
LabelText = "UI Scaling",
|
|
|
|
|
TransferValueOnCommit = true,
|
|
|
|
|
Bindable = osuConfig.GetBindable<float>(OsuSetting.UIScale),
|
|
|
|
|
KeyboardStep = 0.01f
|
|
|
|
|
},
|
2019-01-04 12:29:37 +08:00
|
|
|
|
new SettingsEnumDropdown<ScalingMode>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-01-09 18:01:33 +08:00
|
|
|
|
LabelText = "Screen Scaling",
|
2019-01-04 12:29:37 +08:00
|
|
|
|
Bindable = osuConfig.GetBindable<ScalingMode>(OsuSetting.Scaling),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
2019-01-08 12:48:38 +08:00
|
|
|
|
scalingSettings = new FillFlowContainer<SettingsSlider<float>>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
AutoSizeDuration = transition_duration,
|
|
|
|
|
AutoSizeEasing = Easing.OutQuint,
|
|
|
|
|
Masking = true,
|
2019-02-28 12:31:40 +08:00
|
|
|
|
Children = new[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-01-04 12:29:37 +08:00
|
|
|
|
new SettingsSlider<float>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
LabelText = "Horizontal position",
|
2019-01-08 12:48:38 +08:00
|
|
|
|
Bindable = scalingPositionX,
|
2018-07-10 23:28:56 +08:00
|
|
|
|
KeyboardStep = 0.01f
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
2019-01-04 12:29:37 +08:00
|
|
|
|
new SettingsSlider<float>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
LabelText = "Vertical position",
|
2019-01-08 12:48:38 +08:00
|
|
|
|
Bindable = scalingPositionY,
|
2019-01-04 12:29:37 +08:00
|
|
|
|
KeyboardStep = 0.01f
|
|
|
|
|
},
|
|
|
|
|
new SettingsSlider<float>
|
|
|
|
|
{
|
2019-01-04 13:58:44 +08:00
|
|
|
|
LabelText = "Horizontal scale",
|
2019-01-08 12:48:38 +08:00
|
|
|
|
Bindable = scalingSizeX,
|
2019-01-04 12:29:37 +08:00
|
|
|
|
KeyboardStep = 0.01f
|
|
|
|
|
},
|
|
|
|
|
new SettingsSlider<float>
|
|
|
|
|
{
|
2019-01-04 13:58:44 +08:00
|
|
|
|
LabelText = "Vertical scale",
|
2019-01-08 12:48:38 +08:00
|
|
|
|
Bindable = scalingSizeY,
|
2018-07-10 23:28:56 +08:00
|
|
|
|
KeyboardStep = 0.01f
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-08 12:48:38 +08:00
|
|
|
|
scalingSettings.ForEach(s => bindPreviewEvent(s.Bindable));
|
|
|
|
|
|
2018-09-19 16:52:35 +08:00
|
|
|
|
var resolutions = getResolutions();
|
2018-09-20 18:00:41 +08:00
|
|
|
|
|
2018-09-19 16:52:35 +08:00
|
|
|
|
if (resolutions.Count > 1)
|
2018-06-03 02:02:45 +08:00
|
|
|
|
{
|
2018-11-14 17:02:38 +08:00
|
|
|
|
resolutionSettingsContainer.Child = resolutionDropdown = new ResolutionSettingsDropdown
|
2018-06-22 01:42:22 +08:00
|
|
|
|
{
|
2018-09-19 16:52:35 +08:00
|
|
|
|
LabelText = "Resolution",
|
|
|
|
|
ShowsDefaultIndicator = false,
|
2018-09-20 18:00:41 +08:00
|
|
|
|
Items = resolutions,
|
2018-09-19 16:52:35 +08:00
|
|
|
|
Bindable = sizeFullscreen
|
|
|
|
|
};
|
|
|
|
|
|
2019-02-22 19:13:38 +08:00
|
|
|
|
windowModeDropdown.Bindable.BindValueChanged(mode =>
|
2018-09-19 16:52:35 +08:00
|
|
|
|
{
|
2019-02-22 19:13:38 +08:00
|
|
|
|
if (mode.NewValue == WindowMode.Fullscreen)
|
2018-09-19 16:52:35 +08:00
|
|
|
|
{
|
|
|
|
|
resolutionDropdown.Show();
|
|
|
|
|
sizeFullscreen.TriggerChange();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
resolutionDropdown.Hide();
|
2018-10-01 19:12:34 +08:00
|
|
|
|
}, true);
|
2018-09-19 16:52:35 +08:00
|
|
|
|
}
|
2018-06-03 02:02:45 +08:00
|
|
|
|
|
2019-02-22 19:13:38 +08:00
|
|
|
|
scalingMode.BindValueChanged(mode =>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-01-04 12:29:37 +08:00
|
|
|
|
scalingSettings.ClearTransforms();
|
2019-02-22 19:13:38 +08:00
|
|
|
|
scalingSettings.AutoSizeAxes = mode.NewValue != ScalingMode.Off ? Axes.Y : Axes.None;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-02-22 19:13:38 +08:00
|
|
|
|
if (mode.NewValue == ScalingMode.Off)
|
2019-01-04 12:29:37 +08:00
|
|
|
|
scalingSettings.ResizeHeightTo(0, transition_duration, Easing.OutQuint);
|
2019-01-08 12:48:38 +08:00
|
|
|
|
|
2019-02-22 19:13:38 +08:00
|
|
|
|
scalingSettings.ForEach(s => s.TransferValueOnCommit = mode.NewValue == ScalingMode.Everything);
|
2018-09-05 10:32:38 +08:00
|
|
|
|
}, true);
|
2019-02-28 20:38:55 +08:00
|
|
|
|
|
|
|
|
|
windowModes.ItemsAdded += _ => windowModesChanged();
|
|
|
|
|
windowModes.ItemsRemoved += _ => windowModesChanged();
|
|
|
|
|
|
|
|
|
|
windowModesChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void windowModesChanged()
|
|
|
|
|
{
|
2019-02-28 20:46:49 +08:00
|
|
|
|
if (windowModes.Count > 1)
|
2019-02-28 20:38:55 +08:00
|
|
|
|
windowModeDropdown.Show();
|
|
|
|
|
else
|
|
|
|
|
windowModeDropdown.Hide();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2018-06-03 02:02:45 +08:00
|
|
|
|
|
2019-01-04 13:55:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create a delayed bindable which only updates when a condition is met.
|
|
|
|
|
/// </summary>
|
2019-01-08 12:48:38 +08:00
|
|
|
|
/// <param name="bindable">The config bindable.</param>
|
2019-01-04 13:55:59 +08:00
|
|
|
|
/// <returns>A bindable which will propagate updates with a delay.</returns>
|
2019-01-08 12:48:38 +08:00
|
|
|
|
private void bindPreviewEvent(Bindable<float> bindable)
|
2019-01-04 13:55:59 +08:00
|
|
|
|
{
|
2019-02-22 16:51:39 +08:00
|
|
|
|
bindable.ValueChanged += _ =>
|
2019-01-04 13:55:59 +08:00
|
|
|
|
{
|
2019-01-04 14:28:35 +08:00
|
|
|
|
switch (scalingMode.Value)
|
|
|
|
|
{
|
|
|
|
|
case ScalingMode.Gameplay:
|
|
|
|
|
showPreview();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-01-04 13:55:59 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-04 14:28:35 +08:00
|
|
|
|
private Drawable preview;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2019-01-04 14:28:35 +08:00
|
|
|
|
private void showPreview()
|
|
|
|
|
{
|
|
|
|
|
if (preview?.IsAlive != true)
|
|
|
|
|
game.Add(preview = new ScalingPreview());
|
|
|
|
|
|
|
|
|
|
preview.FadeOutFromOne(1500);
|
|
|
|
|
preview.Expire();
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-14 17:02:38 +08:00
|
|
|
|
private IReadOnlyList<Size> getResolutions()
|
2018-09-07 18:29:51 +08:00
|
|
|
|
{
|
2018-11-14 17:02:38 +08:00
|
|
|
|
var resolutions = new List<Size> { new Size(9999, 9999) };
|
2018-09-07 18:29:51 +08:00
|
|
|
|
|
|
|
|
|
if (game.Window != null)
|
2018-11-14 17:02:38 +08:00
|
|
|
|
{
|
|
|
|
|
resolutions.AddRange(game.Window.AvailableResolutions
|
|
|
|
|
.Where(r => r.Width >= 800 && r.Height >= 600)
|
|
|
|
|
.OrderByDescending(r => r.Width)
|
|
|
|
|
.ThenByDescending(r => r.Height)
|
|
|
|
|
.Select(res => new Size(res.Width, res.Height))
|
|
|
|
|
.Distinct());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resolutions;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-04 14:28:35 +08:00
|
|
|
|
private class ScalingPreview : ScalingContainer
|
|
|
|
|
{
|
|
|
|
|
public ScalingPreview()
|
|
|
|
|
{
|
|
|
|
|
Child = new Box
|
|
|
|
|
{
|
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Alpha = 0.5f,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-09 18:01:33 +08:00
|
|
|
|
private class UIScaleSlider : OsuSliderBar<float>
|
|
|
|
|
{
|
|
|
|
|
public override string TooltipText => base.TooltipText + "x";
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-14 17:02:38 +08:00
|
|
|
|
private class ResolutionSettingsDropdown : SettingsDropdown<Size>
|
|
|
|
|
{
|
2019-06-25 11:00:05 +08:00
|
|
|
|
protected override OsuDropdown<Size> CreateDropdown() => new ResolutionDropdownControl();
|
2018-11-14 17:02:38 +08:00
|
|
|
|
|
|
|
|
|
private class ResolutionDropdownControl : DropdownControl
|
|
|
|
|
{
|
|
|
|
|
protected override string GenerateItemText(Size item)
|
|
|
|
|
{
|
|
|
|
|
if (item == new Size(9999, 9999))
|
|
|
|
|
return "Default";
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2018-11-14 17:02:38 +08:00
|
|
|
|
return $"{item.Width}x{item.Height}";
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-07 18:29:51 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|