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.Collections.Specialized;
|
2020-12-24 09:38:53 +08:00
|
|
|
using System.Diagnostics;
|
2020-12-20 23:04:06 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
2020-12-23 14:58:50 +08:00
|
|
|
using osu.Framework.Bindables;
|
2020-12-20 23:04:06 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Game.Online.Multiplayer;
|
|
|
|
using osu.Game.Online.RealtimeMultiplayer;
|
|
|
|
using osu.Game.Screens.Multi.Components;
|
|
|
|
using osu.Game.Screens.Multi.Match;
|
|
|
|
using osu.Game.Screens.Multi.Match.Components;
|
|
|
|
using osu.Game.Screens.Multi.RealtimeMultiplayer.Match;
|
|
|
|
using osu.Game.Screens.Multi.RealtimeMultiplayer.Participants;
|
|
|
|
using osu.Game.Users;
|
2020-12-23 15:19:03 +08:00
|
|
|
using ParticipantsList = osu.Game.Screens.Multi.RealtimeMultiplayer.Participants.ParticipantsList;
|
2020-12-20 23:04:06 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Multi.RealtimeMultiplayer
|
|
|
|
{
|
|
|
|
[Cached]
|
|
|
|
public class RealtimeMatchSubScreen : RoomSubScreen
|
|
|
|
{
|
|
|
|
public override string Title { get; }
|
|
|
|
|
2020-12-24 23:10:29 +08:00
|
|
|
public override string ShortTitle => "room";
|
2020-12-20 23:04:06 +08:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private StatefulMultiplayerClient client { get; set; }
|
|
|
|
|
|
|
|
private RealtimeMatchSettingsOverlay settingsOverlay;
|
|
|
|
|
2020-12-23 14:58:50 +08:00
|
|
|
private IBindable<bool> isConnected;
|
|
|
|
|
2020-12-20 23:04:06 +08:00
|
|
|
public RealtimeMatchSubScreen(Room room)
|
|
|
|
{
|
2020-12-24 23:10:29 +08:00
|
|
|
Title = room.RoomID.Value == null ? "New room" : room.Name.Value;
|
2020-12-20 23:04:06 +08:00
|
|
|
Activity.Value = new UserActivity.InLobby(room);
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new GridContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding
|
|
|
|
{
|
|
|
|
Horizontal = 105,
|
|
|
|
Vertical = 20
|
|
|
|
},
|
|
|
|
Child = new GridContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
RowDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
new Dimension(),
|
|
|
|
},
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
new RealtimeMatchHeader
|
|
|
|
{
|
|
|
|
OpenSettings = () => settingsOverlay.Show()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
new GridContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding { Horizontal = 5, Vertical = 10 },
|
|
|
|
Child = new GridContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
RowDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(GridSizeMode.AutoSize)
|
|
|
|
},
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[] { new ParticipantsListHeader() },
|
|
|
|
new Drawable[]
|
|
|
|
{
|
2020-12-23 15:19:03 +08:00
|
|
|
new ParticipantsList
|
2020-12-20 23:04:06 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Padding = new MarginPadding { Horizontal = 5 },
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new OverlinedHeader("Beatmap"),
|
|
|
|
new BeatmapSelectionControl { RelativeSizeAxes = Axes.X }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
new GridContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
RowDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(GridSizeMode.AutoSize)
|
|
|
|
},
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[] { new OverlinedHeader("Chat") },
|
|
|
|
new Drawable[] { new MatchChatDisplay { RelativeSizeAxes = Axes.Both } }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new Drawable[]
|
|
|
|
{
|
2020-12-21 16:31:15 +08:00
|
|
|
new RealtimeMatchFooter { SelectedItem = { BindTarget = SelectedItem } }
|
2020-12-20 23:04:06 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
RowDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(),
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
settingsOverlay = new RealtimeMatchSettingsOverlay
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
State = { Value = client.Room == null ? Visibility.Visible : Visibility.Hidden }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
Playlist.BindCollectionChanged(onPlaylistChanged, true);
|
|
|
|
|
|
|
|
client.LoadRequested += onLoadRequested;
|
2020-12-23 14:58:50 +08:00
|
|
|
|
|
|
|
isConnected = client.IsConnected.GetBoundCopy();
|
|
|
|
isConnected.BindValueChanged(connected =>
|
|
|
|
{
|
|
|
|
if (!connected.NewValue)
|
|
|
|
Schedule(this.Exit);
|
|
|
|
}, true);
|
2020-12-20 23:04:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override bool OnBackButton()
|
|
|
|
{
|
|
|
|
if (client.Room != null && settingsOverlay.State.Value == Visibility.Visible)
|
|
|
|
{
|
|
|
|
settingsOverlay.Hide();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return base.OnBackButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onPlaylistChanged(object sender, NotifyCollectionChangedEventArgs e) => SelectedItem.Value = Playlist.FirstOrDefault();
|
|
|
|
|
2020-12-24 09:38:53 +08:00
|
|
|
private void onLoadRequested()
|
|
|
|
{
|
|
|
|
Debug.Assert(client.Room != null);
|
|
|
|
|
|
|
|
int[] userIds = client.Room.Users.Where(u => u.State >= MultiplayerUserState.WaitingForLoad).Select(u => u.UserID).ToArray();
|
|
|
|
|
2020-12-24 15:53:25 +08:00
|
|
|
StartPlay(() => new RealtimePlayer(SelectedItem.Value, userIds));
|
2020-12-24 09:38:53 +08:00
|
|
|
}
|
2020-12-20 23:04:06 +08:00
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
if (client != null)
|
|
|
|
client.LoadRequested -= onLoadRequested;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|