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()
|
public OsuEnumDropdown()
|
||||||
{
|
{
|
||||||
if (!typeof(T).IsEnum)
|
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>>();
|
List<KeyValuePair<string, T>> items = new List<KeyValuePair<string, T>>();
|
||||||
foreach(var val in (T[])Enum.GetValues(typeof(T)))
|
foreach(var val in (T[])Enum.GetValues(typeof(T)))
|
||||||
|
@ -1,32 +1,17 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System;
|
using osu.Framework.Graphics;
|
||||||
using System.Reflection;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Settings
|
namespace osu.Game.Overlays.Settings
|
||||||
{
|
{
|
||||||
public class SettingsEnumDropdown<T> : SettingsDropdown<T>
|
public class SettingsEnumDropdown<T> : SettingsDropdown<T>
|
||||||
{
|
{
|
||||||
public SettingsEnumDropdown()
|
protected override Drawable CreateControl() => new OsuEnumDropdown<T>
|
||||||
{
|
{
|
||||||
if (!typeof(T).IsEnum)
|
Margin = new MarginPadding { Top = 5 },
|
||||||
throw new InvalidOperationException("SettingsDropdown only supports enums as the generic type argument");
|
RelativeSizeAxes = Axes.X,
|
||||||
|
};
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user