mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 20:22:55 +08:00
Add textbox and dropdown support
This commit is contained in:
parent
ed6d1ccd95
commit
2fa0b30fa2
@ -8,6 +8,7 @@ using System.Reflection;
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Game.Overlays.Settings;
|
using osu.Game.Overlays.Settings;
|
||||||
|
|
||||||
namespace osu.Game.Configuration
|
namespace osu.Game.Configuration
|
||||||
@ -40,8 +41,9 @@ namespace osu.Game.Configuration
|
|||||||
foreach (var property in configProperties)
|
foreach (var property in configProperties)
|
||||||
{
|
{
|
||||||
var attr = property.GetCustomAttribute<SettingSourceAttribute>(true);
|
var attr = property.GetCustomAttribute<SettingSourceAttribute>(true);
|
||||||
|
var prop = property.GetValue(obj);
|
||||||
|
|
||||||
switch (property.GetValue(obj))
|
switch (prop)
|
||||||
{
|
{
|
||||||
case BindableNumber<float> bNumber:
|
case BindableNumber<float> bNumber:
|
||||||
yield return new SettingsSlider<float>
|
yield return new SettingsSlider<float>
|
||||||
@ -78,6 +80,30 @@ namespace osu.Game.Configuration
|
|||||||
};
|
};
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Bindable<string> bString:
|
||||||
|
yield return new SettingsTextBox
|
||||||
|
{
|
||||||
|
LabelText = attr.Label,
|
||||||
|
Bindable = bString
|
||||||
|
};
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IBindable bindable:
|
||||||
|
|
||||||
|
var dropdownType = typeof(SettingsEnumDropdown<>).MakeGenericType(bindable.GetType().GetGenericArguments()[0]);
|
||||||
|
|
||||||
|
var dropdown = (Drawable)Activator.CreateInstance(dropdownType);
|
||||||
|
|
||||||
|
dropdown.GetType().GetProperty(nameof(IHasCurrentValue<object>.Current))?.SetValue(dropdown, obj);
|
||||||
|
|
||||||
|
yield return dropdown;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new InvalidOperationException($"{nameof(SettingSourceAttribute)} was attached to an unsupported type ({prop})");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user