1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 23:22:55 +08:00

refactor logic to its own component and handle hit object to string conversion to its ruleset-specific composers

This commit is contained in:
Nathan Alo 2021-03-26 15:25:20 +08:00
parent 2bea69456e
commit b8b7eb4c4b
5 changed files with 76 additions and 1 deletions

View File

@ -119,5 +119,8 @@ namespace osu.Game.Rulesets.Mania.Edit
beatSnapGrid.SelectionTimeRange = null;
}
}
public override IEnumerable<string> ConvertSelectionToString()
=> EditorBeatmap.SelectedHitObjects.Cast<ManiaHitObject>().Select(h => $"{h.StartTime}|{h.Column}");
}
}

View File

@ -82,6 +82,9 @@ namespace osu.Game.Rulesets.Osu.Edit
protected override ComposeBlueprintContainer CreateBlueprintContainer()
=> new OsuBlueprintContainer(this);
public override IEnumerable<string> ConvertSelectionToString()
=> selectedHitObjects.Cast<OsuHitObject>().Select(h => (h.IndexInCurrentCombo + 1).ToString());
private DistanceSnapGrid distanceSnapGrid;
private Container distanceSnapGridContainer;

View File

@ -438,6 +438,8 @@ namespace osu.Game.Rulesets.Edit
/// </summary>
public abstract bool CursorInPlacementArea { get; }
public virtual IEnumerable<string> ConvertSelectionToString() => Array.Empty<string>();
#region IPositionSnapProvider
public abstract SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition);

View File

@ -6,6 +6,8 @@ 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.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Edit;
@ -14,16 +16,19 @@ using osu.Game.Skinning;
namespace osu.Game.Screens.Edit.Compose
{
public class ComposeScreen : EditorScreenWithTimeline
public class ComposeScreen : EditorScreenWithTimeline, IKeyBindingHandler<PlatformAction>
{
[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; }
private HitObjectComposer composer;
private SelectionHelper helper;
public ComposeScreen()
: base(EditorScreenMode.Compose)
{
Add(helper = new SelectionHelper());
}
private Ruleset ruleset;
@ -72,5 +77,21 @@ namespace osu.Game.Screens.Edit.Compose
// this is intentionally done in two stages to ensure things are in a loaded state before exposing the ruleset to skin sources.
return beatmapSkinProvider.WithChild(rulesetSkinProvider.WithChild(content));
}
public bool OnPressed(PlatformAction action)
{
switch (action.ActionType)
{
case PlatformActionType.Copy:
helper.CopySelectionToClipboard();
return false;
default:
return false;
};
}
public void OnReleased(PlatformAction action)
{
}
}
}

View File

@ -0,0 +1,46 @@
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
{
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();
};
builder.Append(editorBeatmap.SelectedHitObjects.First().StartTime.ToEditorFormattedString());
builder.Append($" ({string.Join(',', composer.ConvertSelectionToString())}){separator}");
return builder.ToString();
}
}
}