2020-12-20 23:04:06 +08: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.
|
|
|
|
|
|
|
|
using System;
|
2020-12-29 15:20:43 +08:00
|
|
|
using System.Diagnostics;
|
|
|
|
using JetBrains.Annotations;
|
2020-12-20 23:04:06 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2020-12-24 00:08:28 +08:00
|
|
|
using osu.Framework.Extensions.ExceptionExtensions;
|
2020-12-20 23:04:06 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Online.Multiplayer;
|
2020-12-25 12:38:11 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
2020-12-20 23:04:06 +08:00
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osu.Game.Rulesets;
|
2020-12-25 23:50:00 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Match.Components;
|
2020-12-20 23:04:06 +08:00
|
|
|
using osuTK;
|
|
|
|
|
2020-12-25 23:50:00 +08:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2020-12-25 12:38:11 +08:00
|
|
|
public class MultiplayerMatchSettingsOverlay : MatchSettingsOverlay
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-07-07 15:12:28 +08:00
|
|
|
protected override OnlinePlayComposite CreateSettings()
|
|
|
|
=> new MatchSettings
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
RelativePositionAxes = Axes.Y,
|
|
|
|
SettingsApplied = Hide
|
|
|
|
};
|
|
|
|
|
2020-12-26 00:12:33 +08:00
|
|
|
protected class MatchSettings : OnlinePlayComposite
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
|
|
|
private const float disabled_alpha = 0.2f;
|
|
|
|
|
|
|
|
public Action SettingsApplied;
|
|
|
|
|
|
|
|
public OsuTextBox NameField, MaxParticipantsField;
|
|
|
|
public RoomAvailabilityPicker AvailabilityPicker;
|
|
|
|
public GameTypePicker TypePicker;
|
2021-07-07 15:28:48 +08:00
|
|
|
public OsuTextBox PasswordTextBox;
|
2020-12-20 23:04:06 +08:00
|
|
|
public TriangleButton ApplyButton;
|
|
|
|
|
|
|
|
public OsuSpriteText ErrorText;
|
|
|
|
|
|
|
|
private OsuSpriteText typeLabel;
|
|
|
|
private LoadingLayer loadingLayer;
|
|
|
|
private BeatmapSelectionControl initialBeatmapControl;
|
|
|
|
|
|
|
|
[Resolved]
|
2020-12-20 23:21:48 +08:00
|
|
|
private IRoomManager manager { get; set; }
|
2020-12-20 23:04:06 +08:00
|
|
|
|
|
|
|
[Resolved]
|
2021-05-20 14:39:45 +08:00
|
|
|
private MultiplayerClient client { get; set; }
|
2020-12-20 23:04:06 +08:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private Bindable<Room> currentRoom { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private Bindable<WorkingBeatmap> beatmap { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private Bindable<RulesetInfo> ruleset { get; set; }
|
|
|
|
|
2020-12-29 15:20:43 +08:00
|
|
|
[Resolved]
|
|
|
|
private OngoingOperationTracker ongoingOperationTracker { get; set; }
|
|
|
|
|
|
|
|
private readonly IBindable<bool> operationInProgress = new BindableBool();
|
|
|
|
|
|
|
|
[CanBeNull]
|
|
|
|
private IDisposable applyingSettingsOperation;
|
2020-12-29 04:44:58 +08:00
|
|
|
|
2020-12-20 23:04:06 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
new Box
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-01-04 21:42:39 +08:00
|
|
|
Colour = Color4Extensions.FromHex(@"28242d"),
|
|
|
|
},
|
|
|
|
new GridContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
RowDimensions = new[]
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-07-05 23:52:39 +08:00
|
|
|
new Dimension(),
|
2021-01-04 21:42:39 +08:00
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
},
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[]
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
new OsuScrollContainer
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
Padding = new MarginPadding
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
Horizontal = OsuScreen.HORIZONTAL_OVERFLOW_PADDING,
|
|
|
|
Vertical = 10
|
|
|
|
},
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
new FillFlowContainer
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(0, 10),
|
|
|
|
Children = new Drawable[]
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
new Container
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Padding = new MarginPadding { Horizontal = WaveOverlayContainer.WIDTH_PADDING },
|
2020-12-20 23:04:06 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
new SectionContainer
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
Padding = new MarginPadding { Right = FIELD_PADDING / 2 },
|
|
|
|
Children = new[]
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
new Section("Room name")
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
Child = NameField = new SettingsTextBox
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
TabbableContentContainer = this,
|
2020-12-20 23:04:06 +08:00
|
|
|
},
|
|
|
|
},
|
2021-01-04 21:42:39 +08:00
|
|
|
new Section("Room visibility")
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
Alpha = disabled_alpha,
|
|
|
|
Child = AvailabilityPicker = new RoomAvailabilityPicker
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
Enabled = { Value = false }
|
|
|
|
},
|
|
|
|
},
|
|
|
|
new Section("Game type")
|
|
|
|
{
|
|
|
|
Alpha = disabled_alpha,
|
|
|
|
Child = new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(7),
|
|
|
|
Children = new Drawable[]
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
TypePicker = new GameTypePicker
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2021-01-04 21:42:39 +08:00
|
|
|
Enabled = { Value = false }
|
2020-12-20 23:04:06 +08:00
|
|
|
},
|
2021-01-04 21:42:39 +08:00
|
|
|
typeLabel = new OsuSpriteText
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
Font = OsuFont.GetFont(size: 14),
|
|
|
|
Colour = colours.Yellow
|
2020-12-20 23:04:06 +08:00
|
|
|
},
|
|
|
|
},
|
2021-01-04 21:42:39 +08:00
|
|
|
},
|
|
|
|
},
|
2020-12-20 23:04:06 +08:00
|
|
|
},
|
|
|
|
},
|
2021-01-04 21:42:39 +08:00
|
|
|
new SectionContainer
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
Padding = new MarginPadding { Left = FIELD_PADDING / 2 },
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
new Section("Max participants")
|
|
|
|
{
|
|
|
|
Alpha = disabled_alpha,
|
|
|
|
Child = MaxParticipantsField = new SettingsNumberTextBox
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
TabbableContentContainer = this,
|
|
|
|
ReadOnly = true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
new Section("Password (optional)")
|
|
|
|
{
|
2021-07-07 15:28:48 +08:00
|
|
|
Child = PasswordTextBox = new SettingsPasswordTextBox
|
2021-01-04 21:42:39 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
TabbableContentContainer = this,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-12-20 23:04:06 +08:00
|
|
|
}
|
2021-01-04 21:42:39 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
initialBeatmapControl = new BeatmapSelectionControl
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Width = 0.5f
|
2020-12-20 23:04:06 +08:00
|
|
|
}
|
2021-01-04 21:42:39 +08:00
|
|
|
}
|
|
|
|
}
|
2020-12-20 23:04:06 +08:00
|
|
|
},
|
2021-01-04 21:42:39 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
Y = 2,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Children = new Drawable[]
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4Extensions.FromHex(@"28242d").Darken(0.5f).Opacity(1f),
|
|
|
|
},
|
|
|
|
new FillFlowContainer
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2021-01-04 21:42:39 +08:00
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(0, 20),
|
|
|
|
Margin = new MarginPadding { Vertical = 20 },
|
|
|
|
Padding = new MarginPadding { Horizontal = OsuScreen.HORIZONTAL_OVERFLOW_PADDING },
|
2020-12-20 23:04:06 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
ApplyButton = new CreateOrUpdateButton
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
Size = new Vector2(230, 55),
|
|
|
|
Enabled = { Value = false },
|
|
|
|
Action = apply,
|
2020-12-20 23:04:06 +08:00
|
|
|
},
|
2021-01-04 21:42:39 +08:00
|
|
|
ErrorText = new OsuSpriteText
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
2021-01-04 21:42:39 +08:00
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
Alpha = 0,
|
|
|
|
Depth = 1,
|
|
|
|
Colour = colours.RedDark
|
2020-12-20 23:04:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-04 21:42:39 +08:00
|
|
|
}
|
2020-12-20 23:04:06 +08:00
|
|
|
}
|
|
|
|
},
|
2021-01-04 21:42:39 +08:00
|
|
|
loadingLayer = new LoadingLayer(true)
|
2020-12-20 23:04:06 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
TypePicker.Current.BindValueChanged(type => typeLabel.Text = type.NewValue?.Name ?? string.Empty, true);
|
|
|
|
RoomName.BindValueChanged(name => NameField.Text = name.NewValue, true);
|
|
|
|
Availability.BindValueChanged(availability => AvailabilityPicker.Current.Value = availability.NewValue, true);
|
|
|
|
Type.BindValueChanged(type => TypePicker.Current.Value = type.NewValue, true);
|
|
|
|
MaxParticipants.BindValueChanged(count => MaxParticipantsField.Text = count.NewValue?.ToString(), true);
|
|
|
|
RoomID.BindValueChanged(roomId => initialBeatmapControl.Alpha = roomId.NewValue == null ? 1 : 0, true);
|
2021-07-19 19:02:14 +08:00
|
|
|
Password.BindValueChanged(password => PasswordTextBox.Text = password.NewValue ?? string.Empty, true);
|
2020-12-29 04:44:58 +08:00
|
|
|
|
2020-12-29 15:20:43 +08:00
|
|
|
operationInProgress.BindTo(ongoingOperationTracker.InProgress);
|
|
|
|
operationInProgress.BindValueChanged(v =>
|
2020-12-29 04:44:58 +08:00
|
|
|
{
|
|
|
|
if (v.NewValue)
|
|
|
|
loadingLayer.Show();
|
|
|
|
else
|
|
|
|
loadingLayer.Hide();
|
|
|
|
});
|
2020-12-20 23:04:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2020-12-29 15:20:43 +08:00
|
|
|
ApplyButton.Enabled.Value = Playlist.Count > 0 && NameField.Text.Length > 0 && !operationInProgress.Value;
|
2020-12-20 23:04:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void apply()
|
|
|
|
{
|
|
|
|
if (!ApplyButton.Enabled.Value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
hideError();
|
2020-12-29 15:20:43 +08:00
|
|
|
|
|
|
|
Debug.Assert(applyingSettingsOperation == null);
|
|
|
|
applyingSettingsOperation = ongoingOperationTracker.BeginOperation();
|
2020-12-20 23:04:06 +08:00
|
|
|
|
|
|
|
// If the client is already in a room, update via the client.
|
|
|
|
// Otherwise, update the room directly in preparation for it to be submitted to the API on match creation.
|
|
|
|
if (client.Room != null)
|
|
|
|
{
|
2021-07-10 12:50:52 +08:00
|
|
|
client.ChangeSettings(name: NameField.Text, password: PasswordTextBox.Text).ContinueWith(t => Schedule(() =>
|
2020-12-22 15:50:30 +08:00
|
|
|
{
|
|
|
|
if (t.IsCompletedSuccessfully)
|
|
|
|
onSuccess(currentRoom.Value);
|
|
|
|
else
|
2020-12-24 00:08:28 +08:00
|
|
|
onError(t.Exception?.AsSingular().Message ?? "Error changing settings.");
|
2020-12-22 15:50:30 +08:00
|
|
|
}));
|
2020-12-20 23:04:06 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
currentRoom.Value.Name.Value = NameField.Text;
|
|
|
|
currentRoom.Value.Availability.Value = AvailabilityPicker.Current.Value;
|
|
|
|
currentRoom.Value.Type.Value = TypePicker.Current.Value;
|
2021-07-07 15:28:48 +08:00
|
|
|
currentRoom.Value.Password.Value = PasswordTextBox.Current.Value;
|
2020-12-20 23:04:06 +08:00
|
|
|
|
|
|
|
if (int.TryParse(MaxParticipantsField.Text, out int max))
|
|
|
|
currentRoom.Value.MaxParticipants.Value = max;
|
|
|
|
else
|
|
|
|
currentRoom.Value.MaxParticipants.Value = null;
|
|
|
|
|
|
|
|
manager?.CreateRoom(currentRoom.Value, onSuccess, onError);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void hideError() => ErrorText.FadeOut(50);
|
|
|
|
|
|
|
|
private void onSuccess(Room room)
|
|
|
|
{
|
2020-12-29 15:20:43 +08:00
|
|
|
Debug.Assert(applyingSettingsOperation != null);
|
|
|
|
|
2020-12-20 23:04:06 +08:00
|
|
|
SettingsApplied?.Invoke();
|
2020-12-29 15:20:43 +08:00
|
|
|
|
|
|
|
applyingSettingsOperation.Dispose();
|
|
|
|
applyingSettingsOperation = null;
|
2020-12-20 23:04:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void onError(string text)
|
|
|
|
{
|
2020-12-29 15:20:43 +08:00
|
|
|
Debug.Assert(applyingSettingsOperation != null);
|
|
|
|
|
2020-12-20 23:04:06 +08:00
|
|
|
ErrorText.Text = text;
|
|
|
|
ErrorText.FadeIn(50);
|
2020-12-29 15:20:43 +08:00
|
|
|
|
|
|
|
applyingSettingsOperation.Dispose();
|
|
|
|
applyingSettingsOperation = null;
|
2020-12-20 23:04:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class CreateOrUpdateButton : TriangleButton
|
|
|
|
{
|
|
|
|
[Resolved(typeof(Room), nameof(Room.RoomID))]
|
2021-02-16 18:29:40 +08:00
|
|
|
private Bindable<long?> roomId { get; set; }
|
2020-12-20 23:04:06 +08:00
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
roomId.BindValueChanged(id => Text = id.NewValue == null ? "Create" : "Update", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
BackgroundColour = colours.Yellow;
|
|
|
|
Triangles.ColourLight = colours.YellowLight;
|
|
|
|
Triangles.ColourDark = colours.YellowDark;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|