osu/osu.Game/Screens/Select/PlaySongSelect.cs

163 lines
5.2 KiB
C#
Raw Normal View History

2018-04-13 09:19:50 +00:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using System.Linq;
2018-11-20 07:51:59 +00:00
using osuTK.Input;
2018-04-13 09:19:50 +00:00
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Overlays;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Play;
using osu.Game.Screens.Ranking;
2018-08-31 09:36:35 +00:00
using osu.Game.Skinning;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Screens.Select
{
public class PlaySongSelect : SongSelect
{
private OsuScreen player;
protected readonly BeatmapDetailArea BeatmapDetails;
private bool removeAutoModOnResume;
public PlaySongSelect()
{
LeftContent.Add(BeatmapDetails = new BeatmapDetailArea
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = 10, Right = 5 },
});
BeatmapDetails.Leaderboard.ScoreSelected += s => Push(new Results(s));
}
private SampleChannel sampleConfirm;
2018-08-08 03:26:57 +00:00
[Cached]
[Cached(Type = typeof(IBindable<IEnumerable<Mod>>))]
private readonly Bindable<IEnumerable<Mod>> selectedMods = new Bindable<IEnumerable<Mod>>(new Mod[] { });
2018-04-13 09:19:50 +00:00
[BackgroundDependencyLoader(true)]
2018-08-31 09:36:35 +00:00
private void load(OsuColour colours, AudioManager audio, BeatmapManager beatmaps, SkinManager skins, DialogOverlay dialogOverlay, Bindable<IEnumerable<Mod>> selectedMods)
2018-04-13 09:19:50 +00:00
{
if (selectedMods != null) this.selectedMods.BindTo(selectedMods);
2018-04-13 09:19:50 +00:00
2018-08-30 22:04:40 +00:00
sampleConfirm = audio.Sample.Get(@"SongSelect/confirm-selection");
2018-04-13 09:19:50 +00:00
BeatmapOptions.AddButton(@"Remove", @"from unplayed", FontAwesome.fa_times_circle_o, colours.Purple, null, Key.Number1);
BeatmapOptions.AddButton(@"Clear", @"local scores", FontAwesome.fa_eraser, colours.Purple, null, Key.Number2);
2018-09-15 14:30:11 +00:00
BeatmapOptions.AddButton(@"Edit", @"beatmap", FontAwesome.fa_pencil, colours.Yellow, () =>
2018-04-13 09:19:50 +00:00
{
ValidForResume = false;
Edit();
2018-04-13 09:19:50 +00:00
}, Key.Number3);
if (dialogOverlay != null)
{
Schedule(() =>
{
// if we have no beatmaps but osu-stable is found, let's prompt the user to import.
if (!beatmaps.GetAllUsableBeatmapSets().Any() && beatmaps.StableInstallationAvailable)
2018-08-31 09:36:35 +00:00
dialogOverlay.Push(new ImportFromStablePopup(() =>
{
beatmaps.ImportFromStableAsync();
skins.ImportFromStableAsync();
}));
2018-04-13 09:19:50 +00:00
});
}
}
protected override void ExitFromBack()
{
if (modSelect.State == Visibility.Visible)
2018-12-04 03:14:26 +00:00
{
modSelect.Hide();
2018-12-04 03:14:26 +00:00
return;
}
base.ExitFromBack();
}
2018-04-13 09:19:50 +00:00
protected override void UpdateBeatmap(WorkingBeatmap beatmap)
{
beatmap.Mods.BindTo(selectedMods);
2018-04-13 09:19:50 +00:00
base.UpdateBeatmap(beatmap);
2018-04-13 09:19:50 +00:00
BeatmapDetails.Beatmap = beatmap;
if (beatmap.Track != null)
beatmap.Track.Looping = true;
}
protected override void OnResuming(Screen last)
{
player = null;
if (removeAutoModOnResume)
{
var autoType = Ruleset.Value.CreateInstance().GetAutoplayMod().GetType();
2018-12-06 10:29:18 +00:00
ModSelect.DeselectTypes(new[] { autoType }, true);
2018-04-13 09:19:50 +00:00
removeAutoModOnResume = false;
}
BeatmapDetails.Leaderboard.RefreshScores();
2018-04-13 09:19:50 +00:00
Beatmap.Value.Track.Looping = true;
base.OnResuming(last);
}
protected override bool OnExiting(Screen next)
{
if (base.OnExiting(next))
return true;
if (Beatmap.Value.Track != null)
Beatmap.Value.Track.Looping = false;
selectedMods.UnbindAll();
2018-04-13 09:19:50 +00:00
Beatmap.Value.Mods.Value = new Mod[] { };
return false;
}
protected override bool OnStart()
2018-04-13 09:19:50 +00:00
{
if (player != null) return false;
// Ctrl+Enter should start map with autoplay enabled.
if (GetContainingInputManager().CurrentState?.Keyboard.ControlPressed == true)
{
var auto = Ruleset.Value.CreateInstance().GetAutoplayMod();
var autoType = auto.GetType();
var mods = selectedMods.Value;
2018-04-13 09:19:50 +00:00
if (mods.All(m => m.GetType() != autoType))
{
selectedMods.Value = mods.Append(auto);
2018-04-13 09:19:50 +00:00
removeAutoModOnResume = true;
}
}
Beatmap.Value.Track.Looping = false;
Beatmap.Disabled = true;
sampleConfirm?.Play();
LoadComponentAsync(player = new PlayerLoader(new Player()), l =>
{
if (IsCurrentScreen) Push(player);
});
return true;
}
}
}