1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 10:42:54 +08:00

move copy logic inside ComposeScreen

This commit is contained in:
Nathan Alo 2021-03-29 17:30:23 +08:00
parent 9a02f3868c
commit cdb779f764
2 changed files with 26 additions and 62 deletions

View File

@ -2,13 +2,17 @@
// 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 System.Diagnostics; using System.Diagnostics;
using System.Linq;
using System.Text;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Platform;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Extensions;
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,14 +25,17 @@ namespace osu.Game.Screens.Edit.Compose
[Resolved] [Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; } private IBindable<WorkingBeatmap> beatmap { get; set; }
private HitObjectComposer composer; [Resolved]
private GameHost host { get; set; }
private readonly SelectionHelper helper; [Resolved]
private EditorClock clock { get; set; }
private HitObjectComposer composer;
public ComposeScreen() public ComposeScreen()
: base(EditorScreenMode.Compose) : base(EditorScreenMode.Compose)
{ {
Add(helper = new SelectionHelper());
} }
private Ruleset ruleset; private Ruleset ruleset;
@ -78,17 +85,25 @@ namespace osu.Game.Screens.Edit.Compose
return beatmapSkinProvider.WithChild(rulesetSkinProvider.WithChild(content)); return beatmapSkinProvider.WithChild(rulesetSkinProvider.WithChild(content));
} }
private string formatSelectionAsString()
{
var builder = new StringBuilder();
builder.Append(EditorBeatmap.SelectedHitObjects.OrderBy(h => h.StartTime).FirstOrDefault()?.StartTime.ToEditorFormattedString() ?? clock.CurrentTime.ToEditorFormattedString());
if (EditorBeatmap.SelectedHitObjects.Any() && composer != null)
builder.Append($" ({composer.ConvertSelectionToString()})");
builder.Append(" - ");
return builder.ToString();
}
public bool OnPressed(PlatformAction action) public bool OnPressed(PlatformAction action)
{ {
switch (action.ActionType) if (action.ActionType == PlatformActionType.Copy)
{ host.GetClipboard().SetText(formatSelectionAsString());
case PlatformActionType.Copy:
helper.CopySelectionToClipboard();
return false;
default: return false;
return false;
}
} }
public void OnReleased(PlatformAction action) public void OnReleased(PlatformAction action)

View File

@ -1,51 +0,0 @@
// 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.Linq;
using System.Text;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Platform;
using osu.Game.Extensions;
using osu.Game.Rulesets.Edit;
namespace osu.Game.Screens.Edit.Compose
{
public class SelectionHelper : Component
{
[Resolved]
private GameHost host { get; set; }
[Resolved]
private EditorClock clock { get; set; }
[Resolved]
private EditorBeatmap editorBeatmap { get; set; }
[Resolved(CanBeNull = true)]
private HitObjectComposer composer { get; set; }
public void CopySelectionToClipboard()
{
host.GetClipboard().SetText(formatSelectionAsString());
}
private string formatSelectionAsString()
{
const string separator = " - ";
var builder = new StringBuilder();
if (!editorBeatmap.SelectedHitObjects.Any())
{
builder.Append($"{clock.CurrentTime.ToEditorFormattedString()}{separator}");
return builder.ToString();
}
string hitObjects = composer != null ? string.Join(',', composer.ConvertSelectionToString()) : string.Empty;
builder.Append(editorBeatmap.SelectedHitObjects.Min(h => h.StartTime).ToEditorFormattedString());
builder.Append($" ({hitObjects}){separator}");
return builder.ToString();
}
}
}