Use CMC for all of multiplayer

This commit is contained in:
smoogipoo
2019-02-05 19:00:01 +09:00
parent be51ee4ed5
commit aac371ba6e
38 changed files with 652 additions and 768 deletions

View File

@ -4,6 +4,7 @@
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Screens;
@ -22,130 +23,38 @@ namespace osu.Game.Screens.Multi.Match
{
public override bool AllowBeatmapRulesetChange => false;
public override string Title => room.RoomID.Value == null ? "New room" : room.Name.Value;
public override string Title => roomId?.Value == null ? "New room" : name.Value;
public override string ShortTitle => "room";
private readonly RoomBindings bindings = new RoomBindings();
[Resolved(typeof(Room), nameof(Room.RoomID))]
private Bindable<int?> roomId { get; set; }
private readonly MatchLeaderboard leaderboard;
[Resolved(typeof(Room), nameof(Room.Name))]
private Bindable<string> name { get; set; }
private readonly Action<Screen> pushGameplayScreen;
[Resolved(typeof(Room), nameof(Room.Playlist))]
private BindableList<PlaylistItem> playlist { get; set; }
[Cached]
private readonly Room room;
[Resolved]
private BeatmapManager beatmapManager { get; set; }
public MatchSubScreen(Room room, Action<Screen> pushGameplayScreen)
public MatchSubScreen(Action<Screen> pushGameplayScreen)
{
this.room = room;
this.pushGameplayScreen = pushGameplayScreen;
bindings.Room = room;
MatchChatDisplay chat;
Components.Header header;
Info info;
GridContainer bottomRow;
MatchSettingsOverlay settings;
InternalChildren = new Drawable[]
InternalChild = new Match(pushGameplayScreen)
{
new GridContainer
RelativeSizeAxes = Axes.Both,
RequestBeatmapSelection = () => this.Push(new MatchSongSelect
{
RelativeSizeAxes = Axes.Both,
Content = new[]
Selected = item =>
{
new Drawable[] { header = new Components.Header(room) { Depth = -1 } },
new Drawable[] { info = new Info(room) { OnStart = onStart } },
new Drawable[]
{
bottomRow = new GridContainer
{
RelativeSizeAxes = Axes.Both,
Content = new[]
{
new Drawable[]
{
leaderboard = new MatchLeaderboard
{
Padding = new MarginPadding
{
Left = 10 + OsuScreen.HORIZONTAL_OVERFLOW_PADDING,
Right = 10,
Vertical = 10,
},
RelativeSizeAxes = Axes.Both,
Room = room
},
new Container
{
Padding = new MarginPadding
{
Left = 10,
Right = 10 + OsuScreen.HORIZONTAL_OVERFLOW_PADDING,
Vertical = 10,
},
RelativeSizeAxes = Axes.Both,
Child = chat = new MatchChatDisplay(room)
{
RelativeSizeAxes = Axes.Both
}
},
},
},
}
},
playlist.Clear();
playlist.Add(item);
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.Distributed),
}
},
new Container
}),
RequestExit = () =>
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = Components.Header.HEIGHT },
Child = settings = new MatchSettingsOverlay(room) { RelativeSizeAxes = Axes.Both },
},
};
header.OnRequestSelectBeatmap = () => this.Push(new MatchSongSelect
{
Selected = addPlaylistItem,
});
header.Tabs.Current.ValueChanged += t =>
{
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);
if (this.IsCurrentScreen())
this.Exit();
}
};
chat.Exit += () =>
{
if (this.IsCurrentScreen())
this.Exit();
};
}
[BackgroundDependencyLoader]
private void load()
{
beatmapManager.ItemAdded += beatmapAdded;
}
public override bool OnExiting(IScreen next)
@ -154,73 +63,191 @@ namespace osu.Game.Screens.Multi.Match
return base.OnExiting(next);
}
protected override void LoadComplete()
private class Match : MultiplayerComposite
{
base.LoadComplete();
public Action RequestBeatmapSelection;
public Action RequestExit;
bindings.CurrentBeatmap.BindValueChanged(setBeatmap, true);
bindings.CurrentRuleset.BindValueChanged(setRuleset, true);
}
private readonly Action<Screen> pushGameplayScreen;
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);
private MatchLeaderboard leaderboard;
Game?.ForcefullySetBeatmap(beatmapManager.GetWorkingBeatmap(localBeatmap));
}
[Resolved]
private IBindableBeatmap gameBeatmap { get; set; }
private void setRuleset(RulesetInfo ruleset)
{
if (ruleset == null)
return;
[Resolved]
private BeatmapManager beatmapManager { get; set; }
Game?.ForcefullySetRuleset(ruleset);
}
[Resolved(CanBeNull = true)]
private OsuGame game { get; set; }
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));
});
private void addPlaylistItem(PlaylistItem item)
{
bindings.Playlist.Clear();
bindings.Playlist.Add(item);
}
private void onStart()
{
Beatmap.Value.Mods.Value = bindings.CurrentMods.Value.ToArray();
switch (bindings.Type.Value)
public Match(Action<Screen> pushGameplayScreen)
{
default:
case GameTypeTimeshift _:
pushGameplayScreen?.Invoke(new PlayerLoader(() => new TimeshiftPlayer(room, room.Playlist.First().ID)
{
Exited = () => leaderboard.RefreshScores()
}));
break;
this.pushGameplayScreen = pushGameplayScreen;
}
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
[BackgroundDependencyLoader]
private void load()
{
MatchChatDisplay chat;
Components.Header header;
Info info;
GridContainer bottomRow;
MatchSettingsOverlay settings;
if (beatmapManager != null)
beatmapManager.ItemAdded -= beatmapAdded;
InternalChildren = new Drawable[]
{
new GridContainer
{
RelativeSizeAxes = Axes.Both,
Content = new[]
{
new Drawable[]
{
header = new Components.Header
{
Depth = -1,
RequestBeatmapSelection = () => RequestBeatmapSelection?.Invoke()
}
},
new Drawable[] { info = new Info { OnStart = onStart } },
new Drawable[]
{
bottomRow = new GridContainer
{
RelativeSizeAxes = Axes.Both,
Content = new[]
{
new Drawable[]
{
leaderboard = new MatchLeaderboard
{
Padding = new MarginPadding
{
Left = 10 + OsuScreen.HORIZONTAL_OVERFLOW_PADDING,
Right = 10,
Vertical = 10,
},
RelativeSizeAxes = Axes.Both
},
new Container
{
Padding = new MarginPadding
{
Left = 10,
Right = 10 + OsuScreen.HORIZONTAL_OVERFLOW_PADDING,
Vertical = 10,
},
RelativeSizeAxes = Axes.Both,
Child = chat = new MatchChatDisplay
{
RelativeSizeAxes = Axes.Both
}
},
},
},
}
},
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.Distributed),
}
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = Components.Header.HEIGHT },
Child = settings = new MatchSettingsOverlay { RelativeSizeAxes = Axes.Both },
},
};
header.Tabs.Current.ValueChanged += t =>
{
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);
}
};
chat.Exit += () => RequestExit?.Invoke();
beatmapManager.ItemAdded += beatmapAdded;
}
protected override void LoadComplete()
{
base.LoadComplete();
CurrentBeatmap.BindValueChanged(setBeatmap, true);
CurrentRuleset.BindValueChanged(setRuleset, true);
}
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));
}
private void setRuleset(RulesetInfo ruleset)
{
if (ruleset == null)
return;
game?.ForcefullySetRuleset(ruleset);
}
private void beatmapAdded(BeatmapSetInfo model, bool existing, bool silent) => Schedule(() =>
{
if (gameBeatmap.Value != beatmapManager.DefaultBeatmap)
return;
if (CurrentBeatmap.Value == null)
return;
// Try to retrieve the corresponding local beatmap
var localBeatmap = beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == CurrentBeatmap.Value.OnlineBeatmapID);
if (localBeatmap != null)
game?.ForcefullySetBeatmap(beatmapManager.GetWorkingBeatmap(localBeatmap));
});
private void onStart()
{
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;
}
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (beatmapManager != null)
beatmapManager.ItemAdded -= beatmapAdded;
}
}
}
}