Skip to content

Commit 435cd27

Browse files
committed
Separate fullscreen/windowed dropdowns. Center window on size change.
1 parent 72507b8 commit 435cd27

File tree

1 file changed

+39
-44
lines changed

1 file changed

+39
-44
lines changed

osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public partial class LayoutSettings : SettingsSubsection
3737
private Bindable<ScalingMode> scalingMode = null!;
3838
private Bindable<Size> sizeFullscreen = null!;
3939
private Bindable<Size> sizeWindowed = null!;
40-
private readonly BindableWithCurrent<Size> currentResolution = new BindableWithCurrent<Size>();
4140

42-
private readonly BindableList<Size> resolutions = new BindableList<Size>(new[] { new Size(9999, 9999) });
41+
private readonly BindableList<Size> resolutionsFullscreen = new BindableList<Size>(new[] { new Size(9999, 9999) });
42+
private readonly BindableList<Size> resolutionsWindowed = new BindableList<Size>();
4343
private readonly IBindable<FullscreenCapability> fullscreenCapability = new Bindable<FullscreenCapability>(FullscreenCapability.Capable);
4444

4545
[Resolved]
@@ -50,12 +50,15 @@ public partial class LayoutSettings : SettingsSubsection
5050

5151
private IWindow? window;
5252

53-
private SettingsDropdown<Size> resolutionDropdown = null!;
53+
private SettingsDropdown<Size> resolutionFullscreenDropdown = null!;
54+
private SettingsDropdown<Size> resolutionWindowedDropdown = null!;
5455
private SettingsDropdown<Display> displayDropdown = null!;
5556
private SettingsDropdown<WindowMode> windowModeDropdown = null!;
5657
private SettingsCheckbox minimiseOnFocusLossCheckbox = null!;
5758
private SettingsCheckbox safeAreaConsiderationsCheckbox = null!;
5859

60+
private Bindable<double> windowedPositionX = null!;
61+
private Bindable<double> windowedPositionY = null!;
5962
private Bindable<float> scalingPositionX = null!;
6063
private Bindable<float> scalingPositionY = null!;
6164
private Bindable<float> scalingSizeX = null!;
@@ -73,6 +76,8 @@ private void load(FrameworkConfigManager config, OsuConfigManager osuConfig, Gam
7376
scalingMode = osuConfig.GetBindable<ScalingMode>(OsuSetting.Scaling);
7477
sizeFullscreen = config.GetBindable<Size>(FrameworkSetting.SizeFullscreen);
7578
sizeWindowed = config.GetBindable<Size>(FrameworkSetting.WindowedSize);
79+
windowedPositionX = config.GetBindable<double>(FrameworkSetting.WindowedPositionX);
80+
windowedPositionY = config.GetBindable<double>(FrameworkSetting.WindowedPositionY);
7681
scalingSizeX = osuConfig.GetBindable<float>(OsuSetting.ScalingSizeX);
7782
scalingSizeY = osuConfig.GetBindable<float>(OsuSetting.ScalingSizeY);
7883
scalingPositionX = osuConfig.GetBindable<float>(OsuSetting.ScalingPositionX);
@@ -103,12 +108,19 @@ private void load(FrameworkConfigManager config, OsuConfigManager osuConfig, Gam
103108
Items = window?.Displays,
104109
Current = currentDisplay,
105110
},
106-
resolutionDropdown = new ResolutionSettingsDropdown
111+
resolutionFullscreenDropdown = new ResolutionSettingsDropdown
107112
{
108113
LabelText = GraphicsSettingsStrings.Resolution,
109114
ShowsDefaultIndicator = false,
110-
ItemSource = resolutions,
111-
Current = currentResolution
115+
ItemSource = resolutionsFullscreen,
116+
Current = sizeFullscreen
117+
},
118+
resolutionWindowedDropdown = new ResolutionSettingsDropdown
119+
{
120+
LabelText = GraphicsSettingsStrings.Resolution,
121+
ShowsDefaultIndicator = false,
122+
ItemSource = resolutionsWindowed,
123+
Current = sizeWindowed
112124
},
113125
minimiseOnFocusLossCheckbox = new SettingsCheckbox
114126
{
@@ -199,27 +211,31 @@ protected override void LoadComplete()
199211
{
200212
updateDisplaySettingsVisibility();
201213
updateScreenModeWarning();
202-
updateCurrentResolutionBinding();
203214
}, true);
204215

205216
currentDisplay.BindValueChanged(display => Schedule(() =>
206217
{
207218
if (display.NewValue == null)
208219
{
209-
resolutions.Clear();
220+
resolutionsFullscreen.Clear();
221+
resolutionsWindowed.Clear();
210222
return;
211223
}
212224

213-
var buffer = new Bindable<Size>(currentResolution.Value);
214-
currentResolution.Current = buffer;
225+
var buffer = new Bindable<Size>(sizeWindowed.Value);
226+
resolutionWindowedDropdown.Current = buffer;
227+
228+
var newResolutions = display.NewValue.DisplayModes
229+
.Where(m => m.Size.Width >= 800 && m.Size.Height >= 600)
230+
.OrderByDescending(m => Math.Max(m.Size.Height, m.Size.Width))
231+
.Select(m => m.Size)
232+
.Distinct()
233+
.ToList();
215234

216-
resolutions.ReplaceRange(1, resolutions.Count - 1, display.NewValue.DisplayModes
217-
.Where(m => m.Size.Width >= 800 && m.Size.Height >= 600)
218-
.OrderByDescending(m => Math.Max(m.Size.Height, m.Size.Width))
219-
.Select(m => m.Size)
220-
.Distinct());
235+
resolutionsFullscreen.ReplaceRange(1, resolutionsFullscreen.Count - 1, newResolutions);
236+
resolutionsWindowed.ReplaceRange(0, resolutionsWindowed.Count, newResolutions);
221237

222-
updateCurrentResolutionBinding();
238+
resolutionWindowedDropdown.Current = sizeWindowed;
223239

224240
updateDisplaySettingsVisibility();
225241
}), true);
@@ -229,20 +245,13 @@ protected override void LoadComplete()
229245
if (windowModeDropdown.Current.Value != WindowMode.Windowed)
230246
return;
231247

232-
if (window?.WindowState == Framework.Platform.WindowState.Normal &&
233-
size.NewValue == new Size(9999, 9999)
234-
)
235-
{
236-
window.WindowState = Framework.Platform.WindowState.Maximised;
237-
return;
238-
}
239-
240-
if (window?.WindowState == Framework.Platform.WindowState.Maximised &&
241-
size.NewValue != new Size(9999, 9999)
242-
)
248+
if (window?.WindowState == Framework.Platform.WindowState.Maximised)
243249
{
244250
window.WindowState = Framework.Platform.WindowState.Normal;
245251
}
252+
253+
windowedPositionX.Value = 0.5;
254+
windowedPositionY.Value = 0.5;
246255
});
247256

248257
scalingMode.BindValueChanged(_ =>
@@ -276,20 +285,6 @@ void updateScalingModeVisibility()
276285
}
277286
}
278287

279-
private void updateCurrentResolutionBinding()
280-
{
281-
switch (windowModeDropdown.Current.Value)
282-
{
283-
case WindowMode.Fullscreen:
284-
currentResolution.Current = sizeFullscreen;
285-
break;
286-
287-
case WindowMode.Windowed:
288-
currentResolution.Current = sizeWindowed;
289-
break;
290-
}
291-
}
292-
293288
private void onDisplaysChanged(IEnumerable<Display> displays)
294289
{
295290
Scheduler.AddOnce(d =>
@@ -302,9 +297,9 @@ private void onDisplaysChanged(IEnumerable<Display> displays)
302297

303298
private void updateDisplaySettingsVisibility()
304299
{
305-
resolutionDropdown.CanBeShown.Value = resolutions.Count > 1
306-
&& (windowModeDropdown.Current.Value == WindowMode.Fullscreen ||
307-
windowModeDropdown.Current.Value == WindowMode.Windowed);
300+
resolutionFullscreenDropdown.CanBeShown.Value = windowModeDropdown.Current.Value == WindowMode.Fullscreen && resolutionsFullscreen.Count > 1;
301+
resolutionWindowedDropdown.CanBeShown.Value = windowModeDropdown.Current.Value == WindowMode.Windowed && resolutionsWindowed.Count > 1;
302+
308303
displayDropdown.CanBeShown.Value = displayDropdown.Items.Count() > 1;
309304
minimiseOnFocusLossCheckbox.CanBeShown.Value = RuntimeInfo.IsDesktop && windowModeDropdown.Current.Value == WindowMode.Fullscreen;
310305
safeAreaConsiderationsCheckbox.CanBeShown.Value = host.Window?.SafeAreaPadding.Value.Total != Vector2.Zero;

0 commit comments

Comments
 (0)