mirror of https://github.com/ppy/osu
Split out SkinInfo ID constants and fix random logic
This commit is contained in:
parent
a5e13e4d2c
commit
6b548ef5e4
|
@ -31,9 +31,13 @@ public class SkinSection : SettingsSection
|
|||
private readonly Bindable<SkinInfo> dropdownBindable = new Bindable<SkinInfo> { Default = SkinInfo.Default };
|
||||
private readonly Bindable<int> configBindable = new Bindable<int>();
|
||||
|
||||
private static readonly SkinInfo random_skin_info = new RandomSkinInfo();
|
||||
private static readonly SkinInfo random_skin_info = new SkinInfo
|
||||
{
|
||||
ID = SkinInfo.RANDOM_SKIN,
|
||||
Name = "<Random Skin>",
|
||||
};
|
||||
|
||||
private List<SkinInfo> usableSkins;
|
||||
private List<SkinInfo> 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<WeakReference<SkinInfo>> weakItem)
|
||||
|
@ -150,17 +162,6 @@ private class SkinDropdownControl : DropdownControl
|
|||
}
|
||||
}
|
||||
|
||||
private class RandomSkinInfo : SkinInfo
|
||||
{
|
||||
public RandomSkinInfo()
|
||||
{
|
||||
Name = "<Random Skin>";
|
||||
ID = -1;
|
||||
}
|
||||
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
|
||||
private class ExportSkinButton : SettingsButton
|
||||
{
|
||||
[Resolved]
|
||||
|
|
|
@ -25,7 +25,7 @@ public DefaultLegacySkin(IResourceStore<byte[]> 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!"
|
||||
};
|
||||
|
|
|
@ -10,6 +10,10 @@ namespace osu.Game.Skinning
|
|||
{
|
||||
public class SkinInfo : IHasFiles<SkinFileInfo>, IEquatable<SkinInfo>, 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<SkinFileInfo>, IEquatable<SkinInfo>, IHasPrima
|
|||
|
||||
public static SkinInfo Default { get; } = new SkinInfo
|
||||
{
|
||||
ID = DEFAULT_SKIN,
|
||||
Name = "osu!lazer",
|
||||
Creator = "team osu!"
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue