2018-04-13 17:19:50 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
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;
|
|
|
|
|
using osu.Framework.Configuration;
|
2018-09-07 13:35: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;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Settings.Sections.Graphics
|
|
|
|
|
{
|
|
|
|
|
public class LayoutSettings : SettingsSubsection
|
|
|
|
|
{
|
|
|
|
|
protected override string Header => "Layout";
|
|
|
|
|
|
|
|
|
|
private FillFlowContainer letterboxSettings;
|
|
|
|
|
|
|
|
|
|
private Bindable<bool> letterboxing;
|
2018-06-10 21:17:57 +08:00
|
|
|
|
private Bindable<Size> sizeFullscreen;
|
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;
|
2018-06-03 02:02:45 +08:00
|
|
|
|
private SettingsEnumDropdown<WindowMode> windowModeDropdown;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private const int transition_duration = 400;
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2018-06-23 17:45:13 +08:00
|
|
|
|
private void load(FrameworkConfigManager config, OsuGameBase game)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-06-03 02:02:45 +08:00
|
|
|
|
this.game = game;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
letterboxing = config.GetBindable<bool>(FrameworkSetting.Letterboxing);
|
2018-06-10 21:17:57 +08:00
|
|
|
|
sizeFullscreen = config.GetBindable<Size>(FrameworkSetting.SizeFullscreen);
|
|
|
|
|
|
2018-09-19 16:52:35 +08:00
|
|
|
|
Container resolutionSettingsContainer;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2018-06-03 02:02:45 +08:00
|
|
|
|
windowModeDropdown = new SettingsEnumDropdown<WindowMode>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
LabelText = "Screen mode",
|
|
|
|
|
Bindable = config.GetBindable<WindowMode>(FrameworkSetting.WindowMode),
|
|
|
|
|
},
|
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
|
|
|
|
},
|
2018-04-13 17:19:50 +08:00
|
|
|
|
new SettingsCheckbox
|
|
|
|
|
{
|
|
|
|
|
LabelText = "Letterboxing",
|
|
|
|
|
Bindable = letterboxing,
|
|
|
|
|
},
|
|
|
|
|
letterboxSettings = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
AutoSizeDuration = transition_duration,
|
|
|
|
|
AutoSizeEasing = Easing.OutQuint,
|
|
|
|
|
Masking = true,
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new SettingsSlider<double>
|
|
|
|
|
{
|
|
|
|
|
LabelText = "Horizontal position",
|
|
|
|
|
Bindable = config.GetBindable<double>(FrameworkSetting.LetterboxPositionX),
|
2018-07-10 23:28:56 +08:00
|
|
|
|
KeyboardStep = 0.01f
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
new SettingsSlider<double>
|
|
|
|
|
{
|
|
|
|
|
LabelText = "Vertical position",
|
|
|
|
|
Bindable = config.GetBindable<double>(FrameworkSetting.LetterboxPositionY),
|
2018-07-10 23:28:56 +08:00
|
|
|
|
KeyboardStep = 0.01f
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
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-09-19 16:52:35 +08:00
|
|
|
|
resolutionSettingsContainer.Child = resolutionDropdown = new SettingsDropdown<Size>
|
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
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
windowModeDropdown.Bindable.BindValueChanged(windowMode =>
|
|
|
|
|
{
|
|
|
|
|
if (windowMode == WindowMode.Fullscreen)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
2018-09-05 10:32:38 +08:00
|
|
|
|
letterboxing.BindValueChanged(isVisible =>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
letterboxSettings.ClearTransforms();
|
|
|
|
|
letterboxSettings.AutoSizeAxes = isVisible ? Axes.Y : Axes.None;
|
|
|
|
|
|
|
|
|
|
if (!isVisible)
|
|
|
|
|
letterboxSettings.ResizeHeightTo(0, transition_duration, Easing.OutQuint);
|
2018-09-05 10:32:38 +08:00
|
|
|
|
}, true);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2018-06-03 02:02:45 +08:00
|
|
|
|
|
2018-09-19 16:52:35 +08:00
|
|
|
|
private IReadOnlyList<KeyValuePair<string, Size>> getResolutions()
|
2018-09-07 18:29:51 +08:00
|
|
|
|
{
|
|
|
|
|
var resolutions = new KeyValuePair<string, Size>("Default", new Size(9999, 9999)).Yield();
|
|
|
|
|
|
|
|
|
|
if (game.Window != null)
|
|
|
|
|
resolutions = resolutions.Concat(game.Window.AvailableResolutions
|
|
|
|
|
.Where(r => r.Width >= 800 && r.Height >= 600)
|
|
|
|
|
.OrderByDescending(r => r.Width)
|
|
|
|
|
.ThenByDescending(r => r.Height)
|
|
|
|
|
.Select(res => new KeyValuePair<string, Size>($"{res.Width}x{res.Height}", new Size(res.Width, res.Height)))
|
2018-09-19 16:52:35 +08:00
|
|
|
|
.Distinct());
|
|
|
|
|
return resolutions.ToList();
|
2018-09-07 18:29:51 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|