1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 18:42:56 +08:00

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

View File

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

View File

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

View File

@ -37,15 +37,19 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
protected override bool IsLoading => ongoingOperationTracker.InProgress.Value; protected override bool IsLoading => ongoingOperationTracker.InProgress.Value;
public MultiplayerMatchSettingsOverlay(Room room)
: base(room)
{
}
protected override void SelectBeatmap() => settings.SelectBeatmap(); protected override void SelectBeatmap() => settings.SelectBeatmap();
protected override OnlinePlayComposite CreateSettings() protected override OnlinePlayComposite CreateSettings(Room room) => settings = new MatchSettings(room)
=> settings = new MatchSettings {
{ RelativeSizeAxes = Axes.Both,
RelativeSizeAxes = Axes.Both, RelativePositionAxes = Axes.Y,
RelativePositionAxes = Axes.Y, SettingsApplied = Hide
SettingsApplied = Hide };
};
protected class MatchSettings : OnlinePlayComposite protected class MatchSettings : OnlinePlayComposite
{ {
@ -73,9 +77,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
[Resolved] [Resolved]
private MultiplayerClient client { get; set; } private MultiplayerClient client { get; set; }
[Resolved]
private Bindable<Room> currentRoom { get; set; }
[Resolved] [Resolved]
private Bindable<WorkingBeatmap> beatmap { get; set; } private Bindable<WorkingBeatmap> beatmap { get; set; }
@ -90,6 +91,13 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
[CanBeNull] [CanBeNull]
private IDisposable applyingSettingsOperation; private IDisposable applyingSettingsOperation;
private readonly Room room;
public MatchSettings(Room room)
{
this.room = room;
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) 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(() => client.ChangeSettings(name: NameField.Text, password: PasswordTextBox.Text, matchType: TypePicker.Current.Value).ContinueWith(t => Schedule(() =>
{ {
if (t.IsCompletedSuccessfully) if (t.IsCompletedSuccessfully)
onSuccess(currentRoom.Value); onSuccess(room);
else else
onError(t.Exception?.AsSingular().Message ?? "Error changing settings."); onError(t.Exception?.AsSingular().Message ?? "Error changing settings.");
})); }));
} }
else else
{ {
currentRoom.Value.Name.Value = NameField.Text; room.Name.Value = NameField.Text;
currentRoom.Value.Availability.Value = AvailabilityPicker.Current.Value; room.Availability.Value = AvailabilityPicker.Current.Value;
currentRoom.Value.Type.Value = TypePicker.Current.Value; room.Type.Value = TypePicker.Current.Value;
currentRoom.Value.Password.Value = PasswordTextBox.Current.Value; room.Password.Value = PasswordTextBox.Current.Value;
if (int.TryParse(MaxParticipantsField.Text, out int max)) if (int.TryParse(MaxParticipantsField.Text, out int max))
currentRoom.Value.MaxParticipants.Value = max; room.MaxParticipants.Value = max;
else 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] [Resolved]
private OngoingOperationTracker ongoingOperationTracker { get; set; } 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>(); private readonly IBindable<bool> isConnected = new Bindable<bool>();
[CanBeNull] [CanBeNull]
@ -82,16 +79,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
handleRoomLost(); handleRoomLost();
}, true); }, true);
currentRoom.BindValueChanged(room => if (client.Room == null)
{ handleRoomLost();
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);
} }
protected override Drawable CreateMainContent() => new GridContainer protected override Drawable CreateMainContent() => new GridContainer
@ -223,7 +212,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
OnSpectateClick = onSpectateClick OnSpectateClick = onSpectateClick
}; };
protected override RoomSettingsOverlay CreateRoomSettingsOverlay() => new MultiplayerMatchSettingsOverlay(); protected override RoomSettingsOverlay CreateRoomSettingsOverlay(Room room) => new MultiplayerMatchSettingsOverlay(room);
protected override void UpdateMods() protected override void UpdateMods()
{ {

View File

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

View File

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