1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:37:28 +08:00

Add maintenance settings section for mod presets

This commit is contained in:
Bartłomiej Dach 2022-08-07 16:05:43 +02:00
parent 839409d7ac
commit 7d6efaebbe
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
3 changed files with 101 additions and 1 deletions

View File

@ -74,6 +74,16 @@ namespace osu.Game.Localisation
/// </summary>
public static LocalisableString RestoreAllRecentlyDeletedBeatmaps => new TranslatableString(getKey(@"restore_all_recently_deleted_beatmaps"), @"Restore all recently deleted beatmaps");
/// <summary>
/// "Delete ALL mod presets"
/// </summary>
public static LocalisableString DeleteAllModPresets => new TranslatableString(getKey(@"delete_all_mod_presets"), @"Delete ALL mod presets");
/// <summary>
/// "Restore all recently deleted mod presets"
/// </summary>
public static LocalisableString RestoreAllRecentlyDeletedModPresets => new TranslatableString(getKey(@"restore_all_recently_deleted_mod_presets"), @"Restore all recently deleted mod presets");
private static string getKey(string key) => $"{prefix}:{key}";
}
}

View File

@ -0,0 +1,89 @@
// 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 System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Framework.Logging;
using osu.Game.Database;
using osu.Game.Overlays.Notifications;
using osu.Game.Rulesets.Mods;
using osu.Game.Localisation;
namespace osu.Game.Overlays.Settings.Sections.Maintenance
{
public class ModPresetSettings : SettingsSubsection
{
protected override LocalisableString Header => "Mod presets";
[Resolved]
private RealmAccess realm { get; set; } = null!;
[Resolved]
private INotificationOverlay? notificationOverlay { get; set; }
private SettingsButton undeleteButton = null!;
private SettingsButton deleteAllButton = null!;
[BackgroundDependencyLoader]
private void load(IDialogOverlay? dialogOverlay)
{
AddRange(new Drawable[]
{
deleteAllButton = new DangerousSettingsButton
{
Text = MaintenanceSettingsStrings.DeleteAllModPresets,
Action = () =>
{
dialogOverlay?.Push(new MassDeleteConfirmationDialog(() =>
{
deleteAllButton.Enabled.Value = false;
Task.Run(deleteAllModPresets).ContinueWith(t => Schedule(onAllModPresetsDeleted, t));
}));
}
},
undeleteButton = new SettingsButton
{
Text = MaintenanceSettingsStrings.RestoreAllRecentlyDeletedModPresets,
Action = () => Task.Run(undeleteModPresets).ContinueWith(t => Schedule(onModPresetsUndeleted, t))
}
});
}
private void deleteAllModPresets() =>
realm.Write(r =>
{
foreach (var preset in r.All<ModPreset>())
preset.DeletePending = true;
});
private void onAllModPresetsDeleted(Task deletionTask)
{
deleteAllButton.Enabled.Value = true;
if (deletionTask.IsCompletedSuccessfully)
notificationOverlay?.Post(new ProgressCompletionNotification { Text = "Deleted all mod presets!" });
else if (deletionTask.IsFaulted)
Logger.Error(deletionTask.Exception, "Failed to delete all mod presets");
}
private void undeleteModPresets() =>
realm.Write(r =>
{
foreach (var preset in r.All<ModPreset>().Where(preset => preset.DeletePending))
preset.DeletePending = false;
});
private void onModPresetsUndeleted(Task undeletionTask)
{
undeleteButton.Enabled.Value = true;
if (undeletionTask.IsCompletedSuccessfully)
notificationOverlay?.Post(new ProgressCompletionNotification { Text = "Restored all deleted mod presets!" });
else if (undeletionTask.IsFaulted)
Logger.Error(undeletionTask.Exception, "Failed to restore mod presets");
}
}
}

View File

@ -25,7 +25,8 @@ namespace osu.Game.Overlays.Settings.Sections
new BeatmapSettings(),
new SkinSettings(),
new CollectionsSettings(),
new ScoreSettings()
new ScoreSettings(),
new ModPresetSettings()
};
}
}