From 8046b5a818f8d2a69d7199e6cff6fa2a1db024d8 Mon Sep 17 00:00:00 2001 From: Nathan Alo Date: Wed, 17 Mar 2021 17:35:49 +0800 Subject: [PATCH 01/13] set text to platform clipboard on copy --- osu.Game/Screens/Edit/Editor.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 0ba202b082..88383bd3ed 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -21,6 +21,7 @@ using osu.Framework.Screens; using osu.Framework.Timing; using osu.Game.Beatmaps; using osu.Game.Configuration; +using osu.Game.Extensions; using osu.Game.Graphics; using osu.Game.Graphics.Cursor; using osu.Game.Graphics.UserInterface; @@ -29,6 +30,7 @@ using osu.Game.IO.Serialization; using osu.Game.Online.API; using osu.Game.Overlays; using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Objects.Types; using osu.Game.Screens.Edit.Components; using osu.Game.Screens.Edit.Components.Menus; using osu.Game.Screens.Edit.Components.Timelines.Summary; @@ -60,6 +62,9 @@ namespace osu.Game.Screens.Edit protected bool HasUnsavedChanges => lastSavedHash != changeHandler.CurrentStateHash; + [Resolved] + private GameHost host { get; set; } + [Resolved] private BeatmapManager beatmapManager { get; set; } @@ -104,7 +109,7 @@ namespace osu.Game.Screens.Edit private MusicController music { get; set; } [BackgroundDependencyLoader] - private void load(OsuColour colours, GameHost host, OsuConfigManager config) + private void load(OsuColour colours, OsuConfigManager config) { if (Beatmap.Value is DummyWorkingBeatmap) { @@ -542,8 +547,12 @@ namespace osu.Game.Screens.Edit protected void Copy() { if (editorBeatmap.SelectedHitObjects.Count == 0) + { + host.GetClipboard()?.SetText($"{clock.CurrentTime.ToEditorFormattedString()} - "); return; + } + host.GetClipboard()?.SetText($"{editorBeatmap.SelectedHitObjects.FirstOrDefault().StartTime.ToEditorFormattedString()} ({string.Join(',', editorBeatmap.SelectedHitObjects.Select(h => ((h as IHasComboInformation)?.IndexInCurrentCombo + 1 ?? 0).ToString()))}) - "); clipboard.Value = new ClipboardContent(editorBeatmap).Serialize(); } From 133ff085a53711229834c0c3b3944f1c29d91b73 Mon Sep 17 00:00:00 2001 From: Nathan Alo Date: Wed, 17 Mar 2021 18:06:40 +0800 Subject: [PATCH 02/13] refactor code --- osu.Game/Screens/Edit/Editor.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 88383bd3ed..fdb31a8b8c 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Text; using osu.Framework; using osu.Framework.Allocation; using osu.Framework.Bindables; @@ -546,14 +547,24 @@ namespace osu.Game.Screens.Edit protected void Copy() { + var builder = new StringBuilder(); + const string suffix = " - "; + if (editorBeatmap.SelectedHitObjects.Count == 0) { - host.GetClipboard()?.SetText($"{clock.CurrentTime.ToEditorFormattedString()} - "); - return; + builder.Append(clock.CurrentTime.ToEditorFormattedString()); + } + else + { + var orderedHitObjects = editorBeatmap.SelectedHitObjects.OrderBy(h => h.StartTime); + builder.Append(orderedHitObjects.FirstOrDefault().StartTime.ToEditorFormattedString()); + builder.Append($" ({string.Join(',', orderedHitObjects.Cast().Select(h => h.IndexInCurrentCombo + 1))})"); + + clipboard.Value = new ClipboardContent(editorBeatmap).Serialize(); } - host.GetClipboard()?.SetText($"{editorBeatmap.SelectedHitObjects.FirstOrDefault().StartTime.ToEditorFormattedString()} ({string.Join(',', editorBeatmap.SelectedHitObjects.Select(h => ((h as IHasComboInformation)?.IndexInCurrentCombo + 1 ?? 0).ToString()))}) - "); - clipboard.Value = new ClipboardContent(editorBeatmap).Serialize(); + builder.Append(suffix); + host.GetClipboard()?.SetText(builder.ToString()); } protected void Paste() From 51e0304c54a604bab6d6c8007c59ec755b115b2d Mon Sep 17 00:00:00 2001 From: Nathan Alo Date: Wed, 17 Mar 2021 18:31:09 +0800 Subject: [PATCH 03/13] properly format strings per ruleset --- osu.Game.Rulesets.Catch/Objects/CatchHitObject.cs | 2 ++ osu.Game.Rulesets.Mania/Objects/ManiaHitObject.cs | 2 ++ osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs | 2 ++ osu.Game/Rulesets/Objects/HitObject.cs | 2 ++ osu.Game/Screens/Edit/Editor.cs | 2 +- 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Catch/Objects/CatchHitObject.cs b/osu.Game.Rulesets.Catch/Objects/CatchHitObject.cs index ae45182960..631b50d686 100644 --- a/osu.Game.Rulesets.Catch/Objects/CatchHitObject.cs +++ b/osu.Game.Rulesets.Catch/Objects/CatchHitObject.cs @@ -120,5 +120,7 @@ namespace osu.Game.Rulesets.Catch.Objects } protected override HitWindows CreateHitWindows() => HitWindows.Empty; + + public override string ToEditorString() => (IndexInCurrentCombo + 1).ToString(); } } diff --git a/osu.Game.Rulesets.Mania/Objects/ManiaHitObject.cs b/osu.Game.Rulesets.Mania/Objects/ManiaHitObject.cs index 27bf50493d..c43d223335 100644 --- a/osu.Game.Rulesets.Mania/Objects/ManiaHitObject.cs +++ b/osu.Game.Rulesets.Mania/Objects/ManiaHitObject.cs @@ -22,6 +22,8 @@ namespace osu.Game.Rulesets.Mania.Objects protected override HitWindows CreateHitWindows() => new ManiaHitWindows(); + public override string ToEditorString() => $"{StartTime}|{Column}"; + #region LegacyBeatmapEncoder float IHasXPosition.X => Column; diff --git a/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs b/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs index 22b64af3df..e784d13084 100644 --- a/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs +++ b/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs @@ -130,5 +130,7 @@ namespace osu.Game.Rulesets.Osu.Objects } protected override HitWindows CreateHitWindows() => new OsuHitWindows(); + + public override string ToEditorString() => (IndexInCurrentCombo + 1).ToString(); } } diff --git a/osu.Game/Rulesets/Objects/HitObject.cs b/osu.Game/Rulesets/Objects/HitObject.cs index 826d411822..fa7b2811cc 100644 --- a/osu.Game/Rulesets/Objects/HitObject.cs +++ b/osu.Game/Rulesets/Objects/HitObject.cs @@ -168,6 +168,8 @@ namespace osu.Game.Rulesets.Objects /// [NotNull] protected virtual HitWindows CreateHitWindows() => new HitWindows(); + + public virtual string ToEditorString() => string.Empty; } public static class HitObjectExtensions diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index fdb31a8b8c..a6e84d59a7 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -558,7 +558,7 @@ namespace osu.Game.Screens.Edit { var orderedHitObjects = editorBeatmap.SelectedHitObjects.OrderBy(h => h.StartTime); builder.Append(orderedHitObjects.FirstOrDefault().StartTime.ToEditorFormattedString()); - builder.Append($" ({string.Join(',', orderedHitObjects.Cast().Select(h => h.IndexInCurrentCombo + 1))})"); + builder.Append($" ({string.Join(',', orderedHitObjects.Select(h => h.ToEditorString()))})"); clipboard.Value = new ClipboardContent(editorBeatmap).Serialize(); } From 2bea69456e8bfbcdf780bd6e8adab5002913f3e3 Mon Sep 17 00:00:00 2001 From: Nathan Alo Date: Fri, 26 Mar 2021 15:24:33 +0800 Subject: [PATCH 04/13] remove implementations --- .../Objects/CatchHitObject.cs | 2 -- .../Objects/ManiaHitObject.cs | 2 -- osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs | 2 -- osu.Game/Rulesets/Objects/HitObject.cs | 2 -- osu.Game/Screens/Edit/Editor.cs | 23 +++---------------- 5 files changed, 3 insertions(+), 28 deletions(-) diff --git a/osu.Game.Rulesets.Catch/Objects/CatchHitObject.cs b/osu.Game.Rulesets.Catch/Objects/CatchHitObject.cs index 631b50d686..ae45182960 100644 --- a/osu.Game.Rulesets.Catch/Objects/CatchHitObject.cs +++ b/osu.Game.Rulesets.Catch/Objects/CatchHitObject.cs @@ -120,7 +120,5 @@ namespace osu.Game.Rulesets.Catch.Objects } protected override HitWindows CreateHitWindows() => HitWindows.Empty; - - public override string ToEditorString() => (IndexInCurrentCombo + 1).ToString(); } } diff --git a/osu.Game.Rulesets.Mania/Objects/ManiaHitObject.cs b/osu.Game.Rulesets.Mania/Objects/ManiaHitObject.cs index c43d223335..27bf50493d 100644 --- a/osu.Game.Rulesets.Mania/Objects/ManiaHitObject.cs +++ b/osu.Game.Rulesets.Mania/Objects/ManiaHitObject.cs @@ -22,8 +22,6 @@ namespace osu.Game.Rulesets.Mania.Objects protected override HitWindows CreateHitWindows() => new ManiaHitWindows(); - public override string ToEditorString() => $"{StartTime}|{Column}"; - #region LegacyBeatmapEncoder float IHasXPosition.X => Column; diff --git a/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs b/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs index e784d13084..22b64af3df 100644 --- a/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs +++ b/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs @@ -130,7 +130,5 @@ namespace osu.Game.Rulesets.Osu.Objects } protected override HitWindows CreateHitWindows() => new OsuHitWindows(); - - public override string ToEditorString() => (IndexInCurrentCombo + 1).ToString(); } } diff --git a/osu.Game/Rulesets/Objects/HitObject.cs b/osu.Game/Rulesets/Objects/HitObject.cs index fa7b2811cc..826d411822 100644 --- a/osu.Game/Rulesets/Objects/HitObject.cs +++ b/osu.Game/Rulesets/Objects/HitObject.cs @@ -168,8 +168,6 @@ namespace osu.Game.Rulesets.Objects /// [NotNull] protected virtual HitWindows CreateHitWindows() => new HitWindows(); - - public virtual string ToEditorString() => string.Empty; } public static class HitObjectExtensions diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index a6e84d59a7..c2a9fd49b1 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -63,9 +63,6 @@ namespace osu.Game.Screens.Edit protected bool HasUnsavedChanges => lastSavedHash != changeHandler.CurrentStateHash; - [Resolved] - private GameHost host { get; set; } - [Resolved] private BeatmapManager beatmapManager { get; set; } @@ -110,7 +107,7 @@ namespace osu.Game.Screens.Edit private MusicController music { get; set; } [BackgroundDependencyLoader] - private void load(OsuColour colours, OsuConfigManager config) + private void load(OsuColour colours, GameHost host, OsuConfigManager config) { if (Beatmap.Value is DummyWorkingBeatmap) { @@ -547,24 +544,10 @@ namespace osu.Game.Screens.Edit protected void Copy() { - var builder = new StringBuilder(); - const string suffix = " - "; - if (editorBeatmap.SelectedHitObjects.Count == 0) - { - builder.Append(clock.CurrentTime.ToEditorFormattedString()); - } - else - { - var orderedHitObjects = editorBeatmap.SelectedHitObjects.OrderBy(h => h.StartTime); - builder.Append(orderedHitObjects.FirstOrDefault().StartTime.ToEditorFormattedString()); - builder.Append($" ({string.Join(',', orderedHitObjects.Select(h => h.ToEditorString()))})"); + return; - clipboard.Value = new ClipboardContent(editorBeatmap).Serialize(); - } - - builder.Append(suffix); - host.GetClipboard()?.SetText(builder.ToString()); + clipboard.Value = new ClipboardContent(editorBeatmap).Serialize(); } protected void Paste() From b8b7eb4c4b8e0af156ebdad46a83ecbe3427b0b2 Mon Sep 17 00:00:00 2001 From: Nathan Alo Date: Fri, 26 Mar 2021 15:25:20 +0800 Subject: [PATCH 05/13] refactor logic to its own component and handle hit object to string conversion to its ruleset-specific composers --- .../Edit/ManiaHitObjectComposer.cs | 3 ++ .../Edit/OsuHitObjectComposer.cs | 3 ++ osu.Game/Rulesets/Edit/HitObjectComposer.cs | 2 + .../Screens/Edit/Compose/ComposeScreen.cs | 23 +++++++++- osu.Game/Screens/Edit/SelectionHelper.cs | 46 +++++++++++++++++++ 5 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 osu.Game/Screens/Edit/SelectionHelper.cs diff --git a/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs b/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs index 324670c4b2..4cb34a217c 100644 --- a/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs +++ b/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs @@ -119,5 +119,8 @@ namespace osu.Game.Rulesets.Mania.Edit beatSnapGrid.SelectionTimeRange = null; } } + + public override IEnumerable ConvertSelectionToString() + => EditorBeatmap.SelectedHitObjects.Cast().Select(h => $"{h.StartTime}|{h.Column}"); } } diff --git a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs index 0490e8b8ce..1943f52c73 100644 --- a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs +++ b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs @@ -82,6 +82,9 @@ namespace osu.Game.Rulesets.Osu.Edit protected override ComposeBlueprintContainer CreateBlueprintContainer() => new OsuBlueprintContainer(this); + public override IEnumerable ConvertSelectionToString() + => selectedHitObjects.Cast().Select(h => (h.IndexInCurrentCombo + 1).ToString()); + private DistanceSnapGrid distanceSnapGrid; private Container distanceSnapGridContainer; diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index e927951d0a..eee16043e4 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -438,6 +438,8 @@ namespace osu.Game.Rulesets.Edit /// public abstract bool CursorInPlacementArea { get; } + public virtual IEnumerable ConvertSelectionToString() => Array.Empty(); + #region IPositionSnapProvider public abstract SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition); diff --git a/osu.Game/Screens/Edit/Compose/ComposeScreen.cs b/osu.Game/Screens/Edit/Compose/ComposeScreen.cs index 81b1195a40..c63ef11c74 100644 --- a/osu.Game/Screens/Edit/Compose/ComposeScreen.cs +++ b/osu.Game/Screens/Edit/Compose/ComposeScreen.cs @@ -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 { [Resolved] private IBindable 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) + { + } } } diff --git a/osu.Game/Screens/Edit/SelectionHelper.cs b/osu.Game/Screens/Edit/SelectionHelper.cs new file mode 100644 index 0000000000..e0eb868c9f --- /dev/null +++ b/osu.Game/Screens/Edit/SelectionHelper.cs @@ -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(); + } + } +} From 374f8c5e229b314a2f7cf1de9b29285cccbff0d2 Mon Sep 17 00:00:00 2001 From: Nathan Alo Date: Fri, 26 Mar 2021 15:33:28 +0800 Subject: [PATCH 06/13] move to compose namespace and add license header --- osu.Game/Screens/Edit/{ => Compose}/SelectionHelper.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) rename osu.Game/Screens/Edit/{ => Compose}/SelectionHelper.cs (85%) diff --git a/osu.Game/Screens/Edit/SelectionHelper.cs b/osu.Game/Screens/Edit/Compose/SelectionHelper.cs similarity index 85% rename from osu.Game/Screens/Edit/SelectionHelper.cs rename to osu.Game/Screens/Edit/Compose/SelectionHelper.cs index e0eb868c9f..39d6d57a2a 100644 --- a/osu.Game/Screens/Edit/SelectionHelper.cs +++ b/osu.Game/Screens/Edit/Compose/SelectionHelper.cs @@ -1,4 +1,7 @@ -using System.Linq; +// Copyright (c) ppy Pty Ltd . 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; @@ -6,7 +9,7 @@ using osu.Framework.Platform; using osu.Game.Extensions; using osu.Game.Rulesets.Edit; -namespace osu.Game.Screens.Edit +namespace osu.Game.Screens.Edit.Compose { public class SelectionHelper : Component { From 71a0616861916129456e0a301d0386269c51cd6c Mon Sep 17 00:00:00 2001 From: Nathan Alo Date: Fri, 26 Mar 2021 15:34:45 +0800 Subject: [PATCH 07/13] remove extra semi colons --- osu.Game/Screens/Edit/Compose/ComposeScreen.cs | 2 +- osu.Game/Screens/Edit/Compose/SelectionHelper.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/ComposeScreen.cs b/osu.Game/Screens/Edit/Compose/ComposeScreen.cs index c63ef11c74..b249ae9bcd 100644 --- a/osu.Game/Screens/Edit/Compose/ComposeScreen.cs +++ b/osu.Game/Screens/Edit/Compose/ComposeScreen.cs @@ -87,7 +87,7 @@ namespace osu.Game.Screens.Edit.Compose return false; default: return false; - }; + } } public void OnReleased(PlatformAction action) diff --git a/osu.Game/Screens/Edit/Compose/SelectionHelper.cs b/osu.Game/Screens/Edit/Compose/SelectionHelper.cs index 39d6d57a2a..2e172c12dc 100644 --- a/osu.Game/Screens/Edit/Compose/SelectionHelper.cs +++ b/osu.Game/Screens/Edit/Compose/SelectionHelper.cs @@ -39,7 +39,7 @@ namespace osu.Game.Screens.Edit.Compose { builder.Append($"{clock.CurrentTime.ToEditorFormattedString()}{separator}"); return builder.ToString(); - }; + } builder.Append(editorBeatmap.SelectedHitObjects.First().StartTime.ToEditorFormattedString()); builder.Append($" ({string.Join(',', composer.ConvertSelectionToString())}){separator}"); From c96321206a0e5157d8864e5d84204706f918ce30 Mon Sep 17 00:00:00 2001 From: Nathan Alo Date: Fri, 26 Mar 2021 16:17:24 +0800 Subject: [PATCH 08/13] fix appveyor complaints --- osu.Game/Screens/Edit/Compose/ComposeScreen.cs | 3 ++- osu.Game/Screens/Edit/Editor.cs | 6 +----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/ComposeScreen.cs b/osu.Game/Screens/Edit/Compose/ComposeScreen.cs index b249ae9bcd..16043ff64b 100644 --- a/osu.Game/Screens/Edit/Compose/ComposeScreen.cs +++ b/osu.Game/Screens/Edit/Compose/ComposeScreen.cs @@ -23,7 +23,7 @@ namespace osu.Game.Screens.Edit.Compose private HitObjectComposer composer; - private SelectionHelper helper; + private readonly SelectionHelper helper; public ComposeScreen() : base(EditorScreenMode.Compose) @@ -85,6 +85,7 @@ namespace osu.Game.Screens.Edit.Compose case PlatformActionType.Copy: helper.CopySelectionToClipboard(); return false; + default: return false; } diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index c2a9fd49b1..d9ba12d331 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Text; using osu.Framework; using osu.Framework.Allocation; using osu.Framework.Bindables; @@ -17,12 +16,10 @@ using osu.Framework.Input; using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; using osu.Framework.Logging; -using osu.Framework.Platform; using osu.Framework.Screens; using osu.Framework.Timing; using osu.Game.Beatmaps; using osu.Game.Configuration; -using osu.Game.Extensions; using osu.Game.Graphics; using osu.Game.Graphics.Cursor; using osu.Game.Graphics.UserInterface; @@ -31,7 +28,6 @@ using osu.Game.IO.Serialization; using osu.Game.Online.API; using osu.Game.Overlays; using osu.Game.Rulesets.Edit; -using osu.Game.Rulesets.Objects.Types; using osu.Game.Screens.Edit.Components; using osu.Game.Screens.Edit.Components.Menus; using osu.Game.Screens.Edit.Components.Timelines.Summary; @@ -107,7 +103,7 @@ namespace osu.Game.Screens.Edit private MusicController music { get; set; } [BackgroundDependencyLoader] - private void load(OsuColour colours, GameHost host, OsuConfigManager config) + private void load(OsuColour colours, OsuConfigManager config) { if (Beatmap.Value is DummyWorkingBeatmap) { From 21398e25b5b939ae40e15be42bb6ffb93365d315 Mon Sep 17 00:00:00 2001 From: Nathan Alo Date: Sat, 27 Mar 2021 10:02:21 +0800 Subject: [PATCH 09/13] null check composer and ensure the correct start time from selected hit objects --- osu.Game/Screens/Edit/Compose/SelectionHelper.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/SelectionHelper.cs b/osu.Game/Screens/Edit/Compose/SelectionHelper.cs index 2e172c12dc..a01a9e0144 100644 --- a/osu.Game/Screens/Edit/Compose/SelectionHelper.cs +++ b/osu.Game/Screens/Edit/Compose/SelectionHelper.cs @@ -41,8 +41,10 @@ namespace osu.Game.Screens.Edit.Compose return builder.ToString(); } - builder.Append(editorBeatmap.SelectedHitObjects.First().StartTime.ToEditorFormattedString()); - builder.Append($" ({string.Join(',', composer.ConvertSelectionToString())}){separator}"); + 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(); } } From 9a02f3868c2105e51dbd7e64ce4443d08938d02e Mon Sep 17 00:00:00 2001 From: Nathan Alo Date: Mon, 29 Mar 2021 17:29:05 +0800 Subject: [PATCH 10/13] return a string instead --- osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs | 4 ++-- osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs | 4 ++-- osu.Game/Rulesets/Edit/HitObjectComposer.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs b/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs index 4cb34a217c..d9570bf8be 100644 --- a/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs +++ b/osu.Game.Rulesets.Mania/Edit/ManiaHitObjectComposer.cs @@ -120,7 +120,7 @@ namespace osu.Game.Rulesets.Mania.Edit } } - public override IEnumerable ConvertSelectionToString() - => EditorBeatmap.SelectedHitObjects.Cast().Select(h => $"{h.StartTime}|{h.Column}"); + public override string ConvertSelectionToString() + => string.Join(',', EditorBeatmap.SelectedHitObjects.Cast().OrderBy(h => h.StartTime).Select(h => $"{h.StartTime}|{h.Column}")); } } diff --git a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs index 1943f52c73..396fd41377 100644 --- a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs +++ b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs @@ -82,8 +82,8 @@ namespace osu.Game.Rulesets.Osu.Edit protected override ComposeBlueprintContainer CreateBlueprintContainer() => new OsuBlueprintContainer(this); - public override IEnumerable ConvertSelectionToString() - => selectedHitObjects.Cast().Select(h => (h.IndexInCurrentCombo + 1).ToString()); + public override string ConvertSelectionToString() + => string.Join(',', selectedHitObjects.Cast().OrderBy(h => h.StartTime).Select(h => (h.IndexInCurrentCombo + 1).ToString())); private DistanceSnapGrid distanceSnapGrid; private Container distanceSnapGridContainer; diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index eee16043e4..736fc47dee 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -438,7 +438,7 @@ namespace osu.Game.Rulesets.Edit /// public abstract bool CursorInPlacementArea { get; } - public virtual IEnumerable ConvertSelectionToString() => Array.Empty(); + public virtual string ConvertSelectionToString() => string.Empty; #region IPositionSnapProvider From cdb779f764bb09dcba1784f66fc87aab9debfd8b Mon Sep 17 00:00:00 2001 From: Nathan Alo Date: Mon, 29 Mar 2021 17:30:23 +0800 Subject: [PATCH 11/13] move copy logic inside ComposeScreen --- .../Screens/Edit/Compose/ComposeScreen.cs | 37 ++++++++++---- .../Screens/Edit/Compose/SelectionHelper.cs | 51 ------------------- 2 files changed, 26 insertions(+), 62 deletions(-) delete mode 100644 osu.Game/Screens/Edit/Compose/SelectionHelper.cs diff --git a/osu.Game/Screens/Edit/Compose/ComposeScreen.cs b/osu.Game/Screens/Edit/Compose/ComposeScreen.cs index 16043ff64b..f6ce5a4e3d 100644 --- a/osu.Game/Screens/Edit/Compose/ComposeScreen.cs +++ b/osu.Game/Screens/Edit/Compose/ComposeScreen.cs @@ -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 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,17 +85,25 @@ 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; - } + return false; } public void OnReleased(PlatformAction action) diff --git a/osu.Game/Screens/Edit/Compose/SelectionHelper.cs b/osu.Game/Screens/Edit/Compose/SelectionHelper.cs deleted file mode 100644 index a01a9e0144..0000000000 --- a/osu.Game/Screens/Edit/Compose/SelectionHelper.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) ppy Pty Ltd . 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(); - } - } -} From 90ab765cf519be8be956175f492f3c7aff4e0f0e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 29 Mar 2021 18:46:32 +0900 Subject: [PATCH 12/13] Reorder methods and surround with region --- .../Screens/Edit/Compose/ComposeScreen.cs | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/ComposeScreen.cs b/osu.Game/Screens/Edit/Compose/ComposeScreen.cs index f6ce5a4e3d..1d52cc60fd 100644 --- a/osu.Game/Screens/Edit/Compose/ComposeScreen.cs +++ b/osu.Game/Screens/Edit/Compose/ComposeScreen.cs @@ -85,6 +85,20 @@ namespace osu.Game.Screens.Edit.Compose return beatmapSkinProvider.WithChild(rulesetSkinProvider.WithChild(content)); } + #region Input Handling + + public bool OnPressed(PlatformAction action) + { + if (action.ActionType == PlatformActionType.Copy) + host.GetClipboard().SetText(formatSelectionAsString()); + + return false; + } + + public void OnReleased(PlatformAction action) + { + } + private string formatSelectionAsString() { var builder = new StringBuilder(); @@ -98,16 +112,6 @@ namespace osu.Game.Screens.Edit.Compose return builder.ToString(); } - public bool OnPressed(PlatformAction action) - { - if (action.ActionType == PlatformActionType.Copy) - host.GetClipboard().SetText(formatSelectionAsString()); - - return false; - } - - public void OnReleased(PlatformAction action) - { - } + #endregion } } From 3909eda095ce5f6fcfdc7afa7e3ea4fdaf826540 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 29 Mar 2021 18:51:28 +0900 Subject: [PATCH 13/13] Avoid using a StringBuilder --- osu.Game/Screens/Edit/Compose/ComposeScreen.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/ComposeScreen.cs b/osu.Game/Screens/Edit/Compose/ComposeScreen.cs index 1d52cc60fd..61056aeced 100644 --- a/osu.Game/Screens/Edit/Compose/ComposeScreen.cs +++ b/osu.Game/Screens/Edit/Compose/ComposeScreen.cs @@ -3,7 +3,6 @@ using System.Diagnostics; using System.Linq; -using System.Text; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -101,15 +100,15 @@ namespace osu.Game.Screens.Edit.Compose private string formatSelectionAsString() { - var builder = new StringBuilder(); - builder.Append(EditorBeatmap.SelectedHitObjects.OrderBy(h => h.StartTime).FirstOrDefault()?.StartTime.ToEditorFormattedString() ?? clock.CurrentTime.ToEditorFormattedString()); + if (composer == null) + return string.Empty; - if (EditorBeatmap.SelectedHitObjects.Any() && composer != null) - builder.Append($" ({composer.ConvertSelectionToString()})"); + double displayTime = EditorBeatmap.SelectedHitObjects.OrderBy(h => h.StartTime).FirstOrDefault()?.StartTime ?? clock.CurrentTime; + string selectionAsString = composer.ConvertSelectionToString(); - builder.Append(" - "); - - return builder.ToString(); + return !string.IsNullOrEmpty(selectionAsString) + ? $"{displayTime.ToEditorFormattedString()} ({selectionAsString}) - " + : $"{displayTime.ToEditorFormattedString()} - "; } #endregion