1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 10:42:55 +08:00

Use leased bindables

This commit is contained in:
Dean Herbert 2019-02-01 15:42:15 +09:00
parent 499e06797a
commit ca5c8d37d1
40 changed files with 186 additions and 141 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

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

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

@ -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

@ -292,7 +292,7 @@ namespace osu.Game
return;
}
if ((screenStack.CurrentScreen as IOsuScreen)?.AllowExternalScreenChange != true)
if ((screenStack.CurrentScreen as IOsuScreen)?.DisallowExternalBeatmapRulesetChanges != false)
{
notifications.Post(new SimpleNotification
{
@ -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,9 +15,7 @@ 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 AllowExternalScreenChange { get; }
bool DisallowExternalBeatmapRulesetChanges { get; }
/// <summary>
/// Whether this <see cref="OsuScreen"/> allows the cursor to be displayed.
@ -35,5 +36,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

@ -19,7 +19,7 @@ namespace osu.Game.Screens.Multi.Match.Components
private readonly Room room;
[Resolved]
private IBindableBeatmap gameBeatmap { get; set; }
private IBindable<WorkingBeatmap> gameBeatmap { get; set; }
[Resolved]
private BeatmapManager beatmaps { get; set; }

View File

@ -20,7 +20,7 @@ namespace osu.Game.Screens.Multi.Match
{
public class MatchSubScreen : MultiplayerSubScreen
{
public override bool AllowBeatmapRulesetChange => false;
public override bool DisallowExternalBeatmapRulesetChanges => true;
public override string Title => room.RoomID.Value == null ? "New room" : room.Name.Value;
public override string ShortTitle => "room";
@ -167,7 +167,7 @@ namespace osu.Game.Screens.Multi.Match
// 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));
Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap);
}
private void setRuleset(RulesetInfo ruleset)
@ -175,7 +175,7 @@ namespace osu.Game.Screens.Multi.Match
if (ruleset == null)
return;
Game?.ForcefullySetRuleset(ruleset);
Ruleset.Value = ruleset;
}
private void beatmapAdded(BeatmapSetInfo model, bool existing, bool silent) => Schedule(() =>
@ -190,7 +190,7 @@ namespace osu.Game.Screens.Multi.Match
var localBeatmap = beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == bindings.CurrentBeatmap.Value.OnlineBeatmapID);
if (localBeatmap != null)
Game?.ForcefullySetBeatmap(beatmapManager.GetWorkingBeatmap(localBeatmap));
Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap);
});
private void addPlaylistItem(PlaylistItem item)

View File

@ -18,6 +18,7 @@ using osu.Game.Online.API;
using osu.Game.Online.Multiplayer;
using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapSet.Buttons;
using osu.Game.Rulesets;
using osu.Game.Screens.Menu;
using osu.Game.Screens.Multi.Lounge;
using osu.Game.Screens.Multi.Match;
@ -28,9 +29,9 @@ namespace osu.Game.Screens.Multi
[Cached]
public class Multiplayer : CompositeDrawable, IOsuScreen, 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 bool DisallowExternalBeatmapRulesetChanges => false;
public bool CursorVisible => (screenStack.CurrentScreen as IMultiplayerSubScreen)?.CursorVisible ?? true;
public bool HideOverlaysOnEnter => false;
public OverlayActivation InitialOverlayActivationMode => OverlayActivation.All;
@ -51,9 +52,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; }
@ -63,6 +61,14 @@ namespace osu.Game.Screens.Multi
[Resolved(CanBeNull = true)]
private OsuLogo logo { get; set; }
public Bindable<WorkingBeatmap> Beatmap => screenDependencies.Beatmap;
public Bindable<RulesetInfo> Ruleset => screenDependencies.Ruleset;
private OsuScreenDependencies screenDependencies;
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) => screenDependencies = new OsuScreenDependencies(DisallowExternalBeatmapRulesetChanges, base.CreateChildDependencies(parent));
public Multiplayer()
{
Anchor = Anchor.Centre;
@ -182,6 +188,8 @@ namespace osu.Game.Screens.Multi
{
waves.Hide();
screenDependencies.Dispose();
this.Delay(WaveContainer.DISAPPEAR_DURATION).FadeOut();
cancelLooping();
@ -218,7 +226,7 @@ namespace osu.Game.Screens.Multi
private void cancelLooping()
{
var track = beatmap.Value.Track;
var track = Beatmap.Value.Track;
if (track != null)
track.Looping = false;
}
@ -231,7 +239,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;
@ -239,7 +247,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

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Bindings;
@ -10,13 +11,14 @@ using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers;
using osu.Game.Input.Bindings;
using osu.Game.Overlays;
using osu.Game.Rulesets;
namespace osu.Game.Screens.Multi
{
public abstract class MultiplayerSubScreen : CompositeDrawable, IMultiplayerSubScreen, IKeyBindingHandler<GlobalAction>
{
public virtual bool AllowBeatmapRulesetChange => true;
public bool AllowExternalScreenChange => true;
public virtual bool DisallowExternalBeatmapRulesetChanges => false;
public bool CursorVisible => true;
public bool HideOverlaysOnEnter => false;
@ -32,8 +34,13 @@ namespace osu.Game.Screens.Multi
public abstract string Title { get; }
public virtual string ShortTitle => Title;
[Resolved]
protected IBindableBeatmap Beatmap { get; private set; }
public Bindable<WorkingBeatmap> Beatmap => screenDependencies.Beatmap;
public Bindable<RulesetInfo> Ruleset => screenDependencies.Ruleset;
private OsuScreenDependencies screenDependencies;
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) => screenDependencies = new OsuScreenDependencies(DisallowExternalBeatmapRulesetChanges, base.CreateChildDependencies(parent));
[Resolved(CanBeNull = true)]
protected OsuGame Game { get; private set; }
@ -60,6 +67,8 @@ namespace osu.Game.Screens.Multi
this.FadeOut(WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint);
this.MoveToX(200, WaveContainer.DISAPPEAR_DURATION, Easing.OutQuint);
screenDependencies.Dispose();
return false;
}

View File

@ -22,9 +22,9 @@ namespace osu.Game.Screens.Multi.Ranking
protected override IEnumerable<IResultPageInfo> CreateResultPages() => new IResultPageInfo[]
{
new ScoreOverviewPageInfo(Score, Beatmap),
new LocalLeaderboardPageInfo(Score, Beatmap),
new RoomLeaderboardPageInfo(Score, Beatmap, room),
new ScoreOverviewPageInfo(Score, Beatmap.Value),
new LocalLeaderboardPageInfo(Score, Beatmap.Value),
new RoomLeaderboardPageInfo(Score, Beatmap.Value, room),
};
}
}

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 Microsoft.EntityFrameworkCore.Internal;
using osu.Framework.Allocation;
using osu.Framework.Audio;
@ -50,15 +51,23 @@ namespace osu.Game.Screens
protected new OsuGameBase Game => base.Game as OsuGameBase;
public virtual bool AllowBeatmapRulesetChange => true;
protected readonly Bindable<WorkingBeatmap> Beatmap = new Bindable<WorkingBeatmap>();
/// <summary>
/// Disallow changes to game-wise Beatmap/Ruleset bindables for this screen (and all children).
/// </summary>
public virtual bool DisallowExternalBeatmapRulesetChanges => false;
private SampleChannel sampleExit;
public virtual float BackgroundParallaxAmount => 1;
protected readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
public Bindable<WorkingBeatmap> Beatmap => screenDependencies.Beatmap;
private SampleChannel sampleExit;
public Bindable<RulesetInfo> Ruleset => screenDependencies.Ruleset;
private OsuScreenDependencies screenDependencies;
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) => screenDependencies = new OsuScreenDependencies(DisallowExternalBeatmapRulesetChanges, base.CreateChildDependencies(parent));
protected BackgroundScreen Background => backgroundStack?.CurrentScreen as BackgroundScreen;
@ -77,11 +86,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 +140,8 @@ namespace osu.Game.Screens
if (localBackground != null && backgroundStack?.CurrentScreen == localBackground)
backgroundStack?.Exit();
Beatmap.UnbindAll();
screenDependencies.Dispose();
return false;
}
@ -201,4 +208,53 @@ namespace osu.Game.Screens
/// </summary>
protected virtual BackgroundScreen CreateBackground() => null;
}
public class OsuScreenDependencies : DependencyContainer, IDisposable
{
private readonly bool leaseOwner;
public Bindable<WorkingBeatmap> Beatmap { get; private set; }
public Bindable<RulesetInfo> Ruleset { get; private set; }
public OsuScreenDependencies(bool requireLease, IReadOnlyDependencyContainer parent)
: base(parent)
{
if (requireLease)
{
Beatmap = parent.Get<LeasedBindable<WorkingBeatmap>>()?.GetBoundCopy();
if (Beatmap == null)
{
leaseOwner = true;
Cache(Beatmap = parent.Get<Bindable<WorkingBeatmap>>().BeginLease(true));
}
Ruleset = parent.Get<LeasedBindable<RulesetInfo>>()?.GetBoundCopy();
if (Ruleset == null)
{
leaseOwner = true;
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();
}
}
public void Dispose()
{
if (leaseOwner)
{
((LeasedBindable<WorkingBeatmap>)Beatmap).Return();
((LeasedBindable<RulesetInfo>)Ruleset).Return();
}
else
{
Beatmap.UnbindAll();
Ruleset.UnbindAll();
}
}
}
}

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

@ -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

@ -77,7 +77,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>>))]
@ -267,8 +267,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;
}
@ -333,9 +333,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);
}
}
@ -376,12 +376,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.
@ -538,7 +538,7 @@ namespace osu.Game.Screens.Select
{
base.Dispose(isDisposing);
Ruleset.UnbindAll();
decoupledRuleset.UnbindAll();
if (beatmaps != null)
{
@ -599,9 +599,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

@ -33,7 +33,7 @@ namespace osu.Game.Tests.Visual
beatmap.Default = new DummyWorkingBeatmap(Dependencies.Get<OsuGameBase>());
Dependencies.CacheAs<BindableBeatmap>(beatmap);
Dependencies.CacheAs<IBindableBeatmap>(beatmap);
Dependencies.CacheAs<IBindable<WorkingBeatmap>>(beatmap);
Dependencies.CacheAs(Ruleset);
Dependencies.CacheAs<IBindable<RulesetInfo>>(Ruleset);

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>