Attempt full editor reload on key count change

This commit is contained in:
Bartłomiej Dach 2024-06-11 11:31:49 +02:00
parent 3afe98612c
commit da53a11d3c
No known key found for this signature in database
4 changed files with 82 additions and 0 deletions

View File

@ -110,9 +110,31 @@ private void load()
tickRateSlider.Current.BindValueChanged(_ => updateValues());
}
private bool updatingKeyCount;
private void updateKeyCount(ValueChangedEvent<float> keyCount)
{
if (updatingKeyCount) return;
updatingKeyCount = true;
updateValues();
editor.Reload().ContinueWith(t =>
{
if (!t.GetResultSafely())
{
Schedule(() =>
{
changeHandler.RestoreState(-1);
Beatmap.Difficulty.CircleSize = keyCountSlider.Current.Value = keyCount.OldValue;
updatingKeyCount = false;
});
}
else
{
updatingKeyCount = false;
}
});
}
private void updateValues()

View File

@ -49,6 +49,11 @@ public static class EditorDialogsStrings
/// </summary>
public static LocalisableString ContinueEditing => new TranslatableString(getKey(@"continue_editing"), @"Oops, continue editing");
/// <summary>
/// "The editor must be reloaded to apply this change. The beatmap will be saved."
/// </summary>
public static LocalisableString EditorReloadDialogHeader => new TranslatableString(getKey(@"editor_reload_dialog_header"), @"The editor must be reloaded to apply this change. The beatmap will be saved.");
private static string getKey(string key) => $@"{prefix}:{key}";
}
}

View File

@ -1231,6 +1231,27 @@ private void cancelExit()
loader?.CancelPendingDifficultySwitch();
}
public Task<bool> Reload()
{
var tcs = new TaskCompletionSource<bool>();
dialogOverlay.Push(new ReloadEditorDialog(
reload: () =>
{
bool reloadedSuccessfully = attemptMutationOperation(() =>
{
if (!Save())
return false;
SwitchToDifficulty(editorBeatmap.BeatmapInfo);
return true;
});
tcs.SetResult(reloadedSuccessfully);
},
cancel: () => tcs.SetResult(false)));
return tcs.Task;
}
public void HandleTimestamp(string timestamp)
{
if (!EditorTimestampParser.TryParse(timestamp, out var timeSpan, out string selection))

View File

@ -0,0 +1,34 @@
// 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;
using osu.Framework.Graphics.Sprites;
using osu.Game.Overlays.Dialog;
using osu.Game.Localisation;
namespace osu.Game.Screens.Edit
{
public partial class ReloadEditorDialog : PopupDialog
{
public ReloadEditorDialog(Action reload, Action cancel)
{
HeaderText = EditorDialogsStrings.EditorReloadDialogHeader;
Icon = FontAwesome.Solid.Sync;
Buttons = new PopupDialogButton[]
{
new PopupDialogOkButton
{
Text = DialogStrings.Confirm,
Action = reload
},
new PopupDialogCancelButton
{
Text = DialogStrings.Cancel,
Action = cancel
}
};
}
}
}