1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 07:38:21 +08:00
osu-lazer/osu.Game/Screens/Multi/Match/MatchSubScreen.cs

210 lines
7.2 KiB
C#
Raw Normal View History

2018-05-29 08:01:56 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
2018-12-12 13:38:03 +08:00
using System.Linq;
2018-12-06 11:21:30 +08:00
using osu.Framework.Allocation;
2018-05-29 09:11:01 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Screens;
2018-05-29 09:11:01 +08:00
using osu.Game.Beatmaps;
2018-05-29 08:01:56 +08:00
using osu.Game.Online.Multiplayer;
2018-12-26 15:46:50 +08:00
using osu.Game.Online.Multiplayer.GameTypes;
2018-12-22 13:01:06 +08:00
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
2018-12-10 18:20:41 +08:00
using osu.Game.Screens.Multi.Match.Components;
using osu.Game.Screens.Multi.Play;
using osu.Game.Screens.Play;
2018-05-29 09:11:01 +08:00
using osu.Game.Screens.Select;
2018-05-29 08:01:56 +08:00
2018-12-10 18:20:41 +08:00
namespace osu.Game.Screens.Multi.Match
2018-05-29 08:01:56 +08:00
{
2018-12-26 19:05:57 +08:00
public class MatchSubScreen : MultiplayerSubScreen
2018-05-29 08:01:56 +08:00
{
public override bool AllowBeatmapRulesetChange => false;
2018-12-26 15:46:50 +08:00
public override string Title => room.RoomID.Value == null ? "New room" : room.Name.Value;
public override string ShortTitle => "room";
2018-12-22 13:01:06 +08:00
private readonly RoomBindings bindings = new RoomBindings();
private readonly MatchLeaderboard leaderboard;
2018-12-25 16:14:56 +08:00
private readonly Action<Screen> pushGameplayScreen;
2018-12-13 17:38:03 +08:00
[Cached]
private readonly Room room;
2018-12-06 11:21:30 +08:00
[Resolved]
private BeatmapManager beatmapManager { get; set; }
[Resolved(CanBeNull = true)]
private OsuGame game { get; set; }
2018-12-20 19:58:34 +08:00
[Resolved(CanBeNull = true)]
private IRoomManager manager { get; set; }
2018-12-20 19:58:34 +08:00
2018-12-26 19:05:57 +08:00
public MatchSubScreen(Room room, Action<Screen> pushGameplayScreen)
2018-05-29 08:01:56 +08:00
{
this.room = room;
this.pushGameplayScreen = pushGameplayScreen;
2018-12-06 11:21:30 +08:00
2018-12-22 13:01:06 +08:00
bindings.Room = room;
2018-12-07 15:20:05 +08:00
2018-12-25 16:14:56 +08:00
MatchChatDisplay chat;
2018-12-22 13:01:06 +08:00
Components.Header header;
MatchSettingsOverlay settings;
2018-05-29 09:11:01 +08:00
Children = new Drawable[]
{
2018-12-14 13:20:03 +08:00
new GridContainer
{
RelativeSizeAxes = Axes.Both,
2018-12-14 13:20:03 +08:00
Content = new[]
{
2018-12-20 14:17:33 +08:00
new Drawable[] { header = new Components.Header(room) { Depth = -1 } },
2018-12-22 13:08:00 +08:00
new Drawable[] { new Info(room) { OnStart = onStart } },
2018-12-14 18:52:03 +08:00
new Drawable[]
{
new GridContainer
{
RelativeSizeAxes = Axes.Both,
Content = new[]
{
new Drawable[]
{
leaderboard = new MatchLeaderboard(room)
{
Padding = new MarginPadding(10),
RelativeSizeAxes = Axes.Both
},
new Container
{
Padding = new MarginPadding(10),
RelativeSizeAxes = Axes.Both,
Child = chat = new MatchChatDisplay(room)
{
RelativeSizeAxes = Axes.Both
}
},
2018-12-14 18:52:03 +08:00
},
},
}
},
2018-12-14 13:20:03 +08:00
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.Distributed),
}
},
new Container
{
RelativeSizeAxes = Axes.Both,
2018-12-10 18:20:41 +08:00
Padding = new MarginPadding { Top = Components.Header.HEIGHT },
Child = settings = new MatchSettingsOverlay(room) { RelativeSizeAxes = Axes.Both },
},
2018-05-29 09:11:01 +08:00
};
header.OnRequestSelectBeatmap = () => Push(new MatchSongSelect { Selected = addPlaylistItem });
header.Tabs.Current.ValueChanged += t =>
{
if (t is SettingsMatchPage)
settings.Show();
else
settings.Hide();
};
2018-12-25 16:14:56 +08:00
chat.Exit += Exit;
2018-05-29 08:01:56 +08:00
}
2018-12-06 11:21:30 +08:00
2018-12-27 17:10:49 +08:00
[BackgroundDependencyLoader]
private void load()
{
beatmapManager.ItemAdded += beatmapAdded;
}
2018-12-26 19:05:57 +08:00
protected override bool OnExiting(Screen next)
{
manager?.PartRoom();
return base.OnExiting(next);
}
protected override void LoadComplete()
2018-12-06 11:21:30 +08:00
{
base.LoadComplete();
2018-12-22 13:01:06 +08:00
bindings.CurrentBeatmap.BindValueChanged(setBeatmap, true);
bindings.CurrentMods.BindValueChanged(setMods, true);
bindings.CurrentRuleset.BindValueChanged(setRuleset, true);
2018-12-13 17:38:03 +08:00
}
2018-12-22 13:01:06 +08:00
private void setBeatmap(BeatmapInfo beatmap)
{
// Retrieve the corresponding local beatmap, since we can't directly use the playlist's beatmap info
var localBeatmap = beatmap == null ? null : beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == beatmap.OnlineBeatmapID);
game?.ForcefullySetBeatmap(beatmapManager.GetWorkingBeatmap(localBeatmap));
2018-12-22 13:01:06 +08:00
}
private void setMods(IEnumerable<Mod> mods)
{
2018-12-22 13:01:06 +08:00
Beatmap.Value.Mods.Value = mods.ToArray();
}
2018-12-22 13:01:06 +08:00
private void setRuleset(RulesetInfo ruleset)
2018-12-13 17:38:03 +08:00
{
2018-12-22 13:01:06 +08:00
if (ruleset == null)
2018-12-13 17:38:03 +08:00
return;
game?.ForcefullySetRuleset(ruleset);
2018-12-22 13:01:06 +08:00
}
2018-12-14 16:35:18 +08:00
2018-12-27 17:10:49 +08:00
private void beatmapAdded(BeatmapSetInfo model, bool existing, bool silent) => Schedule(() =>
{
if (Beatmap.Value != beatmapManager.DefaultBeatmap)
return;
if (bindings.CurrentBeatmap.Value == null)
return;
// Try to retrieve the corresponding local beatmap
var localBeatmap = beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == bindings.CurrentBeatmap.Value.OnlineBeatmapID);
if (localBeatmap != null)
game?.ForcefullySetBeatmap(beatmapManager.GetWorkingBeatmap(localBeatmap));
});
2018-12-22 13:01:06 +08:00
private void addPlaylistItem(PlaylistItem item)
{
bindings.Playlist.Clear();
bindings.Playlist.Add(item);
2018-12-06 11:21:30 +08:00
}
private void onStart()
{
2018-12-22 13:01:06 +08:00
switch (bindings.Type.Value)
{
default:
case GameTypeTimeshift _:
2018-12-26 21:16:35 +08:00
pushGameplayScreen?.Invoke(new PlayerLoader(() => {
var player = new TimeshiftPlayer(room, room.Playlist.First().ID);
player.Exited += _ => leaderboard.RefreshScores();
2018-12-26 21:16:35 +08:00
return player;
}));
break;
}
}
2018-12-27 17:10:49 +08:00
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (beatmapManager != null)
beatmapManager.ItemAdded -= beatmapAdded;
}
2018-05-29 08:01:56 +08:00
}
}