mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 14:53:21 +08:00
Allow specifying order to SettingSource
This commit is contained in:
parent
e6111a1888
commit
88a56d00bf
@ -10,7 +10,7 @@ namespace osu.Game.Rulesets.Catch.Mods
|
||||
{
|
||||
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
|
||||
{
|
||||
Precision = 0.1f,
|
||||
@ -20,7 +20,7 @@ namespace osu.Game.Rulesets.Catch.Mods
|
||||
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
|
||||
{
|
||||
Precision = 0.1f,
|
||||
|
@ -10,7 +10,7 @@ namespace osu.Game.Rulesets.Osu.Mods
|
||||
{
|
||||
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
|
||||
{
|
||||
Precision = 0.1f,
|
||||
@ -20,7 +20,7 @@ namespace osu.Game.Rulesets.Osu.Mods
|
||||
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
|
||||
{
|
||||
Precision = 0.1f,
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Bindables;
|
||||
@ -20,14 +21,25 @@ namespace osu.Game.Configuration
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
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 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;
|
||||
Description = description ?? string.Empty;
|
||||
OrderMode = order;
|
||||
OrderPosition = orderPosition;
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +47,7 @@ namespace osu.Game.Configuration
|
||||
{
|
||||
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);
|
||||
|
||||
@ -116,5 +128,17 @@ namespace osu.Game.Configuration
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
|
||||
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
|
||||
{
|
||||
Precision = 0.1f,
|
||||
@ -38,7 +38,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
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
|
||||
{
|
||||
Precision = 0.1f,
|
||||
|
Loading…
Reference in New Issue
Block a user