mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Restructure
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
@ -11,11 +12,12 @@ using osu.Framework.Screens;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Multiplayer.GameTypes;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Screens.Multi.Match.Components;
|
||||
using osu.Game.Screens.Multi.Play;
|
||||
using osu.Game.Screens.Play;
|
||||
using osu.Game.Screens.Select;
|
||||
using PlaylistItem = osu.Game.Online.Multiplayer.PlaylistItem;
|
||||
|
||||
namespace osu.Game.Screens.Multi.Match
|
||||
{
|
||||
@ -33,223 +35,208 @@ namespace osu.Game.Screens.Multi.Match
|
||||
[Resolved(typeof(Room), nameof(Room.Name))]
|
||||
private Bindable<string> name { get; set; }
|
||||
|
||||
[Resolved(typeof(Room), nameof(Room.Playlist))]
|
||||
private BindableList<PlaylistItem> playlist { get; set; }
|
||||
[Resolved(typeof(Room), nameof(Room.Type))]
|
||||
private Bindable<GameType> type { get; set; }
|
||||
|
||||
public MatchSubScreen(Room room, Action<Screen> pushGameplayScreen)
|
||||
[Resolved(typeof(Room))]
|
||||
protected BindableList<PlaylistItem> Playlist { get; private set; }
|
||||
|
||||
[Resolved(typeof(Room))]
|
||||
protected Bindable<PlaylistItem> CurrentItem { get; private set; }
|
||||
|
||||
[Resolved]
|
||||
protected Bindable<IEnumerable<Mod>> CurrentMods { get; private set; }
|
||||
|
||||
public MatchSubScreen(Room room)
|
||||
{
|
||||
Title = room.RoomID.Value == null ? "New room" : room.Name;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
};
|
||||
private readonly Action<Screen> pushGameplayScreen;
|
||||
|
||||
private MatchLeaderboard leaderboard;
|
||||
|
||||
[Resolved]
|
||||
private BeatmapManager beatmapManager { get; set; }
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private OsuGame game { get; set; }
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
CurrentItem.BindValueChanged(currentItemChanged, true);
|
||||
}
|
||||
|
||||
private void currentItemChanged(PlaylistItem item)
|
||||
{
|
||||
// Retrieve the corresponding local beatmap, since we can't directly use the playlist's beatmap info
|
||||
var localBeatmap = item?.Beatmap == null ? null : beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == item.Beatmap.OnlineBeatmapID);
|
||||
|
||||
Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap);
|
||||
CurrentMods.Value = item?.RequiredMods ?? Enumerable.Empty<Mod>();
|
||||
if (item?.Ruleset != null)
|
||||
Ruleset.Value = item.Ruleset;
|
||||
}
|
||||
|
||||
public override bool OnExiting(IScreen next)
|
||||
{
|
||||
Manager?.PartRoom();
|
||||
RoomManager?.PartRoom();
|
||||
return base.OnExiting(next);
|
||||
}
|
||||
|
||||
private class Match : MultiplayerComposite
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
public Action RequestBeatmapSelection;
|
||||
public Action RequestExit;
|
||||
MatchChatDisplay chat;
|
||||
Components.Header header;
|
||||
Info info;
|
||||
GridContainer bottomRow;
|
||||
MatchSettingsOverlay settings;
|
||||
|
||||
private readonly Action<Screen> pushGameplayScreen;
|
||||
|
||||
private MatchLeaderboard leaderboard;
|
||||
|
||||
[Resolved]
|
||||
private IBindableBeatmap gameBeatmap { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private BeatmapManager beatmapManager { get; set; }
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private OsuGame game { get; set; }
|
||||
|
||||
public Match(Action<Screen> pushGameplayScreen)
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
this.pushGameplayScreen = pushGameplayScreen;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
MatchChatDisplay chat;
|
||||
Components.Header header;
|
||||
Info info;
|
||||
GridContainer bottomRow;
|
||||
MatchSettingsOverlay settings;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
new GridContainer
|
||||
{
|
||||
new GridContainer
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Content = new[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Content = new[]
|
||||
new Drawable[]
|
||||
{
|
||||
new Drawable[]
|
||||
header = new Components.Header
|
||||
{
|
||||
header = new Components.Header
|
||||
Depth = -1,
|
||||
RequestBeatmapSelection = () =>
|
||||
{
|
||||
Depth = -1,
|
||||
RequestBeatmapSelection = () => RequestBeatmapSelection?.Invoke()
|
||||
}
|
||||
},
|
||||
new Drawable[] { info = new Info { OnStart = onStart } },
|
||||
new Drawable[]
|
||||
{
|
||||
bottomRow = new GridContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Content = new[]
|
||||
this.Push(new MatchSongSelect
|
||||
{
|
||||
new Drawable[]
|
||||
Selected = item =>
|
||||
{
|
||||
leaderboard = new MatchLeaderboard
|
||||
Playlist.Clear();
|
||||
Playlist.Add(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
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 + HORIZONTAL_OVERFLOW_PADDING,
|
||||
Right = 10,
|
||||
Vertical = 10,
|
||||
},
|
||||
RelativeSizeAxes = Axes.Both
|
||||
},
|
||||
new Container
|
||||
{
|
||||
Padding = new MarginPadding
|
||||
{
|
||||
Left = 10,
|
||||
Right = 10 + HORIZONTAL_OVERFLOW_PADDING,
|
||||
Vertical = 10,
|
||||
},
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = chat = new MatchChatDisplay
|
||||
{
|
||||
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
|
||||
RowDimensions = new[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding { Top = Components.Header.HEIGHT },
|
||||
Child = settings = new MatchSettingsOverlay { RelativeSizeAxes = Axes.Both },
|
||||
},
|
||||
};
|
||||
|
||||
header.Tabs.Current.BindValueChanged(t =>
|
||||
{
|
||||
const float fade_duration = 500;
|
||||
if (t is SettingsMatchPage)
|
||||
{
|
||||
settings.Show();
|
||||
info.FadeOut(fade_duration, Easing.OutQuint);
|
||||
bottomRow.FadeOut(fade_duration, Easing.OutQuint);
|
||||
new Dimension(GridSizeMode.AutoSize),
|
||||
new Dimension(GridSizeMode.AutoSize),
|
||||
new Dimension(GridSizeMode.Distributed),
|
||||
}
|
||||
else
|
||||
{
|
||||
settings.Hide();
|
||||
info.FadeIn(fade_duration, Easing.OutQuint);
|
||||
bottomRow.FadeIn(fade_duration, Easing.OutQuint);
|
||||
}
|
||||
}, true);
|
||||
|
||||
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)
|
||||
},
|
||||
new Container
|
||||
{
|
||||
default:
|
||||
case GameTypeTimeshift _:
|
||||
pushGameplayScreen?.Invoke(new PlayerLoader(() => new TimeshiftPlayer(Playlist.First())
|
||||
{
|
||||
Exited = () => leaderboard.RefreshScores()
|
||||
}));
|
||||
break;
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding { Top = Components.Header.HEIGHT },
|
||||
Child = settings = new MatchSettingsOverlay { RelativeSizeAxes = Axes.Both },
|
||||
},
|
||||
};
|
||||
|
||||
header.Tabs.Current.BindValueChanged(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);
|
||||
}
|
||||
}, true);
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
chat.Exit += () =>
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
if (this.IsCurrentScreen())
|
||||
this.Exit();
|
||||
};
|
||||
|
||||
if (beatmapManager != null)
|
||||
beatmapManager.ItemAdded -= beatmapAdded;
|
||||
beatmapManager.ItemAdded += beatmapAdded;
|
||||
}
|
||||
|
||||
private void beatmapAdded(BeatmapSetInfo model, bool existing, bool silent) => Schedule(() =>
|
||||
{
|
||||
if (Beatmap.Value != beatmapManager.DefaultBeatmap)
|
||||
return;
|
||||
|
||||
if (Beatmap.Value == null)
|
||||
return;
|
||||
|
||||
// Try to retrieve the corresponding local beatmap
|
||||
var localBeatmap = beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == CurrentItem.Value.Beatmap.OnlineBeatmapID);
|
||||
|
||||
if (localBeatmap != null)
|
||||
Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap);
|
||||
});
|
||||
|
||||
private void onStart()
|
||||
{
|
||||
//Beatmap.Value.Mods.Value = CurrentMods.Value.ToArray();
|
||||
|
||||
switch (type.Value)
|
||||
{
|
||||
default:
|
||||
case GameTypeTimeshift _:
|
||||
pushGameplayScreen?.Invoke(new PlayerLoader(() => new TimeshiftPlayer(CurrentItem)
|
||||
{
|
||||
Exited = () => leaderboard.RefreshScores()
|
||||
}));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (beatmapManager != null)
|
||||
beatmapManager.ItemAdded -= beatmapAdded;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user