mirror of https://github.com/ppy/osu
Remove duplicate code in SettingsEnumDropdown
This commit is contained in:
parent
5b2c74be50
commit
1d61fc84c7
|
@ -13,12 +13,12 @@ public class OsuEnumDropdown<T> : OsuDropdown<T>
|
|||
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)))
|
||||
{
|
||||
var field = typeof(T).GetField(Enum.GetName(typeof(T), val));
|
||||
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),
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
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;
|
||||
}
|
||||
protected override Drawable CreateControl() => new OsuEnumDropdown<T>
|
||||
{
|
||||
Margin = new MarginPadding { Top = 5 },
|
||||
RelativeSizeAxes = Axes.X,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue