Allow OsuScreens to decide whether ruleset switching should be allowed.

Tidies up ToolbarModeSelector a lot by using DI.
This commit is contained in:
Dean Herbert 2017-04-21 16:03:59 +09:00
parent 4a3ae6937d
commit 5aa90df819
No known key found for this signature in database
GPG Key ID: 46D71BF4958ABB49
7 changed files with 41 additions and 28 deletions

View File

@ -203,13 +203,7 @@ namespace osu.Game
{
Depth = -3,
OnHome = delegate { intro?.ChildScreen?.MakeCurrent(); },
OnRulesetChange = r => Ruleset.Value = r,
}, t =>
{
Ruleset.ValueChanged += delegate { Toolbar.SetRuleset(Ruleset.Value); };
Ruleset.TriggerChange();
overlayContent.Add(Toolbar);
});
}, overlayContent.Add);
options.StateChanged += delegate
{

View File

@ -8,7 +8,6 @@ using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input;
using osu.Game.Database;
using osu.Game.Graphics;
using OpenTK;
@ -20,7 +19,6 @@ namespace osu.Game.Overlays.Toolbar
public const float TOOLTIP_HEIGHT = 30;
public Action OnHome;
public Action<RulesetInfo> OnRulesetChange;
private readonly ToolbarModeSelector modeSelector;
private readonly ToolbarUserArea userArea;
@ -53,13 +51,7 @@ namespace osu.Game.Overlays.Toolbar
{
Action = () => OnHome?.Invoke()
},
modeSelector = new ToolbarModeSelector
{
OnRulesetChange = mode =>
{
OnRulesetChange?.Invoke(mode);
}
}
modeSelector = new ToolbarModeSelector()
}
},
new FillFlowContainer
@ -130,8 +122,6 @@ namespace osu.Game.Overlays.Toolbar
}
}
public void SetRuleset(RulesetInfo ruleset) => modeSelector.SetRuleset(ruleset);
protected override void PopIn()
{
MoveToY(0, transition_time, EasingTypes.OutQuint);

View File

@ -1,7 +1,6 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Caching;
@ -12,6 +11,7 @@ using osu.Framework.Graphics.Sprites;
using osu.Game.Database;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Configuration;
namespace osu.Game.Overlays.Toolbar
{
@ -23,7 +23,7 @@ namespace osu.Game.Overlays.Toolbar
private readonly Drawable modeButtonLine;
private ToolbarModeButton activeButton;
public Action<RulesetInfo> OnRulesetChange;
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
public ToolbarModeSelector()
{
@ -66,30 +66,36 @@ namespace osu.Game.Overlays.Toolbar
}
[BackgroundDependencyLoader]
private void load(RulesetDatabase rulesets)
private void load(RulesetDatabase rulesets, OsuGame game)
{
foreach (var ruleset in rulesets.AllRulesets)
foreach (var r in rulesets.AllRulesets)
{
modeButtons.Add(new ToolbarModeButton
{
Ruleset = ruleset,
Ruleset = r,
Action = delegate
{
SetRuleset(ruleset);
OnRulesetChange?.Invoke(ruleset);
ruleset.Value = r;
}
});
}
ruleset.ValueChanged += rulesetChanged;
ruleset.DisabledChanged += disabledChanged;
ruleset.BindTo(game.Ruleset);
}
public override bool HandleInput => !ruleset.Disabled;
private void disabledChanged(bool isDisabled) => FadeColour(isDisabled ? Color4.Gray : Color4.White, 300);
protected override void Update()
{
base.Update();
Size = new Vector2(modeButtons.DrawSize.X, 1);
}
public void SetRuleset(RulesetInfo ruleset)
private void rulesetChanged(RulesetInfo ruleset)
{
foreach (ToolbarModeButton m in modeButtons.Children.Cast<ToolbarModeButton>())
{

View File

@ -5,6 +5,7 @@ using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Graphics.Containers;
namespace osu.Game.Screens
@ -25,8 +26,12 @@ namespace osu.Game.Screens
internal virtual bool HasLocalCursorDisplayed => false;
internal virtual bool AllowRulesetChange => true;
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
public WorkingBeatmap Beatmap
{
get
@ -40,7 +45,7 @@ namespace osu.Game.Screens
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuGameBase game)
private void load(OsuGameBase game, OsuGame osuGame)
{
if (game != null)
{
@ -52,11 +57,23 @@ namespace osu.Game.Screens
}
beatmap.ValueChanged += OnBeatmapChanged;
if (osuGame != null)
ruleset.BindTo(osuGame.Ruleset);
}
/// <summary>
/// The global Beatmap was changed.
/// </summary>
protected virtual void OnBeatmapChanged(WorkingBeatmap beatmap)
{
}
protected override void Update()
{
if (!IsCurrentScreen) return;
ruleset.Disabled = !AllowRulesetChange;
}
protected override void OnEntering(Screen last)

View File

@ -39,6 +39,8 @@ namespace osu.Game.Screens.Play
public bool IsPaused => !interpolatedSourceClock.IsRunning;
internal override bool AllowRulesetChange => false;
public bool HasFailed { get; private set; }
public int RestartCount;

View File

@ -27,6 +27,8 @@ namespace osu.Game.Screens.Play
private bool showOverlays = true;
internal override bool ShowOverlays => showOverlays;
internal override bool AllowRulesetChange => false;
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap);
public PlayerLoader(Player player)

View File

@ -31,6 +31,8 @@ namespace osu.Game.Screens.Ranking
private ResultModeTabControl modeChangeButtons;
internal override bool AllowRulesetChange => false;
private Container currentPage;
private static readonly Vector2 background_blur = new Vector2(20);