mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 03:25:11 +08:00
Merge pull request #16676 from peppy/fix-editor-custom-ruleset
Fix editor crashing on custom rulesets due to `ChangeHandler` not being supported
This commit is contained in:
commit
bdc9ca40f2
@ -82,6 +82,11 @@ namespace osu.Game.Screens.Edit.Compose
|
|||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
|
// May be null in the case of a ruleset that doesn't have editor support, see CreateMainContent().
|
||||||
|
if (composer == null)
|
||||||
|
return;
|
||||||
|
|
||||||
EditorBeatmap.SelectedHitObjects.BindCollectionChanged((_, __) => updateClipboardActionAvailability());
|
EditorBeatmap.SelectedHitObjects.BindCollectionChanged((_, __) => updateClipboardActionAvailability());
|
||||||
clipboard.BindValueChanged(_ => updateClipboardActionAvailability());
|
clipboard.BindValueChanged(_ => updateClipboardActionAvailability());
|
||||||
composer.OnLoadComplete += _ => updateClipboardActionAvailability();
|
composer.OnLoadComplete += _ => updateClipboardActionAvailability();
|
||||||
|
@ -28,6 +28,8 @@ using osu.Game.Graphics.UserInterface;
|
|||||||
using osu.Game.Input.Bindings;
|
using osu.Game.Input.Bindings;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
|
using osu.Game.Overlays.Notifications;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Edit;
|
using osu.Game.Rulesets.Edit;
|
||||||
using osu.Game.Screens.Edit.Components;
|
using osu.Game.Screens.Edit.Components;
|
||||||
using osu.Game.Screens.Edit.Components.Menus;
|
using osu.Game.Screens.Edit.Components.Menus;
|
||||||
@ -61,7 +63,16 @@ namespace osu.Game.Screens.Edit
|
|||||||
|
|
||||||
public override bool? AllowTrackAdjustments => false;
|
public override bool? AllowTrackAdjustments => false;
|
||||||
|
|
||||||
protected bool HasUnsavedChanges => lastSavedHash != changeHandler.CurrentStateHash;
|
protected bool HasUnsavedChanges
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!canSave)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return lastSavedHash != changeHandler?.CurrentStateHash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private BeatmapManager beatmapManager { get; set; }
|
private BeatmapManager beatmapManager { get; set; }
|
||||||
@ -72,10 +83,15 @@ namespace osu.Game.Screens.Edit
|
|||||||
[Resolved(canBeNull: true)]
|
[Resolved(canBeNull: true)]
|
||||||
private DialogOverlay dialogOverlay { get; set; }
|
private DialogOverlay dialogOverlay { get; set; }
|
||||||
|
|
||||||
|
[Resolved(canBeNull: true)]
|
||||||
|
private NotificationOverlay notifications { get; set; }
|
||||||
|
|
||||||
public IBindable<bool> SamplePlaybackDisabled => samplePlaybackDisabled;
|
public IBindable<bool> SamplePlaybackDisabled => samplePlaybackDisabled;
|
||||||
|
|
||||||
private readonly Bindable<bool> samplePlaybackDisabled = new Bindable<bool>();
|
private readonly Bindable<bool> samplePlaybackDisabled = new Bindable<bool>();
|
||||||
|
|
||||||
|
private bool canSave;
|
||||||
|
|
||||||
private bool exitConfirmed;
|
private bool exitConfirmed;
|
||||||
|
|
||||||
private string lastSavedHash;
|
private string lastSavedHash;
|
||||||
@ -92,6 +108,8 @@ namespace osu.Game.Screens.Edit
|
|||||||
|
|
||||||
private IBeatmap playableBeatmap;
|
private IBeatmap playableBeatmap;
|
||||||
private EditorBeatmap editorBeatmap;
|
private EditorBeatmap editorBeatmap;
|
||||||
|
|
||||||
|
[CanBeNull] // Should be non-null once it can support custom rulesets.
|
||||||
private EditorChangeHandler changeHandler;
|
private EditorChangeHandler changeHandler;
|
||||||
|
|
||||||
private EditorMenuBar menuBar;
|
private EditorMenuBar menuBar;
|
||||||
@ -172,8 +190,14 @@ namespace osu.Game.Screens.Edit
|
|||||||
|
|
||||||
AddInternal(editorBeatmap = new EditorBeatmap(playableBeatmap, loadableBeatmap.GetSkin(), loadableBeatmap.BeatmapInfo));
|
AddInternal(editorBeatmap = new EditorBeatmap(playableBeatmap, loadableBeatmap.GetSkin(), loadableBeatmap.BeatmapInfo));
|
||||||
dependencies.CacheAs(editorBeatmap);
|
dependencies.CacheAs(editorBeatmap);
|
||||||
changeHandler = new EditorChangeHandler(editorBeatmap);
|
|
||||||
dependencies.CacheAs<IEditorChangeHandler>(changeHandler);
|
canSave = editorBeatmap.BeatmapInfo.Ruleset.CreateInstance() is ILegacyRuleset;
|
||||||
|
|
||||||
|
if (canSave)
|
||||||
|
{
|
||||||
|
changeHandler = new EditorChangeHandler(editorBeatmap);
|
||||||
|
dependencies.CacheAs<IEditorChangeHandler>(changeHandler);
|
||||||
|
}
|
||||||
|
|
||||||
beatDivisor.Value = editorBeatmap.BeatmapInfo.BeatDivisor;
|
beatDivisor.Value = editorBeatmap.BeatmapInfo.BeatDivisor;
|
||||||
beatDivisor.BindValueChanged(divisor => editorBeatmap.BeatmapInfo.BeatDivisor = divisor.NewValue);
|
beatDivisor.BindValueChanged(divisor => editorBeatmap.BeatmapInfo.BeatDivisor = divisor.NewValue);
|
||||||
@ -311,8 +335,8 @@ namespace osu.Game.Screens.Edit
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
changeHandler.CanUndo.BindValueChanged(v => undoMenuItem.Action.Disabled = !v.NewValue, true);
|
changeHandler?.CanUndo.BindValueChanged(v => undoMenuItem.Action.Disabled = !v.NewValue, true);
|
||||||
changeHandler.CanRedo.BindValueChanged(v => redoMenuItem.Action.Disabled = !v.NewValue, true);
|
changeHandler?.CanRedo.BindValueChanged(v => redoMenuItem.Action.Disabled = !v.NewValue, true);
|
||||||
|
|
||||||
menuBar.Mode.ValueChanged += onModeChanged;
|
menuBar.Mode.ValueChanged += onModeChanged;
|
||||||
}
|
}
|
||||||
@ -353,6 +377,12 @@ namespace osu.Game.Screens.Edit
|
|||||||
|
|
||||||
protected void Save()
|
protected void Save()
|
||||||
{
|
{
|
||||||
|
if (!canSave)
|
||||||
|
{
|
||||||
|
notifications?.Post(new SimpleErrorNotification { Text = "Saving is not supported for this ruleset yet, sorry!" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// no longer new after first user-triggered save.
|
// no longer new after first user-triggered save.
|
||||||
isNewBeatmap = false;
|
isNewBeatmap = false;
|
||||||
|
|
||||||
@ -648,9 +678,9 @@ namespace osu.Game.Screens.Edit
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
protected void Undo() => changeHandler.RestoreState(-1);
|
protected void Undo() => changeHandler?.RestoreState(-1);
|
||||||
|
|
||||||
protected void Redo() => changeHandler.RestoreState(1);
|
protected void Redo() => changeHandler?.RestoreState(1);
|
||||||
|
|
||||||
private void resetTrack(bool seekToStart = false)
|
private void resetTrack(bool seekToStart = false)
|
||||||
{
|
{
|
||||||
@ -761,7 +791,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
|
|
||||||
private void updateLastSavedHash()
|
private void updateLastSavedHash()
|
||||||
{
|
{
|
||||||
lastSavedHash = changeHandler.CurrentStateHash;
|
lastSavedHash = changeHandler?.CurrentStateHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<MenuItem> createFileMenuItems()
|
private List<MenuItem> createFileMenuItems()
|
||||||
|
Loading…
Reference in New Issue
Block a user