1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-19 06:02:55 +08:00

Add DisplayName

This commit is contained in:
Drew DeVault 2016-12-01 16:45:43 -05:00
parent 9daf524120
commit 0378de8346
4 changed files with 25 additions and 3 deletions

View File

@ -0,0 +1,15 @@
using System;
namespace osu.Game.Configuration
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class DisplayNameAttribute : Attribute
{
public string Name { get; set; }
public DisplayNameAttribute(string name)
{
Name = name;
}
}
}

View File

@ -1,11 +1,14 @@
using System;
using System;
namespace osu.Game.Configuration
{
public enum ProgressBarType
{
Off,
Pie,
[DisplayName("Top Right")]
TopRight,
[DisplayName("Bottom Right")]
BottomRight,
Bottom
}

View File

@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Reflection;
using OpenTK.Graphics;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
@ -7,6 +8,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Configuration;
namespace osu.Game.Overlays.Options
{
@ -52,8 +54,9 @@ namespace osu.Game.Overlays.Options
Direction = FlowDirection.VerticalOnly;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
var items = Enum.GetNames(typeof(T)).Zip(
(T[])Enum.GetValues(typeof(T)), (a, b) => new Tuple<string, T>(a, b));
var items = typeof(T).GetFields().Where(f => !f.IsSpecialName).Zip(
(T[])Enum.GetValues(typeof(T)), (a, b) => new Tuple<string, T>(
a.GetCustomAttribute<DisplayNameAttribute>()?.Name ?? a.Name, b));
Children = new Drawable[]
{
text = new SpriteText { Alpha = 0 },

View File

@ -225,6 +225,7 @@
<Compile Include="Overlays\Options\SliderOption.cs" />
<Compile Include="Configuration\ProgressBarType.cs" />
<Compile Include="Overlays\Options\OptionsDropdown.cs" />
<Compile Include="Configuration\DisplayNameAttribute.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)\osu-framework\osu.Framework\osu.Framework.csproj">