1
0
mirror of https://github.com/ppy/osu.git synced 2026-06-05 17:54:14 +08:00

Add playlists/multiplayer versions of RoomPanel

This commit is contained in:
Dan Balasescu
2025-03-19 15:22:13 +09:00
Unverified
parent 36e78119ae
commit ec0f8142c2
7 changed files with 126 additions and 118 deletions
@@ -330,10 +330,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddUntilStep("wait for join", () => RoomJoined);
AddUntilStep("button visible", () => this.ChildrenOfType<MatchRoomPanel>().Single().ChangeSettingsButton?.Alpha, () => Is.GreaterThan(0));
AddUntilStep("button visible", () => this.ChildrenOfType<MultiplayerRoomPanel>().Single().ChangeSettingsButton?.Alpha, () => Is.GreaterThan(0));
AddStep("join other user", void () => MultiplayerClient.AddUser(new APIUser { Id = PLAYER_1_ID }));
AddStep("make other user host", () => MultiplayerClient.TransferHost(PLAYER_1_ID));
AddAssert("button hidden", () => this.ChildrenOfType<MatchRoomPanel>().Single().ChangeSettingsButton?.Alpha, () => Is.EqualTo(0));
AddAssert("button hidden", () => this.ChildrenOfType<MultiplayerRoomPanel>().Single().ChangeSettingsButton?.Alpha, () => Is.EqualTo(0));
}
private partial class TestMultiplayerMatchSubScreen : MultiplayerMatchSubScreen
@@ -18,6 +18,7 @@ using osu.Game.Overlays;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.OnlinePlay.Lounge;
using osu.Game.Screens.OnlinePlay.Lounge.Components;
using osu.Game.Screens.OnlinePlay.Multiplayer;
using osu.Game.Tests.Beatmaps;
using osuTK;
@@ -159,33 +160,24 @@ namespace osu.Game.Tests.Visual.Multiplayer
Spacing = new Vector2(5),
Children = new[]
{
new MatchRoomPanel(new Room
new MultiplayerRoomPanel(new Room
{
Name = "A host-only room",
QueueMode = QueueMode.HostOnly,
Type = MatchType.HeadToHead,
})
{
SelectedItem = new Bindable<PlaylistItem?>()
},
new MatchRoomPanel(new Room
}),
new MultiplayerRoomPanel(new Room
{
Name = "An all-players, team-versus room",
QueueMode = QueueMode.AllPlayers,
Type = MatchType.TeamVersus
})
{
SelectedItem = new Bindable<PlaylistItem?>()
},
new MatchRoomPanel(new Room
}),
new MultiplayerRoomPanel(new Room
{
Name = "A round-robin room",
QueueMode = QueueMode.AllPlayersRoundRobin,
Type = MatchType.HeadToHead
})
{
SelectedItem = new Bindable<PlaylistItem?>()
},
}),
}
});
}
@@ -1,92 +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 System;
using System.ComponentModel;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Online.API;
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Lounge.Components;
using osu.Game.Screens.OnlinePlay.Match.Components;
using osuTK;
namespace osu.Game.Screens.OnlinePlay.Match
{
public partial class MatchRoomPanel : RoomPanel
{
public Action? OnEdit;
public new required Bindable<PlaylistItem?> SelectedItem
{
get => selectedItem;
set => selectedItem.Current = value;
}
public Drawable? ChangeSettingsButton { get; private set; }
[Resolved]
private IAPIProvider api { get; set; } = null!;
private readonly BindableWithCurrent<PlaylistItem?> selectedItem = new BindableWithCurrent<PlaylistItem?>();
private readonly bool allowEdit;
public MatchRoomPanel(Room room, bool allowEdit = true)
: base(room)
{
this.allowEdit = allowEdit;
base.SelectedItem.BindTo(SelectedItem);
}
[BackgroundDependencyLoader]
private void load()
{
if (allowEdit)
{
ButtonsContainer.Add(ChangeSettingsButton = new PurpleRoundedButton
{
RelativeSizeAxes = Axes.Y,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(120, 0.7f),
Text = "Change settings",
Action = () => OnEdit?.Invoke()
});
}
}
protected override void LoadComplete()
{
base.LoadComplete();
Room.PropertyChanged += onRoomPropertyChanged;
updateRoomHost();
}
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Room.Host))
updateRoomHost();
}
private void updateRoomHost()
{
if (ChangeSettingsButton != null)
ChangeSettingsButton.Alpha = Room.Host?.Equals(api.LocalUser.Value) == true ? 1 : 0;
}
protected override UpdateableBeatmapBackgroundSprite CreateBackground() => base.CreateBackground().With(d =>
{
d.BackgroundLoadDelay = 0;
});
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
Room.PropertyChanged -= onRoomPropertyChanged;
}
}
}
@@ -100,7 +100,6 @@ namespace osu.Game.Screens.OnlinePlay.Match
protected IBindable<BeatmapAvailability> BeatmapAvailability => beatmapAvailabilityTracker.Availability;
public readonly Room Room;
private readonly bool allowEdit;
internal ModSelectOverlay UserModsSelectOverlay { get; private set; } = null!;
@@ -112,12 +111,9 @@ namespace osu.Game.Screens.OnlinePlay.Match
/// Creates a new <see cref="RoomSubScreen"/>.
/// </summary>
/// <param name="room">The <see cref="Room"/>.</param>
/// <param name="allowEdit">Whether to allow editing room settings post-creation.</param>
protected RoomSubScreen(Room room, bool allowEdit = true)
protected RoomSubScreen(Room room)
{
Room = room;
this.allowEdit = allowEdit;
Padding = new MarginPadding { Top = Header.HEIGHT };
}
@@ -172,10 +168,9 @@ namespace osu.Game.Screens.OnlinePlay.Match
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Child = new MatchRoomPanel(Room, allowEdit)
Child = new MultiplayerRoomPanel(Room)
{
OnEdit = () => settingsOverlay.Show(),
SelectedItem = SelectedItem
}
}
},
@@ -0,0 +1,78 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Lounge.Components;
using osu.Game.Screens.OnlinePlay.Match.Components;
using osuTK;
namespace osu.Game.Screens.OnlinePlay.Multiplayer
{
/// <summary>
/// A <see cref="RoomPanel"/> to be displayed in a multiplayer lobby.
/// </summary>
public partial class MultiplayerRoomPanel : RoomPanel
{
public Action? OnEdit { get; set; }
public Drawable ChangeSettingsButton { get; private set; } = null!;
[Resolved]
private MultiplayerClient client { get; set; } = null!;
public MultiplayerRoomPanel(Room room)
: base(room)
{
}
[BackgroundDependencyLoader]
private void load()
{
ButtonsContainer.Add(ChangeSettingsButton = new PurpleRoundedButton
{
RelativeSizeAxes = Axes.Y,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(120, 0.7f),
Text = "Change settings",
Action = () => OnEdit?.Invoke()
});
}
protected override void LoadComplete()
{
base.LoadComplete();
client.RoomUpdated += onRoomUpdated;
onRoomUpdated();
}
private void onRoomUpdated() => Scheduler.AddOnce(() =>
{
if (client.Room == null || client.LocalUser == null)
return;
ChangeSettingsButton.Alpha = client.IsHost ? 1 : 0;
SelectedItem.Value = new PlaylistItem(client.Room.CurrentPlaylistItem);
});
protected override UpdateableBeatmapBackgroundSprite CreateBackground() => base.CreateBackground().With(d =>
{
d.BackgroundLoadDelay = 0;
});
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (client.IsNotNull())
client.RoomUpdated -= onRoomUpdated;
}
}
}
@@ -0,0 +1,36 @@
// 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.Bindables;
using osu.Framework.Graphics;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Lounge.Components;
namespace osu.Game.Screens.OnlinePlay.Playlists
{
/// <summary>
/// A <see cref="RoomPanel"/> to be displayed in a playlists lobby.
/// </summary>
public partial class PlaylistsRoomPanel : RoomPanel
{
public new required Bindable<PlaylistItem?> SelectedItem
{
get => selectedItem.Current;
set => selectedItem.Current = value;
}
private readonly BindableWithCurrent<PlaylistItem?> selectedItem = new BindableWithCurrent<PlaylistItem?>();
public PlaylistsRoomPanel(Room room)
: base(room)
{
base.SelectedItem.BindTo(SelectedItem);
}
protected override UpdateableBeatmapBackgroundSprite CreateBackground() => base.CreateBackground().With(d =>
{
d.BackgroundLoadDelay = 0;
});
}
}
@@ -186,9 +186,8 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
{
new Drawable[]
{
new MatchRoomPanel(room, false)
new PlaylistsRoomPanel(room)
{
OnEdit = () => settingsOverlay.Show(),
SelectedItem = SelectedItem
}
},