1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:47:29 +08:00

Merge pull request #2885 from peppy/non-null-ruleset

Make BindableRuleset non-null
This commit is contained in:
Dan Balasescu 2018-07-02 16:04:31 +09:00 committed by GitHub
commit 7d256f6595
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 39 additions and 35 deletions

View File

@ -65,17 +65,19 @@ namespace osu.Game.Tests.Visual
foreach (var rulesetInfo in rulesets.AvailableRulesets)
{
var ruleset = rulesetInfo.CreateInstance();
var instance = rulesetInfo.CreateInstance();
var testBeatmap = createTestBeatmap(rulesetInfo);
beatmaps.Add(testBeatmap);
AddStep("set ruleset", () => Ruleset.Value = rulesetInfo);
selectBeatmap(testBeatmap);
testBeatmapLabels(ruleset);
testBeatmapLabels(instance);
// TODO: adjust cases once more info is shown for other gamemodes
switch (ruleset)
switch (instance)
{
case OsuRuleset _:
testInfoLabels(5);

View File

@ -77,7 +77,7 @@ namespace osu.Game.Tests.Visual
foreach (var rulesetInfo in rulesets.AvailableRulesets)
{
Ruleset ruleset = rulesetInfo.CreateInstance();
AddStep($"switch to {ruleset.Description}", () => modSelect.Ruleset.Value = rulesetInfo);
AddStep($"switch to {ruleset.Description}", () => Ruleset.Value = rulesetInfo);
switch (ruleset)
{

View File

@ -40,7 +40,7 @@ namespace osu.Game.Overlays.Mods
public readonly Bindable<IEnumerable<Mod>> SelectedMods = new Bindable<IEnumerable<Mod>>();
public readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
public readonly IBindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
private void rulesetChanged(RulesetInfo newRuleset)
{
@ -51,8 +51,8 @@ namespace osu.Game.Overlays.Mods
refreshSelectedMods();
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuColour colours, Bindable<RulesetInfo> ruleset, RulesetStore rulesets, AudioManager audio)
[BackgroundDependencyLoader]
private void load(OsuColour colours, IBindable<RulesetInfo> ruleset, AudioManager audio)
{
SelectedMods.ValueChanged += selectedModsChanged;
@ -60,13 +60,8 @@ namespace osu.Game.Overlays.Mods
HighMultiplierColour = colours.Green;
UnrankedLabel.Colour = colours.Blue;
if (ruleset != null)
Ruleset.BindTo(ruleset);
else
Ruleset.Value = rulesets.AvailableRulesets.First();
Ruleset.ValueChanged += rulesetChanged;
Ruleset.TriggerChange();
Ruleset.BindTo(ruleset);
Ruleset.BindValueChanged(rulesetChanged, true);
sampleOn = audio.Sample.Get(@"UI/check-on");
sampleOff = audio.Sample.Get(@"UI/check-off");

View File

@ -67,7 +67,7 @@ namespace osu.Game.Overlays.Toolbar
};
}
[BackgroundDependencyLoader(true)]
[BackgroundDependencyLoader]
private void load(RulesetStore rulesets, Bindable<RulesetInfo> parentRuleset)
{
this.rulesets = rulesets;
@ -82,11 +82,7 @@ namespace osu.Game.Overlays.Toolbar
ruleset.ValueChanged += rulesetChanged;
ruleset.DisabledChanged += disabledChanged;
if (parentRuleset != null)
ruleset.BindTo(parentRuleset);
else
ruleset.Value = rulesets.AvailableRulesets.FirstOrDefault();
ruleset.BindTo(parentRuleset);
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)

View File

@ -82,11 +82,8 @@ namespace osu.Game.Screens
[BackgroundDependencyLoader(true)]
private void load(BindableBeatmap beatmap, OsuGame osu, AudioManager audio, Bindable<RulesetInfo> ruleset)
{
if (beatmap != null)
Beatmap.BindTo(beatmap);
if (ruleset != null)
Ruleset.BindTo(ruleset);
Beatmap.BindTo(beatmap);
Ruleset.BindTo(ruleset);
if (osu != null)
{

View File

@ -55,8 +55,7 @@ namespace osu.Game.Screens.Select
[BackgroundDependencyLoader(true)]
private void load([CanBeNull] Bindable<RulesetInfo> parentRuleset)
{
if (parentRuleset != null)
ruleset.BindTo(parentRuleset);
ruleset.BindTo(parentRuleset);
ruleset.ValueChanged += _ => updateDisplay();
}

View File

@ -29,6 +29,7 @@ namespace osu.Game.Screens.Select
private readonly TabControl<GroupMode> groupTabs;
private SortMode sort = SortMode.Title;
public SortMode Sort
{
get { return sort; }
@ -43,6 +44,7 @@ namespace osu.Game.Screens.Select
}
private GroupMode group = GroupMode.All;
public GroupMode Group
{
get { return group; }
@ -69,7 +71,8 @@ namespace osu.Game.Screens.Select
private readonly SearchTextBox searchTextBox;
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => base.ReceiveMouseInputAt(screenSpacePos) || groupTabs.ReceiveMouseInputAt(screenSpacePos) || sortTabs.ReceiveMouseInputAt(screenSpacePos);
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) =>
base.ReceiveMouseInputAt(screenSpacePos) || groupTabs.ReceiveMouseInputAt(screenSpacePos) || sortTabs.ReceiveMouseInputAt(screenSpacePos);
public FilterControl()
{
@ -177,8 +180,7 @@ namespace osu.Game.Screens.Select
showConverted = config.GetBindable<bool>(OsuSetting.ShowConvertedBeatmaps);
showConverted.ValueChanged += val => updateCriteria();
if (parentRuleset != null)
ruleset.BindTo(parentRuleset);
ruleset.BindTo(parentRuleset);
ruleset.BindValueChanged(val => updateCriteria(), true);
}

View File

@ -41,6 +41,7 @@ namespace osu.Game.Screens.Select.Leaderboards
private ScheduledDelegate showScoresDelegate;
private IEnumerable<Score> scores;
public IEnumerable<Score> Scores
{
get { return scores; }
@ -196,9 +197,7 @@ namespace osu.Game.Screens.Select.Leaderboards
{
this.api = api;
if (parentRuleset != null)
ruleset.BindTo(parentRuleset);
ruleset.BindTo(parentRuleset);
ruleset.ValueChanged += _ => updateScores();
if (api != null)

View File

@ -1,10 +1,13 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Configuration;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
namespace osu.Game.Tests.Visual
{
@ -13,6 +16,8 @@ namespace osu.Game.Tests.Visual
private readonly OsuTestBeatmap beatmap = new OsuTestBeatmap(new DummyWorkingBeatmap());
protected BindableBeatmap Beatmap => beatmap;
protected readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
protected DependencyContainer Dependencies { get; private set; }
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
@ -22,13 +27,18 @@ namespace osu.Game.Tests.Visual
Dependencies.CacheAs<BindableBeatmap>(beatmap);
Dependencies.CacheAs<IBindableBeatmap>(beatmap);
Dependencies.CacheAs(Ruleset);
Dependencies.CacheAs<IBindable<RulesetInfo>>(Ruleset);
return Dependencies;
}
[BackgroundDependencyLoader]
private void load(AudioManager audioManager)
private void load(AudioManager audioManager, RulesetStore rulesets)
{
beatmap.SetAudioManager(audioManager);
Ruleset.Value = rulesets.AvailableRulesets.First();
}
protected override void Dispose(bool isDisposing)

View File

@ -86,7 +86,11 @@ namespace osu.Game.Tests.Visual
private readonly WeakList<WorkingBeatmap> workingWeakReferences = new WeakList<WorkingBeatmap>();
private readonly WeakList<Player> playerWeakReferences = new WeakList<Player>();
private Player loadPlayerFor(RulesetInfo ri) => loadPlayerFor(ri.CreateInstance());
private Player loadPlayerFor(RulesetInfo ri)
{
Ruleset.Value = ri;
return loadPlayerFor(ri.CreateInstance());
}
private Player loadPlayerFor(Ruleset r)
{