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

254 lines
9.5 KiB
C#
Raw Normal View History

// 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-29 08:01:56 +08:00
using System;
2018-12-12 13:38:03 +08:00
using System.Linq;
2018-12-06 11:21:30 +08:00
using osu.Framework.Allocation;
2019-02-05 18:00:01 +08:00
using osu.Framework.Configuration;
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;
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
{
2019-01-25 18:32:37 +08:00
public class MatchSubScreen : MultiplayerSubScreen
2018-05-29 08:01:56 +08:00
{
public override bool AllowBeatmapRulesetChange => false;
2019-02-05 18:00:01 +08:00
public override string Title => roomId?.Value == null ? "New room" : name.Value;
2019-01-25 18:32:37 +08:00
public override string ShortTitle => "room";
2019-02-05 18:00:01 +08:00
[Resolved(typeof(Room), nameof(Room.RoomID))]
private Bindable<int?> roomId { get; set; }
2018-12-22 13:01:06 +08:00
2019-02-05 18:00:01 +08:00
[Resolved(typeof(Room), nameof(Room.Name))]
private Bindable<string> name { get; set; }
2018-12-25 16:14:56 +08:00
2019-02-05 18:00:01 +08:00
[Resolved(typeof(Room), nameof(Room.Playlist))]
private BindableList<PlaylistItem> playlist { get; set; }
2018-12-13 17:38:03 +08:00
2019-02-05 18:00:01 +08:00
public MatchSubScreen(Action<Screen> pushGameplayScreen)
{
InternalChild = new Match(pushGameplayScreen)
{
RelativeSizeAxes = Axes.Both,
RequestBeatmapSelection = () => this.Push(new MatchSongSelect
{
Selected = item =>
{
playlist.Clear();
playlist.Add(item);
},
}),
RequestExit = () =>
{
if (this.IsCurrentScreen())
this.Exit();
}
};
}
2019-02-05 18:00:01 +08:00
public override bool OnExiting(IScreen next)
{
Manager?.PartRoom();
return base.OnExiting(next);
}
2018-12-06 11:21:30 +08:00
2019-02-05 18:00:01 +08:00
private class Match : MultiplayerComposite
2018-05-29 08:01:56 +08:00
{
2019-02-05 18:00:01 +08:00
public Action RequestBeatmapSelection;
public Action RequestExit;
private readonly Action<Screen> pushGameplayScreen;
private MatchLeaderboard leaderboard;
2018-12-06 11:21:30 +08:00
2019-02-05 18:00:01 +08:00
[Resolved]
private IBindableBeatmap gameBeatmap { get; set; }
2018-12-07 15:20:05 +08:00
2019-02-05 18:00:01 +08:00
[Resolved]
private BeatmapManager beatmapManager { get; set; }
2018-05-29 09:11:01 +08:00
2019-02-05 18:00:01 +08:00
[Resolved(CanBeNull = true)]
private OsuGame game { get; set; }
public Match(Action<Screen> pushGameplayScreen)
2018-05-29 09:11:01 +08:00
{
2019-02-05 18:00:01 +08:00
this.pushGameplayScreen = pushGameplayScreen;
}
[BackgroundDependencyLoader]
private void load()
{
MatchChatDisplay chat;
Components.Header header;
Info info;
GridContainer bottomRow;
MatchSettingsOverlay settings;
InternalChildren = new Drawable[]
{
2019-02-05 18:00:01 +08:00
new GridContainer
2018-12-14 13:20:03 +08:00
{
2019-02-05 18:00:01 +08:00
RelativeSizeAxes = Axes.Both,
Content = new[]
2018-12-14 18:52:03 +08:00
{
2019-02-05 18:00:01 +08:00
new Drawable[]
2018-12-14 18:52:03 +08:00
{
2019-02-05 18:00:01 +08:00
header = new Components.Header
2018-12-14 18:52:03 +08:00
{
2019-02-05 18:00:01 +08:00
Depth = -1,
RequestBeatmapSelection = () => RequestBeatmapSelection?.Invoke()
}
},
new Drawable[] { info = new Info { OnStart = onStart } },
new Drawable[]
{
bottomRow = new GridContainer
{
RelativeSizeAxes = Axes.Both,
Content = new[]
2018-12-14 18:52:03 +08:00
{
2019-02-05 18:00:01 +08:00
new Drawable[]
{
2019-02-05 18:00:01 +08:00
leaderboard = new MatchLeaderboard
{
2019-02-05 18:00:01 +08:00
Padding = new MarginPadding
{
Left = 10 + OsuScreen.HORIZONTAL_OVERFLOW_PADDING,
Right = 10,
Vertical = 10,
},
RelativeSizeAxes = Axes.Both
},
2019-02-05 18:00:01 +08:00
new Container
{
2019-02-05 18:00:01 +08:00
Padding = new MarginPadding
{
Left = 10,
Right = 10 + OsuScreen.HORIZONTAL_OVERFLOW_PADDING,
Vertical = 10,
},
RelativeSizeAxes = Axes.Both,
Child = chat = new MatchChatDisplay
{
RelativeSizeAxes = Axes.Both
}
},
},
2018-12-14 18:52:03 +08:00
},
2019-02-05 18:00:01 +08:00
}
},
2018-12-14 18:52:03 +08:00
},
2019-02-05 18:00:01 +08:00
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.Distributed),
}
2018-12-14 13:20:03 +08:00
},
2019-02-05 18:00:01 +08:00
new Container
2018-12-14 13:20:03 +08:00
{
2019-02-05 18:00:01 +08:00
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = Components.Header.HEIGHT },
Child = settings = new MatchSettingsOverlay { RelativeSizeAxes = Axes.Both },
},
};
2019-01-25 13:10:59 +08:00
2019-02-05 18:00:01 +08:00
header.Tabs.Current.ValueChanged += t =>
{
2019-02-05 18:00:01 +08:00
const float fade_duration = 500;
if (t is SettingsMatchPage)
{
settings.Show();
info.FadeOut(fade_duration, Easing.OutQuint);
bottomRow.FadeOut(fade_duration, Easing.OutQuint);
}
else
{
settings.Hide();
info.FadeIn(fade_duration, Easing.OutQuint);
bottomRow.FadeIn(fade_duration, Easing.OutQuint);
}
};
2018-12-26 19:05:57 +08:00
2019-02-05 18:00:01 +08:00
chat.Exit += () => RequestExit?.Invoke();
2019-02-05 18:00:01 +08:00
beatmapManager.ItemAdded += beatmapAdded;
}
2018-12-13 17:38:03 +08:00
2019-02-05 18:00:01 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
2018-12-22 13:01:06 +08:00
2019-02-05 18:00:01 +08:00
CurrentBeatmap.BindValueChanged(setBeatmap, true);
CurrentRuleset.BindValueChanged(setRuleset, true);
}
2018-12-22 13:01:06 +08:00
2019-02-05 18:00:01 +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);
2018-12-13 17:38:03 +08:00
2019-02-05 18:00:01 +08:00
game?.ForcefullySetBeatmap(beatmapManager.GetWorkingBeatmap(localBeatmap));
}
2018-12-14 16:35:18 +08:00
2019-02-05 18:00:01 +08:00
private void setRuleset(RulesetInfo ruleset)
{
if (ruleset == null)
return;
2018-12-27 17:10:49 +08:00
2019-02-05 18:00:01 +08:00
game?.ForcefullySetRuleset(ruleset);
}
2018-12-27 17:10:49 +08:00
2019-02-05 18:00:01 +08:00
private void beatmapAdded(BeatmapSetInfo model, bool existing, bool silent) => Schedule(() =>
{
if (gameBeatmap.Value != beatmapManager.DefaultBeatmap)
return;
2018-12-27 17:10:49 +08:00
2019-02-05 18:00:01 +08:00
if (CurrentBeatmap.Value == null)
return;
2018-12-27 17:10:49 +08:00
2019-02-05 18:00:01 +08:00
// Try to retrieve the corresponding local beatmap
var localBeatmap = beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == CurrentBeatmap.Value.OnlineBeatmapID);
2019-02-05 18:00:01 +08:00
if (localBeatmap != null)
game?.ForcefullySetBeatmap(beatmapManager.GetWorkingBeatmap(localBeatmap));
});
2019-02-05 18:00:01 +08:00
private void onStart()
{
2019-02-05 18:00:01 +08:00
gameBeatmap.Value.Mods.Value = CurrentMods.Value.ToArray();
switch (Type.Value)
{
default:
case GameTypeTimeshift _:
pushGameplayScreen?.Invoke(new PlayerLoader(() => new TimeshiftPlayer(Playlist.First().ID)
{
Exited = () => leaderboard.RefreshScores()
}));
break;
}
}
2018-12-27 17:10:49 +08:00
2019-02-05 18:00:01 +08:00
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
2018-12-27 17:10:49 +08:00
2019-02-05 18:00:01 +08:00
if (beatmapManager != null)
beatmapManager.ItemAdded -= beatmapAdded;
}
2018-12-27 17:10:49 +08:00
}
2018-05-29 08:01:56 +08:00
}
}