mirror of
https://github.com/ppy/osu
synced 2024-12-11 09:27:08 +00:00
Remove duplicate code in SettingsEnumDropdown
This commit is contained in:
parent
5b2c74be50
commit
1d61fc84c7
@ -13,7 +13,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
public OsuEnumDropdown()
|
||||
{
|
||||
if (!typeof(T).IsEnum)
|
||||
throw new InvalidOperationException("SettingsDropdown 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>>();
|
||||
foreach(var val in (T[])Enum.GetValues(typeof(T)))
|
||||
|
@ -1,32 +1,17 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Game.Overlays.Settings
|
||||
{
|
||||
public class SettingsEnumDropdown<T> : SettingsDropdown<T>
|
||||
{
|
||||
public SettingsEnumDropdown()
|
||||
protected override Drawable CreateControl() => new OsuEnumDropdown<T>
|
||||
{
|
||||
if (!typeof(T).IsEnum)
|
||||
throw new InvalidOperationException("SettingsDropdown 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;
|
||||
}
|
||||
Margin = new MarginPadding { Top = 5 },
|
||||
RelativeSizeAxes = Axes.X,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user