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
|
|
|
|
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-26 15:25:20 +08:00
|
|
|
using osu.Framework.Input;
|
|
|
|
using osu.Framework.Input.Bindings;
|
2021-03-29 17:30:23 +08:00
|
|
|
using osu.Framework.Platform;
|
2020-09-29 16:26:49 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2021-03-29 17:30:23 +08:00
|
|
|
using osu.Game.Extensions;
|
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;
|
2019-10-08 11:52:34 +08:00
|
|
|
using osu.Game.Skinning;
|
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
|
|
|
{
|
2021-03-26 15:25:20 +08:00
|
|
|
public class ComposeScreen : EditorScreenWithTimeline, IKeyBindingHandler<PlatformAction>
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2021-01-04 15:47:08 +08:00
|
|
|
[Resolved]
|
|
|
|
private IBindable<WorkingBeatmap> beatmap { get; set; }
|
|
|
|
|
2021-03-29 17:30:23 +08:00
|
|
|
[Resolved]
|
|
|
|
private GameHost host { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private EditorClock clock { get; set; }
|
2019-12-05 19:12:25 +08:00
|
|
|
|
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));
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
return wrapSkinnableContent(new TimelineBlueprintContainer(composer));
|
|
|
|
}
|
|
|
|
|
|
|
|
private Drawable wrapSkinnableContent(Drawable content)
|
|
|
|
{
|
|
|
|
Debug.Assert(ruleset != null);
|
|
|
|
|
2021-06-10 02:30:26 +08:00
|
|
|
return new RulesetSkinProvidingContainer(ruleset, EditorBeatmap.PlayableBeatmap, beatmap.Value.Skin).WithChild(content);
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
2021-03-26 15:25:20 +08:00
|
|
|
|
2021-03-29 17:46:32 +08:00
|
|
|
#region Input Handling
|
|
|
|
|
|
|
|
public bool OnPressed(PlatformAction action)
|
|
|
|
{
|
2021-07-20 13:23:34 +08:00
|
|
|
if (action == PlatformAction.Copy)
|
2021-03-29 17:46:32 +08:00
|
|
|
host.GetClipboard().SetText(formatSelectionAsString());
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnReleased(PlatformAction action)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-03-29 17:30:23 +08:00
|
|
|
private string formatSelectionAsString()
|
|
|
|
{
|
2021-03-29 17:51:28 +08:00
|
|
|
if (composer == null)
|
|
|
|
return string.Empty;
|
2021-03-29 17:30:23 +08:00
|
|
|
|
2021-03-29 17:51:28 +08:00
|
|
|
double displayTime = EditorBeatmap.SelectedHitObjects.OrderBy(h => h.StartTime).FirstOrDefault()?.StartTime ?? clock.CurrentTime;
|
|
|
|
string selectionAsString = composer.ConvertSelectionToString();
|
2021-03-29 17:30:23 +08:00
|
|
|
|
2021-03-29 17:51:28 +08:00
|
|
|
return !string.IsNullOrEmpty(selectionAsString)
|
|
|
|
? $"{displayTime.ToEditorFormattedString()} ({selectionAsString}) - "
|
|
|
|
: $"{displayTime.ToEditorFormattedString()} - ";
|
2021-03-29 17:30:23 +08:00
|
|
|
}
|
|
|
|
|
2021-03-29 17:46:32 +08:00
|
|
|
#endregion
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|