// Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; using System.Reflection; using System.ComponentModel; using System.Collections.Generic; namespace osu.Game.Overlays.Options { public class OptionEnumDropDown : OptionDropDown { public OptionEnumDropDown() { if (!typeof(T).IsEnum) throw new InvalidOperationException("OptionsDropdown only supports enums as the generic type argument"); List> items = new List>(); foreach(var val in (T[])Enum.GetValues(typeof(T))) { var field = typeof(T).GetField(Enum.GetName(typeof(T), val)); items.Add( new KeyValuePair( field.GetCustomAttribute()?.Description ?? Enum.GetName(typeof(T), val), val ) ); } Items = items; } } }