1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 19:27:24 +08:00

Merge pull request #4191 from peppy/leased-bindables-dont-work

Add screen leased bindables via DependencyContainer
This commit is contained in:
Dean Herbert 2019-02-14 17:05:39 +09:00 committed by GitHub
commit 813b36e98e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
58 changed files with 497 additions and 507 deletions

View File

@ -112,7 +112,7 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config, IBindableBeatmap beatmap)
private void load(OsuConfigManager config, IBindable<WorkingBeatmap> beatmap)
{
InternalChild = expandTarget = new Container
{

View File

@ -85,7 +85,7 @@ namespace osu.Game.Tests.Visual
}
[BackgroundDependencyLoader]
private void load(IAdjustableClock adjustableClock, IBindableBeatmap beatmap)
private void load(IAdjustableClock adjustableClock, IBindable<WorkingBeatmap> beatmap)
{
this.adjustableClock = adjustableClock;
this.beatmap.BindTo(beatmap);

View File

@ -53,7 +53,7 @@ namespace osu.Game.Tests.Visual
{
}
protected override IEnumerable<IResultPageInfo> CreateResultPages() => new[] { new TestRoomLeaderboardPageInfo(Score, Beatmap) };
protected override IEnumerable<IResultPageInfo> CreateResultPages() => new[] { new TestRoomLeaderboardPageInfo(Score, Beatmap.Value) };
}
private class TestRoomLeaderboardPageInfo : RoomLeaderboardPageInfo

View File

@ -3,6 +3,7 @@
using System.Threading;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Screens.Play;
@ -12,28 +13,37 @@ namespace osu.Game.Tests.Visual
public class TestCasePlayerLoader : ManualInputManagerTestCase
{
private PlayerLoader loader;
private ScreenStack stack;
[BackgroundDependencyLoader]
private void load(OsuGameBase game)
{
Beatmap.Value = new DummyWorkingBeatmap(game);
AddStep("load dummy beatmap", () => Add(loader = new PlayerLoader(() => new Player
InputManager.Add(stack = new ScreenStack { RelativeSizeAxes = Axes.Both });
AddStep("load dummy beatmap", () => stack.Push(loader = new PlayerLoader(() => new Player
{
AllowPause = false,
AllowLeadIn = false,
AllowResults = false,
})));
AddUntilStep(() => loader.IsCurrentScreen(), "wait for current");
AddStep("mouse in centre", () => InputManager.MoveMouseTo(loader.ScreenSpaceDrawQuad.Centre));
AddUntilStep(() => !loader.IsCurrentScreen(), "wait for no longer current");
AddStep("exit loader", () => loader.Exit());
AddUntilStep(() => !loader.IsAlive, "wait for no longer alive");
AddStep("load slow dummy beatmap", () =>
{
SlowLoadPlayer slow = null;
Add(loader = new PlayerLoader(() => slow = new SlowLoadPlayer
stack.Push(loader = new PlayerLoader(() => slow = new SlowLoadPlayer
{
AllowPause = false,
AllowLeadIn = false,

View File

@ -12,9 +12,9 @@ namespace osu.Game.Beatmaps
{
/// <summary>
/// A <see cref="Bindable{WorkingBeatmap}"/> for the <see cref="OsuGame"/> beatmap.
/// This should be used sparingly in-favour of <see cref="IBindableBeatmap"/>.
/// This should be used sparingly in-favour of <see cref="IBindable<WorkingBeatmap>"/>.
/// </summary>
public abstract class BindableBeatmap : NonNullableBindable<WorkingBeatmap>, IBindableBeatmap
public abstract class BindableBeatmap : NonNullableBindable<WorkingBeatmap>
{
private AudioManager audioManager;
private WorkingBeatmap lastBeatmap;
@ -62,9 +62,6 @@ namespace osu.Game.Beatmaps
lastBeatmap = beatmap;
}
[NotNull]
IBindableBeatmap IBindableBeatmap.GetBoundCopy() => GetBoundCopy();
/// <summary>
/// Retrieve a new <see cref="BindableBeatmap"/> instance weakly bound to this <see cref="BindableBeatmap"/>.
/// If you are further binding to events of the retrieved <see cref="BindableBeatmap"/>, ensure a local reference is held.

View File

@ -13,7 +13,7 @@ namespace osu.Game.Beatmaps.Drawables
/// </summary>
public class UpdateableBeatmapBackgroundSprite : ModelBackedDrawable<BeatmapInfo>
{
public readonly IBindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
[Resolved]
private BeatmapManager beatmaps { get; set; }

View File

@ -1,19 +0,0 @@
// 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.
using osu.Framework.Configuration;
namespace osu.Game.Beatmaps
{
/// <summary>
/// Read-only interface for the <see cref="OsuGame"/> beatmap.
/// </summary>
public interface IBindableBeatmap : IBindable<WorkingBeatmap>
{
/// <summary>
/// Retrieve a new <see cref="IBindableBeatmap"/> instance weakly bound to this <see cref="IBindableBeatmap"/>.
/// If you are further binding to events of the retrieved <see cref="IBindableBeatmap"/>, ensure a local reference is held.
/// </summary>
IBindableBeatmap GetBoundCopy();
}
}

View File

@ -74,7 +74,7 @@ namespace osu.Game.Graphics.Containers
}
[BackgroundDependencyLoader]
private void load(IBindableBeatmap beatmap)
private void load(IBindable<WorkingBeatmap> beatmap)
{
Beatmap.BindTo(beatmap);
}

View File

@ -1,9 +1,9 @@
// 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.
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using osu.Framework.Configuration;
using osu.Game.Beatmaps;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
@ -37,10 +37,10 @@ namespace osu.Game.Online.Multiplayer
public RulesetInfo Ruleset { get; set; }
[JsonIgnore]
public readonly BindableList<Mod> AllowedMods = new BindableList<Mod>();
public readonly List<Mod> AllowedMods = new List<Mod>();
[JsonIgnore]
public readonly BindableList<Mod> RequiredMods = new BindableList<Mod>();
public readonly List<Mod> RequiredMods = new List<Mod>();
[JsonProperty("beatmap")]
private APIBeatmap apiBeatmap { get; set; }

View File

@ -31,6 +31,10 @@ namespace osu.Game.Online.Multiplayer
[JsonProperty("playlist")]
public BindableList<PlaylistItem> Playlist { get; private set; } = new BindableList<PlaylistItem>();
[Cached]
[JsonIgnore]
public Bindable<PlaylistItem> CurrentItem { get; private set; } = new Bindable<PlaylistItem>();
[Cached]
[JsonProperty("channel_id")]
public Bindable<int> ChannelId { get; private set; } = new Bindable<int>();
@ -66,6 +70,18 @@ namespace osu.Game.Online.Multiplayer
[Cached]
public Bindable<int> ParticipantCount { get; private set; } = new Bindable<int>();
public Room()
{
Playlist.ItemsAdded += updateCurrent;
Playlist.ItemsRemoved += updateCurrent;
updateCurrent(Playlist);
}
private void updateCurrent(IEnumerable<PlaylistItem> playlist)
{
CurrentItem.Value = playlist.FirstOrDefault();
}
// todo: TEMPORARY
[JsonProperty("participant_count")]
private int? participantCount

View File

@ -292,7 +292,7 @@ namespace osu.Game
return;
}
if ((screenStack.CurrentScreen as IOsuScreen)?.AllowExternalScreenChange != true)
if ((screenStack.CurrentScreen as IOsuScreen)?.AllowExternalScreenChange == false)
{
notifications.Post(new SimpleNotification
{
@ -311,7 +311,7 @@ namespace osu.Game
void loadScore()
{
if (!menuScreen.IsCurrentScreen())
if (!menuScreen.IsCurrentScreen() || Beatmap.Disabled)
{
menuScreen.MakeCurrent();
this.Delay(500).Schedule(loadScore, out scoreLoad);
@ -723,46 +723,13 @@ namespace osu.Game
{
base.UpdateAfterChildren();
// we only want to apply these restrictions when we are inside a screen stack.
// the use case for not applying is in visual/unit tests.
bool applyBeatmapRulesetRestrictions = !(screenStack.CurrentScreen as IOsuScreen)?.AllowBeatmapRulesetChange ?? false;
ruleset.Disabled = applyBeatmapRulesetRestrictions;
Beatmap.Disabled = applyBeatmapRulesetRestrictions;
screenContainer.Padding = new MarginPadding { Top = ToolbarOffset };
overlayContent.Padding = new MarginPadding { Top = ToolbarOffset };
MenuCursorContainer.CanShowCursor = (screenStack.CurrentScreen as IOsuScreen)?.CursorVisible ?? false;
}
/// <summary>
/// Sets <see cref="Beatmap"/> while ignoring any beatmap.
/// </summary>
/// <param name="beatmap">The beatmap to set.</param>
public void ForcefullySetBeatmap(WorkingBeatmap beatmap)
{
var beatmapDisabled = Beatmap.Disabled;
Beatmap.Disabled = false;
Beatmap.Value = beatmap;
Beatmap.Disabled = beatmapDisabled;
}
/// <summary>
/// Sets <see cref="Ruleset"/> while ignoring any ruleset restrictions.
/// </summary>
/// <param name="beatmap">The beatmap to set.</param>
public void ForcefullySetRuleset(RulesetInfo ruleset)
{
var rulesetDisabled = this.ruleset.Disabled;
this.ruleset.Disabled = false;
this.ruleset.Value = ruleset;
this.ruleset.Disabled = rulesetDisabled;
}
protected virtual void ScreenChanged(IScreen lastScreen, IScreen newScreen)
protected virtual void ScreenChanged(IScreen current, IScreen newScreen)
{
switch (newScreen)
{

View File

@ -69,8 +69,9 @@ namespace osu.Game
protected override Container<Drawable> Content => content;
private OsuBindableBeatmap beatmap;
protected BindableBeatmap Beatmap => beatmap;
private Bindable<WorkingBeatmap> beatmap;
protected Bindable<WorkingBeatmap> Beatmap => beatmap;
private Bindable<bool> fpsDisplayVisible;
@ -155,7 +156,6 @@ namespace osu.Game
dependencies.CacheAs<IAPIProvider>(API);
var defaultBeatmap = new DummyWorkingBeatmap(this);
beatmap = new OsuBindableBeatmap(defaultBeatmap, Audio);
dependencies.Cache(RulesetStore = new RulesetStore(contextFactory));
dependencies.Cache(FileStore = new FileStore(contextFactory, Host.Storage));
@ -174,8 +174,10 @@ namespace osu.Game
// this adds a global reduction of track volume for the time being.
Audio.Track.AddAdjustment(AdjustableProperty.Volume, new BindableDouble(0.8));
dependencies.CacheAs<BindableBeatmap>(beatmap);
dependencies.CacheAs<IBindableBeatmap>(beatmap);
beatmap = new OsuBindableBeatmap(defaultBeatmap, Audio);
dependencies.CacheAs<IBindable<WorkingBeatmap>>(beatmap);
dependencies.CacheAs(beatmap);
FileStore.Cleanup();

View File

@ -73,7 +73,7 @@ namespace osu.Game.Overlays.Music
}
[BackgroundDependencyLoader]
private void load(BeatmapManager beatmaps, IBindableBeatmap beatmap)
private void load(BeatmapManager beatmaps, IBindable<WorkingBeatmap> beatmap)
{
beatmaps.GetAllUsableBeatmapSets().ForEach(b => addBeatmapSet(b, false, false));
beatmaps.ItemAdded += addBeatmapSet;

View File

@ -34,7 +34,7 @@ namespace osu.Game.Overlays.Music
private PlaylistList list;
[BackgroundDependencyLoader]
private void load(OsuColour colours, BindableBeatmap beatmap, BeatmapManager beatmaps)
private void load(OsuColour colours, Bindable<WorkingBeatmap> beatmap, BeatmapManager beatmaps)
{
this.beatmap.BindTo(beatmap);
this.beatmaps = beatmaps;

View File

@ -66,7 +66,7 @@ namespace osu.Game.Overlays
}
[BackgroundDependencyLoader]
private void load(BindableBeatmap beatmap, BeatmapManager beatmaps, OsuColour colours)
private void load(Bindable<WorkingBeatmap> beatmap, BeatmapManager beatmaps, OsuColour colours)
{
this.beatmap.BindTo(beatmap);
this.beatmaps = beatmaps;

View File

@ -48,7 +48,7 @@ namespace osu.Game.Rulesets.Edit
}
[BackgroundDependencyLoader]
private void load(IBindableBeatmap beatmap, IFrameBasedClock framedClock)
private void load(IBindable<WorkingBeatmap> beatmap, IFrameBasedClock framedClock)
{
Beatmap.BindTo(beatmap);

View File

@ -57,7 +57,7 @@ namespace osu.Game.Rulesets.Edit
}
[BackgroundDependencyLoader]
private void load(IBindableBeatmap beatmap, IAdjustableClock clock)
private void load(IBindable<WorkingBeatmap> beatmap, IAdjustableClock clock)
{
this.beatmap.BindTo(beatmap);

View File

@ -60,7 +60,7 @@ namespace osu.Game.Rulesets.UI
private WorkingBeatmap beatmap;
[BackgroundDependencyLoader]
private void load(IBindableBeatmap beatmap)
private void load(IBindable<WorkingBeatmap> beatmap)
{
this.beatmap = beatmap.Value;
}

View File

@ -42,7 +42,7 @@ namespace osu.Game.Screens.Edit.Components
}
[BackgroundDependencyLoader]
private void load(IBindableBeatmap beatmap, OsuColour colours)
private void load(IBindable<WorkingBeatmap> beatmap, OsuColour colours)
{
Beatmap.BindTo(beatmap);
background.Colour = colours.Gray1;

View File

@ -32,7 +32,7 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
}
[BackgroundDependencyLoader]
private void load(IBindableBeatmap beatmap)
private void load(IBindable<WorkingBeatmap> beatmap)
{
Beatmap.BindTo(beatmap);
}

View File

@ -32,7 +32,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
private WaveformGraph waveform;
[BackgroundDependencyLoader]
private void load(IBindableBeatmap beatmap, IAdjustableClock adjustableClock, OsuColour colours)
private void load(IBindable<WorkingBeatmap> beatmap, IAdjustableClock adjustableClock, OsuColour colours)
{
this.adjustableClock = adjustableClock;

View File

@ -29,7 +29,8 @@ namespace osu.Game.Screens.Edit
protected override BackgroundScreen CreateBackground() => new BackgroundScreenCustom(@"Backgrounds/bg4");
public override bool HideOverlaysOnEnter => true;
public override bool AllowBeatmapRulesetChange => false;
public override bool DisallowExternalBeatmapRulesetChanges => true;
private Box bottomBackground;
private Container screenContainer;

View File

@ -29,7 +29,7 @@ namespace osu.Game.Screens.Edit
}
[BackgroundDependencyLoader]
private void load(IBindableBeatmap beatmap)
private void load(IBindable<WorkingBeatmap> beatmap)
{
Beatmap.BindTo(beatmap);
}

View File

@ -1,8 +1,11 @@
// 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.
using osu.Framework.Configuration;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Overlays;
using osu.Game.Rulesets;
namespace osu.Game.Screens
{
@ -12,8 +15,12 @@ namespace osu.Game.Screens
/// Whether the beatmap or ruleset should be allowed to be changed by the user or game.
/// Used to mark exclusive areas where this is strongly prohibited, like gameplay.
/// </summary>
bool AllowBeatmapRulesetChange { get; }
bool DisallowExternalBeatmapRulesetChanges { get; }
/// <summary>
/// Whether a top-level component should be allowed to exit the current screen to, for example,
/// complete an import.
/// </summary>
bool AllowExternalScreenChange { get; }
/// <summary>
@ -35,5 +42,9 @@ namespace osu.Game.Screens
/// The amount of parallax to be applied while this screen is displayed.
/// </summary>
float BackgroundParallaxAmount { get; }
Bindable<WorkingBeatmap> Beatmap { get; }
Bindable<RulesetInfo> Ruleset { get; }
}
}

View File

@ -28,8 +28,6 @@ namespace osu.Game.Screens.Menu
/// </summary>
public bool DidLoadMenu;
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
private MainMenu mainMenu;
private SampleChannel welcome;
private SampleChannel seeya;
@ -47,10 +45,8 @@ namespace osu.Game.Screens.Menu
private WorkingBeatmap introBeatmap;
[BackgroundDependencyLoader]
private void load(AudioManager audio, OsuConfigManager config, BeatmapManager beatmaps, Framework.Game game, BindableBeatmap beatmap)
private void load(AudioManager audio, OsuConfigManager config, BeatmapManager beatmaps, Framework.Game game)
{
this.beatmap.BindTo(beatmap);
menuVoice = config.GetBindable<bool>(OsuSetting.MenuVoice);
menuMusic = config.GetBindable<bool>(OsuSetting.MenuMusic);
@ -95,7 +91,7 @@ namespace osu.Game.Screens.Menu
if (!resuming)
{
beatmap.Value = introBeatmap;
Beatmap.Value = introBeatmap;
if (menuVoice)
welcome.Play();

View File

@ -74,7 +74,7 @@ namespace osu.Game.Screens.Menu
}
[BackgroundDependencyLoader]
private void load(ShaderManager shaders, IBindableBeatmap beatmap)
private void load(ShaderManager shaders, IBindable<WorkingBeatmap> beatmap)
{
this.beatmap.BindTo(beatmap);
shader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE_ROUNDED);

View File

@ -42,7 +42,7 @@ namespace osu.Game.Screens.Menu
}
[BackgroundDependencyLoader]
private void load(IBindableBeatmap beatmap, OsuColour colours)
private void load(IBindable<WorkingBeatmap> beatmap, OsuColour colours)
{
this.beatmap.BindTo(beatmap);

View File

@ -25,7 +25,7 @@ namespace osu.Game.Screens.Multi.Components
[BackgroundDependencyLoader]
private void load()
{
CurrentBeatmap.BindValueChanged(v => updateText(), true);
CurrentItem.BindValueChanged(v => updateText(), true);
}
private float textSize = OsuSpriteText.FONT_SIZE;
@ -48,12 +48,14 @@ namespace osu.Game.Screens.Multi.Components
private void updateText()
{
if (!IsLoaded)
if (LoadState < LoadState.Loading)
return;
textFlow.Clear();
if (CurrentBeatmap.Value == null)
var beatmap = CurrentItem.Value?.Beatmap;
if (beatmap == null)
textFlow.AddText("No beatmap selected", s =>
{
s.TextSize = TextSize;
@ -65,7 +67,7 @@ namespace osu.Game.Screens.Multi.Components
{
new OsuSpriteText
{
Text = new LocalisedString((CurrentBeatmap.Value.Metadata.ArtistUnicode, CurrentBeatmap.Value.Metadata.Artist)),
Text = new LocalisedString((beatmap.Metadata.ArtistUnicode, beatmap.Metadata.Artist)),
TextSize = TextSize,
},
new OsuSpriteText
@ -75,10 +77,10 @@ namespace osu.Game.Screens.Multi.Components
},
new OsuSpriteText
{
Text = new LocalisedString((CurrentBeatmap.Value.Metadata.TitleUnicode, CurrentBeatmap.Value.Metadata.Title)),
Text = new LocalisedString((beatmap.Metadata.TitleUnicode, beatmap.Metadata.Title)),
TextSize = TextSize,
}
}, null, LinkAction.OpenBeatmap, CurrentBeatmap.Value.OnlineBeatmapID.ToString(), "Open beatmap");
}, null, LinkAction.OpenBeatmap, beatmap.OnlineBeatmapID.ToString(), "Open beatmap");
}
}
}

View File

@ -51,14 +51,16 @@ namespace osu.Game.Screens.Multi.Components
}
};
CurrentBeatmap.BindValueChanged(v =>
CurrentItem.BindValueChanged(item =>
{
beatmapAuthor.Clear();
if (v != null)
var beatmap = item?.Beatmap;
if (beatmap != null)
{
beatmapAuthor.AddText("mapped by ", s => s.Colour = OsuColour.Gray(0.8f));
beatmapAuthor.AddLink(v.Metadata.Author.Username, null, LinkAction.OpenUserProfile, v.Metadata.Author.Id.ToString(), "View Profile");
beatmapAuthor.AddLink(beatmap.Metadata.Author.Username, null, LinkAction.OpenUserProfile, beatmap.Metadata.Author.Id.ToString(), "View Profile");
}
}, true);
}

View File

@ -5,6 +5,7 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Online.Multiplayer;
using osuTK;
namespace osu.Game.Screens.Multi.Components
@ -45,17 +46,17 @@ namespace osu.Game.Screens.Multi.Components
},
};
CurrentBeatmap.BindValueChanged(_ => updateBeatmap());
CurrentRuleset.BindValueChanged(_ => updateBeatmap(), true);
CurrentItem.BindValueChanged(updateBeatmap, true);
Type.BindValueChanged(v => gameTypeContainer.Child = new DrawableGameType(v) { Size = new Vector2(height) }, true);
}
private void updateBeatmap()
private void updateBeatmap(PlaylistItem item)
{
if (CurrentBeatmap.Value != null)
if (item?.Beatmap != null)
{
rulesetContainer.FadeIn(transition_duration);
rulesetContainer.Child = new DifficultyIcon(CurrentBeatmap.Value, CurrentRuleset.Value) { Size = new Vector2(height) };
rulesetContainer.Child = new DifficultyIcon(item.Beatmap, item.Ruleset) { Size = new Vector2(height) };
}
else
rulesetContainer.FadeOut(transition_duration);

View File

@ -16,7 +16,7 @@ namespace osu.Game.Screens.Multi.Components
InternalChild = sprite = CreateBackgroundSprite();
sprite.Beatmap.BindTo(CurrentBeatmap);
CurrentItem.BindValueChanged(i => sprite.Beatmap.Value = i?.Beatmap, true);
}
protected virtual UpdateableBeatmapBackgroundSprite CreateBackgroundSprite() => new UpdateableBeatmapBackgroundSprite { RelativeSizeAxes = Axes.Both };

View File

@ -1,7 +1,6 @@
// 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.
using System;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
@ -23,16 +22,13 @@ namespace osu.Game.Screens.Multi.Lounge
protected readonly FilterControl Filter;
private readonly Container content;
private readonly Action<Screen> pushGameplayScreen;
private readonly ProcessingOverlay processingOverlay;
[Resolved]
private Bindable<Room> currentRoom { get; set; }
public LoungeSubScreen(Action<Screen> pushGameplayScreen)
public LoungeSubScreen()
{
this.pushGameplayScreen = pushGameplayScreen;
InternalChildren = new Drawable[]
{
Filter = new FilterControl { Depth = -1 },
@ -83,8 +79,8 @@ namespace osu.Game.Screens.Multi.Lounge
content.Padding = new MarginPadding
{
Top = Filter.DrawHeight,
Left = SearchableListOverlay.WIDTH_PADDING - DrawableRoom.SELECTION_BORDER_WIDTH + OsuScreen.HORIZONTAL_OVERFLOW_PADDING,
Right = SearchableListOverlay.WIDTH_PADDING + OsuScreen.HORIZONTAL_OVERFLOW_PADDING,
Left = SearchableListOverlay.WIDTH_PADDING - DrawableRoom.SELECTION_BORDER_WIDTH + HORIZONTAL_OVERFLOW_PADDING,
Right = SearchableListOverlay.WIDTH_PADDING + HORIZONTAL_OVERFLOW_PADDING,
};
}
@ -114,7 +110,7 @@ namespace osu.Game.Screens.Multi.Lounge
private void joinRequested(Room room)
{
processingOverlay.Show();
Manager?.JoinRoom(room, r =>
RoomManager?.JoinRoom(room, r =>
{
Open(room);
processingOverlay.Hide();
@ -132,7 +128,7 @@ namespace osu.Game.Screens.Multi.Lounge
currentRoom.Value = room;
this.Push(new MatchSubScreen(room, s => pushGameplayScreen?.Invoke(s)));
this.Push(new MatchSubScreen(room));
}
}
}

View File

@ -108,7 +108,7 @@ namespace osu.Game.Screens.Multi.Match.Components
},
};
CurrentMods.BindValueChanged(m => modDisplay.Current.Value = m, true);
CurrentItem.BindValueChanged(i => modDisplay.Current.Value = i?.RequiredMods, true);
beatmapButton.Action = () => RequestBeatmapSelection?.Invoke();
}

View File

@ -92,8 +92,12 @@ namespace osu.Game.Screens.Multi.Match.Components
},
};
viewBeatmapButton.Beatmap.BindTo(CurrentBeatmap);
readyButton.Beatmap.BindTo(CurrentBeatmap);
CurrentItem.BindValueChanged(item =>
{
viewBeatmapButton.Beatmap.Value = item?.Beatmap;
readyButton.Beatmap.Value = item?.Beatmap;
}, true);
hostInfo.Host.BindTo(Host);
}
}

View File

@ -14,13 +14,13 @@ namespace osu.Game.Screens.Multi.Match.Components
{
public class ReadyButton : HeaderButton
{
public readonly IBindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
[Resolved(typeof(Room), nameof(Room.EndDate))]
private Bindable<DateTimeOffset> endDate { get; set; }
[Resolved]
private IBindableBeatmap gameBeatmap { get; set; }
private IBindable<WorkingBeatmap> gameBeatmap { get; set; }
[Resolved]
private BeatmapManager beatmaps { get; set; }

View File

@ -11,7 +11,7 @@ namespace osu.Game.Screens.Multi.Match.Components
{
public class ViewBeatmapButton : HeaderButton
{
public readonly IBindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
[Resolved(CanBeNull = true)]
private OsuGame osuGame { get; set; }

View File

@ -1,7 +1,7 @@
// 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.
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
@ -11,17 +11,17 @@ 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
{
public class MatchSubScreen : MultiplayerSubScreen
{
public override bool AllowBeatmapRulesetChange => false;
public override bool DisallowExternalBeatmapRulesetChanges => true;
public override string Title { get; }
@ -33,223 +33,215 @@ 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; }
[Resolved]
private BeatmapManager beatmapManager { get; set; }
[Resolved(CanBeNull = true)]
private OsuGame game { get; set; }
private MatchLeaderboard leaderboard;
public MatchSubScreen(Room room)
{
Title = room.RoomID.Value == null ? "New room" : room.Name;
}
InternalChild = new Match(pushGameplayScreen)
[BackgroundDependencyLoader]
private void load()
{
MatchChatDisplay chat;
Components.Header header;
Info info;
GridContainer bottomRow;
MatchSettingsOverlay settings;
InternalChildren = new Drawable[]
{
RelativeSizeAxes = Axes.Both,
RequestBeatmapSelection = () => this.Push(new MatchSongSelect
new GridContainer
{
Selected = item =>
RelativeSizeAxes = Axes.Both,
Content = new[]
{
playlist.Clear();
playlist.Add(item);
new Drawable[]
{
header = new Components.Header
{
Depth = -1,
RequestBeatmapSelection = () =>
{
this.Push(new MatchSongSelect
{
Selected = item =>
{
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
{
RelativeSizeAxes = Axes.Both
}
},
},
},
}
},
},
}),
RequestExit = () =>
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.Distributed),
}
},
new Container
{
if (this.IsCurrentScreen())
this.Exit();
}
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);
chat.Exit += () =>
{
if (this.IsCurrentScreen())
this.Exit();
};
beatmapManager.ItemAdded += beatmapAdded;
}
protected override void LoadComplete()
{
base.LoadComplete();
CurrentItem.BindValueChanged(currentItemChanged, true);
}
public override bool OnExiting(IScreen next)
{
Manager?.PartRoom();
RoomManager?.PartRoom();
return base.OnExiting(next);
}
private class Match : MultiplayerComposite
/// <summary>
/// Handles propagation of the current playlist item's content to game-wide mechanisms.
/// </summary>
private void currentItemChanged(PlaylistItem item)
{
public Action RequestBeatmapSelection;
public Action RequestExit;
// 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);
private readonly Action<Screen> pushGameplayScreen;
Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap);
CurrentMods.Value = item?.RequiredMods ?? Enumerable.Empty<Mod>();
if (item?.Ruleset != null)
Ruleset.Value = item.Ruleset;
}
private MatchLeaderboard leaderboard;
/// <summary>
/// Handle the case where a beatmap is imported (and can be used by this match).
/// </summary>
private void beatmapAdded(BeatmapSetInfo model, bool existing, bool silent) => Schedule(() =>
{
if (Beatmap.Value != beatmapManager.DefaultBeatmap)
return;
[Resolved]
private IBindableBeatmap gameBeatmap { get; set; }
if (Beatmap.Value == null)
return;
[Resolved]
private BeatmapManager beatmapManager { get; set; }
// Try to retrieve the corresponding local beatmap
var localBeatmap = beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == CurrentItem.Value.Beatmap.OnlineBeatmapID);
[Resolved(CanBeNull = true)]
private OsuGame game { get; set; }
if (localBeatmap != null)
Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap);
});
public Match(Action<Screen> pushGameplayScreen)
[Resolved(canBeNull: true)]
private Multiplayer multiplayer { get; set; }
private void onStart()
{
Beatmap.Value.Mods.Value = CurrentMods.Value.ToArray();
switch (type.Value)
{
this.pushGameplayScreen = pushGameplayScreen;
}
[BackgroundDependencyLoader]
private void load()
{
MatchChatDisplay chat;
Components.Header header;
Info info;
GridContainer bottomRow;
MatchSettingsOverlay settings;
InternalChildren = new Drawable[]
{
new GridContainer
default:
case GameTypeTimeshift _:
multiplayer?.Start(() => new TimeshiftPlayer(CurrentItem)
{
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.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);
chat.Exit += () => RequestExit?.Invoke();
beatmapManager.ItemAdded += beatmapAdded;
Exited = () => leaderboard.RefreshScores()
});
break;
}
}
protected override void LoadComplete()
{
base.LoadComplete();
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
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())
{
Exited = () => leaderboard.RefreshScores()
}));
break;
}
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (beatmapManager != null)
beatmapManager.ItemAdded -= beatmapAdded;
}
if (beatmapManager != null)
beatmapManager.ItemAdded -= beatmapAdded;
}
}
}

View File

@ -1,6 +1,7 @@
// 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.
using System;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
@ -8,7 +9,6 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Logging;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Containers;
@ -16,32 +16,22 @@ using osu.Game.Graphics.UserInterface;
using osu.Game.Input;
using osu.Game.Online.API;
using osu.Game.Online.Multiplayer;
using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapSet.Buttons;
using osu.Game.Screens.Menu;
using osu.Game.Screens.Multi.Lounge;
using osu.Game.Screens.Multi.Lounge.Components;
using osu.Game.Screens.Multi.Match;
using osu.Game.Screens.Play;
using osuTK;
namespace osu.Game.Screens.Multi
{
[Cached]
public class Multiplayer : CompositeDrawable, IOsuScreen, IOnlineComponent
public class Multiplayer : OsuScreen, IOnlineComponent
{
public bool AllowBeatmapRulesetChange => (screenStack.CurrentScreen as IMultiplayerSubScreen)?.AllowBeatmapRulesetChange ?? true;
public bool AllowExternalScreenChange => (screenStack.CurrentScreen as IMultiplayerSubScreen)?.AllowExternalScreenChange ?? true;
public bool CursorVisible => (screenStack.CurrentScreen as IMultiplayerSubScreen)?.AllowExternalScreenChange ?? true;
public override bool CursorVisible => (screenStack.CurrentScreen as IMultiplayerSubScreen)?.CursorVisible ?? true;
public bool HideOverlaysOnEnter => false;
public OverlayActivation InitialOverlayActivationMode => OverlayActivation.All;
public float BackgroundParallaxAmount => 1;
public bool ValidForResume { get; set; } = true;
public bool ValidForPush { get; set; } = true;
public override bool RemoveWhenNotAlive => false;
public override bool DisallowExternalBeatmapRulesetChanges => true;
private readonly MultiplayerWaveContainer waves;
@ -60,9 +50,6 @@ namespace osu.Game.Screens.Multi
[Cached(Type = typeof(IRoomManager))]
private RoomManager roomManager;
[Resolved]
private IBindableBeatmap beatmap { get; set; }
[Resolved]
private OsuGameBase game { get; set; }
@ -77,64 +64,61 @@ namespace osu.Game.Screens.Multi
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
RelativeSizeAxes = Axes.Both;
Padding = new MarginPadding { Horizontal = -HORIZONTAL_OVERFLOW_PADDING };
InternalChild = waves = new MultiplayerWaveContainer
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Masking = true,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex(@"3e3a44"),
},
new Triangles
{
RelativeSizeAxes = Axes.Both,
ColourLight = OsuColour.FromHex(@"3c3842"),
ColourDark = OsuColour.FromHex(@"393540"),
TriangleScale = 5,
},
},
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = Header.HEIGHT },
Child = screenStack = new ScreenStack(loungeSubScreen = new LoungeSubScreen()) { RelativeSizeAxes = Axes.Both }
},
new Header(screenStack),
createButton = new HeaderButton
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.None,
Size = new Vector2(150, Header.HEIGHT - 20),
Margin = new MarginPadding
{
Top = 10,
Right = 10 + HORIZONTAL_OVERFLOW_PADDING,
},
Text = "Create room",
Action = () => loungeSubScreen.Open(new Room
{
Name = { Value = $"{api.LocalUser}'s awesome room" }
}),
},
roomManager = new RoomManager()
}
};
screenStack = new ScreenStack(loungeSubScreen = new LoungeSubScreen(pushGameplayScreen)) { RelativeSizeAxes = Axes.Both };
Padding = new MarginPadding { Horizontal = -OsuScreen.HORIZONTAL_OVERFLOW_PADDING };
waves.AddRange(new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Masking = true,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex(@"3e3a44"),
},
new Triangles
{
RelativeSizeAxes = Axes.Both,
ColourLight = OsuColour.FromHex(@"3c3842"),
ColourDark = OsuColour.FromHex(@"393540"),
TriangleScale = 5,
},
},
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = Header.HEIGHT },
Child = screenStack
},
new Header(screenStack),
createButton = new HeaderButton
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.None,
Size = new Vector2(150, Header.HEIGHT - 20),
Margin = new MarginPadding
{
Top = 10,
Right = 10 + OsuScreen.HORIZONTAL_OVERFLOW_PADDING,
},
Text = "Create room",
Action = () => loungeSubScreen.Open(new Room
{
Name = { Value = $"{api.LocalUser}'s awesome room" }
}),
},
roomManager = new RoomManager()
});
screenStack.ScreenPushed += screenPushed;
screenStack.ScreenExited += screenExited;
}
@ -154,11 +138,9 @@ namespace osu.Game.Screens.Multi
isIdle.BindValueChanged(updatePollingRate, true);
}
private CachedModelDependencyContainer<Room> dependencies;
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
dependencies = new CachedModelDependencyContainer<Room>(base.CreateChildDependencies(parent));
var dependencies = new CachedModelDependencyContainer<Room>(base.CreateChildDependencies(parent));
dependencies.Model.BindTo(currentRoom);
return dependencies;
}
@ -169,12 +151,16 @@ namespace osu.Game.Screens.Multi
Logger.Log($"Polling adjusted to {roomManager.TimeBetweenPolls}");
}
private void pushGameplayScreen(IScreen gameplayScreen)
/// <summary>
/// Push a <see cref="Player"/> to the main screen stack to begin gameplay.
/// Generally called from a <see cref="MatchSubScreen"/> via DI resolution.
/// </summary>
public void Start(Func<Player> player)
{
if (!this.IsCurrentScreen())
return;
this.Push(gameplayScreen);
this.Push(new PlayerLoader(player));
}
public void APIStateChanged(APIAccess api, APIState state)
@ -195,14 +181,13 @@ namespace osu.Game.Screens.Multi
}
}
public void OnEntering(IScreen last)
public override void OnEntering(IScreen last)
{
this.FadeIn();
waves.Show();
}
public bool OnExiting(IScreen next)
public override bool OnExiting(IScreen next)
{
waves.Hide();
@ -215,23 +200,29 @@ namespace osu.Game.Screens.Multi
updatePollingRate(isIdle.Value);
// the wave overlay transition takes longer than expected to run.
logo?.AppendAnimatingAction(() => logo.Delay(WaveContainer.DISAPPEAR_DURATION / 2).FadeOut(), false);
base.OnExiting(next);
return false;
}
public void OnResuming(IScreen last)
protected override void LogoExiting(OsuLogo logo)
{
base.LogoExiting(logo);
// the wave overlay transition takes longer than expected to run.
logo.Delay(WaveContainer.DISAPPEAR_DURATION / 2).FadeOut();
}
public override void OnResuming(IScreen last)
{
this.FadeIn(250);
this.ScaleTo(1, 250, Easing.OutSine);
logo?.AppendAnimatingAction(() => OsuScreen.ApplyLogoArrivingDefaults(logo), true);
base.OnResuming(last);
updatePollingRate(isIdle.Value);
}
public void OnSuspending(IScreen next)
public override void OnSuspending(IScreen next)
{
this.ScaleTo(1.1f, 250, Easing.InSine);
this.FadeOut(250);
@ -242,7 +233,8 @@ namespace osu.Game.Screens.Multi
private void cancelLooping()
{
var track = beatmap?.Value?.Track;
var track = Beatmap?.Value?.Track;
if (track != null)
track.Looping = false;
}
@ -255,7 +247,7 @@ namespace osu.Game.Screens.Multi
if (screenStack.CurrentScreen is MatchSubScreen)
{
var track = beatmap.Value.Track;
var track = Beatmap.Value.Track;
if (track != null)
{
track.Looping = true;
@ -263,7 +255,7 @@ namespace osu.Game.Screens.Multi
if (!track.IsRunning)
{
game.Audio.AddItemToList(track);
track.Seek(beatmap.Value.Metadata.PreviewTime);
track.Seek(Beatmap.Value.Metadata.PreviewTime);
track.Start();
}
}

View File

@ -3,14 +3,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Online.Multiplayer;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Users;
namespace osu.Game.Screens.Multi
@ -35,6 +31,9 @@ namespace osu.Game.Screens.Multi
[Resolved(typeof(Room))]
protected BindableList<PlaylistItem> Playlist { get; private set; }
[Resolved(typeof(Room))]
protected Bindable<PlaylistItem> CurrentItem { get; private set; }
[Resolved(typeof(Room))]
protected Bindable<IEnumerable<User>> Participants { get; private set; }
@ -52,35 +51,5 @@ namespace osu.Game.Screens.Multi
[Resolved(typeof(Room))]
protected Bindable<TimeSpan> Duration { get; private set; }
private readonly Bindable<BeatmapInfo> currentBeatmap = new Bindable<BeatmapInfo>();
protected IBindable<BeatmapInfo> CurrentBeatmap => currentBeatmap;
private readonly Bindable<IEnumerable<Mod>> currentMods = new Bindable<IEnumerable<Mod>>();
protected IBindable<IEnumerable<Mod>> CurrentMods => currentMods;
private readonly Bindable<RulesetInfo> currentRuleset = new Bindable<RulesetInfo>();
protected IBindable<RulesetInfo> CurrentRuleset => currentRuleset;
protected override void LoadComplete()
{
base.LoadComplete();
Playlist.ItemsAdded += _ => updatePlaylist();
Playlist.ItemsRemoved += _ => updatePlaylist();
updatePlaylist();
}
private void updatePlaylist()
{
// Todo: We only ever have one playlist item for now. In the future, this will be user-settable
var playlistItem = Playlist.FirstOrDefault();
currentBeatmap.Value = playlistItem?.Beatmap;
currentMods.Value = playlistItem?.RequiredMods ?? Enumerable.Empty<Mod>();
currentRuleset.Value = playlistItem?.Ruleset;
}
}
}

View File

@ -3,43 +3,26 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Bindings;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers;
using osu.Game.Input.Bindings;
using osu.Game.Overlays;
namespace osu.Game.Screens.Multi
{
public abstract class MultiplayerSubScreen : CompositeDrawable, IMultiplayerSubScreen, IKeyBindingHandler<GlobalAction>
public abstract class MultiplayerSubScreen : OsuScreen, IMultiplayerSubScreen, IKeyBindingHandler<GlobalAction>
{
public virtual bool AllowBeatmapRulesetChange => true;
public bool AllowExternalScreenChange => true;
public bool CursorVisible => true;
public bool HideOverlaysOnEnter => false;
public OverlayActivation InitialOverlayActivationMode => OverlayActivation.All;
public float BackgroundParallaxAmount => 1;
public bool ValidForResume { get; set; } = true;
public bool ValidForPush { get; set; } = true;
public override bool DisallowExternalBeatmapRulesetChanges => false;
public override bool RemoveWhenNotAlive => false;
public abstract string Title { get; }
public virtual string ShortTitle => Title;
[Resolved]
protected IBindableBeatmap Beatmap { get; private set; }
[Resolved(CanBeNull = true)]
protected OsuGame Game { get; private set; }
[Resolved(CanBeNull = true)]
protected IRoomManager Manager { get; private set; }
protected IRoomManager RoomManager { get; private set; }
protected MultiplayerSubScreen()
{
@ -48,14 +31,14 @@ namespace osu.Game.Screens.Multi
RelativeSizeAxes = Axes.Both;
}
public virtual void OnEntering(IScreen last)
public override void OnEntering(IScreen last)
{
this.FadeInFromZero(WaveContainer.APPEAR_DURATION, Easing.OutQuint);
this.FadeInFromZero(WaveContainer.APPEAR_DURATION, Easing.OutQuint);
this.MoveToX(200).MoveToX(0, WaveContainer.APPEAR_DURATION, Easing.OutQuint);
}
public virtual bool OnExiting(IScreen next)
public override bool OnExiting(IScreen next)
{
this.FadeOut(WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint);
this.MoveToX(200, WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint);
@ -63,19 +46,19 @@ namespace osu.Game.Screens.Multi
return false;
}
public virtual void OnResuming(IScreen last)
public override void OnResuming(IScreen last)
{
this.FadeIn(WaveContainer.APPEAR_DURATION, Easing.OutQuint);
this.MoveToX(0, WaveContainer.APPEAR_DURATION, Easing.OutQuint);
}
public virtual void OnSuspending(IScreen next)
public override void OnSuspending(IScreen next)
{
this.FadeOut(WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint);
this.MoveToX(-200, WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint);
}
public virtual bool OnPressed(GlobalAction action)
public override bool OnPressed(GlobalAction action)
{
if (!this.IsCurrentScreen()) return false;

View File

@ -50,15 +50,28 @@ namespace osu.Game.Screens
protected new OsuGameBase Game => base.Game as OsuGameBase;
public virtual bool AllowBeatmapRulesetChange => true;
/// <summary>
/// Whether to disallow changes to game-wise Beatmap/Ruleset bindables for this screen (and all children).
/// </summary>
public virtual bool DisallowExternalBeatmapRulesetChanges => false;
protected readonly Bindable<WorkingBeatmap> Beatmap = new Bindable<WorkingBeatmap>();
private SampleChannel sampleExit;
public virtual float BackgroundParallaxAmount => 1;
protected readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
public Bindable<WorkingBeatmap> Beatmap { get; set; }
private SampleChannel sampleExit;
public Bindable<RulesetInfo> Ruleset { get; set; }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var deps = new OsuScreenDependencies(DisallowExternalBeatmapRulesetChanges, base.CreateChildDependencies(parent));
Beatmap = deps.Beatmap;
Ruleset = deps.Ruleset;
return deps;
}
protected BackgroundScreen Background => backgroundStack?.CurrentScreen as BackgroundScreen;
@ -77,11 +90,8 @@ namespace osu.Game.Screens
}
[BackgroundDependencyLoader(true)]
private void load(BindableBeatmap beatmap, OsuGame osu, AudioManager audio, Bindable<RulesetInfo> ruleset)
private void load(OsuGame osu, AudioManager audio)
{
Beatmap.BindTo(beatmap);
Ruleset.BindTo(ruleset);
sampleExit = audio.Sample.Get(@"UI/screen-back");
}
@ -134,7 +144,6 @@ namespace osu.Game.Screens
if (localBackground != null && backgroundStack?.CurrentScreen == localBackground)
backgroundStack?.Exit();
Beatmap.UnbindAll();
return false;
}

View File

@ -0,0 +1,41 @@
// 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.
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
namespace osu.Game.Screens
{
public class OsuScreenDependencies : DependencyContainer
{
public Bindable<WorkingBeatmap> Beatmap { get; }
public Bindable<RulesetInfo> Ruleset { get; }
public OsuScreenDependencies(bool requireLease, IReadOnlyDependencyContainer parent)
: base(parent)
{
if (requireLease)
{
Beatmap = parent.Get<LeasedBindable<WorkingBeatmap>>()?.GetBoundCopy();
if (Beatmap == null)
{
Cache(Beatmap = parent.Get<Bindable<WorkingBeatmap>>().BeginLease(true));
}
Ruleset = parent.Get<LeasedBindable<RulesetInfo>>()?.GetBoundCopy();
if (Ruleset == null)
{
Cache(Ruleset = parent.Get<Bindable<RulesetInfo>>().BeginLease(true));
}
}
else
{
Beatmap = (parent.Get<LeasedBindable<WorkingBeatmap>>() ?? parent.Get<Bindable<WorkingBeatmap>>()).GetBoundCopy();
Ruleset = (parent.Get<LeasedBindable<RulesetInfo>>() ?? parent.Get<Bindable<RulesetInfo>>()).GetBoundCopy();
}
}
}
}

View File

@ -383,7 +383,7 @@ namespace osu.Game.Screens.Play
return true;
}
if ((!AllowPause || HasFailed || !ValidForResume || pauseContainer?.IsPaused != false || RulesetContainer?.HasReplayLoaded != false) && (!pauseContainer?.IsResuming ?? true))
if ((!AllowPause || HasFailed || !ValidForResume || pauseContainer?.IsPaused.Value != false || RulesetContainer?.HasReplayLoaded.Value != false) && (!pauseContainer?.IsResuming ?? true))
{
// In the case of replays, we may have changed the playback rate.
applyRateFromMods();

View File

@ -37,6 +37,8 @@ namespace osu.Game.Screens.Play
private bool hideOverlays;
public override bool HideOverlaysOnEnter => hideOverlays;
public override bool DisallowExternalBeatmapRulesetChanges => true;
private Task loadTask;
public PlayerLoader(Func<Player> createPlayer)

View File

@ -17,7 +17,7 @@ namespace osu.Game.Screens.Play
protected override void LoadComplete()
{
base.LoadComplete();
RulesetContainer.SetReplayScore(score);
RulesetContainer?.SetReplayScore(score);
}
protected override ScoreInfo CreateScore() => score.ScoreInfo;

View File

@ -18,8 +18,6 @@ namespace osu.Game.Screens.Play
protected new BackgroundScreenBeatmap Background => base.Background as BackgroundScreenBeatmap;
public override bool AllowBeatmapRulesetChange => false;
protected const float BACKGROUND_FADE_DURATION = 800;
protected float BackgroundOpacity => 1 - (float)DimLevel;

View File

@ -17,8 +17,8 @@ namespace osu.Game.Screens.Play
protected override IEnumerable<IResultPageInfo> CreateResultPages() => new IResultPageInfo[]
{
new ScoreOverviewPageInfo(Score, Beatmap),
new LocalLeaderboardPageInfo(Score, Beatmap)
new ScoreOverviewPageInfo(Score, Beatmap.Value),
new LocalLeaderboardPageInfo(Score, Beatmap.Value)
};
}
}

View File

@ -32,7 +32,7 @@ namespace osu.Game.Screens.Ranking
private ResultModeTabControl modeChangeButtons;
public override bool AllowBeatmapRulesetChange => false;
public override bool DisallowExternalBeatmapRulesetChanges => true;
protected readonly ScoreInfo Score;

View File

@ -40,5 +40,21 @@ namespace osu.Game.Screens.Select
return true;
}
public override bool OnExiting(IScreen next)
{
Beatmap.Disabled = true;
Ruleset.Disabled = true;
return base.OnExiting(next);
}
public override void OnEntering(IScreen last)
{
base.OnEntering(last);
Beatmap.Disabled = false;
Ruleset.Disabled = false;
}
}
}

View File

@ -15,6 +15,8 @@ namespace osu.Game.Screens.Select
private bool removeAutoModOnResume;
private OsuScreen player;
public override bool AllowExternalScreenChange => true;
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
@ -58,7 +60,6 @@ namespace osu.Game.Screens.Select
}
Beatmap.Value.Track.Looping = false;
Beatmap.Disabled = true;
SampleConfirm?.Play();

View File

@ -45,8 +45,6 @@ namespace osu.Game.Screens.Select
protected virtual bool ShowFooter => true;
public override bool AllowExternalScreenChange => true;
/// <summary>
/// Can be null if <see cref="ShowFooter"/> is false.
/// </summary>
@ -78,7 +76,7 @@ namespace osu.Game.Screens.Select
protected readonly BeatmapDetailArea BeatmapDetails;
protected new readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
private readonly Bindable<RulesetInfo> decoupledRuleset = new Bindable<RulesetInfo>();
[Cached]
[Cached(Type = typeof(IBindable<IEnumerable<Mod>>))]
@ -268,8 +266,8 @@ namespace osu.Game.Screens.Select
{
dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.CacheAs(this);
dependencies.CacheAs(Ruleset);
dependencies.CacheAs<IBindable<RulesetInfo>>(Ruleset);
dependencies.CacheAs(decoupledRuleset);
dependencies.CacheAs<IBindable<RulesetInfo>>(decoupledRuleset);
return dependencies;
}
@ -334,9 +332,9 @@ namespace osu.Game.Screens.Select
if (this.IsCurrentScreen() && !Carousel.SelectBeatmap(beatmap?.BeatmapInfo, false))
// If selecting new beatmap without bypassing filters failed, there's possibly a ruleset mismatch
if (beatmap?.BeatmapInfo?.Ruleset != null && beatmap.BeatmapInfo.Ruleset != Ruleset.Value)
if (beatmap?.BeatmapInfo?.Ruleset != null && beatmap.BeatmapInfo.Ruleset != decoupledRuleset.Value)
{
base.Ruleset.Value = beatmap.BeatmapInfo.Ruleset;
Ruleset.Value = beatmap.BeatmapInfo.Ruleset;
Carousel.SelectBeatmap(beatmap.BeatmapInfo);
}
}
@ -377,12 +375,12 @@ namespace osu.Game.Screens.Select
bool preview = false;
if (ruleset?.Equals(Ruleset.Value) == false)
if (ruleset?.Equals(decoupledRuleset.Value) == false)
{
Logger.Log($"ruleset changed from \"{Ruleset.Value}\" to \"{ruleset}\"");
Logger.Log($"ruleset changed from \"{decoupledRuleset.Value}\" to \"{ruleset}\"");
Beatmap.Value.Mods.Value = Enumerable.Empty<Mod>();
Ruleset.Value = ruleset;
decoupledRuleset.Value = ruleset;
// force a filter before attempting to change the beatmap.
// we may still be in the wrong ruleset as there is a debounce delay on ruleset changes.
@ -539,7 +537,7 @@ namespace osu.Game.Screens.Select
{
base.Dispose(isDisposing);
Ruleset.UnbindAll();
decoupledRuleset.UnbindAll();
if (beatmaps != null)
{
@ -600,9 +598,11 @@ namespace osu.Game.Screens.Select
if (rulesetNoDebounce == null)
{
// manual binding to parent ruleset to allow for delayed load in the incoming direction.
rulesetNoDebounce = Ruleset.Value = base.Ruleset.Value;
base.Ruleset.ValueChanged += updateSelectedRuleset;
Ruleset.ValueChanged += r => base.Ruleset.Value = r;
rulesetNoDebounce = decoupledRuleset.Value = Ruleset.Value;
Ruleset.ValueChanged += updateSelectedRuleset;
decoupledRuleset.ValueChanged += r => Ruleset.Value = r;
decoupledRuleset.DisabledChanged += r => Ruleset.Disabled = r;
Beatmap.BindDisabledChanged(disabled => Carousel.AllowSelection = !disabled, true);
Beatmap.BindValueChanged(workingBeatmapChanged);

View File

@ -3,6 +3,7 @@
using osuTK;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Animations;
using osu.Framework.Graphics.Textures;
@ -63,7 +64,7 @@ namespace osu.Game.Storyboards.Drawables
}
[BackgroundDependencyLoader]
private void load(IBindableBeatmap beatmap, TextureStore textureStore)
private void load(IBindable<WorkingBeatmap> beatmap, TextureStore textureStore)
{
var basePath = Animation.Path.ToLowerInvariant();
for (var frame = 0; frame < Animation.FrameCount; frame++)

View File

@ -4,6 +4,7 @@
using System.IO;
using osu.Framework.Allocation;
using osu.Framework.Audio.Sample;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
@ -28,7 +29,7 @@ namespace osu.Game.Storyboards.Drawables
}
[BackgroundDependencyLoader]
private void load(IBindableBeatmap beatmap)
private void load(IBindable<WorkingBeatmap> beatmap)
{
// Try first with the full name, then attempt with no path
channel = beatmap.Value.Skin.GetSample(sample.Path) ?? beatmap.Value.Skin.GetSample(Path.ChangeExtension(sample.Path, null));

View File

@ -3,6 +3,7 @@
using osuTK;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
@ -62,7 +63,7 @@ namespace osu.Game.Storyboards.Drawables
}
[BackgroundDependencyLoader]
private void load(IBindableBeatmap beatmap, TextureStore textureStore)
private void load(IBindable<WorkingBeatmap> beatmap, TextureStore textureStore)
{
var spritePath = Sprite.Path.ToLowerInvariant();
var path = beatmap.Value.BeatmapSetInfo.Files.Find(f => f.Filename.ToLowerInvariant() == spritePath)?.FileInfo.StoragePath;

View File

@ -32,8 +32,8 @@ namespace osu.Game.Tests.Visual
// This is the earliest we can get OsuGameBase, which is used by the dummy working beatmap to find textures
beatmap.Default = new DummyWorkingBeatmap(Dependencies.Get<OsuGameBase>());
Dependencies.CacheAs<BindableBeatmap>(beatmap);
Dependencies.CacheAs<IBindableBeatmap>(beatmap);
Dependencies.CacheAs<Bindable<WorkingBeatmap>>(beatmap);
Dependencies.CacheAs<IBindable<WorkingBeatmap>>(beatmap);
Dependencies.CacheAs(Ruleset);
Dependencies.CacheAs<IBindable<RulesetInfo>>(Ruleset);
@ -58,11 +58,7 @@ namespace osu.Game.Tests.Visual
{
base.Dispose(isDisposing);
if (beatmap != null)
{
beatmap.Disabled = true;
beatmap.Value.Track.Stop();
}
beatmap?.Value.Track.Stop();
if (localStorage.IsValueCreated)
{

View File

@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.128.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.208.1" />
<PackageReference Include="ppy.osu.Framework" Version="2019.214.0" />
<PackageReference Include="SharpCompress" Version="0.22.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" />

View File

@ -105,8 +105,8 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.128.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.208.1" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2019.208.1" />
<PackageReference Include="ppy.osu.Framework" Version="2019.214.0" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2019.214.0" />
<PackageReference Include="SharpCompress" Version="0.22.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" />

View File

@ -68,6 +68,7 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ParameterHidesMember/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ParameterOnlyUsedForPreconditionCheck_002EGlobal/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ParameterOnlyUsedForPreconditionCheck_002ELocal/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleInterfaceMemberAmbiguity/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleMultipleEnumeration/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PrivateVariableCanBeMadeReadonly/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PublicConstructorInAbstractClass/@EntryIndexedValue">WARNING</s:String>
@ -204,6 +205,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HID/@EntryIndexedValue">HID</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HUD/@EntryIndexedValue">HUD</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ID/@EntryIndexedValue">ID</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IL/@EntryIndexedValue">IL</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IP/@EntryIndexedValue">IP</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IPC/@EntryIndexedValue">IPC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=LTRB/@EntryIndexedValue">LTRB</s:String>