1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 07:42:57 +08:00

Merge pull request #3719 from smoogipoo/dropdown-updates

Update with osu!-side dropdown changes
This commit is contained in:
Dean Herbert 2018-11-14 21:27:16 +09:00 committed by GitHub
commit 92adcb7613
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 104 additions and 65 deletions

View File

@ -2,9 +2,6 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.ComponentModel;
using System.Reflection;
using System.Collections.Generic;
namespace osu.Game.Graphics.UserInterface
{
@ -15,18 +12,7 @@ namespace osu.Game.Graphics.UserInterface
if (!typeof(T).IsEnum)
throw new InvalidOperationException("OsuEnumDropdown only supports enums as the generic type argument");
List<KeyValuePair<string, T>> items = new List<KeyValuePair<string, 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;
Items = (T[])Enum.GetValues(typeof(T));
}
}
}

View File

@ -1,7 +1,6 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -37,7 +36,7 @@ namespace osu.Game.Overlays.Music
new CollectionsDropdown<PlaylistCollection>
{
RelativeSizeAxes = Axes.X,
Items = new[] { new KeyValuePair<string, PlaylistCollection>(@"All", PlaylistCollection.All) },
Items = new[] { PlaylistCollection.All },
}
},
},

View File

@ -6,6 +6,7 @@ using osu.Framework.Audio;
using osu.Framework.Graphics;
using System.Collections.Generic;
using System.Linq;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays.Settings.Sections.Audio
{
@ -35,12 +36,12 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
private void updateItems()
{
var deviceItems = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("Default", string.Empty) };
deviceItems.AddRange(audio.AudioDeviceNames.Select(d => new KeyValuePair<string, string>(d, d)));
var deviceItems = new List<string> { string.Empty };
deviceItems.AddRange(audio.AudioDeviceNames);
var preferredDeviceName = audio.AudioDevice.Value;
if (deviceItems.All(kv => kv.Value != preferredDeviceName))
deviceItems.Add(new KeyValuePair<string, string>(preferredDeviceName, preferredDeviceName));
if (deviceItems.All(kv => kv != preferredDeviceName))
deviceItems.Add(preferredDeviceName);
// The option dropdown for audio device selection lists all audio
// device names. Dropdowns, however, may not have multiple identical
@ -59,7 +60,7 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
Children = new Drawable[]
{
dropdown = new SettingsDropdown<string>()
dropdown = new AudioDeviceSettingsDropdown()
};
updateItems();
@ -69,5 +70,16 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
audio.OnNewDevice += 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);
}
}
}
}

View File

@ -6,9 +6,9 @@ using System.Drawing;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays.Settings.Sections.Graphics
{
@ -85,7 +85,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
if (resolutions.Count > 1)
{
resolutionSettingsContainer.Child = resolutionDropdown = new SettingsDropdown<Size>
resolutionSettingsContainer.Child = resolutionDropdown = new ResolutionSettingsDropdown
{
LabelText = "Resolution",
ShowsDefaultIndicator = false,
@ -115,18 +115,36 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
}, 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)
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)))
.Distinct());
return resolutions.ToList();
{
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;
}
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}";
}
}
}
}
}

View File

@ -1,9 +1,9 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Game.Configuration;
using osu.Game.Graphics;
@ -15,12 +15,15 @@ namespace osu.Game.Overlays.Settings.Sections
{
public class SkinSection : SettingsSection
{
private SettingsDropdown<int> skinDropdown;
private SkinSettingsDropdown skinDropdown;
public override string Header => "Skin";
public override FontAwesome Icon => FontAwesome.fa_paint_brush;
private readonly Bindable<SkinInfo> dropdownBindable = new Bindable<SkinInfo>();
private readonly Bindable<int> configBindable = new Bindable<int>();
private SkinManager skins;
[BackgroundDependencyLoader]
@ -31,7 +34,7 @@ namespace osu.Game.Overlays.Settings.Sections
FlowContent.Spacing = new Vector2(0, 5);
Children = new Drawable[]
{
skinDropdown = new SettingsDropdown<int>(),
skinDropdown = new SkinSettingsDropdown(),
new SettingsSlider<double, SizeSlider>
{
LabelText = "Menu cursor size",
@ -54,19 +57,21 @@ namespace osu.Game.Overlays.Settings.Sections
skins.ItemAdded += itemAdded;
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().ToArray();
// Todo: This should not be necessary when OsuConfigManager is databased
if (skinDropdown.Items.All(s => s.Value != skinBindable.Value))
skinBindable.Value = 0;
if (skinDropdown.Items.All(s => s.ID != configBindable.Value))
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 itemAdded(SkinInfo s) => skinDropdown.Items = skinDropdown.Items.Append(new KeyValuePair<string, int>(s.ToString(), 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(s).ToArray();
protected override void Dispose(bool isDisposing)
{
@ -83,5 +88,15 @@ namespace osu.Game.Overlays.Settings.Sections
{
public override string TooltipText => Current.Value.ToString(@"0.##x");
}
private class SkinSettingsDropdown : SettingsDropdown<SkinInfo>
{
protected override OsuDropdown<SkinInfo> CreateDropdown() => new SkinDropdownControl { Items = Items };
private class SkinDropdownControl : DropdownControl
{
protected override string GenerateItemText(SkinInfo item) => item.ToString();
}
}
}
}

View File

@ -2,36 +2,41 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays.Settings
{
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>[] { };
public IEnumerable<KeyValuePair<string, T>> Items
private IEnumerable<T> items = Enumerable.Empty<T>();
public IEnumerable<T> Items
{
get
{
return items;
}
get => items;
set
{
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 },
RelativeSizeAxes = Axes.X,
Items = Items,
};
public DropdownControl()
{
Margin = new MarginPadding { Top = 5 };
RelativeSizeAxes = Axes.X;
}
}
}
}

View File

@ -8,10 +8,15 @@ namespace osu.Game.Overlays.Settings
{
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 },
RelativeSizeAxes = Axes.X,
};
public DropdownControl()
{
Margin = new MarginPadding { Top = 5 };
RelativeSizeAxes = Axes.X;
}
}
}
}

View File

@ -1,7 +1,6 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Graphics.Sprites;
@ -25,7 +24,7 @@ namespace osu.Game.Screens.Play.PlayerSettings
new CollectionsDropdown<PlaylistCollection>
{
RelativeSizeAxes = Axes.X,
Items = new[] { new KeyValuePair<string, PlaylistCollection>(@"All", PlaylistCollection.All) },
Items = new[] { PlaylistCollection.All },
},
};
}

View File

@ -18,7 +18,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.1.4" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="ppy.osu.Framework" Version="2018.1112.0" />
<PackageReference Include="ppy.osu.Framework" Version="2018.1114.0" />
<PackageReference Include="SharpCompress" Version="0.22.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" />