1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 21:47:25 +08:00
osu-lazer/osu.Game/Screens/Edit/Editor.cs

204 lines
7.9 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-09-29 19:13:58 +08:00
using OpenTK.Graphics;
2017-02-17 17:59:30 +08:00
using osu.Framework.Screens;
2016-11-14 16:23:33 +08:00
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.Menus;
2017-09-26 14:45:27 +08:00
using osu.Game.Screens.Edit.Components.Timelines.Summary;
using osu.Framework.Allocation;
2017-10-06 23:51:30 +08:00
using osu.Framework.Graphics.UserInterface;
2018-03-15 16:19:47 +08:00
using osu.Framework.Timing;
2017-10-06 23:51:30 +08:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Screens.Edit.Screens;
2017-10-02 09:09:21 +08:00
using osu.Game.Screens.Edit.Screens.Compose;
2017-10-04 18:24:19 +08:00
using osu.Game.Screens.Edit.Screens.Design;
using osu.Game.Screens.Edit.Components;
2016-09-29 19:13:58 +08:00
2016-11-14 16:23:33 +08:00
namespace osu.Game.Screens.Edit
2016-09-29 19:13:58 +08:00
{
public class Editor : OsuScreen
2016-09-29 19:13:58 +08:00
{
2017-02-17 17:59:30 +08:00
protected override BackgroundScreen CreateBackground() => new BackgroundScreenCustom(@"Backgrounds/bg4");
2016-10-05 19:03:52 +08:00
public override bool ShowOverlaysOnEnter => false;
2018-03-15 16:10:08 +08:00
private Box bottomBackground;
private Container screenContainer;
private EditorScreen currentScreen;
2018-03-19 15:27:52 +08:00
private DependencyContainer dependencies;
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
=> dependencies = new DependencyContainer(parent);
2018-03-15 16:19:47 +08:00
2018-03-15 16:10:08 +08:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
2018-03-15 16:19:47 +08:00
// TODO: should probably be done at a RulesetContainer level to share logic with Player.
var sourceClock = (IAdjustableClock)Beatmap.Value.Track ?? new StopwatchClock();
2018-03-19 15:27:52 +08:00
var adjustableClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false };
2018-03-15 16:19:47 +08:00
adjustableClock.ChangeSource(sourceClock);
2018-03-19 15:27:52 +08:00
dependencies.CacheAs<IAdjustableClock>(adjustableClock);
dependencies.CacheAs<IFrameBasedClock>(adjustableClock);
2017-10-02 08:26:16 +08:00
EditorMenuBar menuBar;
TimeInfoContainer timeInfo;
2017-10-02 08:26:16 +08:00
SummaryTimeline timeline;
PlaybackControl playback;
2017-10-02 08:26:16 +08:00
Children = new[]
{
new Container
{
Name = "Screen container",
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = 40, Bottom = 60 },
Child = screenContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Masking = true
}
},
2017-10-02 08:26:16 +08:00
new Container
{
2017-10-02 08:26:16 +08:00
Name = "Top bar",
RelativeSizeAxes = Axes.X,
Height = 40,
Child = menuBar = new EditorMenuBar
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
2017-10-06 23:51:30 +08:00
RelativeSizeAxes = Axes.Both,
Items = new[]
{
new MenuItem("File")
{
Items = new[]
{
new EditorMenuItem("Export", MenuItemType.Standard, exportBeatmap),
2017-12-21 18:57:09 +08:00
new EditorMenuItemSpacer(),
2017-10-06 23:51:30 +08:00
new EditorMenuItem("Exit", MenuItemType.Standard, Exit)
}
}
}
}
2017-10-02 08:26:16 +08:00
},
new Container
2017-09-20 16:09:38 +08:00
{
2017-10-02 08:26:16 +08:00
Name = "Bottom bar",
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
Height = 60,
Children = new Drawable[]
{
2017-10-02 08:26:16 +08:00
bottomBackground = new Box { RelativeSizeAxes = Axes.Both },
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Vertical = 5, Horizontal = 10 },
Child = new GridContainer
{
RelativeSizeAxes = Axes.Both,
2017-11-18 08:09:09 +08:00
ColumnDimensions = new[]
{
2017-11-21 16:51:07 +08:00
new Dimension(GridSizeMode.Absolute, 220),
2017-11-18 06:51:23 +08:00
new Dimension(),
2017-11-21 16:51:07 +08:00
new Dimension(GridSizeMode.Absolute, 220)
},
2017-11-18 08:09:09 +08:00
Content = new[]
{
new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Right = 10 },
2018-03-19 15:27:52 +08:00
Child = timeInfo = new TimeInfoContainer { RelativeSizeAxes = Axes.Both },
2017-11-18 08:09:09 +08:00
},
2018-03-19 15:27:52 +08:00
timeline = new SummaryTimeline
{
RelativeSizeAxes = Axes.Both,
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = 10 },
2018-03-19 15:27:52 +08:00
Child = playback = new PlaybackControl { RelativeSizeAxes = Axes.Both },
}
},
}
},
}
}
2017-10-02 08:26:16 +08:00
},
};
timeInfo.Beatmap.BindTo(Beatmap);
2017-10-02 08:26:16 +08:00
timeline.Beatmap.BindTo(Beatmap);
playback.Beatmap.BindTo(Beatmap);
menuBar.Mode.ValueChanged += onModeChanged;
2017-09-20 16:09:38 +08:00
bottomBackground.Colour = colours.Gray2;
2018-03-15 16:10:08 +08:00
}
private void exportBeatmap()
{
Beatmap.Value.Save();
}
private void onModeChanged(EditorScreenMode mode)
{
currentScreen?.Exit();
switch (mode)
{
2017-10-02 09:09:21 +08:00
case EditorScreenMode.Compose:
2018-03-19 15:27:52 +08:00
currentScreen = new Compose();
2017-10-02 09:09:21 +08:00
break;
2017-10-04 18:24:19 +08:00
case EditorScreenMode.Design:
currentScreen = new Design();
break;
default:
currentScreen = new EditorScreen();
break;
}
2017-10-04 14:02:11 +08:00
currentScreen.Beatmap.BindTo(Beatmap);
2017-10-02 08:27:27 +08:00
screenContainer.Add(currentScreen);
}
protected override void OnResuming(Screen last)
{
2017-07-19 12:32:16 +08:00
Beatmap.Value.Track?.Stop();
base.OnResuming(last);
}
2017-02-17 17:59:30 +08:00
protected override void OnEntering(Screen last)
2016-10-05 19:03:52 +08:00
{
base.OnEntering(last);
2017-06-08 13:51:22 +08:00
Background.FadeColour(Color4.DarkGray, 500);
2017-07-19 12:32:16 +08:00
Beatmap.Value.Track?.Stop();
2016-10-05 19:03:52 +08:00
}
2017-02-17 17:59:30 +08:00
protected override bool OnExiting(Screen next)
2016-10-05 19:03:52 +08:00
{
2017-06-08 13:51:22 +08:00
Background.FadeColour(Color4.White, 500);
if (Beatmap.Value.Track != null)
{
Beatmap.Value.Track.Tempo.Value = 1;
Beatmap.Value.Track.Start();
}
return base.OnExiting(next);
2016-10-05 19:03:52 +08:00
}
2016-09-29 19:13:58 +08:00
}
}