2020-12-20 23:36:56 +09: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.
|
|
|
|
|
2025-01-22 21:44:45 +09:00
|
|
|
using System;
|
2022-06-23 11:36:08 -04:00
|
|
|
using System.Collections.Generic;
|
2020-12-23 16:17:55 +09:00
|
|
|
using osu.Framework.Allocation;
|
2025-01-22 21:44:45 +09:00
|
|
|
using osu.Framework.Extensions.ExceptionExtensions;
|
2020-12-23 16:17:55 +09:00
|
|
|
using osu.Framework.Logging;
|
2022-06-23 11:36:08 -04:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2024-01-15 14:30:27 +09:00
|
|
|
using osu.Game.Configuration;
|
2021-07-14 18:55:01 +09:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Online.API;
|
2020-12-21 00:21:30 +09:00
|
|
|
using osu.Game.Online.Multiplayer;
|
2020-12-25 13:38:11 +09:00
|
|
|
using osu.Game.Online.Rooms;
|
2020-12-25 16:50:00 +01:00
|
|
|
using osu.Game.Screens.OnlinePlay.Lounge;
|
|
|
|
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
|
|
|
using osu.Game.Screens.OnlinePlay.Match;
|
2020-12-20 23:36:56 +09:00
|
|
|
|
2020-12-25 16:50:00 +01:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
2020-12-20 23:36:56 +09:00
|
|
|
{
|
2020-12-25 13:38:11 +09:00
|
|
|
public partial class MultiplayerLoungeSubScreen : LoungeSubScreen
|
2020-12-20 23:36:56 +09:00
|
|
|
{
|
2021-07-14 18:55:01 +09:00
|
|
|
[Resolved]
|
2024-11-21 20:26:44 +09:00
|
|
|
private IAPIProvider api { get; set; } = null!;
|
2020-12-23 16:17:55 +09:00
|
|
|
|
|
|
|
[Resolved]
|
2024-11-21 20:26:44 +09:00
|
|
|
private MultiplayerClient client { get; set; } = null!;
|
2020-12-23 16:17:55 +09:00
|
|
|
|
2024-11-21 20:26:44 +09:00
|
|
|
private Dropdown<RoomPermissionsFilter> roomAccessTypeDropdown = null!;
|
2024-12-11 13:01:11 +09:00
|
|
|
private OsuCheckbox showInProgress = null!;
|
2022-06-23 11:36:08 -04:00
|
|
|
|
|
|
|
protected override IEnumerable<Drawable> CreateFilterControls()
|
|
|
|
{
|
2024-12-11 13:24:54 +09:00
|
|
|
foreach (var control in base.CreateFilterControls())
|
|
|
|
yield return control;
|
|
|
|
|
|
|
|
yield return roomAccessTypeDropdown = new SlimEnumDropdown<RoomPermissionsFilter>
|
2022-06-23 11:36:08 -04:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.None,
|
2024-01-15 14:30:27 +09:00
|
|
|
Current = Config.GetBindable<RoomPermissionsFilter>(OsuSetting.MultiplayerRoomFilter),
|
2022-06-23 11:36:08 -04:00
|
|
|
Width = 160,
|
|
|
|
};
|
|
|
|
|
2022-06-23 11:40:25 -04:00
|
|
|
roomAccessTypeDropdown.Current.BindValueChanged(_ => UpdateFilter());
|
2022-06-23 11:36:08 -04:00
|
|
|
|
2024-12-11 13:24:54 +09:00
|
|
|
yield return showInProgress = new OsuCheckbox
|
2024-12-11 13:01:11 +09:00
|
|
|
{
|
2024-12-12 15:16:11 +09:00
|
|
|
LabelText = "Show in-progress rooms",
|
2024-12-11 13:01:11 +09:00
|
|
|
RelativeSizeAxes = Axes.None,
|
2024-12-13 15:42:30 +09:00
|
|
|
Width = 220,
|
2024-12-11 13:24:54 +09:00
|
|
|
Padding = new MarginPadding { Vertical = 5, },
|
2024-12-12 15:16:24 +09:00
|
|
|
Current = Config.GetBindable<bool>(OsuSetting.MultiplayerShowInProgressFilter),
|
2024-12-11 13:01:11 +09:00
|
|
|
};
|
|
|
|
|
2024-12-11 13:24:54 +09:00
|
|
|
showInProgress.Current.BindValueChanged(_ => UpdateFilter());
|
|
|
|
StatusDropdown.Current.BindValueChanged(_ => showInProgress.Alpha = StatusDropdown.Current.Value == RoomModeFilter.Open ? 1 : 0, true);
|
2022-06-23 11:36:08 -04:00
|
|
|
}
|
|
|
|
|
2021-08-12 19:48:15 +09:00
|
|
|
protected override FilterCriteria CreateFilterCriteria()
|
|
|
|
{
|
|
|
|
var criteria = base.CreateFilterCriteria();
|
2021-08-13 13:07:02 +09:00
|
|
|
criteria.Category = @"realtime";
|
2022-07-01 17:26:40 +09:00
|
|
|
criteria.Permissions = roomAccessTypeDropdown.Current.Value;
|
2024-12-11 13:24:54 +09:00
|
|
|
criteria.Status = showInProgress.Current.Value && criteria.Mode == RoomModeFilter.Open ? null : RoomStatusFilter.Idle;
|
2021-08-12 19:48:15 +09:00
|
|
|
return criteria;
|
|
|
|
}
|
2021-07-14 18:55:01 +09:00
|
|
|
|
|
|
|
protected override OsuButton CreateNewRoomButton() => new CreateMultiplayerMatchButton();
|
|
|
|
|
|
|
|
protected override Room CreateNewRoom() => new Room
|
|
|
|
{
|
2024-11-13 16:55:18 +09:00
|
|
|
Name = $"{api.LocalUser}'s awesome room",
|
2024-11-13 18:36:47 +09:00
|
|
|
Type = MatchType.HeadToHead,
|
2021-07-14 18:55:01 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
protected override RoomSubScreen CreateRoomSubScreen(Room room) => new MultiplayerMatchSubScreen(room);
|
|
|
|
|
2025-01-25 19:27:21 +09:00
|
|
|
protected override void JoinInternal(Room room, string? password, Action<Room> onSuccess, Action<string> onFailure)
|
2025-01-22 21:44:45 +09:00
|
|
|
{
|
|
|
|
client.JoinRoom(room, password).ContinueWith(result =>
|
|
|
|
{
|
|
|
|
if (result.IsCompletedSuccessfully)
|
|
|
|
onSuccess(room);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const string message = "Failed to join multiplayer room.";
|
|
|
|
|
|
|
|
if (result.Exception != null)
|
|
|
|
Logger.Error(result.Exception, message);
|
|
|
|
|
|
|
|
onFailure.Invoke(result.Exception?.AsSingular().Message ?? message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2025-02-27 13:39:16 +09:00
|
|
|
public override void Close(Room room)
|
|
|
|
=> throw new NotSupportedException("Cannot close multiplayer rooms.");
|
|
|
|
|
2021-07-23 02:23:37 +09:00
|
|
|
protected override void OpenNewRoom(Room room)
|
2020-12-23 16:17:55 +09:00
|
|
|
{
|
2024-11-21 20:26:44 +09:00
|
|
|
if (!client.IsConnected.Value)
|
2020-12-23 16:17:55 +09:00
|
|
|
{
|
|
|
|
Logger.Log("Not currently connected to the multiplayer server.", LoggingTarget.Runtime, LogLevel.Important);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-23 02:23:37 +09:00
|
|
|
base.OpenNewRoom(room);
|
2020-12-23 16:17:55 +09:00
|
|
|
}
|
2020-12-20 23:36:56 +09:00
|
|
|
}
|
|
|
|
}
|