diff --git a/osu.Game/Overlays/Settings/Sections/SkinSection.cs b/osu.Game/Overlays/Settings/Sections/SkinSection.cs index 412103af38..b21de26dde 100644 --- a/osu.Game/Overlays/Settings/Sections/SkinSection.cs +++ b/osu.Game/Overlays/Settings/Sections/SkinSection.cs @@ -31,9 +31,13 @@ public class SkinSection : SettingsSection private readonly Bindable dropdownBindable = new Bindable { Default = SkinInfo.Default }; private readonly Bindable configBindable = new Bindable(); - private static readonly SkinInfo random_skin_info = new RandomSkinInfo(); + private static readonly SkinInfo random_skin_info = new SkinInfo + { + ID = SkinInfo.RANDOM_SKIN, + Name = "", + }; - private List usableSkins; + private List skinItems; [Resolved] private SkinManager skins { get; set; } @@ -98,29 +102,37 @@ private void load(OsuConfigManager config) dropdownBindable.BindValueChanged(skin => { if (skin.NewValue == random_skin_info) + { randomizeSkin(); - else - configBindable.Value = skin.NewValue.ID; + return; + } + + configBindable.Value = skin.NewValue.ID; }); } private void randomizeSkin() { - int n = usableSkins.Count; - if (n > 1) - configBindable.Value = (configBindable.Value + RNG.Next(n - 1) + 1) % n; // make sure it's always a different one - else - configBindable.Value = 0; + int count = skinItems.Count - 1; // exclude "random" item. + + if (count <= 1) + { + configBindable.Value = SkinInfo.Default.ID; + return; + } + + // ensure the random selection is never the same as the previous. + configBindable.Value = skinItems.Where(s => s.ID != configBindable.Value).ElementAt(RNG.Next(0, count)).ID; } private void updateItems() { - usableSkins = skins.GetAllUsableSkins(); + skinItems = skins.GetAllUsableSkins(); - if (usableSkins.Count > 1) - usableSkins.Add(random_skin_info); + if (skinItems.Count > 1) + skinItems.Add(random_skin_info); - skinDropdown.Items = usableSkins; + skinDropdown.Items = skinItems; } private void itemUpdated(ValueChangedEvent> weakItem) @@ -150,17 +162,6 @@ private class SkinDropdownControl : DropdownControl } } - private class RandomSkinInfo : SkinInfo - { - public RandomSkinInfo() - { - Name = ""; - ID = -1; - } - - public override string ToString() => Name; - } - private class ExportSkinButton : SettingsButton { [Resolved] diff --git a/osu.Game/Skinning/DefaultLegacySkin.cs b/osu.Game/Skinning/DefaultLegacySkin.cs index 78d3a37f7c..2758a4cbba 100644 --- a/osu.Game/Skinning/DefaultLegacySkin.cs +++ b/osu.Game/Skinning/DefaultLegacySkin.cs @@ -25,7 +25,7 @@ public DefaultLegacySkin(IResourceStore storage, AudioManager audioManag public static SkinInfo Info { get; } = new SkinInfo { - ID = -1, // this is temporary until database storage is decided upon. + ID = SkinInfo.CLASSIC_SKIN, // this is temporary until database storage is decided upon. Name = "osu!classic", Creator = "team osu!" }; diff --git a/osu.Game/Skinning/SkinInfo.cs b/osu.Game/Skinning/SkinInfo.cs index b9fe44ef3b..aaccbefb3d 100644 --- a/osu.Game/Skinning/SkinInfo.cs +++ b/osu.Game/Skinning/SkinInfo.cs @@ -10,6 +10,10 @@ namespace osu.Game.Skinning { public class SkinInfo : IHasFiles, IEquatable, IHasPrimaryKey, ISoftDelete { + internal const int DEFAULT_SKIN = 0; + internal const int CLASSIC_SKIN = -1; + internal const int RANDOM_SKIN = -2; + public int ID { get; set; } public string Name { get; set; } @@ -26,6 +30,7 @@ public class SkinInfo : IHasFiles, IEquatable, IHasPrima public static SkinInfo Default { get; } = new SkinInfo { + ID = DEFAULT_SKIN, Name = "osu!lazer", Creator = "team osu!" };