1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-27 11:12:59 +08:00

Rewrite SkinSection to use realm subscriptions and databased defaults

This commit is contained in:
Dean Herbert 2021-11-29 18:04:07 +09:00
parent 6b55de2845
commit 744a5b33f5
2 changed files with 34 additions and 18 deletions

View File

@ -106,7 +106,10 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
dialogOverlay?.Push(new MassDeleteConfirmationDialog(() => dialogOverlay?.Push(new MassDeleteConfirmationDialog(() =>
{ {
deleteSkinsButton.Enabled.Value = false; deleteSkinsButton.Enabled.Value = false;
Task.Run(() => skins.Delete(skins.GetAllUserSkins())).ContinueWith(t => Schedule(() => deleteSkinsButton.Enabled.Value = true)); Task.Run(() =>
{
skins.Delete(s => !s.DeletePending);
}).ContinueWith(t => Schedule(() => deleteSkinsButton.Enabled.Value = true));
})); }));
} }
}); });

View File

@ -32,16 +32,16 @@ namespace osu.Game.Overlays.Settings.Sections
Icon = FontAwesome.Solid.PaintBrush Icon = FontAwesome.Solid.PaintBrush
}; };
private readonly Bindable<SkinInfo> dropdownBindable = new Bindable<SkinInfo> { Default = SkinInfo.Default }; private readonly Bindable<ILive<SkinInfo>> dropdownBindable = new Bindable<ILive<SkinInfo>> { Default = SkinInfo.Default.ToLive() };
private readonly Bindable<string> configBindable = new Bindable<string>(); private readonly Bindable<string> configBindable = new Bindable<string>();
private static readonly SkinInfo random_skin_info = new SkinInfo private static readonly ILive<SkinInfo> random_skin_info = new SkinInfo
{ {
ID = SkinInfo.RANDOM_SKIN, ID = SkinInfo.RANDOM_SKIN,
Name = "<Random Skin>", Name = "<Random Skin>",
}; }.ToLive();
private List<SkinInfo> skinItems; private List<ILive<SkinInfo>> skinItems;
private int firstNonDefaultSkinIndex private int firstNonDefaultSkinIndex
{ {
@ -79,6 +79,11 @@ namespace osu.Game.Overlays.Settings.Sections
skins.ItemRemoved += itemRemoved; skins.ItemRemoved += itemRemoved;
config.BindWith(OsuSetting.Skin, configBindable); config.BindWith(OsuSetting.Skin, configBindable);
}
protected override void LoadComplete()
{
base.LoadComplete();
skinDropdown.Current = dropdownBindable; skinDropdown.Current = dropdownBindable;
updateItems(); updateItems();
@ -125,22 +130,30 @@ namespace osu.Game.Overlays.Settings.Sections
skinDropdown.Items = skinItems; skinDropdown.Items = skinItems;
} }
private void itemUpdated(SkinInfo item) => Schedule(() => addItem(item)); private void itemUpdated(SkinInfo item) => Schedule(() => addItem(item.ToLive()));
private void addItem(SkinInfo item) private void addItem(ILive<SkinInfo> item)
{ {
List<SkinInfo> newDropdownItems = skinDropdown.Items.Where(i => !i.Equals(item)).Append(item).ToList(); List<ILive<SkinInfo>> newDropdownItems = skinDropdown.Items.Where(i => !i.Equals(item)).Append(item).ToList();
sortUserSkins(newDropdownItems); sortUserSkins(newDropdownItems);
skinDropdown.Items = newDropdownItems; skinDropdown.Items = newDropdownItems;
} }
private void itemRemoved(SkinInfo item) => Schedule(() => skinDropdown.Items = skinDropdown.Items.Where(i => !i.Equals(item)).ToArray()); private void itemRemoved(SkinInfo item) => Schedule(() => skinDropdown.Items = skinDropdown.Items.Where(i => !i.ID.Equals(item.ID)).ToArray());
private void sortUserSkins(List<SkinInfo> skinsList) private void sortUserSkins(List<ILive<SkinInfo>> skinsList)
{ {
// Sort user skins separately from built-in skins try
skinsList.Sort(firstNonDefaultSkinIndex, skinsList.Count - firstNonDefaultSkinIndex, {
Comparer<SkinInfo>.Create((a, b) => string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase))); // Sort user skins separately from built-in skins
skinsList.Sort(firstNonDefaultSkinIndex, skinsList.Count - firstNonDefaultSkinIndex,
Comparer<ILive<SkinInfo>>.Create((a, b) =>
{
// o_________________________o
return a.PerformRead(ai => b.PerformRead(bi => string.Compare(ai.Name, bi.Name, StringComparison.OrdinalIgnoreCase)));
}));
}
catch { }
} }
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
@ -154,13 +167,13 @@ namespace osu.Game.Overlays.Settings.Sections
} }
} }
private class SkinSettingsDropdown : SettingsDropdown<SkinInfo> private class SkinSettingsDropdown : SettingsDropdown<ILive<SkinInfo>>
{ {
protected override OsuDropdown<SkinInfo> CreateDropdown() => new SkinDropdownControl(); protected override OsuDropdown<ILive<SkinInfo>> CreateDropdown() => new SkinDropdownControl();
private class SkinDropdownControl : DropdownControl private class SkinDropdownControl : DropdownControl
{ {
protected override LocalisableString GenerateItemText(SkinInfo item) => item.ToString(); protected override LocalisableString GenerateItemText(ILive<SkinInfo> item) => item.ToString();
} }
} }
@ -181,14 +194,14 @@ namespace osu.Game.Overlays.Settings.Sections
Action = export; Action = export;
currentSkin = skins.CurrentSkin.GetBoundCopy(); currentSkin = skins.CurrentSkin.GetBoundCopy();
currentSkin.BindValueChanged(skin => Enabled.Value = skin.NewValue.SkinInfo.IsManaged, true); currentSkin.BindValueChanged(skin => Enabled.Value = skin.NewValue.SkinInfo.PerformRead(s => s.IsManaged), true);
} }
private void export() private void export()
{ {
try try
{ {
new LegacySkinExporter(storage).Export(currentSkin.Value.SkinInfo); currentSkin.Value.SkinInfo.PerformRead(s => new LegacySkinExporter(storage).Export(s));
} }
catch (Exception e) catch (Exception e)
{ {