2020-12-20 15:04:06 +00: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.
|
|
|
|
|
2021-02-01 06:06:50 +00:00
|
|
|
using System;
|
2020-12-28 11:32:06 +00:00
|
|
|
using System.Collections.Generic;
|
2021-02-01 06:06:50 +00:00
|
|
|
using System.Linq;
|
2020-12-20 15:37:13 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2021-01-27 13:15:53 +00:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2020-12-22 07:23:06 +00:00
|
|
|
using osu.Framework.Graphics;
|
2021-01-27 13:15:53 +00:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2020-12-22 07:50:30 +00:00
|
|
|
using osu.Framework.Logging;
|
2020-12-20 15:37:13 +00:00
|
|
|
using osu.Framework.Screens;
|
2021-01-27 13:15:53 +00:00
|
|
|
using osu.Game.Graphics;
|
2020-12-22 08:08:02 +00:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-12-20 15:37:13 +00:00
|
|
|
using osu.Game.Online.Multiplayer;
|
2020-12-25 04:38:11 +00:00
|
|
|
using osu.Game.Online.Rooms;
|
2020-12-28 11:32:06 +00:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2021-01-27 13:15:53 +00:00
|
|
|
using osu.Game.Screens.Play.HUD;
|
2020-12-20 15:04:06 +00:00
|
|
|
using osu.Game.Screens.Select;
|
2021-01-27 13:15:53 +00:00
|
|
|
using osuTK;
|
2020-12-20 15:04:06 +00:00
|
|
|
|
2020-12-25 15:50:00 +00:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
2020-12-20 15:04:06 +00:00
|
|
|
{
|
2021-02-01 05:57:39 +00:00
|
|
|
public class MultiplayerMatchSongSelect : OnlinePlaySongSelect
|
2020-12-20 15:04:06 +00:00
|
|
|
{
|
2020-12-20 15:37:13 +00:00
|
|
|
[Resolved]
|
|
|
|
private StatefulMultiplayerClient client { get; set; }
|
2020-12-20 15:04:06 +00:00
|
|
|
|
2020-12-22 08:08:02 +00:00
|
|
|
private LoadingLayer loadingLayer;
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2021-01-04 13:42:39 +00:00
|
|
|
AddInternal(loadingLayer = new LoadingLayer(true));
|
2020-12-22 08:08:02 +00:00
|
|
|
}
|
|
|
|
|
2021-02-01 06:06:50 +00:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
Mods.Value = Playlist.FirstOrDefault()?.RequiredMods.Select(m => m.CreateCopy()).ToArray() ?? Array.Empty<Mod>();
|
|
|
|
}
|
|
|
|
|
2021-02-01 05:57:39 +00:00
|
|
|
protected override void OnSetItem(PlaylistItem item)
|
2020-12-20 15:04:06 +00:00
|
|
|
{
|
2020-12-20 15:37:13 +00:00
|
|
|
// If the client is already in a room, update via the client.
|
|
|
|
// Otherwise, update the playlist directly in preparation for it to be submitted to the API on match creation.
|
|
|
|
if (client.Room != null)
|
2020-12-22 07:50:30 +00:00
|
|
|
{
|
2020-12-22 08:08:02 +00:00
|
|
|
loadingLayer.Show();
|
|
|
|
|
|
|
|
client.ChangeSettings(item: item).ContinueWith(t =>
|
2020-12-22 07:50:30 +00:00
|
|
|
{
|
2020-12-23 08:10:34 +00:00
|
|
|
Schedule(() =>
|
2020-12-22 08:08:02 +00:00
|
|
|
{
|
|
|
|
loadingLayer.Hide();
|
|
|
|
|
|
|
|
if (t.IsCompletedSuccessfully)
|
|
|
|
this.Exit();
|
|
|
|
else
|
2020-12-23 13:18:24 +00:00
|
|
|
{
|
2020-12-22 08:08:02 +00:00
|
|
|
Logger.Log($"Could not use current beatmap ({t.Exception?.Message})", level: LogLevel.Important);
|
2020-12-23 13:18:24 +00:00
|
|
|
Carousel.AllowSelection = true;
|
|
|
|
}
|
2020-12-22 08:08:02 +00:00
|
|
|
});
|
|
|
|
});
|
2020-12-22 07:50:30 +00:00
|
|
|
}
|
2020-12-20 15:37:13 +00:00
|
|
|
else
|
|
|
|
{
|
2021-02-01 05:57:39 +00:00
|
|
|
Playlist.Clear();
|
|
|
|
Playlist.Add(item);
|
2020-12-22 07:50:30 +00:00
|
|
|
this.Exit();
|
2020-12-20 15:37:13 +00:00
|
|
|
}
|
2020-12-28 11:32:06 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 15:37:13 +00:00
|
|
|
protected override BeatmapDetailArea CreateBeatmapDetailArea() => new PlayBeatmapDetailArea();
|
2020-12-20 15:04:06 +00:00
|
|
|
}
|
2021-01-27 13:15:53 +00:00
|
|
|
|
|
|
|
public class FooterButtonFreeMods : FooterButton, IHasCurrentValue<IReadOnlyList<Mod>>
|
|
|
|
{
|
|
|
|
public Bindable<IReadOnlyList<Mod>> Current
|
|
|
|
{
|
|
|
|
get => modDisplay.Current;
|
|
|
|
set => modDisplay.Current = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private readonly ModDisplay modDisplay;
|
|
|
|
|
|
|
|
public FooterButtonFreeMods()
|
|
|
|
{
|
|
|
|
ButtonContentContainer.Add(modDisplay = new ModDisplay
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
DisplayUnrankedText = false,
|
|
|
|
Scale = new Vector2(0.8f),
|
|
|
|
ExpansionMode = ExpansionMode.AlwaysContracted,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
SelectedColour = colours.Yellow;
|
|
|
|
DeselectedColour = SelectedColour.Opacity(0.5f);
|
|
|
|
Text = @"freemods";
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
Current.BindValueChanged(_ => updateModDisplay(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateModDisplay()
|
|
|
|
{
|
|
|
|
if (Current.Value?.Count > 0)
|
|
|
|
modDisplay.FadeIn();
|
|
|
|
else
|
|
|
|
modDisplay.FadeOut();
|
|
|
|
}
|
|
|
|
}
|
2020-12-20 15:04:06 +00:00
|
|
|
}
|