mirror of
https://github.com/ppy/osu.git
synced 2025-01-30 23:23:18 +08:00
Move clipboard operation implementation down to current screen
This commit is contained in:
parent
baa5285b59
commit
286754f6f7
@ -13,6 +13,7 @@ using osu.Framework.Input.Events;
|
|||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Extensions;
|
using osu.Game.Extensions;
|
||||||
|
using osu.Game.IO.Serialization;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Edit;
|
using osu.Game.Rulesets.Edit;
|
||||||
using osu.Game.Screens.Edit.Compose.Components.Timeline;
|
using osu.Game.Screens.Edit.Compose.Components.Timeline;
|
||||||
@ -21,15 +22,15 @@ namespace osu.Game.Screens.Edit.Compose
|
|||||||
{
|
{
|
||||||
public class ComposeScreen : EditorScreenWithTimeline, IKeyBindingHandler<PlatformAction>
|
public class ComposeScreen : EditorScreenWithTimeline, IKeyBindingHandler<PlatformAction>
|
||||||
{
|
{
|
||||||
[Resolved]
|
|
||||||
private IBindable<WorkingBeatmap> beatmap { get; set; }
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private GameHost host { get; set; }
|
private GameHost host { get; set; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private EditorClock clock { get; set; }
|
private EditorClock clock { get; set; }
|
||||||
|
|
||||||
|
[Resolved(Name = nameof(Editor.Clipboard))]
|
||||||
|
private Bindable<string> clipboard { get; set; }
|
||||||
|
|
||||||
private HitObjectComposer composer;
|
private HitObjectComposer composer;
|
||||||
|
|
||||||
public ComposeScreen()
|
public ComposeScreen()
|
||||||
@ -104,5 +105,53 @@ namespace osu.Game.Screens.Edit.Compose
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Clipboard operations
|
||||||
|
|
||||||
|
public override void Cut()
|
||||||
|
{
|
||||||
|
base.Cut();
|
||||||
|
|
||||||
|
Copy();
|
||||||
|
EditorBeatmap.RemoveRange(EditorBeatmap.SelectedHitObjects.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Copy()
|
||||||
|
{
|
||||||
|
base.Copy();
|
||||||
|
|
||||||
|
if (EditorBeatmap.SelectedHitObjects.Count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
clipboard.Value = new ClipboardContent(EditorBeatmap).Serialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Paste()
|
||||||
|
{
|
||||||
|
base.Paste();
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(clipboard.Value))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var objects = clipboard.Value.Deserialize<ClipboardContent>().HitObjects;
|
||||||
|
|
||||||
|
Debug.Assert(objects.Any());
|
||||||
|
|
||||||
|
double timeOffset = clock.CurrentTime - objects.Min(o => o.StartTime);
|
||||||
|
|
||||||
|
foreach (var h in objects)
|
||||||
|
h.StartTime += timeOffset;
|
||||||
|
|
||||||
|
EditorBeatmap.BeginChange();
|
||||||
|
|
||||||
|
EditorBeatmap.SelectedHitObjects.Clear();
|
||||||
|
|
||||||
|
EditorBeatmap.AddRange(objects);
|
||||||
|
EditorBeatmap.SelectedHitObjects.AddRange(objects);
|
||||||
|
|
||||||
|
EditorBeatmap.EndChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework;
|
using osu.Framework;
|
||||||
@ -24,7 +23,6 @@ using osu.Game.Graphics;
|
|||||||
using osu.Game.Graphics.Cursor;
|
using osu.Game.Graphics.Cursor;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Input.Bindings;
|
using osu.Game.Input.Bindings;
|
||||||
using osu.Game.IO.Serialization;
|
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Rulesets.Edit;
|
using osu.Game.Rulesets.Edit;
|
||||||
@ -105,6 +103,9 @@ namespace osu.Game.Screens.Edit
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private MusicController music { get; set; }
|
private MusicController music { get; set; }
|
||||||
|
|
||||||
|
[Cached(Name = nameof(Clipboard))]
|
||||||
|
public readonly Bindable<string> Clipboard = new Bindable<string>();
|
||||||
|
|
||||||
public Editor(EditorLoader loader = null)
|
public Editor(EditorLoader loader = null)
|
||||||
{
|
{
|
||||||
this.loader = loader;
|
this.loader = loader;
|
||||||
@ -307,7 +308,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
copyMenuItem.Action.Disabled = !hasObjects;
|
copyMenuItem.Action.Disabled = !hasObjects;
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
clipboard.BindValueChanged(content => pasteMenuItem.Action.Disabled = string.IsNullOrEmpty(content.NewValue));
|
Clipboard.BindValueChanged(content => pasteMenuItem.Action.Disabled = string.IsNullOrEmpty(content.NewValue));
|
||||||
|
|
||||||
menuBar.Mode.ValueChanged += onModeChanged;
|
menuBar.Mode.ValueChanged += onModeChanged;
|
||||||
}
|
}
|
||||||
@ -324,7 +325,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
public void RestoreState([NotNull] EditorState state) => Schedule(() =>
|
public void RestoreState([NotNull] EditorState state) => Schedule(() =>
|
||||||
{
|
{
|
||||||
clock.Seek(state.Time);
|
clock.Seek(state.Time);
|
||||||
clipboard.Value = state.ClipboardContent;
|
Clipboard.Value = state.ClipboardContent;
|
||||||
});
|
});
|
||||||
|
|
||||||
protected void Save()
|
protected void Save()
|
||||||
@ -561,45 +562,11 @@ namespace osu.Game.Screens.Edit
|
|||||||
this.Exit();
|
this.Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly Bindable<string> clipboard = new Bindable<string>();
|
protected void Cut() => currentScreen?.Cut();
|
||||||
|
|
||||||
protected void Cut()
|
protected void Copy() => currentScreen?.Copy();
|
||||||
{
|
|
||||||
Copy();
|
|
||||||
editorBeatmap.RemoveRange(editorBeatmap.SelectedHitObjects.ToArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void Copy()
|
protected void Paste() => currentScreen?.Paste();
|
||||||
{
|
|
||||||
if (editorBeatmap.SelectedHitObjects.Count == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
clipboard.Value = new ClipboardContent(editorBeatmap).Serialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void Paste()
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(clipboard.Value))
|
|
||||||
return;
|
|
||||||
|
|
||||||
var objects = clipboard.Value.Deserialize<ClipboardContent>().HitObjects;
|
|
||||||
|
|
||||||
Debug.Assert(objects.Any());
|
|
||||||
|
|
||||||
double timeOffset = clock.CurrentTime - objects.Min(o => o.StartTime);
|
|
||||||
|
|
||||||
foreach (var h in objects)
|
|
||||||
h.StartTime += timeOffset;
|
|
||||||
|
|
||||||
editorBeatmap.BeginChange();
|
|
||||||
|
|
||||||
editorBeatmap.SelectedHitObjects.Clear();
|
|
||||||
|
|
||||||
editorBeatmap.AddRange(objects);
|
|
||||||
editorBeatmap.SelectedHitObjects.AddRange(objects);
|
|
||||||
|
|
||||||
editorBeatmap.EndChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void Undo() => changeHandler.RestoreState(-1);
|
protected void Undo() => changeHandler.RestoreState(-1);
|
||||||
|
|
||||||
@ -757,7 +724,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
protected void SwitchToDifficulty(BeatmapInfo nextBeatmap) => loader?.ScheduleDifficultySwitch(nextBeatmap, new EditorState
|
protected void SwitchToDifficulty(BeatmapInfo nextBeatmap) => loader?.ScheduleDifficultySwitch(nextBeatmap, new EditorState
|
||||||
{
|
{
|
||||||
Time = clock.CurrentTimeAccurate,
|
Time = clock.CurrentTimeAccurate,
|
||||||
ClipboardContent = editorBeatmap.BeatmapInfo.RulesetID == nextBeatmap.RulesetID ? clipboard.Value : string.Empty
|
ClipboardContent = editorBeatmap.BeatmapInfo.RulesetID == nextBeatmap.RulesetID ? Clipboard.Value : string.Empty
|
||||||
});
|
});
|
||||||
|
|
||||||
private void cancelExit()
|
private void cancelExit()
|
||||||
|
@ -49,5 +49,30 @@ namespace osu.Game.Screens.Edit
|
|||||||
this.ScaleTo(0.98f, 200, Easing.OutQuint)
|
this.ScaleTo(0.98f, 200, Easing.OutQuint)
|
||||||
.FadeOut(200, Easing.OutQuint);
|
.FadeOut(200, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Clipboard operations
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Performs a "cut to clipboard" operation appropriate for the given screen.
|
||||||
|
/// </summary>
|
||||||
|
public virtual void Cut()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Performs a "copy to clipboard" operation appropriate for the given screen.
|
||||||
|
/// </summary>
|
||||||
|
public virtual void Copy()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Performs a "paste from clipboard" operation appropriate for the given screen.
|
||||||
|
/// </summary>
|
||||||
|
public virtual void Paste()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user