2021-02-27 13:46:48 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Bindables;
|
2021-04-27 17:46:34 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2021-02-27 13:46:48 +00:00
|
|
|
using osu.Game.Configuration;
|
2021-04-27 17:46:34 +00:00
|
|
|
using osu.Game.Overlays.Settings;
|
2021-02-27 13:46:48 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Mods
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2023-02-28 02:45:32 +00:00
|
|
|
public partial class SettingSourceAttributeTest
|
2021-02-27 13:46:48 +00:00
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void TestOrdering()
|
|
|
|
{
|
|
|
|
var objectWithSettings = new ClassWithSettings();
|
|
|
|
|
|
|
|
var orderedSettings = objectWithSettings.GetOrderedSettingsSourceProperties().ToArray();
|
|
|
|
|
2021-02-27 14:14:25 +00:00
|
|
|
Assert.That(orderedSettings, Has.Length.EqualTo(4));
|
2021-02-27 13:57:37 +00:00
|
|
|
|
|
|
|
Assert.That(orderedSettings[0].Item2.Name, Is.EqualTo(nameof(ClassWithSettings.FirstSetting)));
|
|
|
|
Assert.That(orderedSettings[1].Item2.Name, Is.EqualTo(nameof(ClassWithSettings.SecondSetting)));
|
|
|
|
Assert.That(orderedSettings[2].Item2.Name, Is.EqualTo(nameof(ClassWithSettings.ThirdSetting)));
|
2021-02-27 14:14:25 +00:00
|
|
|
Assert.That(orderedSettings[3].Item2.Name, Is.EqualTo(nameof(ClassWithSettings.UnorderedSetting)));
|
2021-02-27 13:46:48 +00:00
|
|
|
}
|
|
|
|
|
2021-04-27 17:46:34 +00:00
|
|
|
[Test]
|
|
|
|
public void TestCustomControl()
|
|
|
|
{
|
|
|
|
var objectWithCustomSettingControl = new ClassWithCustomSettingControl();
|
|
|
|
var settings = objectWithCustomSettingControl.CreateSettingsControls().ToArray();
|
|
|
|
|
|
|
|
Assert.That(settings, Has.Length.EqualTo(1));
|
|
|
|
Assert.That(settings[0], Is.TypeOf<CustomSettingsControl>());
|
|
|
|
}
|
|
|
|
|
2021-02-27 13:46:48 +00:00
|
|
|
private class ClassWithSettings
|
|
|
|
{
|
2021-02-27 14:14:25 +00:00
|
|
|
[SettingSource("Unordered setting", "Should be last")]
|
2023-10-06 07:51:24 +00:00
|
|
|
public BindableFloat UnorderedSetting { get; } = new BindableFloat();
|
2021-02-27 14:14:25 +00:00
|
|
|
|
2021-02-27 13:46:48 +00:00
|
|
|
[SettingSource("Second setting", "Another description", 2)]
|
2023-10-06 07:51:24 +00:00
|
|
|
public BindableBool SecondSetting { get; } = new BindableBool();
|
2021-02-27 13:46:48 +00:00
|
|
|
|
|
|
|
[SettingSource("First setting", "A description", 1)]
|
2023-10-06 07:51:24 +00:00
|
|
|
public BindableDouble FirstSetting { get; } = new BindableDouble();
|
2021-02-27 13:46:48 +00:00
|
|
|
|
|
|
|
[SettingSource("Third setting", "Yet another description", 3)]
|
2023-10-06 07:51:24 +00:00
|
|
|
public BindableInt ThirdSetting { get; } = new BindableInt();
|
2021-02-27 13:46:48 +00:00
|
|
|
}
|
2021-04-27 17:46:34 +00:00
|
|
|
|
|
|
|
private class ClassWithCustomSettingControl
|
|
|
|
{
|
|
|
|
[SettingSource("Custom setting", "Should be a custom control", SettingControlType = typeof(CustomSettingsControl))]
|
2023-10-06 07:51:24 +00:00
|
|
|
public BindableInt UnorderedSetting { get; } = new BindableInt();
|
2021-04-27 17:46:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private partial class CustomSettingsControl : SettingsItem<int>
|
|
|
|
{
|
|
|
|
protected override Drawable CreateControl() => new CustomControl();
|
|
|
|
|
|
|
|
private partial class CustomControl : Drawable, IHasCurrentValue<int>
|
|
|
|
{
|
2023-10-06 09:13:02 +00:00
|
|
|
public Bindable<int> Current { get; set; } = new Bindable<int>();
|
2021-04-27 17:46:34 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-27 13:46:48 +00:00
|
|
|
}
|
|
|
|
}
|