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:
parent
9a02f3868c
commit
cdb779f764
@ -2,13 +2,17 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Extensions;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Screens.Edit.Compose.Components.Timeline;
|
||||
@ -21,14 +25,17 @@ namespace osu.Game.Screens.Edit.Compose
|
||||
[Resolved]
|
||||
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()
|
||||
: base(EditorScreenMode.Compose)
|
||||
{
|
||||
Add(helper = new SelectionHelper());
|
||||
}
|
||||
|
||||
private Ruleset ruleset;
|
||||
@ -78,18 +85,26 @@ namespace osu.Game.Screens.Edit.Compose
|
||||
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)
|
||||
{
|
||||
switch (action.ActionType)
|
||||
{
|
||||
case PlatformActionType.Copy:
|
||||
helper.CopySelectionToClipboard();
|
||||
return false;
|
||||
if (action.ActionType == PlatformActionType.Copy)
|
||||
host.GetClipboard().SetText(formatSelectionAsString());
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnReleased(PlatformAction action)
|
||||
{
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user