1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 13:33:03 +08:00

Merge pull request #10789 from peppy/add-random-skin-hotkey

Add hotkey to select a new random skin
This commit is contained in:
Dan Balasescu 2020-11-11 16:25:12 +09:00 committed by GitHub
commit 31dcdb4427
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 17 deletions

View File

@ -189,7 +189,7 @@ namespace osu.Game.Configuration
new TrackedSetting<int>(OsuSetting.Skin, m =>
{
string skinName = LookupSkinName(m) ?? string.Empty;
return new SettingDescription(skinName, "skin", skinName);
return new SettingDescription(skinName, "skin", skinName, $"random: {LookupKeyBindings(GlobalAction.RandomSkin)}");
})
};
}

View File

@ -48,6 +48,8 @@ namespace osu.Game.Input.Bindings
new KeyBinding(InputKey.Space, GlobalAction.Select),
new KeyBinding(InputKey.Enter, GlobalAction.Select),
new KeyBinding(InputKey.KeypadEnter, GlobalAction.Select),
new KeyBinding(new[] { InputKey.Control, InputKey.Shift, InputKey.R }, GlobalAction.RandomSkin),
};
public IEnumerable<KeyBinding> EditorKeyBindings => new[]
@ -191,5 +193,8 @@ namespace osu.Game.Input.Bindings
[Description("Hold for HUD")]
HoldForHUD,
[Description("Random Skin")]
RandomSkin,
}
}

View File

@ -892,6 +892,10 @@ namespace osu.Game
case GlobalAction.ToggleGameplayMouseButtons:
LocalConfig.Set(OsuSetting.MouseDisableButtons, !LocalConfig.Get<bool>(OsuSetting.MouseDisableButtons));
return true;
case GlobalAction.RandomSkin:
SkinManager.SelectRandomSkin();
return true;
}
return false;

View File

@ -9,7 +9,6 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Logging;
using osu.Framework.Utils;
using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface;
using osu.Game.Skinning;
@ -103,7 +102,7 @@ namespace osu.Game.Overlays.Settings.Sections
{
if (skin.NewValue == random_skin_info)
{
randomizeSkin();
skins.SelectRandomSkin();
return;
}
@ -111,20 +110,6 @@ namespace osu.Game.Overlays.Settings.Sections
});
}
private void randomizeSkin()
{
// choose from only user skins, removing the current selection to ensure a new one is chosen.
var randomChoices = skinItems.Where(s => s.ID > 0 && s.ID != configBindable.Value).ToArray();
if (randomChoices.Length == 0)
{
configBindable.Value = SkinInfo.Default.ID;
return;
}
configBindable.Value = randomChoices.ElementAt(RNG.Next(0, randomChoices.Length)).ID;
}
private void updateItems()
{
skinItems = skins.GetAllUsableSkins();

View File

@ -19,6 +19,7 @@ using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores;
using osu.Framework.Platform;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Audio;
using osu.Game.Database;
using osu.Game.IO.Archives;
@ -87,6 +88,20 @@ namespace osu.Game.Skinning
/// <returns>A newly allocated list of available <see cref="SkinInfo"/>.</returns>
public List<SkinInfo> GetAllUserSkins() => ModelStore.ConsumableItems.Where(s => !s.DeletePending).ToList();
public void SelectRandomSkin()
{
// choose from only user skins, removing the current selection to ensure a new one is chosen.
var randomChoices = GetAllUsableSkins().Where(s => s.ID > 0 && s.ID != CurrentSkinInfo.Value.ID).ToArray();
if (randomChoices.Length == 0)
{
CurrentSkinInfo.Value = SkinInfo.Default;
return;
}
CurrentSkinInfo.Value = randomChoices.ElementAt(RNG.Next(0, randomChoices.Length));
}
protected override SkinInfo CreateModel(ArchiveReader archive) => new SkinInfo { Name = archive.Name };
private const string unknown_creator_string = "Unknown";