1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 19:17:25 +08:00
osu-lazer/osu.Game/Screens/Select/PlaySongSelect.cs

135 lines
4.3 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
2017-03-14 18:38:06 +08:00
using OpenTK.Input;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
2017-03-14 18:38:06 +08:00
using osu.Game.Graphics;
using osu.Game.Overlays.Mods;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Play;
2017-04-11 13:01:47 +08:00
using osu.Game.Screens.Ranking;
namespace osu.Game.Screens.Select
{
public class PlaySongSelect : SongSelect
{
private OsuScreen player;
private readonly ModSelectOverlay modSelect;
2017-03-23 13:29:23 +08:00
private readonly BeatmapDetailArea beatmapDetails;
2017-08-04 15:34:11 +08:00
private bool removeAutoModOnResume;
2017-03-14 18:38:06 +08:00
2017-03-15 10:10:59 +08:00
public PlaySongSelect()
2017-03-14 18:38:06 +08:00
{
FooterPanels.Add(modSelect = new ModSelectOverlay
2017-03-14 18:38:06 +08:00
{
RelativeSizeAxes = Axes.X,
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre,
});
2017-03-15 16:11:08 +08:00
2017-03-23 12:19:29 +08:00
LeftContent.Add(beatmapDetails = new BeatmapDetailArea
2017-03-15 16:11:08 +08:00
{
RelativeSizeAxes = Axes.Both,
2017-03-23 15:36:52 +08:00
Padding = new MarginPadding { Top = 10, Right = 5 },
2017-03-15 16:11:08 +08:00
});
2017-04-11 13:01:47 +08:00
beatmapDetails.Leaderboard.ScoreSelected += s => Push(new Results(s));
2017-03-14 21:51:26 +08:00
}
2017-03-14 18:38:06 +08:00
2017-03-14 21:51:26 +08:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
2017-03-14 21:51:26 +08:00
{
Footer.AddButton(@"mods", colours.Yellow, modSelect, Key.F1, float.MaxValue);
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);
BeatmapOptions.AddButton(@"Edit", @"Beatmap", FontAwesome.fa_pencil, colours.Yellow, () =>
{
ValidForResume = false;
Push(new Editor());
}, Key.Number3);
2017-03-14 18:38:06 +08:00
}
protected override void UpdateBeatmap(WorkingBeatmap beatmap)
2017-03-14 18:38:06 +08:00
{
base.UpdateBeatmap(beatmap);
2017-03-15 16:11:08 +08:00
beatmap.Mods.BindTo(modSelect.SelectedMods);
2017-05-22 00:00:31 +08:00
beatmapDetails.Beatmap = beatmap;
2017-05-22 00:00:31 +08:00
if (beatmap.Track != null)
2017-05-22 00:16:54 +08:00
beatmap.Track.Looping = true;
}
protected override void OnResuming(Screen last)
{
player = null;
2017-05-22 03:33:54 +08:00
2017-08-04 15:34:11 +08:00
if (removeAutoModOnResume)
{
var autoType = Ruleset.Value.CreateInstance().GetAutoplayMod().GetType();
modSelect.SelectedMods.Value = modSelect.SelectedMods.Value.Where(m => m.GetType() != autoType).ToArray();
2017-08-04 16:20:05 +08:00
removeAutoModOnResume = false;
2017-08-04 15:34:11 +08:00
}
2017-07-19 12:32:16 +08:00
Beatmap.Value.Track.Looping = true;
base.OnResuming(last);
}
protected override void OnSuspending(Screen next)
{
modSelect.Hide();
base.OnSuspending(next);
}
protected override bool OnExiting(Screen next)
{
if (modSelect.State == Visibility.Visible)
{
modSelect.Hide();
return true;
}
if (base.OnExiting(next))
return true;
2017-05-21 22:13:20 +08:00
if (Beatmap.Value.Track != null)
2017-07-19 12:32:16 +08:00
Beatmap.Value.Track.Looping = false;
return false;
}
2017-08-04 00:09:41 +08:00
protected override void OnSelected(InputState state)
{
if (player != null) return;
2017-08-04 00:09:41 +08:00
if (state?.Keyboard.ControlPressed == true)
2017-08-04 00:25:24 +08:00
{
var auto = Ruleset.Value.CreateInstance().GetAutoplayMod();
var autoType = auto.GetType();
2017-08-04 15:34:11 +08:00
var mods = modSelect.SelectedMods.Value;
if (mods.All(m => m.GetType() != autoType))
{
modSelect.SelectedMods.Value = mods.Concat(new[] { auto });
removeAutoModOnResume = true;
}
2017-08-04 00:25:24 +08:00
}
2017-07-19 12:32:16 +08:00
Beatmap.Value.Track.Looping = false;
Beatmap.Disabled = true;
2017-07-19 12:32:16 +08:00
LoadComponentAsync(player = new PlayerLoader(new Player()), l => Push(player));
}
}
}