2017-02-14 07:13:25 +00:00
|
|
|
|
// 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;
|
2017-02-06 00:21:26 +00:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2017-05-15 01:55:29 +00:00
|
|
|
|
namespace osu.Game.Overlays.Settings
|
2017-02-06 00:21:26 +00:00
|
|
|
|
{
|
2017-05-15 01:55:29 +00:00
|
|
|
|
public class SettingsEnumDropdown<T> : SettingsDropdown<T>
|
2017-02-06 00:21:26 +00:00
|
|
|
|
{
|
2017-05-15 01:55:29 +00:00
|
|
|
|
public SettingsEnumDropdown()
|
2017-02-06 00:21:26 +00:00
|
|
|
|
{
|
|
|
|
|
if (!typeof(T).IsEnum)
|
2017-05-15 01:55:29 +00:00
|
|
|
|
throw new InvalidOperationException("SettingsDropdown only supports enums as the generic type argument");
|
2017-02-06 00:21:26 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|