1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 06:35:05 +08:00

Restructure proof of concept

This commit is contained in:
Bartłomiej Dach 2021-09-05 17:26:09 +02:00
parent fe2520c599
commit c397cc2027
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
3 changed files with 47 additions and 18 deletions

View File

@ -0,0 +1,24 @@
// 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.Beatmaps;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Screens.Edit.Components.Menus
{
public class DifficultyMenuItem : StatefulMenuItem<bool>
{
public DifficultyMenuItem(BeatmapInfo beatmapInfo, bool selected, Action<BeatmapInfo> 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;
}
}

View File

@ -727,28 +727,24 @@ namespace osu.Game.Screens.Edit
return fileMenuItems; 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 (screen == null || screen != loader)
{ return;
if (loader != null)
loader.ValidForResume = true;
game?.PerformFromScreen(screen => loader.PushEditor(beatmapInfo);
{ }, new[] { typeof(EditorLoader) });
if (screen != null && screen == loader)
loader.PushEditor();
}, new[] { typeof(EditorLoader) });
};
}
return menuItem;
} }
public double SnapTime(double time, double? referenceTime) => editorBeatmap.SnapTime(time, referenceTime); public double SnapTime(double time, double? referenceTime) => editorBeatmap.SnapTime(time, referenceTime);

View File

@ -1,7 +1,10 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // 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.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
namespace osu.Game.Screens.Edit namespace osu.Game.Screens.Edit
@ -12,14 +15,20 @@ namespace osu.Game.Screens.Edit
/// </summary> /// </summary>
public class EditorLoader : ScreenWithBeatmapBackground public class EditorLoader : ScreenWithBeatmapBackground
{ {
[Resolved]
private BeatmapManager beatmapManager { get; set; }
public override void OnEntering(IScreen last) public override void OnEntering(IScreen last)
{ {
base.OnEntering(last); base.OnEntering(last);
PushEditor(); PushEditor();
} }
public void PushEditor() public void PushEditor([CanBeNull] BeatmapInfo beatmapInfo = null)
{ {
if (beatmapInfo != null)
Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmapInfo);
this.Push(new Editor(this)); this.Push(new Editor(this));
ValidForResume = false; ValidForResume = false;
} }