From 5e31e890ae8779a880f214c66aa64defacdae8a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 10 Nov 2021 12:36:23 +0100 Subject: [PATCH] Extract class for clipboard contents for DI purposes --- .../Editor/TestSceneManiaComposeScreen.cs | 5 ++--- .../Visual/Editing/TestSceneComposeScreen.cs | 5 ++--- osu.Game/Screens/Edit/Compose/ComposeScreen.cs | 7 ++++++- osu.Game/Screens/Edit/Editor.cs | 8 ++++---- osu.Game/Screens/Edit/EditorClipboard.cs | 15 +++++++++++++++ 5 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 osu.Game/Screens/Edit/EditorClipboard.cs diff --git a/osu.Game.Rulesets.Mania.Tests/Editor/TestSceneManiaComposeScreen.cs b/osu.Game.Rulesets.Mania.Tests/Editor/TestSceneManiaComposeScreen.cs index 60a5051fb5..24d2a786a0 100644 --- a/osu.Game.Rulesets.Mania.Tests/Editor/TestSceneManiaComposeScreen.cs +++ b/osu.Game.Rulesets.Mania.Tests/Editor/TestSceneManiaComposeScreen.cs @@ -5,7 +5,6 @@ using System; using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; -using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Testing; @@ -23,8 +22,8 @@ namespace osu.Game.Rulesets.Mania.Tests.Editor [Resolved] private SkinManager skins { get; set; } - [Cached(Name = nameof(Screens.Edit.Editor.Clipboard))] - private Bindable clipboard = new Bindable(); + [Cached] + private EditorClipboard clipboard = new EditorClipboard(); [SetUpSteps] public void SetUpSteps() diff --git a/osu.Game.Tests/Visual/Editing/TestSceneComposeScreen.cs b/osu.Game.Tests/Visual/Editing/TestSceneComposeScreen.cs index 8796088ec6..9b8567e853 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneComposeScreen.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneComposeScreen.cs @@ -3,7 +3,6 @@ using NUnit.Framework; using osu.Framework.Allocation; -using osu.Framework.Bindables; using osu.Framework.Graphics.Containers; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Osu; @@ -27,8 +26,8 @@ namespace osu.Game.Tests.Visual.Editing } }); - [Cached(Name = nameof(Editor.Clipboard))] - private Bindable clipboard = new Bindable(); + [Cached] + private EditorClipboard clipboard = new EditorClipboard(); [BackgroundDependencyLoader] private void load() diff --git a/osu.Game/Screens/Edit/Compose/ComposeScreen.cs b/osu.Game/Screens/Edit/Compose/ComposeScreen.cs index b0a85f33d9..d78dce5b60 100644 --- a/osu.Game/Screens/Edit/Compose/ComposeScreen.cs +++ b/osu.Game/Screens/Edit/Compose/ComposeScreen.cs @@ -28,7 +28,6 @@ namespace osu.Game.Screens.Edit.Compose [Resolved] private EditorClock clock { get; set; } - [Resolved(Name = nameof(Editor.Clipboard))] private Bindable clipboard { get; set; } private HitObjectComposer composer; @@ -77,6 +76,12 @@ namespace osu.Game.Screens.Edit.Compose return new EditorSkinProvidingContainer(EditorBeatmap).WithChild(content); } + [BackgroundDependencyLoader] + private void load(EditorClipboard clipboard) + { + this.clipboard = clipboard.Content.GetBoundCopy(); + } + protected override void LoadComplete() { base.LoadComplete(); diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index b8a1dda508..de265ad94b 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -103,8 +103,8 @@ namespace osu.Game.Screens.Edit [Resolved] private MusicController music { get; set; } - [Cached(Name = nameof(Clipboard))] - public readonly Bindable Clipboard = new Bindable(); + [Cached] + public readonly EditorClipboard Clipboard = new EditorClipboard(); public Editor(EditorLoader loader = null) { @@ -317,7 +317,7 @@ namespace osu.Game.Screens.Edit public void RestoreState([NotNull] EditorState state) => Schedule(() => { clock.Seek(state.Time); - Clipboard.Value = state.ClipboardContent; + Clipboard.Content.Value = state.ClipboardContent; }); protected void Save() @@ -743,7 +743,7 @@ namespace osu.Game.Screens.Edit protected void SwitchToDifficulty(BeatmapInfo nextBeatmap) => loader?.ScheduleDifficultySwitch(nextBeatmap, new EditorState { Time = clock.CurrentTimeAccurate, - ClipboardContent = editorBeatmap.BeatmapInfo.RulesetID == nextBeatmap.RulesetID ? Clipboard.Value : string.Empty + ClipboardContent = editorBeatmap.BeatmapInfo.RulesetID == nextBeatmap.RulesetID ? Clipboard.Content.Value : string.Empty }); private void cancelExit() diff --git a/osu.Game/Screens/Edit/EditorClipboard.cs b/osu.Game/Screens/Edit/EditorClipboard.cs new file mode 100644 index 0000000000..f6f0c09e00 --- /dev/null +++ b/osu.Game/Screens/Edit/EditorClipboard.cs @@ -0,0 +1,15 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Bindables; + +namespace osu.Game.Screens.Edit +{ + /// + /// Wraps the contents of the editor clipboard. + /// + public class EditorClipboard + { + public Bindable Content { get; } = new Bindable(); + } +}