1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 10:52:53 +08:00

Move MenuMusic logic to MainMenu

This commit is contained in:
ColdVolcano 2017-04-23 00:36:23 -05:00
parent ca1f89f2cf
commit 094a0f9639
2 changed files with 36 additions and 24 deletions

View File

@ -74,17 +74,6 @@ namespace osu.Game.Screens.Menu
{
menuVoice = config.GetBindable<bool>(OsuConfig.MenuVoice);
menuMusic = config.GetBindable<bool>(OsuConfig.MenuMusic);
if (!menuMusic)
{
trackManager = game.Audio.Track;
choosableBeatmapsetAmmout = beatmaps.Query<BeatmapSetInfo>().Count();
if (choosableBeatmapsetAmmout > 0)
{
beatmap = beatmaps.GetWithChildren<BeatmapSetInfo>(RNG.Next(1, choosableBeatmapsetAmmout)).Beatmaps[0];
song = beatmaps.GetWorkingBeatmap(beatmap);
Beatmap = song;
}
}
bgm = audio.Track.Get(@"circles");
bgm.Looping = true;
@ -105,23 +94,11 @@ namespace osu.Game.Screens.Menu
{
if(menuMusic)
bgm.Start();
else if (song != null)
{
Task.Run(() =>
{
trackManager.SetExclusive(song.Track);
song.Track.Seek(beatmap.Metadata.PreviewTime);
if (beatmap.Metadata.PreviewTime == -1)
song.Track.Seek(song.Track.Length * .4f);
});
}
LoadComponentAsync(mainMenu = new MainMenu());
Scheduler.AddDelayed(delegate
{
if (!menuMusic && song != null)
Task.Run(() => song.Track.Start());
DidLoadMenu = true;
Push(mainMenu);
}, 2300);

View File

@ -2,8 +2,14 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.MathUtils;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Database;
using osu.Game.Graphics.Containers;
using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Charts;
@ -15,6 +21,7 @@ using osu.Game.Screens.Select;
using osu.Game.Screens.Tournament;
using osu.Framework.Input;
using OpenTK.Input;
using System.Threading.Tasks;
namespace osu.Game.Screens.Menu
{
@ -54,11 +61,30 @@ namespace osu.Game.Screens.Menu
};
}
private Bindable<bool> menuMusic;
private TrackManager trackManager;
private BeatmapInfo beatmap;
private WorkingBeatmap song;
private int choosableBeatmapsetAmmout;
[BackgroundDependencyLoader]
private void load(OsuGame game)
private void load(OsuGame game, OsuConfigManager config, BeatmapDatabase beatmaps)
{
menuMusic = config.GetBindable<bool>(OsuConfig.MenuMusic);
LoadComponentAsync(background);
if (!menuMusic)
{
trackManager = game.Audio.Track;
choosableBeatmapsetAmmout = beatmaps.Query<BeatmapSetInfo>().Count();
if (choosableBeatmapsetAmmout > 0)
{
beatmap = beatmaps.GetWithChildren<BeatmapSetInfo>(RNG.Next(1, choosableBeatmapsetAmmout)).Beatmaps[0];
song = beatmaps.GetWorkingBeatmap(beatmap);
Beatmap = song;
}
}
buttons.OnSettings = game.ToggleOptions;
preloadSongSelect();
@ -81,6 +107,15 @@ namespace osu.Game.Screens.Menu
{
base.OnEntering(last);
buttons.FadeInFromZero(500);
if(last is Intro && song != null)
Task.Run(() =>
{
trackManager.SetExclusive(song.Track);
song.Track.Seek(beatmap.Metadata.PreviewTime);
if (beatmap.Metadata.PreviewTime == -1)
song.Track.Seek(song.Track.Length * .4f);
song.Track.Start();
});
}
protected override void OnSuspending(Screen next)