Pass room into RoomSettingsOverlay

This commit is contained in:
smoogipoo 2021-08-19 16:40:27 +09:00
parent 1fd746524d
commit c31af96f1d
7 changed files with 66 additions and 51 deletions

View File

@ -28,7 +28,7 @@ namespace osu.Game.Tests.Visual.Playlists
{
SelectedRoom.Value = new Room();
Child = settings = new TestRoomSettings
Child = settings = new TestRoomSettings(SelectedRoom.Value)
{
RelativeSizeAxes = Axes.Both,
State = { Value = Visibility.Visible }
@ -118,6 +118,11 @@ namespace osu.Game.Tests.Visual.Playlists
public OsuDropdown<TimeSpan> DurationField => ((MatchSettings)Settings).DurationField;
public OsuSpriteText ErrorText => ((MatchSettings)Settings).ErrorText;
public TestRoomSettings(Room room)
: base(room)
{
}
}
private class TestDependencies : OnlinePlayTestSceneDependencies

View File

@ -9,6 +9,7 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings;
using osu.Game.Online.Rooms;
using osuTK;
using osuTK.Graphics;
@ -27,8 +28,12 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
protected abstract bool IsLoading { get; }
protected RoomSettingsOverlay()
private readonly Room room;
protected RoomSettingsOverlay(Room room)
{
this.room = room;
RelativeSizeAxes = Axes.Both;
Masking = true;
CornerRadius = 10;
@ -37,12 +42,12 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
[BackgroundDependencyLoader]
private void load()
{
Add(Settings = CreateSettings());
Add(Settings = CreateSettings(room));
}
protected abstract void SelectBeatmap();
protected abstract OnlinePlayComposite CreateSettings();
protected abstract OnlinePlayComposite CreateSettings(Room room);
protected override void PopIn()
{

View File

@ -184,7 +184,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
RelativeSizeAxes = Axes.Both,
// Resolves 1px masking errors between the settings overlay and the room panel.
Padding = new MarginPadding(-1),
Child = settingsOverlay = CreateRoomSettingsOverlay()
Child = settingsOverlay = CreateRoomSettingsOverlay(Room)
}
},
},
@ -406,7 +406,8 @@ namespace osu.Game.Screens.OnlinePlay.Match
/// <summary>
/// Creates the room settings overlay.
/// </summary>
protected abstract RoomSettingsOverlay CreateRoomSettingsOverlay();
/// <param name="room"></param>
protected abstract RoomSettingsOverlay CreateRoomSettingsOverlay(Room room);
private class UserModSelectOverlay : LocalPlayerModSelectOverlay
{

View File

@ -37,15 +37,19 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
protected override bool IsLoading => ongoingOperationTracker.InProgress.Value;
public MultiplayerMatchSettingsOverlay(Room room)
: base(room)
{
}
protected override void SelectBeatmap() => settings.SelectBeatmap();
protected override OnlinePlayComposite CreateSettings()
=> settings = new MatchSettings
{
RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Y,
SettingsApplied = Hide
};
protected override OnlinePlayComposite CreateSettings(Room room) => settings = new MatchSettings(room)
{
RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Y,
SettingsApplied = Hide
};
protected class MatchSettings : OnlinePlayComposite
{
@ -73,9 +77,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
[Resolved]
private MultiplayerClient client { get; set; }
[Resolved]
private Bindable<Room> currentRoom { get; set; }
[Resolved]
private Bindable<WorkingBeatmap> beatmap { get; set; }
@ -90,6 +91,13 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
[CanBeNull]
private IDisposable applyingSettingsOperation;
private readonly Room room;
public MatchSettings(Room room)
{
this.room = room;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
@ -319,24 +327,24 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
client.ChangeSettings(name: NameField.Text, password: PasswordTextBox.Text, matchType: TypePicker.Current.Value).ContinueWith(t => Schedule(() =>
{
if (t.IsCompletedSuccessfully)
onSuccess(currentRoom.Value);
onSuccess(room);
else
onError(t.Exception?.AsSingular().Message ?? "Error changing settings.");
}));
}
else
{
currentRoom.Value.Name.Value = NameField.Text;
currentRoom.Value.Availability.Value = AvailabilityPicker.Current.Value;
currentRoom.Value.Type.Value = TypePicker.Current.Value;
currentRoom.Value.Password.Value = PasswordTextBox.Current.Value;
room.Name.Value = NameField.Text;
room.Availability.Value = AvailabilityPicker.Current.Value;
room.Type.Value = TypePicker.Current.Value;
room.Password.Value = PasswordTextBox.Current.Value;
if (int.TryParse(MaxParticipantsField.Text, out int max))
currentRoom.Value.MaxParticipants.Value = max;
room.MaxParticipants.Value = max;
else
currentRoom.Value.MaxParticipants.Value = null;
room.MaxParticipants.Value = null;
manager?.CreateRoom(currentRoom.Value, onSuccess, onError);
manager?.CreateRoom(room, onSuccess, onError);
}
}

View File

@ -48,9 +48,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
[Resolved]
private OngoingOperationTracker ongoingOperationTracker { get; set; }
[Resolved]
private Bindable<Room> currentRoom { get; set; } // Todo: This should not exist.
private readonly IBindable<bool> isConnected = new Bindable<bool>();
[CanBeNull]
@ -82,16 +79,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
handleRoomLost();
}, true);
currentRoom.BindValueChanged(room =>
{
if (room.NewValue == null)
{
// the room has gone away.
// this could mean something happened during the join process, or an external connection issue occurred.
// one specific scenario is where the underlying room is created, but the signalr server returns an error during the join process. this triggers a PartRoom operation (see https://github.com/ppy/osu/blob/7654df94f6f37b8382be7dfcb4f674e03bd35427/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomManager.cs#L97)
handleRoomLost();
}
}, true);
if (client.Room == null)
handleRoomLost();
}
protected override Drawable CreateMainContent() => new GridContainer
@ -223,7 +212,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
OnSpectateClick = onSpectateClick
};
protected override RoomSettingsOverlay CreateRoomSettingsOverlay() => new MultiplayerMatchSettingsOverlay();
protected override RoomSettingsOverlay CreateRoomSettingsOverlay(Room room) => new MultiplayerMatchSettingsOverlay(room);
protected override void UpdateMods()
{

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Specialized;
using Humanizer;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -32,15 +31,19 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
protected override bool IsLoading => settings.IsLoading; // should probably be replaced with an OngoingOperationTracker.
public PlaylistsRoomSettingsOverlay(Room room)
: base(room)
{
}
protected override void SelectBeatmap() => settings.SelectBeatmap();
protected override OnlinePlayComposite CreateSettings()
=> settings = new MatchSettings
{
RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Y,
EditPlaylist = () => EditPlaylist?.Invoke()
};
protected override OnlinePlayComposite CreateSettings(Room room) => settings = new MatchSettings(room)
{
RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Y,
EditPlaylist = () => EditPlaylist?.Invoke()
};
protected class MatchSettings : OnlinePlayComposite
{
@ -66,8 +69,12 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
[Resolved(CanBeNull = true)]
private IRoomManager manager { get; set; }
[Resolved]
private Bindable<Room> currentRoom { get; set; }
private readonly Room room;
public MatchSettings(Room room)
{
this.room = room;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
@ -333,7 +340,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
Duration.Value = DurationField.Current.Value;
manager?.CreateRoom(currentRoom.Value, onSuccess, onError);
manager?.CreateRoom(room, onSuccess, onError);
loadingLayer.Show();
}

View File

@ -50,7 +50,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
if (idleTracker != null)
isIdle.BindTo(idleTracker.IsIdle);
AddInternal(selectionPollingComponent = new SelectionPollingComponent());
AddInternal(selectionPollingComponent = new SelectionPollingComponent(Room));
}
protected override void LoadComplete()
@ -183,7 +183,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
OnStart = StartPlay
};
protected override RoomSettingsOverlay CreateRoomSettingsOverlay() => new PlaylistsRoomSettingsOverlay
protected override RoomSettingsOverlay CreateRoomSettingsOverlay(Room room) => new PlaylistsRoomSettingsOverlay(room)
{
EditPlaylist = () =>
{