mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 02:32:55 +08:00
Add beatmap panel to multiplayer match screen (#5643)
Add beatmap panel to multiplayer match screen Co-authored-by: Dean Herbert <pe@ppy.sh> Co-authored-by: Dan Balasescu <smoogipoo@smgi.me>
This commit is contained in:
commit
42464acd7e
@ -0,0 +1,53 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Screens.Multi.Match.Components;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.MathUtils;
|
||||
using osu.Game.Audio;
|
||||
using osu.Framework.Allocation;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
[Cached(typeof(IPreviewTrackOwner))]
|
||||
public class TestSceneMatchBeatmapPanel : MultiplayerTestScene, IPreviewTrackOwner
|
||||
{
|
||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||
{
|
||||
typeof(MatchBeatmapPanel)
|
||||
};
|
||||
|
||||
[Resolved]
|
||||
private PreviewTrackManager previewTrackManager { get; set; }
|
||||
|
||||
public TestSceneMatchBeatmapPanel()
|
||||
{
|
||||
Add(new MatchBeatmapPanel
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
});
|
||||
|
||||
Room.Playlist.Add(new PlaylistItem { Beatmap = new BeatmapInfo { OnlineBeatmapID = 1763072 } });
|
||||
Room.Playlist.Add(new PlaylistItem { Beatmap = new BeatmapInfo { OnlineBeatmapID = 2101557 } });
|
||||
Room.Playlist.Add(new PlaylistItem { Beatmap = new BeatmapInfo { OnlineBeatmapID = 1973466 } });
|
||||
Room.Playlist.Add(new PlaylistItem { Beatmap = new BeatmapInfo { OnlineBeatmapID = 2109801 } });
|
||||
Room.Playlist.Add(new PlaylistItem { Beatmap = new BeatmapInfo { OnlineBeatmapID = 1922035 } });
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
AddStep("Select random beatmap", () =>
|
||||
{
|
||||
Room.CurrentItem.Value = Room.Playlist[RNG.Next(Room.Playlist.Count)];
|
||||
previewTrackManager.StopAnyPlaying(this);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
typeof(Info),
|
||||
typeof(HeaderButton),
|
||||
typeof(ReadyButton),
|
||||
typeof(ViewBeatmapButton)
|
||||
typeof(MatchBeatmapPanel)
|
||||
};
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
|
@ -25,10 +25,14 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
{
|
||||
public const float HEIGHT = 200;
|
||||
|
||||
public MatchTabControl Tabs;
|
||||
public readonly BindableBool ShowBeatmapPanel = new BindableBool();
|
||||
|
||||
public MatchTabControl Tabs { get; private set; }
|
||||
|
||||
public Action RequestBeatmapSelection;
|
||||
|
||||
private MatchBeatmapPanel beatmapPanel;
|
||||
|
||||
public Header()
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
@ -53,8 +57,14 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = ColourInfo.GradientVertical(Color4.Black.Opacity(0.4f), Color4.Black.Opacity(0.6f)),
|
||||
Colour = ColourInfo.GradientVertical(Color4.Black.Opacity(0.7f), Color4.Black.Opacity(0.8f)),
|
||||
},
|
||||
beatmapPanel = new MatchBeatmapPanel
|
||||
{
|
||||
Anchor = Anchor.CentreRight,
|
||||
Origin = Anchor.CentreRight,
|
||||
Margin = new MarginPadding { Right = 100 },
|
||||
}
|
||||
}
|
||||
},
|
||||
new Box
|
||||
@ -114,6 +124,12 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
beatmapButton.Action = () => RequestBeatmapSelection?.Invoke();
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
ShowBeatmapPanel.BindValueChanged(value => beatmapPanel.FadeTo(value.NewValue ? 1 : 0, 200, Easing.OutQuint), true);
|
||||
}
|
||||
|
||||
private class BeatmapSelectButton : HeaderButton
|
||||
{
|
||||
[Resolved(typeof(Room), nameof(Room.RoomID))]
|
||||
|
@ -28,7 +28,6 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
private void load()
|
||||
{
|
||||
ReadyButton readyButton;
|
||||
ViewBeatmapButton viewBeatmapButton;
|
||||
HostInfo hostInfo;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
@ -80,7 +79,6 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
Direction = FillDirection.Horizontal,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
viewBeatmapButton = new ViewBeatmapButton(),
|
||||
readyButton = new ReadyButton
|
||||
{
|
||||
Action = () => OnStart?.Invoke()
|
||||
@ -91,11 +89,7 @@ namespace osu.Game.Screens.Multi.Match.Components
|
||||
},
|
||||
};
|
||||
|
||||
CurrentItem.BindValueChanged(item =>
|
||||
{
|
||||
viewBeatmapButton.Beatmap.Value = item.NewValue?.Beatmap;
|
||||
readyButton.Beatmap.Value = item.NewValue?.Beatmap;
|
||||
}, true);
|
||||
CurrentItem.BindValueChanged(item => readyButton.Beatmap.Value = item.NewValue?.Beatmap, true);
|
||||
|
||||
hostInfo.Host.BindTo(Host);
|
||||
}
|
||||
|
62
osu.Game/Screens/Multi/Match/Components/MatchBeatmapPanel.cs
Normal file
62
osu.Game/Screens/Multi/Match/Components/MatchBeatmapPanel.cs
Normal file
@ -0,0 +1,62 @@
|
||||
// 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.
|
||||
|
||||
using System.Threading;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Overlays.Direct;
|
||||
using osu.Game.Rulesets;
|
||||
|
||||
namespace osu.Game.Screens.Multi.Match.Components
|
||||
{
|
||||
public class MatchBeatmapPanel : MultiplayerComposite
|
||||
{
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private RulesetStore rulesets { get; set; }
|
||||
|
||||
private CancellationTokenSource loadCancellation;
|
||||
private GetBeatmapSetRequest request;
|
||||
private DirectGridPanel panel;
|
||||
|
||||
public MatchBeatmapPanel()
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
CurrentItem.BindValueChanged(item => loadNewPanel(item.NewValue?.Beatmap), true);
|
||||
}
|
||||
|
||||
private void loadNewPanel(BeatmapInfo beatmap)
|
||||
{
|
||||
loadCancellation?.Cancel();
|
||||
request?.Cancel();
|
||||
|
||||
panel?.FadeOut(200);
|
||||
panel?.Expire();
|
||||
panel = null;
|
||||
|
||||
if (beatmap?.OnlineBeatmapID == null)
|
||||
return;
|
||||
|
||||
loadCancellation = new CancellationTokenSource();
|
||||
|
||||
request = new GetBeatmapSetRequest(beatmap.OnlineBeatmapID.Value, BeatmapSetLookupType.BeatmapId);
|
||||
request.Success += res => Schedule(() =>
|
||||
{
|
||||
panel = new DirectGridPanel(res.ToBeatmapSet(rulesets));
|
||||
LoadComponentAsync(panel, AddInternal, loadCancellation.Token);
|
||||
});
|
||||
|
||||
api.Queue(request);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
// 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.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Beatmaps;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Multi.Match.Components
|
||||
{
|
||||
public class ViewBeatmapButton : HeaderButton
|
||||
{
|
||||
public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private OsuGame osuGame { get; set; }
|
||||
|
||||
public ViewBeatmapButton()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Y;
|
||||
Size = new Vector2(200, 1);
|
||||
|
||||
Text = "View beatmap";
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
if (osuGame != null)
|
||||
Beatmap.BindValueChanged(beatmap => updateAction(beatmap.NewValue), true);
|
||||
}
|
||||
|
||||
private void updateAction(BeatmapInfo beatmap)
|
||||
{
|
||||
if (beatmap == null)
|
||||
{
|
||||
Enabled.Value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
Action = () => osuGame.ShowBeatmap(beatmap.OnlineBeatmapID ?? 0);
|
||||
Enabled.Value = true;
|
||||
}
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Audio;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Multiplayer.GameTypes;
|
||||
@ -18,7 +19,8 @@ using PlaylistItem = osu.Game.Online.Multiplayer.PlaylistItem;
|
||||
|
||||
namespace osu.Game.Screens.Multi.Match
|
||||
{
|
||||
public class MatchSubScreen : MultiplayerSubScreen
|
||||
[Cached(typeof(IPreviewTrackOwner))]
|
||||
public class MatchSubScreen : MultiplayerSubScreen, IPreviewTrackOwner
|
||||
{
|
||||
public override bool DisallowExternalBeatmapRulesetChanges => true;
|
||||
|
||||
@ -44,6 +46,9 @@ namespace osu.Game.Screens.Multi.Match
|
||||
[Resolved]
|
||||
private BeatmapManager beatmapManager { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private PreviewTrackManager previewTrackManager { get; set; }
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private OsuGame game { get; set; }
|
||||
|
||||
@ -146,18 +151,12 @@ namespace osu.Game.Screens.Multi.Match
|
||||
{
|
||||
const float fade_duration = 500;
|
||||
|
||||
if (tab.NewValue is SettingsMatchPage)
|
||||
{
|
||||
settings.Show();
|
||||
info.FadeOut(fade_duration, Easing.OutQuint);
|
||||
bottomRow.FadeOut(fade_duration, Easing.OutQuint);
|
||||
}
|
||||
else
|
||||
{
|
||||
settings.Hide();
|
||||
info.FadeIn(fade_duration, Easing.OutQuint);
|
||||
bottomRow.FadeIn(fade_duration, Easing.OutQuint);
|
||||
}
|
||||
var settingsDisplayed = tab.NewValue is SettingsMatchPage;
|
||||
|
||||
header.ShowBeatmapPanel.Value = !settingsDisplayed;
|
||||
settings.State.Value = settingsDisplayed ? Visibility.Visible : Visibility.Hidden;
|
||||
info.FadeTo(settingsDisplayed ? 0 : 1, fade_duration, Easing.OutQuint);
|
||||
bottomRow.FadeTo(settingsDisplayed ? 0 : 1, fade_duration, Easing.OutQuint);
|
||||
}, true);
|
||||
|
||||
chat.Exit += () =>
|
||||
@ -179,8 +178,8 @@ namespace osu.Game.Screens.Multi.Match
|
||||
public override bool OnExiting(IScreen next)
|
||||
{
|
||||
RoomManager?.PartRoom();
|
||||
|
||||
Mods.Value = Array.Empty<Mod>();
|
||||
previewTrackManager.StopAnyPlaying(this);
|
||||
|
||||
return base.OnExiting(next);
|
||||
}
|
||||
@ -198,6 +197,8 @@ namespace osu.Game.Screens.Multi.Match
|
||||
|
||||
if (e.NewValue?.Ruleset != null)
|
||||
Ruleset.Value = e.NewValue.Ruleset;
|
||||
|
||||
previewTrackManager.StopAnyPlaying(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -223,6 +224,8 @@ namespace osu.Game.Screens.Multi.Match
|
||||
|
||||
private void onStart()
|
||||
{
|
||||
previewTrackManager.StopAnyPlaying(this);
|
||||
|
||||
switch (type.Value)
|
||||
{
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user