1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 01:52:55 +08:00

Use AddRangeInternal for simplicity, but disallow ClearInternal for safety

This commit is contained in:
Dean Herbert 2021-02-05 14:39:25 +09:00
parent fc37d8b7df
commit de8724b1f6
3 changed files with 9 additions and 20 deletions

View File

@ -7,8 +7,6 @@ using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Screens;
using osu.Game.Audio;
using osu.Game.Beatmaps;
@ -45,25 +43,16 @@ namespace osu.Game.Screens.OnlinePlay.Match
[Cached]
protected OnlinePlayBeatmapAvailablilityTracker BeatmapAvailablilityTracker { get; }
private readonly Container content;
protected RoomSubScreen()
{
InternalChildren = new Drawable[]
{
BeatmapAvailablilityTracker = new OnlinePlayBeatmapAvailablilityTracker
AddInternal(BeatmapAvailablilityTracker = new OnlinePlayBeatmapAvailablilityTracker
{
SelectedItem = { BindTarget = SelectedItem }
},
content = new Container { RelativeSizeAxes = Axes.Both },
};
});
}
// Forward all internal management to content to ensure locally added components are not removed unintentionally.
// This is a bit ugly but we don't have the concept of InternalContent so it'll have to do for now. (https://github.com/ppy/osu-framework/issues/1690)
protected override void AddInternal(Drawable drawable) => content.Add(drawable);
protected override bool RemoveInternal(Drawable drawable) => content.Remove(drawable);
protected override void ClearInternal(bool disposeChildren = true) => content.Clear(disposeChildren);
protected override void ClearInternal(bool disposeChildren = true) =>
throw new InvalidOperationException($"{nameof(RoomSubScreen)}'s children should not be cleared as it will remove required components");
[BackgroundDependencyLoader]
private void load(AudioManager audio)

View File

@ -54,7 +54,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
[BackgroundDependencyLoader]
private void load()
{
InternalChildren = new Drawable[]
AddRangeInternal(new Drawable[]
{
mainContent = new GridContainer
{
@ -177,7 +177,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
RelativeSizeAxes = Axes.Both,
State = { Value = client.Room == null ? Visibility.Visible : Visibility.Hidden }
}
};
});
if (client.Room == null)
{

View File

@ -44,7 +44,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
[BackgroundDependencyLoader]
private void load()
{
InternalChildren = new Drawable[]
AddRangeInternal(new Drawable[]
{
mainContent = new GridContainer
{
@ -190,7 +190,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
EditPlaylist = () => this.Push(new MatchSongSelect()),
State = { Value = roomId.Value == null ? Visibility.Visible : Visibility.Hidden }
}
};
});
if (roomId.Value == null)
{