2019-01-24 16:43:03 +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.
|
2018-05-22 11:07:04 +08:00
|
|
|
|
|
2020-12-29 15:20:43 +08:00
|
|
|
|
using System;
|
2020-07-09 16:28:22 +08:00
|
|
|
|
using System.Linq;
|
2020-12-29 15:20:43 +08:00
|
|
|
|
using JetBrains.Annotations;
|
2019-02-08 14:20:11 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-05-22 11:07:04 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-05-22 11:24:39 +08:00
|
|
|
|
using osu.Framework.Screens;
|
2019-06-14 14:55:32 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-12-26 20:10:31 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-12-25 12:38:11 +08:00
|
|
|
|
using osu.Game.Online.Rooms;
|
2020-07-10 15:33:45 +08:00
|
|
|
|
using osu.Game.Overlays;
|
2020-12-25 23:50:00 +08:00
|
|
|
|
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
|
|
|
|
using osu.Game.Screens.OnlinePlay.Match;
|
2020-11-08 20:21:21 +08:00
|
|
|
|
using osu.Game.Users;
|
2018-05-22 11:07:04 +08:00
|
|
|
|
|
2020-12-25 23:50:00 +08:00
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Lounge
|
2018-05-22 11:07:04 +08:00
|
|
|
|
{
|
2020-08-16 04:06:16 +08:00
|
|
|
|
[Cached]
|
2020-12-26 00:02:35 +08:00
|
|
|
|
public abstract class LoungeSubScreen : OnlinePlaySubScreen
|
2018-05-22 11:07:04 +08:00
|
|
|
|
{
|
2019-01-25 18:32:37 +08:00
|
|
|
|
public override string Title => "Lounge";
|
2019-01-25 16:44:33 +08:00
|
|
|
|
|
2020-11-08 20:21:21 +08:00
|
|
|
|
protected override UserActivity InitialActivity => new UserActivity.SearchingForLobby();
|
|
|
|
|
|
2020-12-20 22:05:17 +08:00
|
|
|
|
private readonly IBindable<bool> initialRoomsReceived = new Bindable<bool>();
|
2021-01-09 05:23:38 +08:00
|
|
|
|
private readonly IBindable<bool> operationInProgress = new Bindable<bool>();
|
2020-06-05 19:52:27 +08:00
|
|
|
|
|
2020-12-20 22:36:56 +08:00
|
|
|
|
private FilterControl filter;
|
2020-07-09 16:28:22 +08:00
|
|
|
|
private Container content;
|
|
|
|
|
private LoadingLayer loadingLayer;
|
2018-05-22 11:07:04 +08:00
|
|
|
|
|
2019-02-08 14:20:11 +08:00
|
|
|
|
[Resolved]
|
2020-02-27 18:23:21 +08:00
|
|
|
|
private Bindable<Room> selectedRoom { get; set; }
|
2019-02-08 14:20:11 +08:00
|
|
|
|
|
2020-08-11 11:40:58 +08:00
|
|
|
|
[Resolved]
|
2020-07-10 15:33:45 +08:00
|
|
|
|
private MusicController music { get; set; }
|
|
|
|
|
|
2020-12-29 05:54:52 +08:00
|
|
|
|
[Resolved(CanBeNull = true)]
|
2020-12-29 15:20:43 +08:00
|
|
|
|
private OngoingOperationTracker ongoingOperationTracker { get; set; }
|
|
|
|
|
|
|
|
|
|
[CanBeNull]
|
|
|
|
|
private IDisposable joiningRoomOperation { get; set; }
|
2020-06-05 19:52:27 +08:00
|
|
|
|
|
2020-07-09 16:28:22 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
2018-05-22 11:07:04 +08:00
|
|
|
|
{
|
2020-07-09 16:43:26 +08:00
|
|
|
|
RoomsContainer roomsContainer;
|
2020-07-09 16:28:22 +08:00
|
|
|
|
OsuScrollContainer scrollContainer;
|
2020-02-20 18:47:50 +08:00
|
|
|
|
|
2019-01-23 19:52:00 +08:00
|
|
|
|
InternalChildren = new Drawable[]
|
2018-05-22 11:07:04 +08:00
|
|
|
|
{
|
|
|
|
|
content = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2018-12-26 20:10:31 +08:00
|
|
|
|
new Container
|
2018-05-22 11:07:04 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Width = 0.55f,
|
2018-12-26 20:10:31 +08:00
|
|
|
|
Children = new Drawable[]
|
2018-05-22 11:07:04 +08:00
|
|
|
|
{
|
2020-07-09 16:28:22 +08:00
|
|
|
|
scrollContainer = new OsuScrollContainer
|
2018-12-26 20:10:31 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
ScrollbarOverlapsContent = false,
|
|
|
|
|
Padding = new MarginPadding(10),
|
2020-08-16 04:06:16 +08:00
|
|
|
|
Child = roomsContainer = new RoomsContainer { JoinRequested = joinRequested }
|
2018-12-26 20:10:31 +08:00
|
|
|
|
},
|
2021-01-04 21:42:39 +08:00
|
|
|
|
loadingLayer = new LoadingLayer(true),
|
2018-12-26 20:10:31 +08:00
|
|
|
|
}
|
2018-05-22 11:07:04 +08:00
|
|
|
|
},
|
2019-02-05 18:00:01 +08:00
|
|
|
|
new RoomInspector
|
2018-05-22 11:07:04 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Width = 0.45f,
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-12-11 18:07:40 +08:00
|
|
|
|
},
|
2020-12-20 22:36:56 +08:00
|
|
|
|
filter = CreateFilterControl().With(d =>
|
2020-12-07 20:59:38 +08:00
|
|
|
|
{
|
2020-12-20 22:36:56 +08:00
|
|
|
|
d.RelativeSizeAxes = Axes.X;
|
|
|
|
|
d.Height = 80;
|
|
|
|
|
})
|
2018-05-22 11:07:04 +08:00
|
|
|
|
};
|
2020-07-09 16:28:22 +08: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 11:07:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-05 19:52:27 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
initialRoomsReceived.BindTo(RoomManager.InitialRoomsReceived);
|
2020-12-29 04:39:11 +08:00
|
|
|
|
initialRoomsReceived.BindValueChanged(_ => updateLoadingLayer());
|
|
|
|
|
|
2020-12-29 15:20:43 +08:00
|
|
|
|
if (ongoingOperationTracker != null)
|
2020-12-29 05:54:52 +08:00
|
|
|
|
{
|
2021-01-09 05:23:38 +08:00
|
|
|
|
operationInProgress.BindTo(ongoingOperationTracker.InProgress);
|
|
|
|
|
operationInProgress.BindValueChanged(_ => updateLoadingLayer(), true);
|
2020-12-29 05:54:52 +08:00
|
|
|
|
}
|
2020-06-05 19:52:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-22 11:07:04 +08:00
|
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateAfterChildren();
|
|
|
|
|
|
|
|
|
|
content.Padding = new MarginPadding
|
|
|
|
|
{
|
2020-12-20 22:36:56 +08:00
|
|
|
|
Top = filter.DrawHeight,
|
2020-09-03 15:28:14 +08:00
|
|
|
|
Left = WaveOverlayContainer.WIDTH_PADDING - DrawableRoom.SELECTION_BORDER_WIDTH + HORIZONTAL_OVERFLOW_PADDING,
|
|
|
|
|
Right = WaveOverlayContainer.WIDTH_PADDING + HORIZONTAL_OVERFLOW_PADDING,
|
2018-05-22 11:07:04 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override void OnFocus(FocusEvent e)
|
2018-05-22 11:24:39 +08:00
|
|
|
|
{
|
2020-12-20 22:36:56 +08:00
|
|
|
|
filter.TakeFocus();
|
2018-05-22 11:24:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-25 18:32:37 +08:00
|
|
|
|
public override void OnEntering(IScreen last)
|
2018-05-22 11:24:39 +08:00
|
|
|
|
{
|
2019-01-25 18:32:37 +08:00
|
|
|
|
base.OnEntering(last);
|
2020-02-06 13:22:01 +08:00
|
|
|
|
|
|
|
|
|
onReturning();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnResuming(IScreen last)
|
|
|
|
|
{
|
|
|
|
|
base.OnResuming(last);
|
|
|
|
|
|
2020-02-27 18:23:21 +08:00
|
|
|
|
if (selectedRoom.Value?.RoomID.Value == null)
|
|
|
|
|
selectedRoom.Value = new Room();
|
2020-02-06 13:22:01 +08:00
|
|
|
|
|
2020-08-10 07:16:01 +08:00
|
|
|
|
music?.EnsurePlayingSomething();
|
2020-07-10 15:33:45 +08:00
|
|
|
|
|
2020-02-06 13:22:01 +08:00
|
|
|
|
onReturning();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onReturning()
|
|
|
|
|
{
|
2020-12-20 22:36:56 +08:00
|
|
|
|
filter.HoldFocus = true;
|
2018-05-22 11:24:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-25 18:32:37 +08:00
|
|
|
|
public override bool OnExiting(IScreen next)
|
2018-05-22 11:24:39 +08:00
|
|
|
|
{
|
2020-12-20 22:36:56 +08:00
|
|
|
|
filter.HoldFocus = false;
|
2019-01-25 18:32:37 +08:00
|
|
|
|
return base.OnExiting(next);
|
2019-01-25 16:44:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-25 18:32:37 +08:00
|
|
|
|
public override void OnSuspending(IScreen next)
|
2019-01-25 16:44:33 +08:00
|
|
|
|
{
|
2019-01-25 18:32:37 +08:00
|
|
|
|
base.OnSuspending(next);
|
2020-12-20 22:36:56 +08:00
|
|
|
|
filter.HoldFocus = false;
|
2018-05-22 11:24:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 20:10:31 +08:00
|
|
|
|
private void joinRequested(Room room)
|
|
|
|
|
{
|
2021-03-26 13:49:02 +08:00
|
|
|
|
if (joiningRoomOperation != null)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-12-29 15:20:43 +08:00
|
|
|
|
joiningRoomOperation = ongoingOperationTracker?.BeginOperation();
|
2020-06-05 19:52:27 +08:00
|
|
|
|
|
2019-02-11 18:11:34 +08:00
|
|
|
|
RoomManager?.JoinRoom(room, r =>
|
2018-12-26 20:10:31 +08:00
|
|
|
|
{
|
2019-02-05 18:00:01 +08:00
|
|
|
|
Open(room);
|
2020-12-29 15:20:43 +08:00
|
|
|
|
joiningRoomOperation?.Dispose();
|
|
|
|
|
joiningRoomOperation = null;
|
2020-06-05 19:52:27 +08:00
|
|
|
|
}, _ =>
|
|
|
|
|
{
|
2020-12-29 15:20:43 +08:00
|
|
|
|
joiningRoomOperation?.Dispose();
|
|
|
|
|
joiningRoomOperation = null;
|
2020-06-05 19:52:27 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateLoadingLayer()
|
|
|
|
|
{
|
2021-01-09 05:23:38 +08:00
|
|
|
|
if (operationInProgress.Value || !initialRoomsReceived.Value)
|
2020-06-05 19:52:27 +08:00
|
|
|
|
loadingLayer.Show();
|
|
|
|
|
else
|
2020-02-21 14:31:40 +08:00
|
|
|
|
loadingLayer.Hide();
|
2018-12-26 20:10:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 19:21:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Push a room as a new subscreen.
|
|
|
|
|
/// </summary>
|
2020-12-23 15:17:55 +08:00
|
|
|
|
public virtual void Open(Room room)
|
2018-12-04 14:26:06 +08:00
|
|
|
|
{
|
2018-12-11 18:07:40 +08:00
|
|
|
|
// Handles the case where a room is clicked 3 times in quick succession
|
2019-01-23 19:52:00 +08:00
|
|
|
|
if (!this.IsCurrentScreen())
|
2018-12-04 14:26:06 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2020-02-27 18:23:21 +08:00
|
|
|
|
selectedRoom.Value = room;
|
2019-02-08 14:20:11 +08:00
|
|
|
|
|
2020-12-20 23:21:30 +08:00
|
|
|
|
this.Push(CreateRoomSubScreen(room));
|
2018-05-22 11:33:41 +08:00
|
|
|
|
}
|
2020-12-20 22:36:56 +08:00
|
|
|
|
|
|
|
|
|
protected abstract FilterControl CreateFilterControl();
|
2020-12-20 23:21:30 +08:00
|
|
|
|
|
|
|
|
|
protected abstract RoomSubScreen CreateRoomSubScreen(Room room);
|
2018-05-22 11:07:04 +08:00
|
|
|
|
}
|
|
|
|
|
}
|