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

add OverlayActivation enum

+ fix Toolbar being toggleable when it shouldn't be able to
+ allow opening overlays in MenuState.Initial again
This commit is contained in:
Aergwyn 2018-05-28 13:43:47 +02:00
parent 1572635fc8
commit 2b3a630270
9 changed files with 89 additions and 44 deletions

View File

@ -8,6 +8,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Input; using osu.Framework.Input;
using OpenTK; using OpenTK;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Game.Overlays;
namespace osu.Game.Graphics.Containers namespace osu.Game.Graphics.Containers
{ {
@ -16,13 +17,16 @@ namespace osu.Game.Graphics.Containers
private SampleChannel samplePopIn; private SampleChannel samplePopIn;
private SampleChannel samplePopOut; private SampleChannel samplePopOut;
private readonly BindableBool allowOpeningOverlays = new BindableBool(true); /// <summary>
/// Defaults to <see cref="OverlayActivation.All"/> so that the overlay works even if BDL couldn't pass an <see cref="OsuGame"/>.
/// </summary>
private readonly Bindable<OverlayActivation> allowOverlays = new Bindable<OverlayActivation>(OverlayActivation.All);
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(OsuGame osuGame, AudioManager audio) private void load(OsuGame osuGame, AudioManager audio)
{ {
if (osuGame != null) if (osuGame != null)
allowOpeningOverlays.BindTo(osuGame.AllowOpeningOverlays); allowOverlays.BindTo(osuGame.AllowOverlays);
samplePopIn = audio.Sample.Get(@"UI/overlay-pop-in"); samplePopIn = audio.Sample.Get(@"UI/overlay-pop-in");
samplePopOut = audio.Sample.Get(@"UI/overlay-pop-out"); samplePopOut = audio.Sample.Get(@"UI/overlay-pop-out");
@ -52,7 +56,7 @@ namespace osu.Game.Graphics.Containers
private void onStateChanged(Visibility visibility) private void onStateChanged(Visibility visibility)
{ {
if (allowOpeningOverlays) if (allowOverlays == OverlayActivation.All)
{ {
switch (visibility) switch (visibility)
{ {

View File

@ -77,8 +77,7 @@ namespace osu.Game
public float ToolbarOffset => Toolbar.Position.Y + Toolbar.DrawHeight; public float ToolbarOffset => Toolbar.Position.Y + Toolbar.DrawHeight;
public readonly BindableBool HideOverlaysOnEnter = new BindableBool(); public readonly Bindable<OverlayActivation> AllowOverlays = new Bindable<OverlayActivation>();
public readonly BindableBool AllowOpeningOverlays = new BindableBool(true);
private OsuScreen screenStack; private OsuScreen screenStack;
@ -368,20 +367,13 @@ namespace osu.Game
settings.StateChanged += _ => updateScreenOffset(); settings.StateChanged += _ => updateScreenOffset();
notifications.StateChanged += _ => updateScreenOffset(); notifications.StateChanged += _ => updateScreenOffset();
notifications.Enabled.BindTo(AllowOpeningOverlays); AllowOverlays.ValueChanged += state => notifications.Enabled.Value = state == OverlayActivation.All;
}
HideOverlaysOnEnter.ValueChanged += hide => public void CloseAllOverlays()
{
//central game screen change logic.
if (hide)
{ {
hideAllOverlays(); hideAllOverlays();
musicController.State = Visibility.Hidden; musicController.State = Visibility.Hidden;
Toolbar.State = Visibility.Hidden;
}
else
Toolbar.State = Visibility.Visible;
};
} }
private void forwardLoggedErrorsToNotifications() private void forwardLoggedErrorsToNotifications()

View File

@ -0,0 +1,12 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Overlays
{
public enum OverlayActivation
{
Disabled,
//UserTriggered, // currently there is no way to discern user action
All
}
}

View File

@ -10,6 +10,8 @@ using osu.Framework.Input;
using osu.Game.Graphics; using osu.Game.Graphics;
using OpenTK; using OpenTK;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
namespace osu.Game.Overlays.Toolbar namespace osu.Game.Overlays.Toolbar
{ {
@ -29,6 +31,11 @@ namespace osu.Game.Overlays.Toolbar
private const float alpha_hovering = 0.8f; private const float alpha_hovering = 0.8f;
private const float alpha_normal = 0.6f; private const float alpha_normal = 0.6f;
/// <summary>
/// Defaults to <see cref="OverlayActivation.All"/> so that the overlay works even if BDL couldn't pass an <see cref="OsuGame"/>.
/// </summary>
private readonly Bindable<OverlayActivation> allowOverlays = new Bindable<OverlayActivation>(OverlayActivation.All);
public Toolbar() public Toolbar()
{ {
Children = new Drawable[] Children = new Drawable[]
@ -76,6 +83,19 @@ namespace osu.Game.Overlays.Toolbar
Size = new Vector2(1, HEIGHT); Size = new Vector2(1, HEIGHT);
} }
[BackgroundDependencyLoader(true)]
private void load(OsuGame osuGame)
{
if (osuGame != null)
allowOverlays.BindTo(osuGame.AllowOverlays);
StateChanged += visibility =>
{
if (allowOverlays == OverlayActivation.Disabled)
State = Visibility.Hidden;
};
}
public class ToolbarBackground : Container public class ToolbarBackground : Container
{ {
private readonly Box solidBackground; private readonly Box solidBackground;

View File

@ -20,6 +20,7 @@ using osu.Game.Input.Bindings;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using OpenTK.Input; using OpenTK.Input;
using osu.Game.Overlays;
namespace osu.Game.Screens.Menu namespace osu.Game.Screens.Menu
{ {
@ -27,8 +28,7 @@ namespace osu.Game.Screens.Menu
{ {
public event Action<MenuState> StateChanged; public event Action<MenuState> StateChanged;
private readonly BindableBool hideOverlaysOnEnter = new BindableBool(); private readonly Bindable<OverlayActivation> allowOverlays = new Bindable<OverlayActivation>();
private readonly BindableBool allowOpeningOverlays = new BindableBool();
public Action OnEdit; public Action OnEdit;
public Action OnExit; public Action OnExit;
@ -137,10 +137,7 @@ namespace osu.Game.Screens.Menu
private void load(AudioManager audio, OsuGame game) private void load(AudioManager audio, OsuGame game)
{ {
if (game != null) if (game != null)
{ allowOverlays.BindTo(game.AllowOverlays);
hideOverlaysOnEnter.BindTo(game.HideOverlaysOnEnter);
allowOpeningOverlays.BindTo(game.AllowOpeningOverlays);
}
sampleBack = audio.Sample.Get(@"Menu/button-back-select"); sampleBack = audio.Sample.Get(@"Menu/button-back-select");
} }
@ -332,19 +329,19 @@ namespace osu.Game.Screens.Menu
case MenuState.Exit: case MenuState.Exit:
case MenuState.Initial: case MenuState.Initial:
logoTracking = false; logoTracking = false;
allowOverlays.Value = OverlayActivation.Disabled;
logoDelayedAction = Scheduler.AddDelayed(() => logoDelayedAction = Scheduler.AddDelayed(() =>
{ {
hideOverlaysOnEnter.Value = true;
allowOpeningOverlays.Value = false;
logo.ClearTransforms(targetMember: nameof(Position)); logo.ClearTransforms(targetMember: nameof(Position));
logo.RelativePositionAxes = Axes.Both; logo.RelativePositionAxes = Axes.Both;
logo.MoveTo(new Vector2(0.5f), 800, Easing.OutExpo); logo.MoveTo(new Vector2(0.5f), 800, Easing.OutExpo);
logo.ScaleTo(1, 800, Easing.OutExpo); logo.ScaleTo(1, 800, Easing.OutExpo);
}, 150);
if(state != MenuState.Exit)
allowOverlays.Value = OverlayActivation.All;
}, 150);
break; break;
case MenuState.TopLevel: case MenuState.TopLevel:
case MenuState.Play: case MenuState.Play:
@ -365,9 +362,6 @@ namespace osu.Game.Screens.Menu
logoTracking = true; logoTracking = true;
logo.Impact(); logo.Impact();
hideOverlaysOnEnter.Value = false;
allowOpeningOverlays.Value = true;
}, 200); }, 200);
break; break;
default: default:

View File

@ -9,6 +9,7 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Game.Overlays;
namespace osu.Game.Screens.Menu namespace osu.Game.Screens.Menu
{ {
@ -19,7 +20,6 @@ namespace osu.Game.Screens.Menu
private Color4 iconColour; private Color4 iconColour;
protected override bool HideOverlaysOnEnter => true; protected override bool HideOverlaysOnEnter => true;
protected override bool AllowOpeningOverlays => false;
public override bool CursorVisible => false; public override bool CursorVisible => false;
@ -93,6 +93,8 @@ namespace osu.Game.Screens.Menu
LoadComponentAsync(intro = new Intro()); LoadComponentAsync(intro = new Intro());
iconColour = colours.Yellow; iconColour = colours.Yellow;
AllowOverlays.Value = OverlayActivation.Disabled;
} }
protected override void OnEntering(Screen last) protected override void OnEntering(Screen last)

View File

@ -15,6 +15,7 @@ using osu.Game.IO.Archives;
using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Backgrounds;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Game.Overlays;
namespace osu.Game.Screens.Menu namespace osu.Game.Screens.Menu
{ {
@ -32,7 +33,6 @@ namespace osu.Game.Screens.Menu
private SampleChannel seeya; private SampleChannel seeya;
protected override bool HideOverlaysOnEnter => true; protected override bool HideOverlaysOnEnter => true;
protected override bool AllowOpeningOverlays => false;
public override bool CursorVisible => false; public override bool CursorVisible => false;
@ -77,6 +77,8 @@ namespace osu.Game.Screens.Menu
welcome = audio.Sample.Get(@"welcome"); welcome = audio.Sample.Get(@"welcome");
seeya = audio.Sample.Get(@"seeya"); seeya = audio.Sample.Get(@"seeya");
AllowOverlays.Value = OverlayActivation.Disabled;
} }
protected override void OnEntering(Screen last) protected override void OnEntering(Screen last)

View File

@ -10,6 +10,7 @@ using osu.Framework.Input;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Overlays;
using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Charts; using osu.Game.Screens.Charts;
using osu.Game.Screens.Direct; using osu.Game.Screens.Direct;
@ -25,7 +26,6 @@ namespace osu.Game.Screens.Menu
private readonly ButtonSystem buttons; private readonly ButtonSystem buttons;
protected override bool HideOverlaysOnEnter => buttons.State == MenuState.Initial; protected override bool HideOverlaysOnEnter => buttons.State == MenuState.Initial;
protected override bool AllowOpeningOverlays => buttons.State != MenuState.Initial;
protected override bool AllowBackButton => buttons.State != MenuState.Initial; protected override bool AllowBackButton => buttons.State != MenuState.Initial;
@ -64,6 +64,8 @@ namespace osu.Game.Screens.Menu
}, },
sideFlashes = new MenuSideFlashes(), sideFlashes = new MenuSideFlashes(),
}; };
buttons.StateChanged += state => UpdateOverlayStates?.Invoke();
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
@ -78,6 +80,8 @@ namespace osu.Game.Screens.Menu
} }
preloadSongSelect(); preloadSongSelect();
AllowOverlays.Value = OverlayActivation.Disabled;
} }
private void preloadSongSelect() private void preloadSongSelect()

View File

@ -18,6 +18,8 @@ using osu.Game.Rulesets;
using osu.Game.Screens.Menu; using osu.Game.Screens.Menu;
using OpenTK; using OpenTK;
using OpenTK.Input; using OpenTK.Input;
using osu.Game.Overlays;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Screens namespace osu.Game.Screens
{ {
@ -40,19 +42,23 @@ namespace osu.Game.Screens
/// </summary> /// </summary>
protected virtual BackgroundScreen CreateBackground() => null; protected virtual BackgroundScreen CreateBackground() => null;
private readonly BindableBool hideOverlaysOnEnter = new BindableBool(); private Action updateOverlayStates;
/// <summary> /// <summary>
/// Whether overlays should be hidden when this screen is entered or resumed. /// Allows manually updating visibility of all overlays if <see cref="HideOverlaysOnEnter"/> is not enough.
/// </summary>
protected Action UpdateOverlayStates => updateOverlayStates;
/// <summary>
/// Whether all overlays should be hidden when this screen is entered or resumed.
/// </summary> /// </summary>
protected virtual bool HideOverlaysOnEnter => false; protected virtual bool HideOverlaysOnEnter => false;
private readonly BindableBool allowOpeningOverlays = new BindableBool();
/// <summary> /// <summary>
/// Whether overlays should be able to be opened while this screen is active. /// Whether overlays should be able to be opened.
/// It's bound at load which means changes at construction will potentially disappear.
/// </summary> /// </summary>
protected virtual bool AllowOpeningOverlays => true; protected readonly Bindable<OverlayActivation> AllowOverlays = new Bindable<OverlayActivation>();
/// <summary> /// <summary>
/// Whether this <see cref="OsuScreen"/> allows the cursor to be displayed. /// Whether this <see cref="OsuScreen"/> allows the cursor to be displayed.
@ -103,8 +109,18 @@ namespace osu.Game.Screens
if (osuGame != null) if (osuGame != null)
{ {
Ruleset.BindTo(osuGame.Ruleset); Ruleset.BindTo(osuGame.Ruleset);
hideOverlaysOnEnter.BindTo(osuGame.HideOverlaysOnEnter); AllowOverlays.BindTo(osuGame.AllowOverlays);
allowOpeningOverlays.BindTo(osuGame.AllowOpeningOverlays);
updateOverlayStates = () =>
{
if (HideOverlaysOnEnter)
{
osuGame.CloseAllOverlays();
osuGame.Toolbar.State = Visibility.Hidden;
}
else
osuGame.Toolbar.State = Visibility.Visible;
};
} }
sampleExit = audio.Sample.Get(@"UI/screen-back"); sampleExit = audio.Sample.Get(@"UI/screen-back");
@ -236,8 +252,7 @@ namespace osu.Game.Screens
if (backgroundParallaxContainer != null) if (backgroundParallaxContainer != null)
backgroundParallaxContainer.ParallaxAmount = ParallaxContainer.DEFAULT_PARALLAX_AMOUNT * BackgroundParallaxAmount; backgroundParallaxContainer.ParallaxAmount = ParallaxContainer.DEFAULT_PARALLAX_AMOUNT * BackgroundParallaxAmount;
hideOverlaysOnEnter.Value = HideOverlaysOnEnter; updateOverlayStates?.Invoke();
allowOpeningOverlays.Value = AllowOpeningOverlays;
} }
private void onExitingLogo() private void onExitingLogo()