mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 10:02:59 +08:00
Update with osu!-side dropdown changes
This commit is contained in:
parent
4fbad65e3d
commit
aff5fa6169
@ -2,9 +2,6 @@
|
|||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace osu.Game.Graphics.UserInterface
|
namespace osu.Game.Graphics.UserInterface
|
||||||
{
|
{
|
||||||
@ -15,18 +12,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
if (!typeof(T).IsEnum)
|
if (!typeof(T).IsEnum)
|
||||||
throw new InvalidOperationException("OsuEnumDropdown only supports enums as the generic type argument");
|
throw new InvalidOperationException("OsuEnumDropdown only supports enums as the generic type argument");
|
||||||
|
|
||||||
List<KeyValuePair<string, T>> items = new List<KeyValuePair<string, T>>();
|
Items = (T[])Enum.GetValues(typeof(T));
|
||||||
foreach (var val in (T[])Enum.GetValues(typeof(T)))
|
|
||||||
{
|
|
||||||
var field = typeof(T).GetField(Enum.GetName(typeof(T), val));
|
|
||||||
items.Add(
|
|
||||||
new KeyValuePair<string, T>(
|
|
||||||
field.GetCustomAttribute<DescriptionAttribute>()?.Description ?? Enum.GetName(typeof(T), val),
|
|
||||||
val
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Items = items;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -37,7 +36,7 @@ namespace osu.Game.Overlays.Music
|
|||||||
new CollectionsDropdown<PlaylistCollection>
|
new CollectionsDropdown<PlaylistCollection>
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Items = new[] { new KeyValuePair<string, PlaylistCollection>(@"All", PlaylistCollection.All) },
|
Items = new[] { PlaylistCollection.All },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -6,6 +6,7 @@ using osu.Framework.Audio;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Settings.Sections.Audio
|
namespace osu.Game.Overlays.Settings.Sections.Audio
|
||||||
{
|
{
|
||||||
@ -35,12 +36,12 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
|
|||||||
|
|
||||||
private void updateItems()
|
private void updateItems()
|
||||||
{
|
{
|
||||||
var deviceItems = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("Default", string.Empty) };
|
var deviceItems = new List<string> { string.Empty };
|
||||||
deviceItems.AddRange(audio.AudioDeviceNames.Select(d => new KeyValuePair<string, string>(d, d)));
|
deviceItems.AddRange(audio.AudioDeviceNames);
|
||||||
|
|
||||||
var preferredDeviceName = audio.AudioDevice.Value;
|
var preferredDeviceName = audio.AudioDevice.Value;
|
||||||
if (deviceItems.All(kv => kv.Value != preferredDeviceName))
|
if (deviceItems.All(kv => kv != preferredDeviceName))
|
||||||
deviceItems.Add(new KeyValuePair<string, string>(preferredDeviceName, preferredDeviceName));
|
deviceItems.Add(preferredDeviceName);
|
||||||
|
|
||||||
// The option dropdown for audio device selection lists all audio
|
// The option dropdown for audio device selection lists all audio
|
||||||
// device names. Dropdowns, however, may not have multiple identical
|
// device names. Dropdowns, however, may not have multiple identical
|
||||||
@ -59,7 +60,7 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
|
|||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
dropdown = new SettingsDropdown<string>()
|
dropdown = new AudioDeviceSettingsDropdown()
|
||||||
};
|
};
|
||||||
|
|
||||||
updateItems();
|
updateItems();
|
||||||
@ -69,5 +70,16 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
|
|||||||
audio.OnNewDevice += onDeviceChanged;
|
audio.OnNewDevice += onDeviceChanged;
|
||||||
audio.OnLostDevice += onDeviceChanged;
|
audio.OnLostDevice += onDeviceChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class AudioDeviceSettingsDropdown : SettingsDropdown<string>
|
||||||
|
{
|
||||||
|
protected override OsuDropdown<string> CreateDropdown() => new AudioDeviceDropdownControl { Items = Items };
|
||||||
|
|
||||||
|
private class AudioDeviceDropdownControl : DropdownControl
|
||||||
|
{
|
||||||
|
protected override string GenerateItemText(string item)
|
||||||
|
=> string.IsNullOrEmpty(item) ? "Default" : base.GenerateItemText(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,9 @@ using System.Drawing;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Settings.Sections.Graphics
|
namespace osu.Game.Overlays.Settings.Sections.Graphics
|
||||||
{
|
{
|
||||||
@ -85,7 +85,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
|||||||
|
|
||||||
if (resolutions.Count > 1)
|
if (resolutions.Count > 1)
|
||||||
{
|
{
|
||||||
resolutionSettingsContainer.Child = resolutionDropdown = new SettingsDropdown<Size>
|
resolutionSettingsContainer.Child = resolutionDropdown = new ResolutionSettingsDropdown
|
||||||
{
|
{
|
||||||
LabelText = "Resolution",
|
LabelText = "Resolution",
|
||||||
ShowsDefaultIndicator = false,
|
ShowsDefaultIndicator = false,
|
||||||
@ -115,18 +115,36 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
|||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IReadOnlyList<KeyValuePair<string, Size>> getResolutions()
|
private IReadOnlyList<Size> getResolutions()
|
||||||
{
|
{
|
||||||
var resolutions = new KeyValuePair<string, Size>("Default", new Size(9999, 9999)).Yield();
|
var resolutions = new List<Size> { new Size(9999, 9999) };
|
||||||
|
|
||||||
if (game.Window != null)
|
if (game.Window != null)
|
||||||
resolutions = resolutions.Concat(game.Window.AvailableResolutions
|
{
|
||||||
.Where(r => r.Width >= 800 && r.Height >= 600)
|
resolutions.AddRange(game.Window.AvailableResolutions
|
||||||
.OrderByDescending(r => r.Width)
|
.Where(r => r.Width >= 800 && r.Height >= 600)
|
||||||
.ThenByDescending(r => r.Height)
|
.OrderByDescending(r => r.Width)
|
||||||
.Select(res => new KeyValuePair<string, Size>($"{res.Width}x{res.Height}", new Size(res.Width, res.Height)))
|
.ThenByDescending(r => r.Height)
|
||||||
.Distinct());
|
.Select(res => new Size(res.Width, res.Height))
|
||||||
return resolutions.ToList();
|
.Distinct());
|
||||||
|
}
|
||||||
|
|
||||||
|
return resolutions;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ResolutionSettingsDropdown : SettingsDropdown<Size>
|
||||||
|
{
|
||||||
|
protected override OsuDropdown<Size> CreateDropdown() => new ResolutionDropdownControl { Items = Items };
|
||||||
|
|
||||||
|
private class ResolutionDropdownControl : DropdownControl
|
||||||
|
{
|
||||||
|
protected override string GenerateItemText(Size item)
|
||||||
|
{
|
||||||
|
if (item == new Size(9999, 9999))
|
||||||
|
return "Default";
|
||||||
|
return $"{item.Width}x{item.Height}";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Configuration;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
@ -15,12 +15,15 @@ namespace osu.Game.Overlays.Settings.Sections
|
|||||||
{
|
{
|
||||||
public class SkinSection : SettingsSection
|
public class SkinSection : SettingsSection
|
||||||
{
|
{
|
||||||
private SettingsDropdown<int> skinDropdown;
|
private SkinSettingsDropdown skinDropdown;
|
||||||
|
|
||||||
public override string Header => "Skin";
|
public override string Header => "Skin";
|
||||||
|
|
||||||
public override FontAwesome Icon => FontAwesome.fa_paint_brush;
|
public override FontAwesome Icon => FontAwesome.fa_paint_brush;
|
||||||
|
|
||||||
|
private readonly Bindable<SkinDescription> dropdownBindable = new Bindable<SkinDescription>();
|
||||||
|
private readonly Bindable<int> configBindable = new Bindable<int>();
|
||||||
|
|
||||||
private SkinManager skins;
|
private SkinManager skins;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -31,7 +34,7 @@ namespace osu.Game.Overlays.Settings.Sections
|
|||||||
FlowContent.Spacing = new Vector2(0, 5);
|
FlowContent.Spacing = new Vector2(0, 5);
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
skinDropdown = new SettingsDropdown<int>(),
|
skinDropdown = new SkinSettingsDropdown(),
|
||||||
new SettingsSlider<double, SizeSlider>
|
new SettingsSlider<double, SizeSlider>
|
||||||
{
|
{
|
||||||
LabelText = "Menu cursor size",
|
LabelText = "Menu cursor size",
|
||||||
@ -54,19 +57,21 @@ namespace osu.Game.Overlays.Settings.Sections
|
|||||||
skins.ItemAdded += itemAdded;
|
skins.ItemAdded += itemAdded;
|
||||||
skins.ItemRemoved += itemRemoved;
|
skins.ItemRemoved += itemRemoved;
|
||||||
|
|
||||||
skinDropdown.Items = skins.GetAllUsableSkins().Select(s => new KeyValuePair<string, int>(s.ToString(), s.ID));
|
config.BindWith(OsuSetting.Skin, configBindable);
|
||||||
|
|
||||||
var skinBindable = config.GetBindable<int>(OsuSetting.Skin);
|
skinDropdown.Bindable = dropdownBindable;
|
||||||
|
skinDropdown.Items = skins.GetAllUsableSkins().Select(s => new SkinDescription { Id = s.ID, Name = s.ToString() }).ToArray();
|
||||||
|
|
||||||
// Todo: This should not be necessary when OsuConfigManager is databased
|
// Todo: This should not be necessary when OsuConfigManager is databased
|
||||||
if (skinDropdown.Items.All(s => s.Value != skinBindable.Value))
|
if (skinDropdown.Items.All(s => s.Id != configBindable.Value))
|
||||||
skinBindable.Value = 0;
|
configBindable.Value = 0;
|
||||||
|
|
||||||
skinDropdown.Bindable = skinBindable;
|
configBindable.BindValueChanged(v => dropdownBindable.Value = skinDropdown.Items.Single(s => s.Id == v), true);
|
||||||
|
dropdownBindable.BindValueChanged(v => configBindable.Value = v.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void itemRemoved(SkinInfo s) => skinDropdown.Items = skinDropdown.Items.Where(i => i.Value != s.ID);
|
private void itemRemoved(SkinInfo s) => skinDropdown.Items = skinDropdown.Items.Where(i => i.Id != s.ID).ToArray();
|
||||||
private void itemAdded(SkinInfo s) => skinDropdown.Items = skinDropdown.Items.Append(new KeyValuePair<string, int>(s.ToString(), s.ID));
|
private void itemAdded(SkinInfo s) => skinDropdown.Items = skinDropdown.Items.Append(new SkinDescription { Id = s.ID, Name = s.ToString() }).ToArray();
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
@ -83,5 +88,21 @@ namespace osu.Game.Overlays.Settings.Sections
|
|||||||
{
|
{
|
||||||
public override string TooltipText => Current.Value.ToString(@"0.##x");
|
public override string TooltipText => Current.Value.ToString(@"0.##x");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class SkinSettingsDropdown : SettingsDropdown<SkinDescription>
|
||||||
|
{
|
||||||
|
protected override OsuDropdown<SkinDescription> CreateDropdown() => new SkinDropdownControl { Items = Items };
|
||||||
|
|
||||||
|
private class SkinDropdownControl : DropdownControl
|
||||||
|
{
|
||||||
|
protected override string GenerateItemText(SkinDescription item) => item.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct SkinDescription
|
||||||
|
{
|
||||||
|
public int Id;
|
||||||
|
public string Name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,36 +2,41 @@
|
|||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Settings
|
namespace osu.Game.Overlays.Settings
|
||||||
{
|
{
|
||||||
public class SettingsDropdown<T> : SettingsItem<T>
|
public class SettingsDropdown<T> : SettingsItem<T>
|
||||||
{
|
{
|
||||||
private Dropdown<T> dropdown;
|
protected new OsuDropdown<T> Control => (OsuDropdown<T>)base.Control;
|
||||||
|
|
||||||
private IEnumerable<KeyValuePair<string, T>> items = new KeyValuePair<string, T>[] { };
|
private IEnumerable<T> items = Enumerable.Empty<T>();
|
||||||
public IEnumerable<KeyValuePair<string, T>> Items
|
|
||||||
|
public IEnumerable<T> Items
|
||||||
{
|
{
|
||||||
get
|
get => items;
|
||||||
{
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
items = value;
|
items = value;
|
||||||
if (dropdown != null)
|
|
||||||
dropdown.Items = value;
|
if (Control != null)
|
||||||
|
Control.Items = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Drawable CreateControl() => dropdown = new OsuDropdown<T>
|
protected sealed override Drawable CreateControl() => CreateDropdown();
|
||||||
|
|
||||||
|
protected virtual OsuDropdown<T> CreateDropdown() => new DropdownControl { Items = Items };
|
||||||
|
|
||||||
|
protected class DropdownControl : OsuDropdown<T>
|
||||||
{
|
{
|
||||||
Margin = new MarginPadding { Top = 5 },
|
public DropdownControl()
|
||||||
RelativeSizeAxes = Axes.X,
|
{
|
||||||
Items = Items,
|
Margin = new MarginPadding { Top = 5 };
|
||||||
};
|
RelativeSizeAxes = Axes.X;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,15 @@ namespace osu.Game.Overlays.Settings
|
|||||||
{
|
{
|
||||||
public class SettingsEnumDropdown<T> : SettingsDropdown<T>
|
public class SettingsEnumDropdown<T> : SettingsDropdown<T>
|
||||||
{
|
{
|
||||||
protected override Drawable CreateControl() => new OsuEnumDropdown<T>
|
protected override OsuDropdown<T> CreateDropdown() => new DropdownControl();
|
||||||
|
|
||||||
|
protected class DropdownControl : OsuEnumDropdown<T>
|
||||||
{
|
{
|
||||||
Margin = new MarginPadding { Top = 5 },
|
public DropdownControl()
|
||||||
RelativeSizeAxes = Axes.X,
|
{
|
||||||
};
|
Margin = new MarginPadding { Top = 5 };
|
||||||
|
RelativeSizeAxes = Axes.X;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
@ -25,7 +24,7 @@ namespace osu.Game.Screens.Play.PlayerSettings
|
|||||||
new CollectionsDropdown<PlaylistCollection>
|
new CollectionsDropdown<PlaylistCollection>
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Items = new[] { new KeyValuePair<string, PlaylistCollection>(@"All", PlaylistCollection.All) },
|
Items = new[] { PlaylistCollection.All },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user