2019-01-24 16:43:03 +08:00
|
|
|
// 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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-11-26 17:14:25 +08:00
|
|
|
using System.Diagnostics;
|
2021-03-29 17:30:23 +08:00
|
|
|
using System.Linq;
|
2020-09-29 16:26:49 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-03-29 17:30:23 +08:00
|
|
|
using osu.Framework.Platform;
|
2020-09-29 16:26:49 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2022-11-17 06:32:54 +08:00
|
|
|
using osu.Game.Configuration;
|
2021-03-29 17:30:23 +08:00
|
|
|
using osu.Game.Extensions;
|
2021-11-08 21:24:39 +08:00
|
|
|
using osu.Game.IO.Serialization;
|
2020-09-29 16:26:49 +08:00
|
|
|
using osu.Game.Rulesets;
|
2019-12-05 19:12:25 +08:00
|
|
|
using osu.Game.Rulesets.Edit;
|
|
|
|
using osu.Game.Screens.Edit.Compose.Components.Timeline;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-11-06 17:28:22 +08:00
|
|
|
namespace osu.Game.Screens.Edit.Compose
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class ComposeScreen : EditorScreenWithTimeline, IGameplaySettings
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2021-03-29 17:30:23 +08:00
|
|
|
[Resolved]
|
2023-07-11 17:42:31 +08:00
|
|
|
private Clipboard hostClipboard { get; set; } = null!;
|
2021-03-29 17:30:23 +08:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private EditorClock clock { get; set; }
|
2019-12-05 19:12:25 +08:00
|
|
|
|
2022-11-17 06:32:54 +08:00
|
|
|
[Resolved]
|
|
|
|
private IGameplaySettings globalGameplaySettings { get; set; }
|
|
|
|
|
2021-11-08 21:24:39 +08:00
|
|
|
private Bindable<string> clipboard { get; set; }
|
|
|
|
|
2021-03-29 17:30:23 +08:00
|
|
|
private HitObjectComposer composer;
|
2021-03-26 15:25:20 +08:00
|
|
|
|
2020-09-24 16:03:54 +08:00
|
|
|
public ComposeScreen()
|
|
|
|
: base(EditorScreenMode.Compose)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-09-29 16:26:49 +08:00
|
|
|
private Ruleset ruleset;
|
|
|
|
|
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2020-09-29 16:26:49 +08:00
|
|
|
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
|
|
|
|
2022-01-12 21:34:07 +08:00
|
|
|
ruleset = parent.Get<IBindable<WorkingBeatmap>>().Value.BeatmapInfo.Ruleset.CreateInstance();
|
2019-12-05 19:12:25 +08:00
|
|
|
composer = ruleset?.CreateHitObjectComposer();
|
2019-04-01 11:16:05 +08:00
|
|
|
|
2020-09-29 16:26:49 +08:00
|
|
|
// make the composer available to the timeline and other components in this screen.
|
2020-11-20 05:11:52 +08:00
|
|
|
if (composer != null)
|
|
|
|
dependencies.CacheAs(composer);
|
2020-09-29 16:26:49 +08:00
|
|
|
|
|
|
|
return dependencies;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override Drawable CreateMainContent()
|
|
|
|
{
|
2019-12-06 11:51:43 +08:00
|
|
|
if (ruleset == null || composer == null)
|
|
|
|
return new ScreenWhiteBox.UnderConstructionMessage(ruleset == null ? "This beatmap" : $"{ruleset.Description}'s composer");
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-11-26 17:14:25 +08:00
|
|
|
return wrapSkinnableContent(composer);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override Drawable CreateTimelineContent()
|
|
|
|
{
|
|
|
|
if (ruleset == null || composer == null)
|
|
|
|
return base.CreateTimelineContent();
|
|
|
|
|
2024-06-18 20:55:59 +08:00
|
|
|
return wrapSkinnableContent(new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2024-06-18 21:41:43 +08:00
|
|
|
new TimelineBlueprintContainer(composer),
|
2024-06-18 20:55:59 +08:00
|
|
|
new TimelineBreakDisplay { RelativeSizeAxes = Axes.Both, },
|
|
|
|
}
|
|
|
|
});
|
2020-11-26 17:14:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private Drawable wrapSkinnableContent(Drawable content)
|
|
|
|
{
|
|
|
|
Debug.Assert(ruleset != null);
|
|
|
|
|
2021-08-15 22:14:41 +08:00
|
|
|
return new EditorSkinProvidingContainer(EditorBeatmap).WithChild(content);
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
2021-03-26 15:25:20 +08:00
|
|
|
|
2021-11-10 19:36:23 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(EditorClipboard clipboard)
|
|
|
|
{
|
|
|
|
this.clipboard = clipboard.Content.GetBoundCopy();
|
|
|
|
}
|
|
|
|
|
2021-11-08 21:54:31 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2022-01-28 13:01:10 +08:00
|
|
|
|
|
|
|
// May be null in the case of a ruleset that doesn't have editor support, see CreateMainContent().
|
|
|
|
if (composer == null)
|
|
|
|
return;
|
|
|
|
|
2022-06-24 20:25:23 +08:00
|
|
|
EditorBeatmap.SelectedHitObjects.BindCollectionChanged((_, _) => updateClipboardActionAvailability());
|
2021-12-08 04:00:25 +08:00
|
|
|
clipboard.BindValueChanged(_ => updateClipboardActionAvailability());
|
|
|
|
composer.OnLoadComplete += _ => updateClipboardActionAvailability();
|
|
|
|
updateClipboardActionAvailability();
|
2021-11-08 21:54:31 +08:00
|
|
|
}
|
|
|
|
|
2021-11-08 21:24:39 +08:00
|
|
|
#region Clipboard operations
|
|
|
|
|
2023-07-10 00:21:43 +08:00
|
|
|
public override void Cut()
|
2021-11-08 21:24:39 +08:00
|
|
|
{
|
2023-07-10 00:21:43 +08:00
|
|
|
if (!CanCut.Value)
|
|
|
|
return;
|
2021-11-08 21:24:39 +08:00
|
|
|
|
|
|
|
Copy();
|
|
|
|
EditorBeatmap.RemoveRange(EditorBeatmap.SelectedHitObjects.ToArray());
|
|
|
|
}
|
|
|
|
|
2023-07-10 00:21:43 +08:00
|
|
|
public override void Copy()
|
2021-11-08 21:24:39 +08:00
|
|
|
{
|
2023-07-10 00:21:43 +08:00
|
|
|
// on stable, pressing Ctrl-C would copy the current timestamp to system clipboard
|
|
|
|
// regardless of whether anything was even selected at all.
|
|
|
|
// UX-wise this is generally strange and unexpected, but make it work anyways to preserve muscle memory.
|
|
|
|
// note that this means that `getTimestamp()` must handle no-selection case, too.
|
2023-07-11 17:42:31 +08:00
|
|
|
hostClipboard.SetText(getTimestamp());
|
2023-07-10 00:21:43 +08:00
|
|
|
|
|
|
|
if (CanCopy.Value)
|
|
|
|
clipboard.Value = new ClipboardContent(EditorBeatmap).Serialize();
|
2021-11-08 21:24:39 +08:00
|
|
|
}
|
|
|
|
|
2023-07-10 00:21:43 +08:00
|
|
|
public override void Paste()
|
2021-11-08 21:24:39 +08:00
|
|
|
{
|
2023-07-10 00:21:43 +08:00
|
|
|
if (!CanPaste.Value)
|
|
|
|
return;
|
2021-11-08 21:24:39 +08:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2021-11-08 21:54:31 +08:00
|
|
|
private void updateClipboardActionAvailability()
|
|
|
|
{
|
|
|
|
CanCut.Value = CanCopy.Value = EditorBeatmap.SelectedHitObjects.Any();
|
2021-12-08 04:00:25 +08:00
|
|
|
CanPaste.Value = composer.IsLoaded && !string.IsNullOrEmpty(clipboard.Value);
|
2021-11-08 21:54:31 +08:00
|
|
|
}
|
|
|
|
|
2023-07-10 00:21:43 +08:00
|
|
|
private string getTimestamp()
|
2021-11-10 19:49:04 +08:00
|
|
|
{
|
|
|
|
if (composer == null)
|
|
|
|
return string.Empty;
|
|
|
|
|
2022-12-19 15:42:21 +08:00
|
|
|
double displayTime = EditorBeatmap.SelectedHitObjects.MinBy(h => h.StartTime)?.StartTime ?? clock.CurrentTime;
|
2021-11-10 19:49:04 +08:00
|
|
|
string selectionAsString = composer.ConvertSelectionToString();
|
|
|
|
|
|
|
|
return !string.IsNullOrEmpty(selectionAsString)
|
|
|
|
? $"{displayTime.ToEditorFormattedString()} ({selectionAsString}) - "
|
|
|
|
: $"{displayTime.ToEditorFormattedString()} - ";
|
|
|
|
}
|
|
|
|
|
2021-11-08 21:24:39 +08:00
|
|
|
#endregion
|
2022-11-17 06:32:54 +08:00
|
|
|
|
|
|
|
// Combo colour normalisation should not be applied in the editor.
|
|
|
|
// Note this doesn't affect editor test mode.
|
|
|
|
IBindable<float> IGameplaySettings.ComboColourNormalisationAmount => new Bindable<float>();
|
|
|
|
|
|
|
|
// Arguable.
|
|
|
|
IBindable<float> IGameplaySettings.PositionalHitsoundsLevel => globalGameplaySettings.PositionalHitsoundsLevel;
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|