mirror of
https://github.com/ppy/osu
synced 2024-12-11 17:42:28 +00:00
Privatise game ruleset and access via DI
Also decouples the bindable at SongSelect, where it is debounced in line with the carousel being updated.
This commit is contained in:
parent
a8579c49f9
commit
b0a1b25983
@ -85,7 +85,7 @@ namespace osu.Game
|
||||
private OnScreenDisplay onscreenDisplay;
|
||||
|
||||
private Bindable<int> configRuleset;
|
||||
public Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
|
||||
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
|
||||
|
||||
private Bindable<int> configSkin;
|
||||
|
||||
@ -146,11 +146,12 @@ namespace osu.Game
|
||||
}
|
||||
|
||||
dependencies.CacheAs(this);
|
||||
dependencies.CacheAs(ruleset);
|
||||
|
||||
// bind config int to database RulesetInfo
|
||||
configRuleset = LocalConfig.GetBindable<int>(OsuSetting.Ruleset);
|
||||
Ruleset.Value = RulesetStore.GetRuleset(configRuleset.Value) ?? RulesetStore.AvailableRulesets.First();
|
||||
Ruleset.ValueChanged += r => configRuleset.Value = r.ID ?? 0;
|
||||
ruleset.Value = RulesetStore.GetRuleset(configRuleset.Value) ?? RulesetStore.AvailableRulesets.First();
|
||||
ruleset.ValueChanged += r => configRuleset.Value = r.ID ?? 0;
|
||||
|
||||
// bind config int to database SkinInfo
|
||||
configSkin = LocalConfig.GetBindable<int>(OsuSetting.Skin);
|
||||
@ -216,7 +217,7 @@ namespace osu.Game
|
||||
return;
|
||||
}
|
||||
|
||||
Ruleset.Value = s.Ruleset;
|
||||
ruleset.Value = s.Ruleset;
|
||||
|
||||
Beatmap.Value = BeatmapManager.GetWorkingBeatmap(s.Beatmap);
|
||||
Beatmap.Value.Mods.Value = s.Mods;
|
||||
@ -550,7 +551,7 @@ namespace osu.Game
|
||||
// the use case for not applying is in visual/unit tests.
|
||||
bool applyRestrictions = !currentScreen?.AllowBeatmapRulesetChange ?? false;
|
||||
|
||||
Ruleset.Disabled = applyRestrictions;
|
||||
ruleset.Disabled = applyRestrictions;
|
||||
Beatmap.Disabled = applyRestrictions;
|
||||
|
||||
mainContent.Padding = new MarginPadding { Top = ToolbarOffset };
|
||||
|
@ -35,15 +35,13 @@ namespace osu.Game.Overlays.Direct
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(OsuGame game, RulesetStore rulesets, OsuColour colours)
|
||||
private void load(RulesetStore rulesets, OsuColour colours, Bindable<RulesetInfo> ruleset)
|
||||
{
|
||||
DisplayStyleControl.Dropdown.AccentColour = colours.BlueDark;
|
||||
|
||||
Ruleset.Value = game?.Ruleset.Value ?? rulesets.GetRuleset(0);
|
||||
Ruleset.Value = ruleset ?? rulesets.GetRuleset(0);
|
||||
foreach (var r in rulesets.AvailableRulesets)
|
||||
{
|
||||
modeButtons.Add(new RulesetToggleButton(Ruleset, r));
|
||||
}
|
||||
}
|
||||
|
||||
private class RulesetToggleButton : OsuClickableContainer
|
||||
|
@ -52,7 +52,7 @@ namespace osu.Game.Overlays.Mods
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(permitNulls: true)]
|
||||
private void load(OsuColour colours, OsuGame osu, RulesetStore rulesets, AudioManager audio)
|
||||
private void load(OsuColour colours, Bindable<RulesetInfo> ruleset, RulesetStore rulesets, AudioManager audio)
|
||||
{
|
||||
SelectedMods.ValueChanged += selectedModsChanged;
|
||||
|
||||
@ -60,8 +60,8 @@ namespace osu.Game.Overlays.Mods
|
||||
HighMultiplierColour = colours.Green;
|
||||
UnrankedLabel.Colour = colours.Blue;
|
||||
|
||||
if (osu != null)
|
||||
Ruleset.BindTo(osu.Ruleset);
|
||||
if (ruleset != null)
|
||||
Ruleset.BindTo(ruleset);
|
||||
else
|
||||
Ruleset.Value = rulesets.AvailableRulesets.First();
|
||||
|
||||
|
@ -68,7 +68,7 @@ namespace osu.Game.Overlays.Toolbar
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(RulesetStore rulesets, OsuGame game)
|
||||
private void load(RulesetStore rulesets, Bindable<RulesetInfo> parentRuleset)
|
||||
{
|
||||
this.rulesets = rulesets;
|
||||
foreach (var r in rulesets.AvailableRulesets)
|
||||
@ -83,8 +83,8 @@ namespace osu.Game.Overlays.Toolbar
|
||||
ruleset.ValueChanged += rulesetChanged;
|
||||
ruleset.DisabledChanged += disabledChanged;
|
||||
|
||||
if (game != null)
|
||||
ruleset.BindTo(game.Ruleset);
|
||||
if (ruleset != null)
|
||||
ruleset.BindTo(parentRuleset);
|
||||
else
|
||||
ruleset.Value = rulesets.AvailableRulesets.FirstOrDefault();
|
||||
}
|
||||
|
@ -82,22 +82,24 @@ namespace osu.Game.Screens
|
||||
private SampleChannel sampleExit;
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(BindableBeatmap beatmap, OsuGame osuGame, AudioManager audio)
|
||||
private void load(BindableBeatmap beatmap, OsuGame osu, AudioManager audio, Bindable<RulesetInfo> ruleset)
|
||||
{
|
||||
if (beatmap != null)
|
||||
Beatmap.BindTo(beatmap);
|
||||
|
||||
if (osuGame != null)
|
||||
if (ruleset != null)
|
||||
Ruleset.BindTo(ruleset);
|
||||
|
||||
if (osu != null)
|
||||
{
|
||||
Ruleset.BindTo(osuGame.Ruleset);
|
||||
OverlayActivationMode.BindTo(osuGame.OverlayActivationMode);
|
||||
OverlayActivationMode.BindTo(osu.OverlayActivationMode);
|
||||
|
||||
updateOverlayStates = () =>
|
||||
{
|
||||
if (HideOverlaysOnEnter)
|
||||
osuGame.CloseAllOverlays();
|
||||
osu.CloseAllOverlays();
|
||||
else
|
||||
osuGame.Toolbar.State = Visibility.Visible;
|
||||
osu.Toolbar.State = Visibility.Visible;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -53,10 +53,10 @@ namespace osu.Game.Screens.Select
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load([CanBeNull] OsuGame osuGame)
|
||||
private void load([CanBeNull] Bindable<RulesetInfo> parentRuleset)
|
||||
{
|
||||
if (osuGame != null)
|
||||
ruleset.BindTo(osuGame.Ruleset);
|
||||
if (parentRuleset != null)
|
||||
ruleset.BindTo(parentRuleset);
|
||||
ruleset.ValueChanged += _ => updateDisplay();
|
||||
}
|
||||
|
||||
|
@ -170,15 +170,15 @@ namespace osu.Game.Screens.Select
|
||||
public readonly Box Background;
|
||||
|
||||
[BackgroundDependencyLoader(permitNulls: true)]
|
||||
private void load(OsuColour colours, OsuGame osu, OsuConfigManager config)
|
||||
private void load(OsuColour colours, Bindable<RulesetInfo> parentRuleset, OsuConfigManager config)
|
||||
{
|
||||
sortTabs.AccentColour = colours.GreenLight;
|
||||
|
||||
showConverted = config.GetBindable<bool>(OsuSetting.ShowConvertedBeatmaps);
|
||||
showConverted.ValueChanged += val => updateCriteria();
|
||||
|
||||
if (osu != null)
|
||||
ruleset.BindTo(osu.Ruleset);
|
||||
if (parentRuleset != null)
|
||||
ruleset.BindTo(parentRuleset);
|
||||
ruleset.ValueChanged += val => updateCriteria();
|
||||
ruleset.TriggerChange();
|
||||
}
|
||||
|
@ -174,7 +174,6 @@ namespace osu.Game.Screens.Select.Leaderboards
|
||||
|
||||
private APIAccess api;
|
||||
private BeatmapInfo beatmap;
|
||||
private OsuGame osuGame;
|
||||
|
||||
private ScheduledDelegate pendingBeatmapSwitch;
|
||||
|
||||
@ -195,15 +194,14 @@ namespace osu.Game.Screens.Select.Leaderboards
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(permitNulls: true)]
|
||||
private void load(APIAccess api, OsuGame osuGame)
|
||||
private void load(APIAccess api, Bindable<RulesetInfo> parentRuleset)
|
||||
{
|
||||
this.api = api;
|
||||
this.osuGame = osuGame;
|
||||
|
||||
if (osuGame != null)
|
||||
ruleset.BindTo(osuGame.Ruleset);
|
||||
if (parentRuleset != null)
|
||||
ruleset.BindTo(parentRuleset);
|
||||
|
||||
ruleset.ValueChanged += r => updateScores();
|
||||
ruleset.ValueChanged += _ => updateScores();
|
||||
|
||||
if (api != null)
|
||||
api.OnStateChange += handleApiStateChange;
|
||||
|
@ -8,6 +8,7 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input;
|
||||
@ -17,6 +18,7 @@ using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.Backgrounds;
|
||||
using osu.Game.Screens.Edit;
|
||||
using osu.Game.Screens.Menu;
|
||||
@ -62,6 +64,8 @@ namespace osu.Game.Screens.Select
|
||||
private SampleChannel sampleChangeDifficulty;
|
||||
private SampleChannel sampleChangeBeatmap;
|
||||
|
||||
protected new readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
|
||||
|
||||
private DependencyContainer dependencies;
|
||||
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
|
||||
=> dependencies = new DependencyContainer(base.CreateLocalDependencies(parent));
|
||||
@ -176,8 +180,9 @@ namespace osu.Game.Screens.Select
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(BeatmapManager beatmaps, AudioManager audio, DialogOverlay dialog, OsuGame osu, OsuColour colours)
|
||||
private void load(BeatmapManager beatmaps, AudioManager audio, DialogOverlay dialog, OsuColour colours)
|
||||
{
|
||||
dependencies.CacheAs(this);
|
||||
|
||||
@ -192,9 +197,6 @@ namespace osu.Game.Screens.Select
|
||||
if (this.beatmaps == null)
|
||||
this.beatmaps = beatmaps;
|
||||
|
||||
if (osu != null)
|
||||
Ruleset.BindTo(osu.Ruleset);
|
||||
|
||||
this.beatmaps.ItemAdded += onBeatmapSetAdded;
|
||||
this.beatmaps.ItemRemoved += onBeatmapSetRemoved;
|
||||
this.beatmaps.BeatmapHidden += onBeatmapHidden;
|
||||
@ -280,6 +282,7 @@ namespace osu.Game.Screens.Select
|
||||
bool preview = beatmap?.BeatmapSetInfoID != Beatmap.Value?.BeatmapInfo.BeatmapSetInfoID;
|
||||
|
||||
Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmap, Beatmap.Value);
|
||||
Ruleset.Value = base.Ruleset.Value;
|
||||
ensurePlayingSelected(preview);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user