2019-01-24 17:43:03 +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.
|
2018-05-22 00:07:04 -03:00
|
|
|
|
|
2020-12-29 08:20:43 +01:00
|
|
|
|
using System;
|
2020-07-09 17:28:22 +09:00
|
|
|
|
using System.Linq;
|
2020-12-29 08:20:43 +01:00
|
|
|
|
using JetBrains.Annotations;
|
2019-02-08 15:20:11 +09:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 19:04:31 +09:00
|
|
|
|
using osu.Framework.Bindables;
|
2021-07-17 22:31:47 +09:00
|
|
|
|
using osu.Framework.Extensions;
|
2018-05-22 00:07:04 -03:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-07-14 18:24:30 +09:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-10-02 12:02:47 +09:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-05-22 00:24:39 -03:00
|
|
|
|
using osu.Framework.Screens;
|
2019-06-14 15:55:32 +09:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-12-26 21:10:31 +09:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-12-25 13:38:11 +09:00
|
|
|
|
using osu.Game.Online.Rooms;
|
2020-07-10 16:33:45 +09:00
|
|
|
|
using osu.Game.Overlays;
|
2020-12-25 16:50:00 +01:00
|
|
|
|
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
|
|
|
|
using osu.Game.Screens.OnlinePlay.Match;
|
2020-11-08 13:21:21 +01:00
|
|
|
|
using osu.Game.Users;
|
2021-07-14 18:55:01 +09:00
|
|
|
|
using osuTK;
|
2021-07-14 18:24:30 +09:00
|
|
|
|
using osuTK.Graphics;
|
2018-05-22 00:07:04 -03:00
|
|
|
|
|
2020-12-25 16:50:00 +01:00
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Lounge
|
2018-05-22 00:07:04 -03:00
|
|
|
|
{
|
2020-08-15 13:06:16 -07:00
|
|
|
|
[Cached]
|
2020-12-25 17:02:35 +01:00
|
|
|
|
public abstract class LoungeSubScreen : OnlinePlaySubScreen
|
2018-05-22 00:07:04 -03:00
|
|
|
|
{
|
2019-01-25 19:32:37 +09:00
|
|
|
|
public override string Title => "Lounge";
|
2019-01-25 17:44:33 +09:00
|
|
|
|
|
2020-11-08 13:21:21 +01:00
|
|
|
|
protected override UserActivity InitialActivity => new UserActivity.SearchingForLobby();
|
|
|
|
|
|
2021-07-14 18:55:01 +09:00
|
|
|
|
protected Container<OsuButton> Buttons { get; } = new Container<OsuButton>
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
AutoSizeAxes = Axes.Both
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-20 23:05:17 +09:00
|
|
|
|
private readonly IBindable<bool> initialRoomsReceived = new Bindable<bool>();
|
2021-01-08 22:23:38 +01:00
|
|
|
|
private readonly IBindable<bool> operationInProgress = new Bindable<bool>();
|
2020-06-05 20:52:27 +09:00
|
|
|
|
|
2020-12-20 23:36:56 +09:00
|
|
|
|
private FilterControl filter;
|
2020-07-09 17:28:22 +09:00
|
|
|
|
private LoadingLayer loadingLayer;
|
2018-05-22 00:07:04 -03:00
|
|
|
|
|
2019-02-08 15:20:11 +09:00
|
|
|
|
[Resolved]
|
2020-02-27 19:23:21 +09:00
|
|
|
|
private Bindable<Room> selectedRoom { get; set; }
|
2019-02-08 15:20:11 +09:00
|
|
|
|
|
2020-08-11 12:40:58 +09:00
|
|
|
|
[Resolved]
|
2020-07-10 16:33:45 +09:00
|
|
|
|
private MusicController music { get; set; }
|
|
|
|
|
|
2020-12-28 22:54:52 +01:00
|
|
|
|
[Resolved(CanBeNull = true)]
|
2020-12-29 08:20:43 +01:00
|
|
|
|
private OngoingOperationTracker ongoingOperationTracker { get; set; }
|
|
|
|
|
|
|
|
|
|
[CanBeNull]
|
|
|
|
|
private IDisposable joiningRoomOperation { get; set; }
|
2020-06-05 20:52:27 +09:00
|
|
|
|
|
2021-07-12 18:54:17 +09:00
|
|
|
|
private RoomsContainer roomsContainer;
|
|
|
|
|
|
2020-07-09 17:28:22 +09:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
2018-05-22 00:07:04 -03:00
|
|
|
|
{
|
2020-07-09 17:28:22 +09:00
|
|
|
|
OsuScrollContainer scrollContainer;
|
2020-02-20 19:47:50 +09:00
|
|
|
|
|
2021-07-14 18:24:30 +09:00
|
|
|
|
InternalChildren = new Drawable[]
|
2018-05-22 00:07:04 -03:00
|
|
|
|
{
|
2021-07-14 18:24:30 +09:00
|
|
|
|
new Box
|
2021-07-14 18:10:59 +09:00
|
|
|
|
{
|
2021-07-14 18:24:30 +09:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 100,
|
|
|
|
|
Colour = Color4.Black,
|
|
|
|
|
Alpha = 0.5f,
|
2021-07-14 18:10:59 +09:00
|
|
|
|
},
|
2021-07-14 18:55:01 +09:00
|
|
|
|
new Container
|
2018-05-22 00:07:04 -03:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-07-14 18:24:30 +09:00
|
|
|
|
Padding = new MarginPadding
|
2018-05-22 00:07:04 -03:00
|
|
|
|
{
|
2021-07-14 18:24:30 +09:00
|
|
|
|
Top = 20,
|
|
|
|
|
Left = WaveOverlayContainer.WIDTH_PADDING,
|
|
|
|
|
Right = WaveOverlayContainer.WIDTH_PADDING,
|
2021-07-14 17:46:45 +09:00
|
|
|
|
},
|
2021-07-14 18:24:30 +09:00
|
|
|
|
Child = new GridContainer
|
2021-07-14 17:46:45 +09:00
|
|
|
|
{
|
2021-07-14 18:24:30 +09:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
RowDimensions = new[]
|
2021-07-14 17:46:45 +09:00
|
|
|
|
{
|
2021-07-14 18:24:30 +09:00
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
|
new Dimension(GridSizeMode.Absolute, 20)
|
2021-07-14 17:46:45 +09:00
|
|
|
|
},
|
2021-07-14 18:24:30 +09:00
|
|
|
|
Content = new[]
|
2018-05-22 00:07:04 -03:00
|
|
|
|
{
|
2021-07-14 18:24:30 +09:00
|
|
|
|
new Drawable[]
|
2018-05-22 00:07:04 -03:00
|
|
|
|
{
|
2021-07-14 18:55:01 +09:00
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 70,
|
|
|
|
|
Depth = -1,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
filter = CreateFilterControl(),
|
|
|
|
|
Buttons.WithChild(CreateNewRoomButton().With(d =>
|
|
|
|
|
{
|
|
|
|
|
d.Size = new Vector2(150, 25);
|
2021-08-03 20:02:31 +09:00
|
|
|
|
d.Action = () => Open();
|
2021-07-14 18:55:01 +09:00
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-14 18:24:30 +09:00
|
|
|
|
},
|
|
|
|
|
null,
|
|
|
|
|
new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Container
|
2021-07-14 17:46:45 +09:00
|
|
|
|
{
|
2021-07-14 18:24:30 +09:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
2021-07-14 17:46:45 +09:00
|
|
|
|
{
|
2021-07-14 18:24:30 +09:00
|
|
|
|
scrollContainer = new OsuScrollContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
ScrollbarOverlapsContent = false,
|
2021-08-03 20:02:31 +09:00
|
|
|
|
Child = roomsContainer = new RoomsContainer()
|
2021-07-14 18:24:30 +09:00
|
|
|
|
},
|
|
|
|
|
loadingLayer = new LoadingLayer(true),
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
2021-07-13 16:00:42 +09:00
|
|
|
|
}
|
2021-07-14 18:24:30 +09:00
|
|
|
|
},
|
|
|
|
|
}
|
2018-05-22 00:07:04 -03:00
|
|
|
|
};
|
2020-07-09 17:28:22 +09:00
|
|
|
|
|
|
|
|
|
// scroll selected room into view on selection.
|
|
|
|
|
selectedRoom.BindValueChanged(val =>
|
|
|
|
|
{
|
|
|
|
|
var drawable = roomsContainer.Rooms.FirstOrDefault(r => r.Room == val.NewValue);
|
|
|
|
|
if (drawable != null)
|
|
|
|
|
scrollContainer.ScrollIntoView(drawable);
|
|
|
|
|
});
|
2018-05-22 00:07:04 -03:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-05 20:52:27 +09:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
initialRoomsReceived.BindTo(RoomManager.InitialRoomsReceived);
|
2020-12-28 21:39:11 +01:00
|
|
|
|
initialRoomsReceived.BindValueChanged(_ => updateLoadingLayer());
|
|
|
|
|
|
2020-12-29 08:20:43 +01:00
|
|
|
|
if (ongoingOperationTracker != null)
|
2020-12-28 22:54:52 +01:00
|
|
|
|
{
|
2021-01-08 22:23:38 +01:00
|
|
|
|
operationInProgress.BindTo(ongoingOperationTracker.InProgress);
|
|
|
|
|
operationInProgress.BindValueChanged(_ => updateLoadingLayer(), true);
|
2020-12-28 22:54:52 +01:00
|
|
|
|
}
|
2020-06-05 20:52:27 +09:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 12:02:47 +09:00
|
|
|
|
protected override void OnFocus(FocusEvent e)
|
2018-05-22 00:24:39 -03:00
|
|
|
|
{
|
2020-12-20 23:36:56 +09:00
|
|
|
|
filter.TakeFocus();
|
2018-05-22 00:24:39 -03:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-25 19:32:37 +09:00
|
|
|
|
public override void OnEntering(IScreen last)
|
2018-05-22 00:24:39 -03:00
|
|
|
|
{
|
2019-01-25 19:32:37 +09:00
|
|
|
|
base.OnEntering(last);
|
2020-02-06 14:22:01 +09:00
|
|
|
|
|
|
|
|
|
onReturning();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnResuming(IScreen last)
|
|
|
|
|
{
|
|
|
|
|
base.OnResuming(last);
|
|
|
|
|
|
2020-02-27 19:23:21 +09:00
|
|
|
|
if (selectedRoom.Value?.RoomID.Value == null)
|
|
|
|
|
selectedRoom.Value = new Room();
|
2020-02-06 14:22:01 +09:00
|
|
|
|
|
2020-08-09 16:16:01 -07:00
|
|
|
|
music?.EnsurePlayingSomething();
|
2020-07-10 16:33:45 +09:00
|
|
|
|
|
2020-02-06 14:22:01 +09:00
|
|
|
|
onReturning();
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-25 19:32:37 +09:00
|
|
|
|
public override bool OnExiting(IScreen next)
|
2018-05-22 00:24:39 -03:00
|
|
|
|
{
|
2021-07-17 22:31:47 +09:00
|
|
|
|
onLeaving();
|
2019-01-25 19:32:37 +09:00
|
|
|
|
return base.OnExiting(next);
|
2019-01-25 17:44:33 +09:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-25 19:32:37 +09:00
|
|
|
|
public override void OnSuspending(IScreen next)
|
2019-01-25 17:44:33 +09:00
|
|
|
|
{
|
2021-07-17 22:31:47 +09:00
|
|
|
|
onLeaving();
|
2019-01-25 19:32:37 +09:00
|
|
|
|
base.OnSuspending(next);
|
2021-07-17 22:31:47 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onReturning()
|
|
|
|
|
{
|
|
|
|
|
filter.HoldFocus = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onLeaving()
|
|
|
|
|
{
|
2020-12-20 23:36:56 +09:00
|
|
|
|
filter.HoldFocus = false;
|
2021-07-12 18:54:17 +09:00
|
|
|
|
|
|
|
|
|
// ensure any password prompt is dismissed.
|
2021-07-17 22:31:47 +09:00
|
|
|
|
this.HidePopover();
|
2018-05-22 00:24:39 -03:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-23 02:23:37 +09:00
|
|
|
|
public void Join(Room room, string password) => Schedule(() =>
|
2018-12-26 21:10:31 +09:00
|
|
|
|
{
|
2021-03-26 14:49:02 +09:00
|
|
|
|
if (joiningRoomOperation != null)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-12-29 08:20:43 +01:00
|
|
|
|
joiningRoomOperation = ongoingOperationTracker?.BeginOperation();
|
2020-06-05 20:52:27 +09:00
|
|
|
|
|
2021-07-10 16:08:12 +09:00
|
|
|
|
RoomManager?.JoinRoom(room, password, r =>
|
2018-12-26 21:10:31 +09:00
|
|
|
|
{
|
2019-02-05 19:00:01 +09:00
|
|
|
|
Open(room);
|
2020-12-29 08:20:43 +01:00
|
|
|
|
joiningRoomOperation?.Dispose();
|
|
|
|
|
joiningRoomOperation = null;
|
2020-06-05 20:52:27 +09:00
|
|
|
|
}, _ =>
|
|
|
|
|
{
|
2020-12-29 08:20:43 +01:00
|
|
|
|
joiningRoomOperation?.Dispose();
|
|
|
|
|
joiningRoomOperation = null;
|
2020-06-05 20:52:27 +09:00
|
|
|
|
});
|
2021-07-23 02:23:37 +09:00
|
|
|
|
});
|
2018-12-26 21:10:31 +09:00
|
|
|
|
|
2018-12-26 20:21:30 +09:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Push a room as a new subscreen.
|
|
|
|
|
/// </summary>
|
2021-08-03 20:02:31 +09:00
|
|
|
|
/// <param name="room">An optional template to use when creating the room.</param>
|
|
|
|
|
public void Open(Room room = null) => Schedule(() =>
|
2018-12-04 15:26:06 +09:00
|
|
|
|
{
|
2018-12-11 19:07:40 +09:00
|
|
|
|
// Handles the case where a room is clicked 3 times in quick succession
|
2019-01-23 20:52:00 +09:00
|
|
|
|
if (!this.IsCurrentScreen())
|
2018-12-04 15:26:06 +09:00
|
|
|
|
return;
|
|
|
|
|
|
2021-08-03 20:02:31 +09:00
|
|
|
|
OpenNewRoom(room ?? CreateNewRoom());
|
2021-07-23 02:23:37 +09:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
protected virtual void OpenNewRoom(Room room)
|
|
|
|
|
{
|
2020-02-27 19:23:21 +09:00
|
|
|
|
selectedRoom.Value = room;
|
2019-02-08 15:20:11 +09:00
|
|
|
|
|
2020-12-21 00:21:30 +09:00
|
|
|
|
this.Push(CreateRoomSubScreen(room));
|
2018-05-22 00:33:41 -03:00
|
|
|
|
}
|
2020-12-20 23:36:56 +09:00
|
|
|
|
|
|
|
|
|
protected abstract FilterControl CreateFilterControl();
|
2020-12-21 00:21:30 +09:00
|
|
|
|
|
2021-07-14 18:55:01 +09:00
|
|
|
|
protected abstract OsuButton CreateNewRoomButton();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a new room.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The created <see cref="Room"/>.</returns>
|
|
|
|
|
protected abstract Room CreateNewRoom();
|
|
|
|
|
|
2020-12-21 00:21:30 +09:00
|
|
|
|
protected abstract RoomSubScreen CreateRoomSubScreen(Room room);
|
2021-07-23 02:23:37 +09:00
|
|
|
|
|
|
|
|
|
private void updateLoadingLayer()
|
|
|
|
|
{
|
|
|
|
|
if (operationInProgress.Value || !initialRoomsReceived.Value)
|
|
|
|
|
loadingLayer.Show();
|
|
|
|
|
else
|
|
|
|
|
loadingLayer.Hide();
|
|
|
|
|
}
|
2018-05-22 00:07:04 -03:00
|
|
|
|
}
|
|
|
|
|
}
|