2019-01-24 08:43:03 +00: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 03:07:04 +00:00
|
|
|
|
|
2020-07-09 08:28:22 +00:00
|
|
|
|
using System.Linq;
|
2019-02-08 06:20:11 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-05-22 03:07:04 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-05-22 03:24:39 +00:00
|
|
|
|
using osu.Framework.Screens;
|
2019-06-14 06:55:32 +00:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-12-26 12:10:31 +00:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2018-05-22 03:07:04 +00:00
|
|
|
|
using osu.Game.Online.Multiplayer;
|
2020-07-10 07:33:45 +00:00
|
|
|
|
using osu.Game.Overlays;
|
2018-05-22 03:07:04 +00:00
|
|
|
|
using osu.Game.Overlays.SearchableList;
|
2018-12-10 10:20:41 +00:00
|
|
|
|
using osu.Game.Screens.Multi.Lounge.Components;
|
|
|
|
|
using osu.Game.Screens.Multi.Match;
|
2018-05-22 03:07:04 +00:00
|
|
|
|
|
2018-12-10 10:20:41 +00:00
|
|
|
|
namespace osu.Game.Screens.Multi.Lounge
|
2018-05-22 03:07:04 +00:00
|
|
|
|
{
|
2019-01-25 10:32:37 +00:00
|
|
|
|
public class LoungeSubScreen : MultiplayerSubScreen
|
2018-05-22 03:07:04 +00:00
|
|
|
|
{
|
2019-01-25 10:32:37 +00:00
|
|
|
|
public override string Title => "Lounge";
|
2019-01-25 08:44:33 +00:00
|
|
|
|
|
2020-07-09 08:28:22 +00:00
|
|
|
|
protected FilterControl Filter;
|
2018-12-11 10:07:40 +00:00
|
|
|
|
|
2020-06-05 11:52:27 +00:00
|
|
|
|
private readonly Bindable<bool> initialRoomsReceived = new Bindable<bool>();
|
|
|
|
|
|
2020-07-09 08:28:22 +00:00
|
|
|
|
private Container content;
|
|
|
|
|
private LoadingLayer loadingLayer;
|
2018-05-22 03:07:04 +00:00
|
|
|
|
|
2019-02-08 06:20:11 +00:00
|
|
|
|
[Resolved]
|
2020-02-27 10:23:21 +00:00
|
|
|
|
private Bindable<Room> selectedRoom { get; set; }
|
2019-02-08 06:20:11 +00:00
|
|
|
|
|
2020-07-10 07:33:45 +00:00
|
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
|
private MusicController music { get; set; }
|
|
|
|
|
|
2020-06-05 11:52:27 +00:00
|
|
|
|
private bool joiningRoom;
|
|
|
|
|
|
2020-07-09 08:28:22 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
2018-05-22 03:07:04 +00:00
|
|
|
|
{
|
2020-07-09 08:43:26 +00:00
|
|
|
|
RoomsContainer roomsContainer;
|
2020-07-09 08:28:22 +00:00
|
|
|
|
OsuScrollContainer scrollContainer;
|
2020-02-20 10:47:50 +00:00
|
|
|
|
|
2019-01-23 11:52:00 +00:00
|
|
|
|
InternalChildren = new Drawable[]
|
2018-05-22 03:07:04 +00:00
|
|
|
|
{
|
2018-12-03 09:30:26 +00:00
|
|
|
|
Filter = new FilterControl { Depth = -1 },
|
2018-05-22 03:07:04 +00:00
|
|
|
|
content = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2018-12-26 12:10:31 +00:00
|
|
|
|
new Container
|
2018-05-22 03:07:04 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Width = 0.55f,
|
2018-12-26 12:10:31 +00:00
|
|
|
|
Children = new Drawable[]
|
2018-05-22 03:07:04 +00:00
|
|
|
|
{
|
2020-07-09 08:28:22 +00:00
|
|
|
|
scrollContainer = new OsuScrollContainer
|
2018-12-26 12:10:31 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
ScrollbarOverlapsContent = false,
|
|
|
|
|
Padding = new MarginPadding(10),
|
2020-07-09 08:43:26 +00:00
|
|
|
|
Child = roomsContainer = new RoomsContainer { JoinRequested = joinRequested }
|
2018-12-26 12:10:31 +00:00
|
|
|
|
},
|
2020-07-09 08:43:26 +00:00
|
|
|
|
loadingLayer = new LoadingLayer(roomsContainer),
|
2018-12-26 12:10:31 +00:00
|
|
|
|
}
|
2018-05-22 03:07:04 +00:00
|
|
|
|
},
|
2019-02-05 10:00:01 +00:00
|
|
|
|
new RoomInspector
|
2018-05-22 03:07:04 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Width = 0.45f,
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-12-11 10:07:40 +00:00
|
|
|
|
},
|
2018-05-22 03:07:04 +00:00
|
|
|
|
};
|
2020-07-09 08:28:22 +00: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 03:07:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-05 11:52:27 +00:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
initialRoomsReceived.BindTo(RoomManager.InitialRoomsReceived);
|
|
|
|
|
initialRoomsReceived.BindValueChanged(onInitialRoomsReceivedChanged, true);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-22 03:07:04 +00:00
|
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateAfterChildren();
|
|
|
|
|
|
|
|
|
|
content.Padding = new MarginPadding
|
|
|
|
|
{
|
2018-05-22 04:22:23 +00:00
|
|
|
|
Top = Filter.DrawHeight,
|
2019-02-11 10:11:34 +00:00
|
|
|
|
Left = SearchableListOverlay.WIDTH_PADDING - DrawableRoom.SELECTION_BORDER_WIDTH + HORIZONTAL_OVERFLOW_PADDING,
|
|
|
|
|
Right = SearchableListOverlay.WIDTH_PADDING + HORIZONTAL_OVERFLOW_PADDING,
|
2018-05-22 03:07:04 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override void OnFocus(FocusEvent e)
|
2018-05-22 03:24:39 +00:00
|
|
|
|
{
|
2019-01-25 10:20:08 +00:00
|
|
|
|
Filter.Search.TakeFocus();
|
2018-05-22 03:24:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-25 10:32:37 +00:00
|
|
|
|
public override void OnEntering(IScreen last)
|
2018-05-22 03:24:39 +00:00
|
|
|
|
{
|
2019-01-25 10:32:37 +00:00
|
|
|
|
base.OnEntering(last);
|
2020-02-06 05:22:01 +00:00
|
|
|
|
|
|
|
|
|
onReturning();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnResuming(IScreen last)
|
|
|
|
|
{
|
|
|
|
|
base.OnResuming(last);
|
|
|
|
|
|
2020-02-27 10:23:21 +00:00
|
|
|
|
if (selectedRoom.Value?.RoomID.Value == null)
|
|
|
|
|
selectedRoom.Value = new Room();
|
2020-02-06 05:22:01 +00:00
|
|
|
|
|
2020-07-10 09:03:56 +00:00
|
|
|
|
music.EnsurePlayingSomething();
|
2020-07-10 07:33:45 +00:00
|
|
|
|
|
2020-02-06 05:22:01 +00:00
|
|
|
|
onReturning();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onReturning()
|
|
|
|
|
{
|
2018-05-22 04:22:23 +00:00
|
|
|
|
Filter.Search.HoldFocus = true;
|
2018-05-22 03:24:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-25 10:32:37 +00:00
|
|
|
|
public override bool OnExiting(IScreen next)
|
2018-05-22 03:24:39 +00:00
|
|
|
|
{
|
2018-05-22 04:22:23 +00:00
|
|
|
|
Filter.Search.HoldFocus = false;
|
2019-01-25 10:32:37 +00:00
|
|
|
|
return base.OnExiting(next);
|
2019-01-25 08:44:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-25 10:32:37 +00:00
|
|
|
|
public override void OnSuspending(IScreen next)
|
2019-01-25 08:44:33 +00:00
|
|
|
|
{
|
2019-01-25 10:32:37 +00:00
|
|
|
|
base.OnSuspending(next);
|
2018-05-22 04:22:23 +00:00
|
|
|
|
Filter.Search.HoldFocus = false;
|
2018-05-22 03:24:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 12:10:31 +00:00
|
|
|
|
private void joinRequested(Room room)
|
|
|
|
|
{
|
2020-06-05 11:52:27 +00:00
|
|
|
|
joiningRoom = true;
|
|
|
|
|
updateLoadingLayer();
|
|
|
|
|
|
2019-02-11 10:11:34 +00:00
|
|
|
|
RoomManager?.JoinRoom(room, r =>
|
2018-12-26 12:10:31 +00:00
|
|
|
|
{
|
2019-02-05 10:00:01 +00:00
|
|
|
|
Open(room);
|
2020-06-05 11:52:27 +00:00
|
|
|
|
joiningRoom = false;
|
|
|
|
|
updateLoadingLayer();
|
|
|
|
|
}, _ =>
|
|
|
|
|
{
|
|
|
|
|
joiningRoom = false;
|
|
|
|
|
updateLoadingLayer();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onInitialRoomsReceivedChanged(ValueChangedEvent<bool> received) => updateLoadingLayer();
|
|
|
|
|
|
|
|
|
|
private void updateLoadingLayer()
|
|
|
|
|
{
|
|
|
|
|
if (joiningRoom || !initialRoomsReceived.Value)
|
|
|
|
|
loadingLayer.Show();
|
|
|
|
|
else
|
2020-02-21 06:31:40 +00:00
|
|
|
|
loadingLayer.Hide();
|
2018-12-26 12:10:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 11:21:30 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Push a room as a new subscreen.
|
|
|
|
|
/// </summary>
|
2019-02-05 10:00:01 +00:00
|
|
|
|
public void Open(Room room)
|
2018-12-04 06:26:06 +00:00
|
|
|
|
{
|
2018-12-11 10:07:40 +00:00
|
|
|
|
// Handles the case where a room is clicked 3 times in quick succession
|
2019-01-23 11:52:00 +00:00
|
|
|
|
if (!this.IsCurrentScreen())
|
2018-12-04 06:26:06 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-02-27 10:23:21 +00:00
|
|
|
|
selectedRoom.Value = room;
|
2019-02-08 06:20:11 +00:00
|
|
|
|
|
2019-02-11 10:11:34 +00:00
|
|
|
|
this.Push(new MatchSubScreen(room));
|
2018-05-22 03:33:41 +00:00
|
|
|
|
}
|
2018-05-22 03:07:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|