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
|
|
|
|
|
2018-11-22 18:40:44 +08:00
|
|
|
|
using System;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
|
using osu.Game.Screens.Backgrounds;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Screens.Edit.Components.Timelines.Summary;
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-06-19 19:19:52 +08:00
|
|
|
|
using osu.Framework.Platform;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Timing;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
using osu.Game.Screens.Edit.Components;
|
2018-11-06 17:28:22 +08:00
|
|
|
|
using osu.Game.Screens.Edit.Components.Menus;
|
2018-11-07 12:04:17 +08:00
|
|
|
|
using osu.Game.Screens.Edit.Compose;
|
|
|
|
|
using osu.Game.Screens.Edit.Design;
|
2018-11-30 13:57:25 +08:00
|
|
|
|
using osuTK.Input;
|
2019-02-28 12:09:38 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using osu.Framework;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit
|
|
|
|
|
{
|
|
|
|
|
public class Editor : OsuScreen
|
|
|
|
|
{
|
|
|
|
|
protected override BackgroundScreen CreateBackground() => new BackgroundScreenCustom(@"Backgrounds/bg4");
|
|
|
|
|
|
2019-01-28 14:41:54 +08:00
|
|
|
|
public override bool HideOverlaysOnEnter => true;
|
2019-02-01 14:42:15 +08:00
|
|
|
|
|
|
|
|
|
public override bool DisallowExternalBeatmapRulesetChanges => true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
private Box bottomBackground;
|
|
|
|
|
private Container screenContainer;
|
|
|
|
|
|
|
|
|
|
private EditorScreen currentScreen;
|
|
|
|
|
|
|
|
|
|
private readonly BindableBeatDivisor beatDivisor = new BindableBeatDivisor();
|
|
|
|
|
|
|
|
|
|
private EditorClock clock;
|
|
|
|
|
|
|
|
|
|
private DependencyContainer dependencies;
|
2018-06-19 19:19:52 +08:00
|
|
|
|
private GameHost host;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-07-11 16:07:14 +08:00
|
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
|
|
|
|
=> dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2018-06-19 19:19:52 +08:00
|
|
|
|
private void load(OsuColour colours, GameHost host)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-06-19 19:19:52 +08:00
|
|
|
|
this.host = host;
|
|
|
|
|
|
2019-03-19 22:44:15 +08:00
|
|
|
|
// TODO: should probably be done at a DrawableRuleset level to share logic with Player.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
var sourceClock = (IAdjustableClock)Beatmap.Value.Track ?? new StopwatchClock();
|
2018-05-28 17:01:15 +08:00
|
|
|
|
clock = new EditorClock(Beatmap.Value, beatDivisor) { IsCoupled = false };
|
2018-04-13 17:19:50 +08:00
|
|
|
|
clock.ChangeSource(sourceClock);
|
|
|
|
|
|
|
|
|
|
dependencies.CacheAs<IFrameBasedClock>(clock);
|
|
|
|
|
dependencies.CacheAs<IAdjustableClock>(clock);
|
|
|
|
|
dependencies.Cache(beatDivisor);
|
|
|
|
|
|
|
|
|
|
EditorMenuBar menuBar;
|
|
|
|
|
TimeInfoContainer timeInfo;
|
|
|
|
|
SummaryTimeline timeline;
|
|
|
|
|
PlaybackControl playback;
|
|
|
|
|
|
2019-02-28 12:09:38 +08:00
|
|
|
|
var fileMenuItems = new List<MenuItem>();
|
|
|
|
|
if (RuntimeInfo.IsDesktop)
|
|
|
|
|
{
|
|
|
|
|
fileMenuItems.Add(new EditorMenuItem("Export", MenuItemType.Standard, exportBeatmap));
|
|
|
|
|
fileMenuItems.Add(new EditorMenuItemSpacer());
|
|
|
|
|
}
|
2019-02-28 17:58:52 +08:00
|
|
|
|
|
2019-02-28 12:09:38 +08:00
|
|
|
|
fileMenuItems.Add(new EditorMenuItem("Exit", MenuItemType.Standard, this.Exit));
|
|
|
|
|
|
2019-01-23 19:52:00 +08:00
|
|
|
|
InternalChildren = new[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
Name = "Screen container",
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Padding = new MarginPadding { Top = 40, Bottom = 60 },
|
|
|
|
|
Child = screenContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Masking = true
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
Name = "Top bar",
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 40,
|
|
|
|
|
Child = menuBar = new EditorMenuBar
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Items = new[]
|
|
|
|
|
{
|
|
|
|
|
new MenuItem("File")
|
|
|
|
|
{
|
2019-02-28 12:09:38 +08:00
|
|
|
|
Items = fileMenuItems
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
Name = "Bottom bar",
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 60,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
bottomBackground = new Box { RelativeSizeAxes = Axes.Both },
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Padding = new MarginPadding { Vertical = 5, Horizontal = 10 },
|
|
|
|
|
Child = new GridContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
ColumnDimensions = new[]
|
|
|
|
|
{
|
|
|
|
|
new Dimension(GridSizeMode.Absolute, 220),
|
|
|
|
|
new Dimension(),
|
|
|
|
|
new Dimension(GridSizeMode.Absolute, 220)
|
|
|
|
|
},
|
|
|
|
|
Content = new[]
|
|
|
|
|
{
|
|
|
|
|
new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Padding = new MarginPadding { Right = 10 },
|
2018-05-23 16:37:39 +08:00
|
|
|
|
Child = new TimeInfoContainer { RelativeSizeAxes = Axes.Both },
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
2018-05-23 16:37:39 +08:00
|
|
|
|
new SummaryTimeline
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Padding = new MarginPadding { Left = 10 },
|
2018-05-23 16:37:39 +08:00
|
|
|
|
Child = new PlaybackControl { RelativeSizeAxes = Axes.Both },
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
menuBar.Mode.ValueChanged += onModeChanged;
|
|
|
|
|
|
|
|
|
|
bottomBackground.Colour = colours.Gray2;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-30 13:57:25 +08:00
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-11-30 13:57:25 +08:00
|
|
|
|
switch (e.Key)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-11-30 13:57:25 +08:00
|
|
|
|
case Key.Left:
|
2018-11-30 14:47:55 +08:00
|
|
|
|
seek(e, -1);
|
2018-11-30 13:57:25 +08:00
|
|
|
|
return true;
|
|
|
|
|
case Key.Right:
|
2018-11-30 14:47:55 +08:00
|
|
|
|
seek(e, 1);
|
2018-11-30 13:57:25 +08:00
|
|
|
|
return true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-30 13:57:25 +08:00
|
|
|
|
return base.OnKeyDown(e);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-22 18:40:44 +08:00
|
|
|
|
private double scrollAccumulation;
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnScroll(ScrollEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-11-23 09:06:06 +08:00
|
|
|
|
scrollAccumulation += (e.ScrollDelta.X + e.ScrollDelta.Y) * (e.IsPrecise ? 0.1 : 1);
|
2018-11-22 18:40:44 +08:00
|
|
|
|
|
2018-11-22 19:13:40 +08:00
|
|
|
|
const int precision = 1;
|
|
|
|
|
|
|
|
|
|
while (Math.Abs(scrollAccumulation) > precision)
|
|
|
|
|
{
|
|
|
|
|
if (scrollAccumulation > 0)
|
2018-11-30 14:47:55 +08:00
|
|
|
|
seek(e, -1);
|
2018-11-22 19:13:40 +08:00
|
|
|
|
else
|
2018-11-30 14:47:55 +08:00
|
|
|
|
seek(e, 1);
|
2018-11-22 19:13:40 +08:00
|
|
|
|
|
|
|
|
|
scrollAccumulation = scrollAccumulation < 0 ? Math.Min(0, scrollAccumulation + precision) : Math.Max(0, scrollAccumulation - precision);
|
|
|
|
|
}
|
2018-11-22 18:40:44 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 19:52:00 +08:00
|
|
|
|
public override void OnResuming(IScreen last)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Beatmap.Value.Track?.Stop();
|
|
|
|
|
base.OnResuming(last);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 19:52:00 +08:00
|
|
|
|
public override void OnEntering(IScreen last)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
base.OnEntering(last);
|
|
|
|
|
Background.FadeColour(Color4.DarkGray, 500);
|
|
|
|
|
Beatmap.Value.Track?.Stop();
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 19:52:00 +08:00
|
|
|
|
public override bool OnExiting(IScreen next)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Background.FadeColour(Color4.White, 500);
|
|
|
|
|
if (Beatmap.Value.Track != null)
|
|
|
|
|
{
|
|
|
|
|
Beatmap.Value.Track.Tempo.Value = 1;
|
|
|
|
|
Beatmap.Value.Track.Start();
|
|
|
|
|
}
|
2018-11-30 13:57:25 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return base.OnExiting(next);
|
|
|
|
|
}
|
2018-11-30 13:57:25 +08:00
|
|
|
|
|
|
|
|
|
private void exportBeatmap() => host.OpenFileExternally(Beatmap.Value.Save());
|
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
|
private void onModeChanged(ValueChangedEvent<EditorScreenMode> e)
|
2018-11-30 13:57:25 +08:00
|
|
|
|
{
|
|
|
|
|
currentScreen?.Exit();
|
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
|
switch (e.NewValue)
|
2018-11-30 13:57:25 +08:00
|
|
|
|
{
|
|
|
|
|
case EditorScreenMode.Compose:
|
|
|
|
|
currentScreen = new ComposeScreen();
|
|
|
|
|
break;
|
|
|
|
|
case EditorScreenMode.Design:
|
|
|
|
|
currentScreen = new DesignScreen();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
currentScreen = new EditorScreen();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LoadComponentAsync(currentScreen, screenContainer.Add);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-30 14:47:55 +08:00
|
|
|
|
private void seek(UIEvent e, int direction)
|
2018-11-30 13:57:25 +08:00
|
|
|
|
{
|
2018-11-30 14:47:55 +08:00
|
|
|
|
double amount = e.ShiftPressed ? 2 : 1;
|
2018-11-30 13:57:25 +08:00
|
|
|
|
|
|
|
|
|
if (direction < 1)
|
|
|
|
|
clock.SeekBackward(!clock.IsRunning, amount);
|
|
|
|
|
else
|
|
|
|
|
clock.SeekForward(!clock.IsRunning, amount);
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|