diff --git a/osu.Game/Screens/Edit/Components/Menus/DifficultyMenuItem.cs b/osu.Game/Screens/Edit/Components/Menus/DifficultyMenuItem.cs new file mode 100644 index 0000000000..74b18f63ab --- /dev/null +++ b/osu.Game/Screens/Edit/Components/Menus/DifficultyMenuItem.cs @@ -0,0 +1,24 @@ +// Copyright (c) ppy Pty Ltd . 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.Beatmaps; +using osu.Game.Graphics.UserInterface; + +namespace osu.Game.Screens.Edit.Components.Menus +{ + public class DifficultyMenuItem : StatefulMenuItem + { + public DifficultyMenuItem(BeatmapInfo beatmapInfo, bool selected, Action difficultyChangeFunc) + : base(beatmapInfo.Version ?? "(unnamed)", null) + { + State.Value = selected; + + if (!selected) + Action.Value = () => difficultyChangeFunc.Invoke(beatmapInfo); + } + + public override IconUsage? GetIconForState(bool state) => state ? (IconUsage?)FontAwesome.Solid.Check : null; + } +} diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index bc6d26135b..f30f92b602 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -727,28 +727,24 @@ namespace osu.Game.Screens.Edit return fileMenuItems; } - private ToggleMenuItem createDifficultyMenuItem(BeatmapInfo b) + private DifficultyMenuItem createDifficultyMenuItem(BeatmapInfo beatmapInfo) { - bool isCurrentDifficulty = playableBeatmap.BeatmapInfo.Equals(b); + bool isCurrentDifficulty = playableBeatmap.BeatmapInfo.Equals(beatmapInfo); + return new DifficultyMenuItem(beatmapInfo, isCurrentDifficulty, switchToDifficulty); + } - var menuItem = new ToggleMenuItem(b.Version ?? "(unnamed)") { State = { Value = isCurrentDifficulty }, }; + private void switchToDifficulty(BeatmapInfo beatmapInfo) + { + if (loader != null) + loader.ValidForResume = true; - if (!isCurrentDifficulty) + game?.PerformFromScreen(screen => { - menuItem.Action.Value = () => - { - if (loader != null) - loader.ValidForResume = true; + if (screen == null || screen != loader) + return; - game?.PerformFromScreen(screen => - { - if (screen != null && screen == loader) - loader.PushEditor(); - }, new[] { typeof(EditorLoader) }); - }; - } - - return menuItem; + loader.PushEditor(beatmapInfo); + }, new[] { typeof(EditorLoader) }); } public double SnapTime(double time, double? referenceTime) => editorBeatmap.SnapTime(time, referenceTime); diff --git a/osu.Game/Screens/Edit/EditorLoader.cs b/osu.Game/Screens/Edit/EditorLoader.cs index 5c8d0f5b16..45f2d1bffd 100644 --- a/osu.Game/Screens/Edit/EditorLoader.cs +++ b/osu.Game/Screens/Edit/EditorLoader.cs @@ -1,7 +1,10 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using JetBrains.Annotations; +using osu.Framework.Allocation; using osu.Framework.Screens; +using osu.Game.Beatmaps; using osu.Game.Screens.Play; namespace osu.Game.Screens.Edit @@ -12,14 +15,20 @@ namespace osu.Game.Screens.Edit /// public class EditorLoader : ScreenWithBeatmapBackground { + [Resolved] + private BeatmapManager beatmapManager { get; set; } + public override void OnEntering(IScreen last) { base.OnEntering(last); PushEditor(); } - public void PushEditor() + public void PushEditor([CanBeNull] BeatmapInfo beatmapInfo = null) { + if (beatmapInfo != null) + Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmapInfo); + this.Push(new Editor(this)); ValidForResume = false; }