Allow specifying order to SettingSource

This commit is contained in:
voidedWarranties
2020-02-09 20:11:37 -08:00
parent e6111a1888
commit 88a56d00bf
4 changed files with 32 additions and 8 deletions

View File

@ -10,7 +10,7 @@ namespace osu.Game.Rulesets.Catch.Mods
{ {
public class CatchModDifficultyAdjust : ModDifficultyAdjust public class CatchModDifficultyAdjust : ModDifficultyAdjust
{ {
[SettingSource("Fruit Size", "Override a beatmap's set CS.")] [SettingSource("Fruit Size", "Override a beatmap's set CS.", SettingSourceAttribute.FIRST)]
public BindableNumber<float> CircleSize { get; } = new BindableFloat public BindableNumber<float> CircleSize { get; } = new BindableFloat
{ {
Precision = 0.1f, Precision = 0.1f,
@ -20,7 +20,7 @@ namespace osu.Game.Rulesets.Catch.Mods
Value = 5, Value = 5,
}; };
[SettingSource("Approach Rate", "Override a beatmap's set AR.")] [SettingSource("Approach Rate", "Override a beatmap's set AR.", SettingSourceAttribute.LAST)]
public BindableNumber<float> ApproachRate { get; } = new BindableFloat public BindableNumber<float> ApproachRate { get; } = new BindableFloat
{ {
Precision = 0.1f, Precision = 0.1f,

View File

@ -10,7 +10,7 @@ namespace osu.Game.Rulesets.Osu.Mods
{ {
public class OsuModDifficultyAdjust : ModDifficultyAdjust public class OsuModDifficultyAdjust : ModDifficultyAdjust
{ {
[SettingSource("Circle Size", "Override a beatmap's set CS.")] [SettingSource("Circle Size", "Override a beatmap's set CS.", SettingSourceAttribute.FIRST)]
public BindableNumber<float> CircleSize { get; } = new BindableFloat public BindableNumber<float> CircleSize { get; } = new BindableFloat
{ {
Precision = 0.1f, Precision = 0.1f,
@ -20,7 +20,7 @@ namespace osu.Game.Rulesets.Osu.Mods
Value = 5, Value = 5,
}; };
[SettingSource("Approach Rate", "Override a beatmap's set AR.")] [SettingSource("Approach Rate", "Override a beatmap's set AR.", SettingSourceAttribute.LAST)]
public BindableNumber<float> ApproachRate { get; } = new BindableFloat public BindableNumber<float> ApproachRate { get; } = new BindableFloat
{ {
Precision = 0.1f, Precision = 0.1f,

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Reflection; using System.Reflection;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -20,14 +21,25 @@ namespace osu.Game.Configuration
[AttributeUsage(AttributeTargets.Property)] [AttributeUsage(AttributeTargets.Property)]
public class SettingSourceAttribute : Attribute public class SettingSourceAttribute : Attribute
{ {
public const int FIRST = 0;
public const int ORDERED_RELATIVE = 1;
public const int UNORDERED = 2;
public const int LAST = 3;
public string Label { get; } public string Label { get; }
public string Description { get; } public string Description { get; }
public SettingSourceAttribute(string label, string description = null) public int OrderMode { get; }
public int OrderPosition { get; }
public SettingSourceAttribute(string label, string description = null, int order = UNORDERED, int orderPosition = 0)
{ {
Label = label ?? string.Empty; Label = label ?? string.Empty;
Description = description ?? string.Empty; Description = description ?? string.Empty;
OrderMode = order;
OrderPosition = orderPosition;
} }
} }
@ -35,7 +47,7 @@ namespace osu.Game.Configuration
{ {
public static IEnumerable<Drawable> CreateSettingsControls(this object obj) public static IEnumerable<Drawable> CreateSettingsControls(this object obj)
{ {
foreach (var (attr, property) in obj.GetSettingsSourceProperties()) foreach (var (attr, property) in obj.GetOrderedSettingsSourceProperties())
{ {
object value = property.GetValue(obj); object value = property.GetValue(obj);
@ -116,5 +128,17 @@ namespace osu.Game.Configuration
yield return (attr, property); yield return (attr, property);
} }
} }
public static IEnumerable<(SettingSourceAttribute, PropertyInfo)> GetOrderedSettingsSourceProperties(this object obj)
{
var original = obj.GetSettingsSourceProperties();
var first = original.Where(attr => attr.Item1.OrderMode == SettingSourceAttribute.FIRST);
var orderedRelative = original.Where(attr => attr.Item1.OrderMode == SettingSourceAttribute.ORDERED_RELATIVE).OrderBy(attr => attr.Item1.OrderPosition);
var unordered = original.Where(attr => attr.Item1.OrderMode == SettingSourceAttribute.UNORDERED);
var last = original.Where(attr => attr.Item1.OrderMode == SettingSourceAttribute.LAST);
return first.Concat(orderedRelative).Concat(unordered).Concat(last);
}
} }
} }

View File

@ -28,7 +28,7 @@ namespace osu.Game.Rulesets.Mods
public override Type[] IncompatibleMods => new[] { typeof(ModEasy), typeof(ModHardRock) }; public override Type[] IncompatibleMods => new[] { typeof(ModEasy), typeof(ModHardRock) };
[SettingSource("Drain Rate", "Override a beatmap's set HP.")] [SettingSource("Drain Rate", "Override a beatmap's set HP.", SettingSourceAttribute.ORDERED_RELATIVE, 1)]
public BindableNumber<float> DrainRate { get; } = new BindableFloat public BindableNumber<float> DrainRate { get; } = new BindableFloat
{ {
Precision = 0.1f, Precision = 0.1f,
@ -38,7 +38,7 @@ namespace osu.Game.Rulesets.Mods
Value = 5, Value = 5,
}; };
[SettingSource("Overall Difficulty", "Override a beatmap's set OD.")] [SettingSource("Overall Difficulty", "Override a beatmap's set OD.", SettingSourceAttribute.ORDERED_RELATIVE, 1)]
public BindableNumber<float> OverallDifficulty { get; } = new BindableFloat public BindableNumber<float> OverallDifficulty { get; } = new BindableFloat
{ {
Precision = 0.1f, Precision = 0.1f,