1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 02:13:21 +08:00

Fix various crashes due to bindable being disabled

This commit is contained in:
smoogipoo 2019-04-09 12:44:03 +09:00
parent ad124bfeec
commit cbb3fdaca8
5 changed files with 13 additions and 25 deletions

View File

@ -35,10 +35,6 @@ namespace osu.Game.Tests.Visual.SongSelect
private WorkingBeatmap defaultBeatmap;
private DatabaseContextFactory factory;
[Cached]
[Cached(Type = typeof(IBindable<IEnumerable<Mod>>))]
private readonly Bindable<IEnumerable<Mod>> selectedMods = new Bindable<IEnumerable<Mod>>(new Mod[] { });
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(Screens.Select.SongSelect),
@ -185,7 +181,7 @@ namespace osu.Game.Tests.Visual.SongSelect
});
AddAssert("mods changed before ruleset", () => modChangeIndex < rulesetChangeIndex);
AddAssert("empty mods", () => !selectedMods.Value.Any());
AddAssert("empty mods", () => !SelectedMods.Value.Any());
void onModChange(ValueChangedEvent<IEnumerable<Mod>> e) => modChangeIndex = actionIndex++;
void onRulesetChange(ValueChangedEvent<RulesetInfo> e) => rulesetChangeIndex = actionIndex--;
@ -218,7 +214,7 @@ namespace osu.Game.Tests.Visual.SongSelect
private static int importId;
private int getImportId() => ++importId;
private void changeMods(params Mod[] mods) => AddStep($"change mods to {string.Join(", ", mods.Select(m => m.Acronym))}", () => selectedMods.Value = mods);
private void changeMods(params Mod[] mods) => AddStep($"change mods to {string.Join(", ", mods.Select(m => m.Acronym))}", () => SelectedMods.Value = mods);
private void changeRuleset(int id) => AddStep($"change ruleset to {id}", () => Ruleset.Value = rulesets.AvailableRulesets.First(r => r.ID == id));

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.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@ -42,9 +41,6 @@ namespace osu.Game.Screens.Multi.Match
[Resolved(typeof(Room))]
protected Bindable<PlaylistItem> CurrentItem { get; private set; }
[Resolved]
protected Bindable<IEnumerable<Mod>> SelectedMods { get; private set; }
[Resolved]
private BeatmapManager beatmapManager { get; set; }

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
@ -14,7 +13,6 @@ using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.Multiplayer;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
using osu.Game.Screens.Multi.Ranking;
using osu.Game.Screens.Play;
@ -37,9 +35,6 @@ namespace osu.Game.Screens.Multi.Play
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; }
[Resolved]
private Bindable<IEnumerable<Mod>> selectedMods { get; set; }
public TimeshiftPlayer(PlaylistItem playlistItem)
{
this.playlistItem = playlistItem;
@ -61,7 +56,7 @@ namespace osu.Game.Screens.Multi.Play
if (ruleset.Value.ID != playlistItem.Ruleset.ID)
throw new InvalidOperationException("Current Ruleset does not match PlaylistItem's Ruleset");
if (!playlistItem.RequiredMods.All(m => selectedMods.Value.Contains(m)))
if (!playlistItem.RequiredMods.All(m => SelectedMods.Value.Contains(m)))
throw new InvalidOperationException("Current Mods do not match PlaylistItem's RequiredMods");
var req = new CreateRoomScoreRequest(roomId.Value ?? 0, playlistItem.ID);

View File

@ -66,6 +66,7 @@ namespace osu.Game.Screens.Select
Beatmap.Disabled = true;
Ruleset.Disabled = true;
SelectedMods.Disabled = true;
return false;
}
@ -76,6 +77,7 @@ namespace osu.Game.Screens.Select
Beatmap.Disabled = false;
Ruleset.Disabled = false;
SelectedMods.Disabled = false;
}
}
}

View File

@ -83,7 +83,9 @@ namespace osu.Game.Screens.Select
private readonly Bindable<RulesetInfo> decoupledRuleset = new Bindable<RulesetInfo>();
protected readonly Bindable<IEnumerable<Mod>> SelectedMods = new Bindable<IEnumerable<Mod>>(Enumerable.Empty<Mod>());
[Cached]
[Cached(Type = typeof(IBindable<IEnumerable<Mod>>))]
private readonly Bindable<IEnumerable<Mod>> selectedMods = new Bindable<IEnumerable<Mod>>(Enumerable.Empty<Mod>()); // Bound to the game's mods, but is not reset on exiting
protected SongSelect()
{
@ -217,6 +219,8 @@ namespace osu.Game.Screens.Select
[BackgroundDependencyLoader(true)]
private void load(BeatmapManager beatmaps, AudioManager audio, DialogOverlay dialog, OsuColour colours, SkinManager skins)
{
selectedMods.BindTo(SelectedMods);
if (Footer != null)
{
Footer.AddButton(@"mods", colours.Yellow, ModSelect, Key.F1);
@ -265,11 +269,6 @@ namespace osu.Game.Screens.Select
{
dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
SelectedMods.BindTo(base.SelectedMods);
dependencies.CacheAs(SelectedMods);
dependencies.CacheAs<IBindable<IEnumerable<Mod>>>(SelectedMods);
dependencies.CacheAs(this);
dependencies.CacheAs(decoupledRuleset);
dependencies.CacheAs<IBindable<RulesetInfo>>(decoupledRuleset);
@ -395,7 +394,7 @@ namespace osu.Game.Screens.Select
{
Logger.Log($"ruleset changed from \"{decoupledRuleset.Value}\" to \"{ruleset}\"");
SelectedMods.Value = Enumerable.Empty<Mod>();
selectedMods.Value = Enumerable.Empty<Mod>();
decoupledRuleset.Value = ruleset;
// force a filter before attempting to change the beatmap.
@ -530,8 +529,8 @@ namespace osu.Game.Screens.Select
if (Beatmap.Value.Track != null)
Beatmap.Value.Track.Looping = false;
SelectedMods.UnbindAll();
base.SelectedMods.Value = Enumerable.Empty<Mod>();
selectedMods.UnbindAll();
SelectedMods.Value = Enumerable.Empty<Mod>();
return false;
}